Transfer system to a new computer

Volker Wysk post at volker-wysk.de
Sun Jan 12 18:34:52 UTC 2020


Hi!

I'm about to buy a new computer, including a new SSD. At the beginning,
I'll habe both SSDs (old and new) in the new machine, and I want to
move the system on the old one to the new one. 

The old system has been set up by the ubuntu installer with an
encrypted root file system. This means that LVM is being used. I want
to take this occasion to get rid of LVM. This means, the new system on
the new SSD should have one encrypted partition for the root file
system, one unencrypted one for /boot and no partition for swap. I'll
use a swap file instead.

I have outlined the procedure of this transition. I'd be grateful if
someone could have a look at it:

1. Boot from maintenance USB stick. 

2. Use gdisk to partition the new SSD, which I assume is at /dev/sda.
Make a /boot partition at /dev/sda1 (2 GB). Dedicate most of the rest
to the new root partition, which is to be encrypted. It will reside at
/dev/sda5. gdisk makes an GPT partition table.

3. LUKS-format the new root partition and unlock it. Make a new ext4
file system on it and mount it at /mnt/newroot.

cryptsetup luksFormat /dev/sda5
cryptsetup open /dev/sda5 sda5_crypt
mkfs.ext4 /dev/mapper/sda5_crypt
mount /dev/mapper/sda5_crypt /mnt/newroot

4. Unlock the old root partition and mount it at /mnt/oldroot. I assume
the old SSD is at /dev/sdc.

cryptsetup open /dev/sdc5 sdc5_crypt
sleep 1
vgchange -a y
mount /dev/ubuntu-vg/root /mnt/oldroot

5. Copy the system over

cp -a /mnt/oldsystem/* /mnt/newsystem

Here, I'm not sure about dev, proc and sys. They should be empty in the
old root, shouldn't they?

6. Update /mnt/newroot/etc/crypttab. The new line for the encrypted
root is:

sda5_crypt /dev/sda5 none luks,discard

7. Update /mnt/newroot/etc/fstab. The new lines for root and /boot
should be:

/dev/mapper/sda5_crypt / ext4 errors=remount-ro 0 1
/dev/sda1 /boot ext4 defaults 0 2

8. Make the new root partition bootable.

mount --rbind /dev /mnt/newroot/dev
mount --rbind /proc /mnt/newroot/proc
mount --rbind /sys /mnt/newroot/sys
mount /dev/sda1 /mnt/newroot/boot
chroot /mnt/newroot
update-initramfs -u
grub-install /dev/sda
update-grub

9. Reboot.


What I'm not so sure about, is UEFI and Secure Boot...

Cheers,
Volker







More information about the ubuntu-users mailing list