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

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.


For Linux, at least, based on a look at the net, this appears to be an example of "cargo culting". The evidence I've see suggests that this option isn't actually necessary or meaningful, but you need to put something there, because the fstab file syntax expects it. You can easily find examples of people using defaults and even just pri=1 or whatever, leaving out both defaults and sw.

And it doesn't make sense that swapon would need to look at the mount options to check that it is swap, because swapon can already see it's swap by looking at the filesystem type. There are certainly mount options for swap that modify behavior, as documented in man swapon, but sw isn't one of them. So the evidence is that it is a placeholder, and foobar would do just as well as a placeholder

I can't be completely sure of this without looking at the source code of course.

Related, a Debian bug report complaining about this exact issue: mount: swapon(8) lacks explanation for sw and defaults options

Tags:

Swap

Fstab