2011. november 13., vasárnap

Moving LVM/LUKS partitions into a new hard drive

I received a new hard drive with bigger capacity and I wanted to move my old Ubuntu installation to the new drive. I connected both disks to a computer and boot from a LiveCD. I tried to use a simple dd command to copy the whole disk:

dd if=/dev/sda of=/dev/sdb

...but it failed to copy the encrypted (LVM/LUKS) partitions. I could unlock the partitions, but the new copy of the encrypted ext4 file system was half-destroyed during the copy process. I changed strategy since the new drive is bigger than the old one, I booted from the LiveCD and installed a new encrypted system with the maximal available space. I booted with the LiveCD again, mounted both disks, deleted the content of the new system and copied the old content to the new, unlocked partitions. I changed the grub/fstab and other config files to use the new UUIDs of the partitions, but the new hard drive did not boot. After updating the grub+initramfs, a strange thing happened. The system did not ask for passphrase to unlock the LVM, but I was dropped to the initramfs debug shell. I could unlock the encrypted partition and leave the debug shell, but the system wanted to ask for the passphrase after that. I found the solution on this Mint Linux forum topic: http://forums.linuxmint.com/viewtopic.php?f=189&t=83763

The solution was pretty easy: Delete the /etc/crypttab and create a new file /etc/initramfs-tools/conf.d/cryptroot with the following content:

CRYPTOPTS=target=sda5_crypt,source=/dev/sda5,lvm=LogicalVolumesOnEncryptedPartition-Root


It rocks now.

Nincsenek megjegyzések: