Ubuntu – Encrypted drive cloning – resizing partitions problem

16.04cloningcryptsetupencryption

I'm trying to clone my SSD to a larger device so I will have a bootable backup in anticipation of doing a system upgrade on several desktop clients. I also want to model a known-correct procedure to see if I can reliably clone my system drives to a larger HDD/SSD (so far all attempts to do this in the past have failed). Currently running 16.04 which was built using the fully encrypted disk option. The test system being used is running fine.

I followed several procedures I found on this site but none worked. I hit a dead end with each procedure, so to simplify things, I did the following:

sudo dd if=/dev/sda of=/dev/sdd  bs=64k

Opened GParted and deleted the old crypt-luks partition on /dev/sdd as instructed in the procedure posted at Cloning Encrypted SSD to larger SSD. This was a mistake and I was dead in the water from here on. I was unable to create a new crypt-luks partition.

So an answer that explains how to [re]create/resize the crypt-luks partition on the new target drive would be very helpful.

I repeated the dd and tried expanding the target filesystem with the following commands (using a live CD):

sudo cryptsetup luksOpen /dev/sda5 sda5_crypt
sudo cryptsetup resize sda5_crypt
sudo modprobe dm-crypt
sudo vgscan --mknodes
sudo vgchange -ay
sudo pvresize /dev/mapper/sda5_crypt
sudo lvresize -l +100%FREE /dev/ubuntu-vg/root

Returns: New size (7020 extents) matches existing size (7020 extents).

sudo pvchange -x n /dev/mapper/sda5_crypt

Returns:

Physical volume "/dev/mapper/sda5_crypt" is already unallocatable.
Physical volume /dev/mapper/sda5_crypt not changed
0 physical volumes changed / 1 physical volume not changed
sudo e2fsck -f /dev/mapper/ubuntu--vg-root

Returns:

Pass 5: Checking group summary information
/dev/mapper/ubuntu--vg-root: 296641/1798720 files (0.8% non-contiguous), 3525828/7188480 blocks

The source SSD was 32GB and the HDD I am trying to expand is 80 GB.

sudo resize2fs -f /dev/mapper/ubuntu--vg-root

Returns:

resize2fs 1.44.1 (24-Mar-2018)
The filesystem is already 7188480 (4k) blocks long.  Nothing to do!

So it appears that the procedure did not expand the partitions. This is verified by rebooting and running GParted which shows the same partitioning before and after:

enter image description here

enter image description here

enter image description here

enter image description here

I've been at this for many days doing research and trying to get this to work and I'm starting to get tunnel vision. I would very much appreciate someone posting a bullet-proof procedure that is known to work in cloning encrypted HDDs/SSDs to larger storage devices.

The target dd drive will indeed boot without expanding any partitions.

My primary question is really much more about expanding encrypted file systems than it is about cloning them. Although these two tasks are obviously very closely related. A bullet-proof, scalable, reliably repeatable procedure that explains how to do both would be extremely helpful. The procedure https://help.ubuntu.com/community/ResizeEncryptedPartitions is a bit too complex for me to follow although I believe I ran the procedure correctly. It's probably very close to what I need, but may be missing a step or two.

It seems to me that simply expanding the encrypted partitions on a properly cloned device ought not require more than several commands. Ideally this is something easily done using GParted.

Best Answer

I'll need to test this on a completely clean set of circumstances but running these commands at the end of the above described procedure seems to work. I will update this solution if I hit any more snags.

sudo parted
(parted) print                                                         
(parted) resizepart
Partition number? 2
End?  [32.0GB]? 100%
(parted) print                                                
(parted) quit 
Related Question