I'm building my first Ubuntu server and I'm struggling with with the swap size.

I have 16GB RAM, however the disk space is limited as I'll be running multiple VM's. I've created a partition for the host machine with 20GB which will be more than enough to start with.

However, when I look at the Logical Volumes through Webmin, the SWAP_1 volume has got about 15GB taking almost the entire partition for nothing.

I'm new to Linux and did my research into how to reduce/remove the swap but couldn't get it to work. I've added the following line:




I have rebooted the system and the swap size remains the same. I have also tried to switch swap off through the command:

swapoff -a

But that also did not work.

I'm a bit confused with all of these things as it is a kind a new world for me.

All I want is to have as close as 20GB as possible available on my partition.

  • SWAP Partition is created before install. It has a fixed size. if it is 15GB in size, it is that way. swap partition size is not dynamic. Your swap partition will remain after you disabled swapping. You'll have to delete it. I am not sure what will happen without swap Partition if RAM gets full. – mondjunge Oct 14 '13 at 12:29

vm.swappiness controls the kernel's preference on how much to use swap vs trimming back the filesystem cache to free up memory. swapoff stops using swap. Neither has a thing to do with disk partitions. If you are using LVM, then you want lvresize to change the size of the volume.

sudo -s
cat /etc/fstab
swapoff -a
lvresize vg0/SWAP_1 -L 4G
mkswap -U long-uuid-here /dev/vg0/SWAP_1
swapon -a

Look at your /etc/fstab and figure out the uuid of the swap volume and copy/paste that into the mkswap line so that it will be reformatted to the new size, but keep the old uuid.

Alternatively since you have plenty of ram, you could do without swap entirely. Edit /etc/fstab to remove the swap line after running swapoff -a, then use lvremove vgo/SWAP_1 to delete the volume.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.