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...)
dd
, I'd usersync
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 therecp /mnt/decrypted-root /mnt/new-root-partition
and expect to end up with a bootable system... Andcryptsetup
is mapping three things in/dev/mapper
:crypt1
, which is probably the whole encrypted extended partition, and the two contained logical partitions mapped asubuntu--vg-root
andubuntu--vg-swap_1
. Andubuntu--vg-root
does contain my old stuff.