What ‘sw’ means in the fstab swap entry for ‘mount options’ column

fstabswap

In my /etc/fstab file I have an entry for my swap as follows:

/root/swap swap swap sw 0 0

I have other machines and also I've seen online that sometimes they put default or xfs or other options. Then, I'm a little confused on what 'sw' means and what's for, and also which one would be the best option to put there and why.

Best Answer

From the fstab manual on my system:

The fourth field, fs_mntops, describes the mount options associated with the filesystem. It is formatted as a comma separated list of options. It contains at least the type of mount (see fs_type below) plus any additional options appropriate to the filesystem type. [...]

If fs_type is “rw”, “rq”, or “ro” then the filesystem whose name is given in the fs_file field is normally mounted read-write or read-only on the specified special file. If fs_type is “sw” then the special file is made available as a piece of swap space by the swapon(8) command at the end of the system reboot procedure.

So basically, sw is used to tell swapon (or swapctl on my system) that this is a valid candidate for use as swap space that will be added as part of the system start-up routine.

From the manual describing swapctl -A:

This option causes swapctl to read the /etc/fstab file for devices and files with an “sw” type, and adds all these entries as swap devices. If no swap devices are configured, swapctl will exit with an error code.

That's on OpenBSD. On the Ubuntu Linux system that I have access to, neither manual mentions sw as a mount option for swap for some reason.

Related Question