How to: easily add swap partition to a live system on btrfs
14th April 2016
Recently I had a need to add a swap file to my Debian installation.
However, I am now using btrfs, and – as with any other COW filesystem – it is not possible to simply create a swap file and use it.
There are workarounds (creating a file with a COW attribute removed, and then loop-mounting it), but I just did not like them.
So I have decided to add a swap partition.
It worked amazingly (and very easily), there was even no need to reboot – at all.
I still did restart, just to make sure the system is bootable – and all was perfectly fine.
My initial setup is very simple: a single /dev/sda1 partition on the /dev/sda disk, fully used by btrfs.
Different important paths/mountpoints are btrfs subvolumes, using flat hierarchy.
For this example, let us assume that /dev/sda (and /dev/sda1) is 25GB large, and that I want to add a 2GB swap /dev/sda2 after /dev/sda1.
Brief explanation before we start:
- shrink btrfs filesystem by more than 2GB;
- shrink btrfs partition by 2GB;
- create new 2GB partition for the swap;
- resize btrfs filesystem to full size of its new-size partition;
- initialize swap and turn it on.
Here are the very easy steps! Just make sure you do not make mistakes anywhere ![]()
Read the rest of this entry »
Posted in *nix, how-to | No Comments »
