Reduce Linux Swap File Size When Using LVM

If you’re looking to free up some space on your hard drive, reducing the swap space may be an option. I wanted to migrate my server’s primary drive from a 750GB spinny disk to a 512GB SSD, so shrinking space where needed was essential.  If your swap “file” is really just a LVM volume, you can reduce the size with lvreduce -L <new size> </path/to/volume> but then when you try to re-add that swap partition:

You’ll get an error that the swap file failed to re-mount. Before you can use the reduced size swap file, you must use the mkswap command on the re-sized partition:

After that, all is well:

My swap “file” went from being 32GB to 16GB.

Leave a Reply