Linux

Where Is Swap Configured on Linux?

Swap lives in fstab plus /proc/swaps at runtime. Partitions vs files, swappiness, and priorities.

Last updated

Swap is configured in /etc/fstab with the swap type, either a partition path or a file path with sw flags. Identification by UUID survives disk reordering, which bare /dev names do not. Runtime truth comes from /proc/swaps and free, not from the config file.

Files work as well as partitions on modern kernels: fallocate, chmod 600, mkswap, swapon, then the fstab line. Hibernation still prefers a partition at least RAM sized. Aggressiveness is the vm.swappiness knob (Ubuntu defaults 60), settable live with sysctl and permanently in sysctl.d.

Where Linux swap stores this, by platform

Linux
/etc/fstab

Swap lines with swap type here; UUID form recommended. Check /proc/swaps for live state. Swap files (e.g. /swapfile) need 600 perms and mkswap before swapon.

Frequently asked questions

how do i add a swap file

fallocate the file, chmod 600, mkswap, swapon, then append the line to /etc/fstab. Verify with cat /proc/swaps. Skip this on btrfs, which does not support swap files.

what is swappiness and what should it be

The kernel's eagerness to swap on a 0 to 100 scale. Check with cat /proc/sys/vm/swappiness, tune live with sysctl, persist in /etc/sysctl.d. Desktops often prefer 10; servers usually keep 60.

Notice an outdated path? Let us know.