How to safely turn off swap permanently from Debian and reclaim the space

Michael

Administrator
Staff member
Feb 11, 2022
87
4
8

How to safely turn off swap permanently and reclaim the space​


First thing, Timeshift your computer, take a snapshot.

This tutorial uses both Terminal commands and a GUI. I have tried many different ways, this one works well and is the easiest to do.

gparted_image.png


If you have GParted open, close it. Its Swapoff feature does not appear to to be permanent.

Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options):

Code:
sudo -i

Turn off the particular swap partition and / or all of the swaps:

Code:
swapoff --all

Make 100% sure the particular swap partition partition is off:

Code:
cat /proc/swaps

Open a text editor you are skilled in with this file, e.g. nano if unsure:

Code:
nano /etc/fstab

Comment out / remove the swap partition's UUID, e.g.:

Code:
   # UUID=1d3c29bb-d730-4ad0-a659-45b25f60c37d    none    swap    sw    0    0

Open a text editor you are skilled in with this file, e.g. nano if unsure:

Code:
nano /etc/initramfs-tools/conf.d/resume

Comment out / remove the previously identified swap partition's UUID, e.g.:

Code:
# RESUME=UUID=1d3c29bb-d730-4ad0-a659-45b25f60c37d

Don't close the terminal as you will need it later anyway.

Note: The next steps differ depending on, whether you rely on CLI or GUI.

GUI:

Open up GParted, either from menu, or more conveniently from the terminal we have opened:

Code:
gparted

If you don't have it installed, you may do so; afterwards run the previous command again:

Code:
apt-get install gparted

Choose your drive from top-right menu.

As the GParted reactivates the swap partition upon launch, you will have to right-click the particular swap partition and click Swapoff -> This will be applied immediately.

Delete the swap partition with right click -> Delete. You must apply the change now.

Resize your main / other partition with right click -> Resize/Move. You must apply the change now.

Back to the terminal, let's recreate the boot images:

Code:
update-initramfs -u -k all

Update GRUB:

Code:
update-grub

You may reboot now if you wish to test that the machine boots up.

Code:
sudo reboot
 
Last edited:

Michael

Administrator
Staff member
Feb 11, 2022
87
4
8
Notes:

If your swap partition is encrypted, then you also need to comment out the related line in /etc/crypttab, otherwise CryptSetup will keep you waiting for 90 seconds during boot time.

Code:
sudo nano /etc/crypttab