From ParabolaWiki
Jump to: navigation, search

The /etc/fstab file contains static filesystem information. It defines how storage devices and partitions are to be mounted and integrated into the overall system. It is read by the mount command to determine which options to use when mounting a specific device or partition.

1 File example

A simple /etc/fstab, using kernel name descriptors:

File: /etc/fstab
# <file system>        <dir>         <type>    <options>             <dump> <pass>
tmpfs                  /tmp          tmpfs     nodev,noexec,nosuid   0      0
/dev/sda1              /             ext4      defaults,noatime      0      1
/dev/sda2              none          swap      defaults              0      0
/dev/sda3              /home         ext4      defaults,noatime      0      2

2 Field definitions

The /etc/fstab file contains the following fields separated by a space or tab:

<file system>	<dir>	<type>	<options>	<dump>	<pass>
  • <file system> - the partition or storage device to be mounted.
  • <dir> - the mountpoint where <file system> is mounted to.
  • <type> - the file system type of the partition or storage device to be mounted. Many different file systems are supported: ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap and auto. The auto type lets the mount command guess what type of file system is used. This is useful for removable devices such as cdroms and dvds.
  • <options> - the options of the filesystem to be used. Note that some options are filesystem specific. Some of the most common options are:
  • auto - Mount automatically at boot, or when the command mount -a is issued.
  • noauto - Mount only when you tell it to.
  • exec - Allow execution of binaries on the filesystem.
  • noexec - Disallow execution of binaries on the filesystem.
  • ro - Mount the filesystem read-only.
  • rw - Mount the filesystem read-write.
  • user - Allow any user to mount the filesystem. This automatically implies noexec, nosuid, nodev, unless overridden.
  • users - Allow any user in the users group to mount the filesystem.
  • nouser - Allow only root to mount the filesystem.
  • owner - Allow the owner of device to mount.
  • sync - I/O should be done synchronously.
  • async - I/O should be done asynchronously.
  • dev - Interpret block special devices on the filesystem.
  • nodev - Don't interpret block special devices on the filesystem.
  • suid - Allow the operation of suid, and sgid bits. They are mostly used to allow users on a computer system to execute binary executables with temporarily elevated privileges in order to perform a specific task.
  • nosuid - Block the operation of suid, and sgid bits.
  • noatime - Don't update inode access times on the filesystem. Can help performance (see atime options).
  • nodiratime - Do not update directory inode access times on the filesystem. Can help performance (see atime options).
  • relatime - Update inode access times relative to modify or change time. Access time is only updated if the previous access time was earlier than the current modify or change time. (Similar to noatime, but doesn't break mutt or other applications that need to know if a file has been read since the last time it was modified.) Can help performance (see atime options).
  • flush - The vfat option to flush data more often, thus making copy dialogs or progress bars to stay up until all data is written.
  • defaults - the default mount options for the filesystem to be used. The default options for ext3 are: rw, suid, dev, exec, auto, nouser, async.
  • <dump> - used by the dump utility to decide when to make a backup. Dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system; if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the <dump> entry.
  • <pass> - used by fsck to decide which order filesystems are to be checked. Possible entries are 0, 1 and 2. The root file system should have the highest priority 1 - all other file systems you want to have checked should have a 2. File systems with a value 0 will not be checked by the fsck utility.

3 Identifying filesystems

There are three ways to identify a partition or storage device in /etc/fstab: by its kernel name descriptor, label or UUID. The advantage of using UUIDs or labels is that they are not dependent on the disks order. This is useful if the storage device order in the BIOS is changed, or if you switch the storage device cabling. Also, sometimes the BIOS may occasionally change the order of storage devices. Read more about this in the persistent block device naming article.

3.1 Kernel name

You can get the kernel name descriptors using fdisk -l. The kernel names are listed in the first row:

# fdisk -l
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2550    20482843+   b  W95 FAT32
/dev/sda2            2551        5100    20482875   83  Linux
/dev/sda3            5101        7650    20482875   83  Linux
/dev/sda4            7651      121601   915311407+   5  Extended
/dev/sda5            7651       10200    20482843+  83  Linux
/dev/sda6           10201       17849    61440561   83  Linux
/dev/sda7           17850       18104     2048256   82  Linux swap / Solaris
/dev/sda8           18105       18113       72261   83  Linux
/dev/sda9           18114      121601   831267328+   7  HPFS/NTFS

See the file example.

3.2 Label

In order to use labels, the devices or partitions must have unambiguous labels. Labels should be unambiguous to prevent any possible conflicts - each label should be unique. To label a device or partition, see this article. To list all devices and partitions with their labels, you can use the command blkid. In /etc/fstab you prefix the device label with LABEL= :

File: /etc/fstab
# <file system>        <dir>         <type>    <options>             <dump> <pass>

tmpfs                  /tmp          tmpfs     nodev,nosuid,noexec   0      0
LABEL=libre       /             ext4      defaults,noatime      0      1
LABEL=libre        none          swap      defaults              0      0

3.3 UUID

All partitions and devices have a unique UUID. They are generated by the make-filesystem utilities (mkfs.*) when you create the filesystem. To list all devices and partitions with their UUID, you can also use blkid. In /etc/fstab you prefix the device UUID with UUID= :

File: /etc/fstab
# <file system>                           <dir>         <type>    <options>             <dump> <pass>

tmpfs                                     /tmp          tmpfs     nodev,nosuid,noexec   0      0
UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26 /     ext4              defaults,noatime      0      1
UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff /home ext4              defaults,noatime      0      2
UUID=4209c845-f495-4c43-8a03-5363dd433153 none  swap              defaults              0      0

4 Tips and tricks

4.1 Swap UUID

In case your swap partition doesn't have an UUID, you can add it manually. This happens when the UUID of the swap is not shown with the blkid command. Here are some steps to assign a UUID to your swap:

Identify the swap partition:

# swapon -s

Disable the swap:

# swapoff /dev/sda7

Recreate the swap with a new UUID assigned to it:

# mkswap -U random /dev/sda7

Activate the swap:

# swapon /dev/sda7

4.2 Filepath spaces

You can use the escape character "\" followed by the 3 digit octal code "040" to emulate spaces in a path:

File: /etc/fstab
/dev/sda7                /home/username/Camera\040Pictures   ext4  defaults,noatime       0  2
UUID=7D4500B3071E18B2    /media/100\040GB\040(Storage)       ntfs  defaults,noatime,user  0  0

4.3 External devices

External devices that are to be mounted when present but ignored if absent may require the nofail option. This prevents errors being reported at boot.

File: /etc/fstab
 /dev/sdg1    /media/backup    jfs    defaults,nofail    0  2

4.4 atime options

The use of noatime, nodiratime or relatime can help disk performance for ext2, ext3, and ext4 filesystems. Linux by default keeps a record (writes to the disk) every times it reads from the disk atime. This was more purposeful when Linux was being used for servers; it doesn't have much value for desktop use. The worst thing about the default atime option is that even reading a file from the page cache (reading from memory instead of the disk) will still result in a disk write! Using the noatime option fully disables writing file access times to the disk every time you read a file. This works well for almost all applications, except for a rare few like Mutt that need the such information. For mutt, you should only use the relatime option. Using the relatime option enables the writing of file access times only when the file is being modified (unlike noatime where the file access time will never be changed and will be older than the modification time). The nodiratime option disables the writing of file access times only for directories while other files still get access times written. The best compromise might be the use of relatime in which case programs like Mutt will continue to work, but you'll still have a performance boost because files will not get access times updated unless they are modified.

Note: noatime already includes nodiratime. You don't need to specify both options.

4.5 tmpfs

tmpfs is a temporary filesystem that resides in memory and/or your swap partition(s), depending on how much you fill it up. Mounting directories as tmpfs can be an effective way of speeding up accesses to their files, or to ensure that their contents are automatically cleared upon reboot.

Some directories where tmpfs is commonly used are /tmp, /var/lock and /var/run. Do NOT use it on /var/tmp, because that folder is meant for temporary files that are preserved across reboots.

By default, a tmpfs partition has its maximum size set to half your total RAM, but this can be customized. Note that the actual memory/swap consumption depends on how much you fill it up, as tmpfs partitions don't consume any memory until it is actually needed.

To use tmpfs for /tmp, add this line to /etc/fstab:

File: /etc/fstab
tmpfs /tmp      tmpfs nodev,nosuid,noexec                 0 0

You may or may not want to specify the size here, but you should leave the mode option alone in these cases to ensure that they have the correct permissions (1777). In the example above, /tmp will be set to use up to half of your total RAM. To explicitly set a maximum size, use the size mount option:

File: /etc/fstab
tmpfs /tmp      tmpfs nodev,nosuid,noexec,size=2G          0 0

See the mount command man page for more information.

Reboot for the changes to take effect. Note that although it may be tempting to simply run mount -a to make the changes effective immediately, this will make any files currently residing in these directories inaccessible (this is especially problematic for running programs with lockfiles, for example). However, if all of them are empty, it should be safe to run mount -a instead of rebooting (or mount them individually).

After applying changes, you may want to verify that they took effect with findmnt:

findmnt --target /tmp
/tmp   tmpfs  tmpfs  rw,nosuid,nodev,noexec,relatime

To use tmpfs for /var/lock and /var/run, you can simply symlink them to /run. Make sure to close anything important before doing this, because you will have to reboot, and daemons may not stop cleanly.

# ln -sf /run/lock /var/lock
# ln -sf /run /var/run
# reboot
Note: Arch will likely do this by default in the future. See https://bugs.archlinux.org/task/18157
Warning: Some daemons still have files and/or directories installed into /var/lock and /var/run, and the /etc/rc.d/ scripts may need to be edited for them to work.

5 Related

6 Other resources