Increase Swap Size on an Encrypted Drive
1 April 2019
I recently started a new job with www.codeenigma.com and they use a very interesting dev stack.
This uses Docker and Vagrant and for this project it hosts several servers locally some of which run quite memory hungry processes.
I also use the Chrome Browser which is notorious for using memory.
I quickly found I was running out of memory and my laptop would hang.
Linux should be able to manage this better - it seems there may be a bug and I’m not quite sure what the problem is - but several posts I read suggested the problem was not enough swap space and sure enough I had only 1Gb swap (with 8GB physical RAM).
I read up on how to increase swap space - but several posts suggested it was easier to reinstall - and I didn’t find any details how to resize when using an encrypted disk.
When you can’t find a post on how to do something in Linux it usually means it’s really hard or really easy … sadly I forgot to consider the second of those reasons and tried to solve by reinstalling.
This didn’t fix it - the installer simply didn’t give an option to customise swap space on an encrypted drive.
Eventually I realised that the encrypted drive uses LVM and resizing was fairly easy.
I booted off a USB stick - I’m not sure if this was needed.
I then ran the following
|
|
I rebooted and all was fine except my swap wasn’t any bigger
I had forgotten to increase the swap partition to fill the bigger volume
This just required turning swap off, running mkswap on the whole device and turning it back on.
|
|
Now hopefully when I run out of RAM my system may slow down but will still be usable.
Last time I messed with LVM was 9 years ago and fortunately I blogged about that too - because my notes were useful to me.