I have Archlinux x86_64 installation on my laptop and desktop. At the time of installation, I have created a swap partition with fdisk and enabled that with sudo swapon /dev/sda3.

But even with sysctl vm.swappiness set to 0, my system still writes to the swap partition when my system memory is half used, and at the time I copy/move a large file to somewhere, which makes the system very slow. In such case, I used to turn off the swap with sudo swapoff /dev/sda3.

Nowadays, I generally turn off the swap after boot, and enable it when I truly need the swap (and I have a ruby script to monitor RAM usage, and turn on swap when it's needed). Swap is activated again in the next boot. I have no entries in the /etc/fstab regarding swap.

Is there a way to permanently disable the swap device without deleting the device?


The ArchWiki mentions that swap on Archlinux is managed by systemd, and describes how to disable automatic activation by masking the systemd unit responsible for swap. Thus, on Archlinux the following should achieve what you are looking for:

  1. Disable swap using #swapoff -a or pass a specific device/file name for a specific swap. At this point the swap is disabled, but will be automatically reactivated and enabled during next boot.
  2. To prevent auto activation of swap, look for the swap systemd units using #systemctl --type swap. For each *.swap unit found mask it using #systemctl mask <unit_name>.

This process can be undone by just running systemctl unmask <unit_name> on the previously masked units, and then turning swap on using swapon.

This is taken from the following two Archwiki articles:


You can let systemd do this by creating the file /lib/systemd/system/turnswapoff.service with the contents:

Description=Turn swap off 

ExecStart=/sbin/swapoff -a


And make sure it runs at boot sudo systemctl enable turnswapoff

It could be that the location of swapoff is not /sbin/swapoff. You can check this with which swapoff and change it if necessary

  • Arch surely uses systemd. Nice answer, I didn't think of it for some reason! – S.Goswami Nov 8 '19 at 19:32
  • Yes, this works as usual... But I wonder if there any other ways because it's just equivalent to turning off swap after they are on... – S.Goswami Nov 8 '19 at 19:37
  • 2
    If your system mounts sda3 as swap and it is not in fstab then it 'magically' knows that sda3 is a swappartion, this really surprises me... If you boot your system (without turnswapoff) is there anything swap related mentioned in /proc/self/mounts ? – Garo Nov 8 '19 at 19:43
  • Yup that's true for every ArchLinux installation I have ever done (except ArchLinux ARM for Raspberry Pi, the swap isn't automatically mounted). When you create a swap during installation before chrooting, and turn on swap, after the installation, when you reboot it will turn on the device without an fstab entry! Event no genfstab is done! The fstab is completely empty, it has just 3 lines of comments. There's no match after running cat /proc/self/mounts | grep -i swap! – S.Goswami Nov 8 '19 at 19:48
  • 1
    If the partitioning tool creates the swap partition with the partition type GUID for swap according to the Discoverable Partitions Specification, then it is automatically used without the need for it to be listed in /etc/fstab. – Johan Myréen Nov 9 '19 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.