Ubuntu 20.04 Remove Swap

Disable Swap from the System

Check if swap is enabled:

sudo swapon --show

If enabled, you will see the path to the swap file, if you have a swap file, save file path, to remove it later.

To start removing the swap file or partition, start by disabling swap:

sudo swapoff -a

Remove Swap File

if you have a swap file, you can remove it next:

sudo rm /path/to/swap/file

Next we need to make sure ubuntu wont create or try to load a swap file after reboot. This can be done by removing the reference line from the fstab file:

sudo nano /etc/fstab

Remove or comment out the swap reference line.

/dev/mapper/vg-server-swap_1 none swap sw 0 0

Save and reboot your system to verify the changes.

sudo reboot

Check and make sure swap is disabled.

sudo swapon --show 

There should be no output if its disabled.

Remove Swap Partition

You can now remove the swap partition if you had a swap partition, this will remove the partition and you can add that extra disk space to your root partition

Use lvremove to remove the LVM logical volume of the swap:

lvremove ubuntu-vg/swap_1

Extend the root partition’s logical volume using lvextend

lvextend ubuntu-vg/root /dev/sda5

This will use all the available space on /dev/sda5.

Use resize2fs to resize the filesystem on the root partition to use the new extra space:

resize2fs /dev/ubuntu-vg/root

That should be all there is to it.


This post currently has one response

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.