Linux Disable Swap Permanently

Linux Disable Swap Permanently

Swap can be active now and return after a reboot if its boot configuration still enables it. The swapoff command turns off active swap areas, while changing the boot configuration prevents them from starting again.

I’ll show you how to check active swap and keep it disabled after reboot.

TL;DR

Run sudo swapoff -a to disable every active swap area, then remove or comment out each boot-time swap entry so it does not return after restart.

  • Check active swap first with swapon --show.
  • Update /etc/fstab and check for a separate systemd swap unit.
  • Keep swap storage unless you have a separate reason to reclaim its disk space.

Swapoff needs elevated privileges and can fail when memory cannot hold the pages moved out of swap. Back up configuration before editing it.

What Is Linux Swap?

Linux swap is disk space that the kernel can use to hold memory pages when physical RAM is under pressure. It can be a file or a dedicated partition, and Linux can use more than one swap area at a time.

Swap is slower than RAM, which can affect performance when pages are read from disk.

TermWhat it meansHow to inspect it
Swap fileA regular file used for pagingAppears as a path in the active swap listing
Swap partitionA disk device configured for pagingAppears as a device path or UUID
PriorityPreference when multiple areas are enabledShown in the PRIO column

Use swapon --show before changing anything. It reveals active paths and priorities.

How to Disable Swap in Linux Step by Step

To disable swap permanently, first identify every active area, turn it off, and then stop its boot-time configuration from enabling it again. Keep the backing file or partition until you have confirmed the change and decided whether reclaiming disk space is necessary.

Step 1: Check memory and active swap

Check current memory availability and list enabled swap areas.

free -h
swapon --show

Low swap use at idle does not show whether swap will be needed under load.

Step 2: Turn off active swap

Use the all-areas option when you intend to disable every active swap file and device. This requires administrator privileges, so run it on your own Linux machine after considering available memory.

sudo swapoff -a

If only one area should be disabled, use its exact path from the listing instead of the all option. Check the exit status. Failure can mean there is not enough memory to stop swapping safely.

Step 3: Prevent activation at boot

Back up /etc/fstab and find entries with swap as the filesystem type. Comment out only those lines with # at the start. Leave other filesystem entries unchanged.

# UUID=example-uuid none swap sw 0 0

Keep the original line so you can restore it. On systemd systems, reload the manager after editing.

sudo systemctl daemon-reload

Also check whether a native swap unit configures the same source. It can take precedence over fstab, so editing that file alone may not cover every setup.

Step 4: Verify the current and boot state

List active swap again after the change. An empty table means no area is active now, while the edited configuration determines whether one starts at boot.

swapon --show
free -h

Check again after reboot because another unit may activate swap.

What Should You Check Before Disabling Swap?

Check these cases before making swap changes permanent.

SituationWhy it mattersNext step
Swapoff failsThere may not be enough available RAM to move pages out of swapKeep swap enabled, reduce memory pressure, then reassess
Swap returns after rebootA remaining fstab entry or systemd unit may activate itInspect both configuration sources and verify again
Hibernation is neededResume-from-disk setup can depend on configured swapCheck your distribution’s hibernation requirements first
Swap appears slowSwap use can coincide with memory pressure, but does not identify its causeInspect processes with the Linux top command and check available memory

If disabling swap leaves too little memory, restore the saved configuration and run sudo swapon -a to re-enable configured areas.

Conclusion: Keep Swap Disabled Deliberately

Swapoff changes active state. Boot configuration determines whether it returns.

For the supporting diagnostics, see the Linux guides to checking available memory and using top.

FAQ

These answers cover common follow-up questions about disabling Linux swap.

How do I disable swap temporarily in Linux?

Run sudo swapoff -a to turn off all active swap areas until they are enabled again or the system restarts.

How do I disable swap permanently in Linux?

Turn off active swap, then comment out its swap entry in /etc/fstab and check for a separate systemd swap unit. Verify again after reboot.

Should I disable a Linux swap file?

Only if your workload and memory capacity make that a deliberate choice. Swap can provide headroom during memory pressure and may be part of a hibernation setup.