Okay, here is what I did to relocate 3 uefi systems recently, which were on single luks partitions. I use swap files not swap partitions.
Use gparted to create your new partition of the correct size. Lets assume new root partition is /dev/sdb1
going forward.
Luks encrypt your partition.
sudo cryptsetup -y -v --type luks1 luksFormat /dev/sdb1
NOTE :
Until recently grub didn’t support containers of type luks2, so I used to create luks1 containers for my root partitions. I think this has changed now and grub now supports luks2. You can remove
--type luks1
if you wish.
Open luks container, create filesystem, which in my case is ext4.
sudo cryptsetup open /dev/sdb1 luksroot
mkfs.ext4 /dev/mapper/luksroot
Mount the new file system.
sudo mount /dev/mapper/luksroot /mnt
When using rsync to copy an entire system exclude these directories. Create file rs-exclude.txt
containing.
/dev
/tmp
/sys
/proc
Use rsync to copy the contents of / to /mnt.
sudo rsync -av --exclude-from=rs-exclude.txt / /mnt
The rsync -a flag (ie archive) will preserve file permissions and attributes.
To make this new system chroot-able.
sudo mkdir /mnt/dev
sudo mkdir /mnt/proc
sudo mkdir /mnt/sys
sudo mkdir /mnt/tmp
Get the UUIDs for your new luks partition and file system.
lsblk -f
Edit /mnt/etc/crypttab and replace any old UUIDs with new UUIDs.
Edit /mnt/etc/fstab and replace any old UUIDs with new UUIDs.
Edit /mnt/default/grub and replace old UUIDs with new UUIDs.
Double check these, if they are incorrect your system won’t boot.
Now chroot into your new system.
sudo arch-chroot /mnt
Mount your efi partition from within chroot shell.
sudo mount /dev/sdXX /boot/efi
Re-install grub on new system from within chroot.
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=EndeavourOS --recheck
Check your efi boot order.
efibootmgr
Re-order if necessary as EndeavourOS will now be first in boot order.
efibootmgr -o [XXXX,YYYY,ZZZZ]
You should also be able to do this from BIOS, but I don’t know your machine.
Regenerate initramfs images and update grub within chroot.
sudo mkinitcpio -P
sudo update-grub
Reboot.
Practice this in a VM first, multiple times, make any mistakes there.
I cannot stress this enough.
This is what I did before attemping this process on my actual system, which subsequently went smoothly as I followed a process I knew worked.
This process is also useful for cloning systems, migrating systems onto a different file system (ie ext4 → btrfs) without re-installing, moving systems onto different drives without re-installing, failsafe luks root paritition resizing … etc.