How to resize/move an encrypted partition
Sorry for the weird style here
Tested with Kubuntu, Home and Root encrypted with Luks/Luks2 on the partitioning system that only allows a small number of partitions.
Shrink
I will do this example with sda here. (sdaX is for example sda3, X = the number of the partition you want to resize)
IF YOU GOT ANY PROBLEM HERE, IMMEDIATELY STOP AND DO NOT TRY ANYTHING TO REPAIR IT IF YOU ARE NOT 110% SURE IT WORKS.
You can write filex.stuff@proton.me to get some help.
First, set up a live disk of a linux OS (for example Lubuntu)
Boot it up in try mode
And follow the following commands while keeping my warning above in mind:
sudo -s
cryptsetup luksOpen /dev/sdaX crypt
umount /dev/sdaX
e2fsck -f /dev/mapper/crypt
resize2fs /dev/mapper/crypt SIZE (you can use S = Sectors, K = KB, M = MB, G = GB here)
cryptsetup luksClose crypt
fdisk /dev/sda
p (make sure to note down the start point)
d
No: X (the X of sdaX)
n
Type: p
New No: X (same as before)
First sector: (EXACTLY the same as the noted down value)
Last sector: (Shrink size or whatever here, hast to be bigger or equal the value before at resize2fs)
Remove Sig.: N
w
cryptsetup luksOpen /dev/sdaX crypt
(next step is only needed if you set a bigger value at last sector than at resize2fs)
resize2fs /dev/mapper/crypt
e2fsck -f /dev/mapper/crypt
I take no guarantee that it works, but I do hope it works.
Expand
Follow the steps above while setting a bigger size for the partition and inverting steps that are needed to be inverted.
Move
You can do this while the partition is locked with your favorite tool.
You can lock your partition with
cryptsetup luksClose (the name you have given it when opening)