Resize swap partition on Ubuntu 20.04 using encrypted LVM
I had the same problem with Kubuntu 20.04. (I actually suspect that my system would have been more stable with no swap at all.)
Here's some info to get you started:
- the Kubuntu installer (based on your post and linked articles, I think the Ubuntu installer is very similar) creates an encrypted LVM volume on one of the disk partitions. Within this volume there are 2 volumes -- effectively partitions. For me, the encrypted volume is
/dev/nvme0n1p3
, but the name will depend on your system. The 2 partitions are:
/dev/vgkubuntu/root
/dev/vgkubuntu/swap_1
- you cannot resize a mounted partition. In this case, once you've booted the machine, decrypted the disk and logged in, the root disk cannot be safely unmounted. Hence the need to use the live USB or another machine.
- there's no real benefit of having a swap partition over a swapfile in this case -- both will be inside the encrypted partition. A swapfile can be more convenient because you can easily resize it later while logged in normally. However, it's a bit more work to set up.
Your 2 options are:
- resize the swap partition
- make a swapfile and (optionally) reclaim the swap partition (by removing it and extending the root partition)
In either case you'll have to use a live USB or move the physical disk to another machine, because you can't resize a mounted partition and you can't see the partitions within the encrypted volume without first decrypting it.
I used the live USB that I'd just used to install Kubuntu 20.04 and I chose to resize the existing partition because I'm lazy.
- start the live USB -- put it in the machine, start it up, mash all the keys that will get you to a way to choose the boot device, etc.
- wait for Kubuntu to load -- choose Try Kubuntu
- open the terminal emulator,
sudo su
to become root - run
lsblk
to find the encrypted device name. It's probably the last and almost certainly the biggest in the list. - decrypt it:
cryptsetup open /dev/<device> <some new device name>
e.g.cryptsetup open /dev/nvme0n1p3 cr-ext
-- you will be prompted for the password. This is the same password you use to decrypt the disk during normal startup. - now you can run KDE Partition Manager. You should see
vgkubuntu
in the devices list -- click to highlight. You should see the root and swap partitions in the partition list. - Resize/Move the root partition to shrink it by however much you want to grow the swap partition. (I chose +32 GB because I'll likely have that much RAM at some point, the extra 900MB or whatever is good padding because you never know exactly how many bytes you'll end up when adding RAM, and you need swap > physical to sleep, and I'm lazy.) It wouldn't let me enter exactly the MB I wanted (current size - (32*1024)) b/c, I dunno, block sizes or something, so I put in something close and clicked the up arrow till it stopped me.
- Increase the swap partition to fill the space.
- Click Apply. Once it succeeds, you can reboot, remove the USB drive and boot normally.