4

Essentially, I'm following this answer to clone the unencrypted content of a system with full-disc encryption to a new (smaller) SSD, from a live stick. I thought that would just consist of mapping the encrypted partitions, and then the usual dd, but no...

These are the partitions/devices involved:

/dev/sda: Old disc, with encrypted partition
/dev/sda1: FAT32 with boot flag
/dev/sda2: EXT2, containing some EFI and grub stuff
/dev/sda3: LUKS partition I want to clone (about 460 GiB);
           contains a swap and an ecrypted EXT4 with about 20 GiB used
/dev/sdc: New SSD

For a start, I simply copied /dev/sda1 and /dev/sda2 to /dev/sdc{1,2} using gparted, which seemed to work (both mountable). Then, I created a fresh EXT4 partition suffiently large to hold the contents of the encrypted EXT4 on /dev/sdc3, and a new swap on the remaining space on /dev/sdc4.

I then decrypted /dev/sda3 with

sudo cryptsetup luksOpen /dev/sda3 crypt1

and copied over its contents, using

sudo dd if=/dev/mapper/ubuntu--vg-root of=/dev/sdc3

(where /dev/mapper/ubuntu--vg-root contains the original root partition and can correctly be mounted). This finishes after the 19 GiB or so that are actually in use on the encrypted partition.

From that point one, something seems to have failed; I can't mount /dev/sdc3 afterwards, as it seems to be broken.

ubuntu@ubuntu:~$ sudo mount /dev/sdc3 /mnt
mount: wrong fs type, bad option, bad superblock on /dev/sdc3,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

ubuntu@ubuntu:~$ sudo fsck /dev/sdc3
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
Error reading block 60325888 (Invalid argument). Ignore error<y>? yes
Force rewrite<y>? yes
Superblock has an invalid journal (inode 8).
Clear<y>? yes
*** ext3 journal has been deleted - filesystem is now ext2 only ***

Superblock has_journal flag is clear, but a journal inode is present.
Clear<y>? yes
The filesystem size (according to the superblock) is 120880128 blocks
The physical size of the device is 14848000 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? yes
Error writing block 60325888 (Invalid argument). Ignore error<y>? yes

/dev/sdc3: ***** FILE SYSTEM WAS MODIFIED *****

And this is what the suggested dmesg | tail produced:

[ 51.575179] EXT4-fs (sdc2): mounting ext2 file system using the ext4 subsystem
[ 51.580102] EXT4-fs (sdc3): bad geometry: block count 120880128 exceeds size of device (14848000 blocks)
[ 51.582477] EXT4-fs (sdc2): warning: mounting unchecked fs, running e2fsck is recommended
[ 51.587740] EXT4-fs (sdc2): mounted filesystem without journal. Opts: (null)
[ 51.633994] FAT-fs (sdc1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[ 107.969122] EXT4-fs (sdc3): bad geometry: block count 120880128 exceeds size of device (14848000 blocks)

I actually don't know that much about partitioning, but I suppose it doesn't like just plainly copying the unencrypted content -- maybe that's incompatible with the old partition table? There seems to be involved something with a wrong size. Maybe I need to resize the encrypted stuff first?

So, can I somehow fix this? Or, what should I do alternatively to achieve the same thing -- essentially cloning the encrypted EXT4 root onto the SSD and get a bootable, unencrypted copy of the old system? (If resizing and then cloning the whole of /dev/sda with encryption turns out to be significantly easier, I could do that too; my original assumption was that cloning it unencryptedly will get me around the whole encrypted-resizing-hassle...)

1 Answers1

2

It turns out the whole thing is easier than I thought. Motivated by @Xen2050's comments, I was able to essentially just rsync the whole system onto a fresh install:

  1. Boot with a live stick
  2. Install a fresh Ubuntu onto the new disc (using a separate efi boot partition)
  3. Mount the new Ubuntu's root partition to /mnt/new-root
  4. Decrypt the old system via cryptsetup luksOpen /dev/sdXY crypt1
  5. Mount the old root partition by mount /dev/mapper/ubuntu--vg-root /mnt/old-root
  6. Copy everything: rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt/old-root /mnt/new-root
  7. Edit the fstab in /mnt/new-root/etc/fstab to contain the UUIDs of the partitions on the new disc (can be obtained via gparted)

And surprisingly, that's all. Restart, and you can boot from the new disc, with everything the same as before (just without encryption and faster).