Disabling swap permanently on a Debian system involves a few steps to ensure that the swap space is not used and does not get re-enabled on reboot. Here’s how you can do it:
Turn off swap immediately:
First, you need to turn off the swap space immediately. You can do this with the following command:
sh
sudo swapoff -a
Remove swap entries from /etc/fstab:
The /etc/fstab file contains information about all the filesystems and swap spaces that should be mounted or activated at boot time. You need to remove or comment out the lines that refer to swap. Open the file with a text editor:
sh
sudo nano /etc/fstab
Look for lines that contain swap or swapfile and comment them out by adding a # at the beginning of the line. For example:
sh
# /swapfile none swap sw 0 0
Save the file and exit the editor.
Remove the swap file (if applicable):
If you have a swap file (e.g., /swapfile), you should remove it. First, delete the swap file:
sh
sudo rm /swapfile
Then, remove the swap file entry from /etc/fstab if it exists.
Remove swap partition (if applicable):
If you have a dedicated swap partition, you need to remove it. First, identify the swap partition using the blkid command:
sh
sudo blkid
Look for the partition labeled as swap. Once identified, you can remove the swap partition using fdisk or parted. For example, using fdisk:
sh
sudo fdisk /dev/sdX
Replace /dev/sdX with the appropriate device name. In fdisk, delete the swap partition and then write the changes to the disk.
Update the bootloader (if necessary):
If you have configured swap in your bootloader (e.g., GRUB), you may need to update the bootloader configuration. Edit the GRUB configuration file:
sh
sudo nano /etc/default/grub
Look for any references to swap and remove or comment them out. Then, update GRUB:
sh
sudo update-grub
Reboot the system:
Finally, reboot your system to ensure that the changes take effect:
sh
sudo reboot
After rebooting, you can verify that swap is disabled by running:
sh
swapon --show
This command should return no output if swap is successfully disabled.
By following these steps, you should have permanently disabled swap on your Debian system.