Every guide presents disabling swap permanently as simply commenting out the corresponding line in /etc/fstab to prevent swap from mounting on reboot; however, that does not work in Debian 11.


sudo swapoff -a works perfectly, but doesn't persist across reboots.

Example fstab File, with line commented out:

# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=6b762cb8-b92b-489a-98cf-2bf200e3c4ae /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=4847-3887  /boot/efi       vfat    umask=0077      0       1
# swap was on /dev/sda3 during installation
# UUID=b9aeb506-ad7d-488d-b2b9-7c68dff21906 none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0


After turning off swap manually:

sudo swapoff -a


the Swap Partition is still mounted but is no longer listed as a swap partition. Swap is successfully disabled:

sda      8:0    0   127G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 125.5G  0 part /
└─sda3   8:3    0   976M  0 part
sr0     11:0    1  1024M  0 rom

Editing Fstab

After editing fstab file, running sudo systemctl daemon-reload and performing a system reboot, swap is still there

lsblk -o +PARTTYPE

sda      8:0    0   127G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi  c12a7328-f81f-11d2-ba4b-00a0c93ec93b
├─sda2   8:2    0 125.5G  0 part /          0fc63daf-8483-4772-8e79-3d69d8477de4
└─sda3   8:3    0   976M  0 part [SWAP]     0657fd6d-a4ab-43c4-84e5-0933c84b4f4f
sr0     11:0    1  1024M  0 rom

Clearly there's still a step missing.

  • 1
    Could you edit your question to show the output of lsblk -o +PARTTYPE instead of plain lsblk? Oct 5, 2021 at 13:21
  • @StephenKitt testing in a debian 11 the swap parttype is different to the one in fstab, following OP's process. Oct 5, 2021 at 13:51
  • @schrodigerscatcuriosity yes, that’s normal, the fstab lists the partition UUID, not the type UUID, and it’s the latter I’m interested in (because it’s what the systemd generator uses). Oct 5, 2021 at 14:00

6 Answers 6


It is activated by systemd. See man systemd-fstab-generator and man systemd.swap.

Archlinux wiki: Activation by systemd

systemd activates swap partitions based on two different mechanisms. Both are executables in /usr/lib/systemd/system-generators. The generators are run on start-up and create native systemd units for mounts. The first, systemd-fstab-generator, reads the fstab to generate units, including a unit for swap. The second, systemd-gpt-auto-generator inspects the root disk to generate units. It operates on GPT disks only, and can identify swap partitions by their type GUID, see systemd#GPT partition automounting for more information.

Disabling swap

To deactivate specific swap space:

# swapoff /dev/sdxy

Alternatively use the -a switch to deactivate all swap space.

Since swap is managed by systemd, it will be activated again on the next system startup. To disable the automatic activation of detected swap space permanently, run systemctl --type swap to find the responsible .swap unit and mask it.

Check the status:

systemctl status *swap

or :

systemctl --type swap

Then disable the service:

sudo systemctl mask  "dev-*.swap"
  • Can you expand on why this would add swap when not configured to do so. Disabling the systemd unit which adds swap by configuration seems overkill otherwise. Oct 5, 2021 at 13:37
  • 1
    @PhilipCouling See my edit with some documentations.
    – GAD3R
    Oct 5, 2021 at 14:34
  • This methodology of masking the systemctl service made the most sense to me and was effective. -- I am curious if this is the best way to do it though. Oct 6, 2021 at 15:20
  • should be marked as the answer. Works very well in debian 11
    – Jerome
    Sep 25, 2022 at 13:53
  • The answer is too complex. The exact .swap unit is required at the sudo systemctl mask "dev-*.swap", and the unit name is known only after a reboot. I have a better solution: changing swap mount options to noauto so that both systemd-fstab-generator and systemd-gpt-auto-generator ignore this swap device. May 5 at 6:18

systemd is by default in automatic mode and does not need fstab to get active:

systemd-gpt-auto-generator is a unit generator that automatically discovers root, /home/, /srv/, /var/, /var/tmp/, the EFI System Partition, the Extended Boot Loader Partition and swap partitions

This generator can be masked in a separate admin override dir:

/etc/systemd/system-generators/systemd-gpt-auto-generator -> /dev/null

systemd.gpt_auto=no as boot param should have the same effect.

The man page continues:

systemd-gpt-auto-generator is useful for centralizing file system configuration in the partition table and making configuration in /etc/fstab or on the kernel command line unnecessary.

fstab-generator comes second/can override. But since you did comment swap out, I guess gpt-auto is turning it on.

The sda3 is not still mounted. lsblk works like fdisk -l at partition level. [SWAP] entry is like a mountpoint.

Try swapon --show because there can be also swap files and several swaps.

  • Here is a similar, self-answered Q: unix.stackexchange.com/questions/554601/…. With a special kind of solution.
    – user495217
    Oct 5, 2021 at 14:33
  • Results of swapon --show /dev/sda3 partition 976M 0B -2 Oct 6, 2021 at 15:03
  • In this answer, where would I mark systemd.gpt_auto=no in the system? Oct 6, 2021 at 15:23
  • That would be a kernel boot parameter. You could add it to /etc/default/grub and run update-grub for persistent use, or press e in GRUB boot menu and add it to the linux... line for one-time use.
    – telcoM
    Oct 6, 2021 at 18:29

You need change vm.swappiness linux kernel parameter and make changes permanently in /etc/sysctl.conf file. And reboot system.

The default value of vm.swappiness is 60 and represents the percentage of the free memory before activating swap. The lower the value, the less swapping is used and the more memory pages are kept in physical memory.

For disable swap permanently on your debian system:

  • edit /etc/sysctl.conf file file and add to end of file if not present vm.swappiness = 0
  • reboot system
# edit /etc/sysctl.conf file
~] vi /etc/sysctl.conf 

# disable swap
# add to end of file if not present:
vm.swappiness = 0

# reboot for changes
~] systemctl reboot

Here is guide how disable swap on linux permanently.

  • No, this isn't the right solution. I used to work in mission critical telecoms and we investigated this, swappiness does very little actually. The tl;dr it doesn't do what people think it does.
    – Owl
    May 29, 2022 at 20:25

GAD3R's answer is too complicated. The exact .swap unit is required at the sudo systemctl mask "dev-*.swap", and the unit name is known only after a reboot. I have a better solution: changing swap mount options to noauto so that both systemd-fstab-generator and systemd-gpt-auto-generator ignore this swap device.


The missed step might be running sudo update-initramfs -u after changing /etc/fstab, to make sure that also the copy of fstab within the initramfs file is up to date.

Otherwise, the swap might be activated very early in the boot process, when the system is still running on initramfs. If that happens, there is no step in the boot process that would later deactivate it.


This worked for me on a raspberry pi running Ubuntu 11:

Disable the dphys-swapfile.service, by running:

$ sudo swapoff -a
$ sudo systemctl stop dphys-swapfile
$ sudo dphys-swapfile uninstall
$ sudo systemctl mask dphys-swapfile

then reboot, and the auto-generated swap file in /var/swap should be gone, and no swap should be active. Note that the command 'dphys-swapfile uninstall' does not uninstall the dphys-swapfile system. It is there to remove /var/swap, which on my system was 100M in size.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .