What does "sw" option mean in /etc/fstab?

8,747

Solution 1

According to the link below, the 'sw' option indicates that the swap partition is to be activated with 'swapon -a' command:

/dev/hda6 none swap sw 0 0

http://www.linuxquestions.org/questions/linux-newbie-8/fstab-defaults-sets-wrong-permissions-145958/

Solution 2

This column is described in Linux's man fstab as:

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 plus any additional options appropriate to the filesystem type. For documentation on the available options for non-nfs file systems, see mount(8).

When the file system is swap, these mount options don't do anything. See: What is the difference between swap entries in fstab?

These fstab options are part of struct fstab:

 struct fstab {
         char    *fs_spec;       /* block special device name */
         char    *fs_file;       /* filesystem path prefix */
         char    *fs_vfstype;    /* type of filesystem */
         char    *fs_mntops;     /* comma separated mount options */
         char    *fs_type;       /* rw, ro, sw, or xx */
         int     fs_freq;        /* dump frequency, in days */
         int     fs_passno;      /* pass number on parallel fsck */
 };

So in summary there are 6 columns in /etc/fstab means:

  1. fs_spec: describes the block special device, the local filesystem, or the remote filesystem to be mounted.
  2. fs_file: describes the mount point for the filesystem. For swap partitions, this field should be specified as none.
  3. fs_vfstype: describes the type of the filesystem.
  4. fs_mntops: describes the mount options associated with the filesystem.
  5. fs_freq: is used for these filesystems by the dump command to determine which filesystems need to be dumped.
  6. fs_passno: is used by the fsck program to determine the order in which filesystem checks are done at reboot time.
Share:
8,747

Related videos on Youtube

Cinlloc
Author by

Cinlloc

Updated on September 18, 2022

Comments

  • Cinlloc
    Cinlloc over 1 year

    In my Ubuntu 14.04 /etc/fstab, I have following line:

    UUID=e4YGg1-2bHU-Ylum-3FwK-MK3s-1Fjf-ZvQEh2 none            swap    sw              0       0
    

    Which seems pretty current for swap.

    I can't figure out what the sw option stand for. There is no indication in fstab man neither swapon's.

    Any idea?

    • AFH
      AFH about 8 years
      I think this may tell you what you want to know: it confirms what I always assumed.
  • Tom Yan
    Tom Yan about 8 years
    man7.org/linux/man-pages/man8/swapon.8.html: -a, --all: All devices marked as ``swap'' in /etc/fstab are made available, except for those with the ``noauto'' option. Also: git.kernel.org/cgit/utils/util-linux/util-linux.git/tree/…
  • Tom Yan
    Tom Yan about 8 years
  • Tom Yan
    Tom Yan about 8 years
    Well, ro and rw are documented in mount(8): man7.org/linux/man-pages/man8/mount.8.html, while sw and xx probably make no sense in Linux. Also, fstab in Linux has only 6 fields, ro and rw belongs to the mount options field.
  • kenorb
    kenorb about 8 years
    That's correct, 4th column describes the mount options associated with the filesystem.
  • kenorb
    kenorb about 8 years
    Clarified further more.
  • Tom Yan
    Tom Yan about 8 years
    Hm actually my point is, it's a bit pointless to bring up the BSD fstab for the question. fstab in Linux has 6 fields, while according to the code you quoted, fstab in BSD has 7. And the extra one that BSD has while Linux doesn't is char *fs_type; /* rw, ro, sw, or xx */. I mean, yeah BSD has it, but so? It's a bit like saying "both sw and swap starts with sw, so sw means swap".
  • kenorb
    kenorb about 8 years
    @Tom Corrected the inconsistency issues.