2

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...)

  • For copying the problem files, once they're decrypted so you can read them, I wouldn't use dd, I'd use rsync or just copy / cp them to a new ext3/4 partition. May not matter, but your cryptsetup step decrypts to /dev/mapper/crypt1 but you dd'd from a different place, some steps missing there – Xen2050 Feb 12 '16 at 11:57
  • @Xen2050 It's not the files I want to recreate, but the whole file system (aka the full partition). At least in my understanding I won't be able to just cp /mnt/decrypted-root /mnt/new-root-partition and expect to end up with a bootable system... And cryptsetup is mapping three things in /dev/mapper: crypt1, which is probably the whole encrypted extended partition, and the two contained logical partitions mapped as ubuntu--vg-root and ubuntu--vg-swap_1. And ubuntu--vg-root does contain my old stuff. – phg Feb 12 '16 at 16:16
  • If you're thinking it may throw up if some files are in different on-disk positions, it shouldn't, not like windows would (or used to). Only changes may be need to update UUID's for root, home, temp, etc. lvm's aren't my "thing" but it sounds like some required info didn't get copied, like a mbr or gpt on a regular drive, but I've no idea what or how. A better idea may be the accepted answer of your quoted Q- to backup any important files (home, config files, etc) and do a fresh install, then restore your home & files. Have the opportunity to upgrade to a newer version too – Xen2050 Feb 13 '16 at 7:57
  • Hm, seems I was wrong -- or at least overcomplicating things. Thanks for the hints! – phg Feb 16 '16 at 15:26
1

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).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.