How to permanently disable swap on debian?
- User
How to permanently disable swap on debian?
Assistant
To permanently disable swap on Debian, follow these steps:
1. Check Current Swap Usage
sudo swapon --show free -hThis will list active swap partitions/files.
2. Temporarily Disable Swap
sudo swapoff -aThis turns off all swap devices immediately.
3. Permanently Remove Swap Entries
Edit
/etc/fstabto comment out or remove swap entries:sudo nano /etc/fstabLook for lines containing
swapand either:- Comment them out (add
#at the start):# /dev/mapper/vg0-swap none swap sw 0 0 - Or delete them entirely.
Save (
Ctrl+O,Enter) and exit (Ctrl+X).4. (Optional) Remove Swap Partition or File
If you want to completely remove the swap partition/file:
-
For a swap partition:
sudo fdisk /dev/sdX # Replace X with your disk (e.g., sda)Delete the swap partition and save changes.
-
For a swap file:
sudo rm /swapfile
5. Verify Swap is Disabled
free -h sudo swapon --showIf swap is disabled, no entries should appear.
6. (Optional) Disable ZRAM Swap (if used)
If using ZRAM (common on newer Debian installs), disable it:
sudo systemctl disable --now zramswap7. Reboot (Optional)
sudo rebootAfter reboot, verify again with
free -h.Conclusion
Now swap is permanently disabled on your Debian system. If you later need to re-enable it, reverse these steps (uncomment in
/etc/fstaband runswapon -a).Let me know if you need further assistance!
- Comment them out (add
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.