From ArchWiki
Revision as of 11:58, 29 July 2016 by Lahwaacz (talk | contribs) (atime options: fix misleading description of relatime)
Jump to: navigation, search

ro:Fstab zh-CN:Fstab zh-TW:Fstab

The /etc/fstab file can be used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem.

Each filesystem is described in a separate line. These definitions will be converted into systemd mount units dynamically at boot, and when the configuration of the system manager is reloaded. The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like NFS or Samba are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in /etc/fstab should work out of the box. See man 5 systemd.mount for details.

The mount command will use fstab, if just one of either directory or device is given, to fill in the value for the other parameter. When doing so, mount options which are listed in fstab will also be used.

File example

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

# <file system>        <dir>         <type>    <options>             <dump> <pass>
/dev/sda1              /             ext4      defaults,noatime      0      1
/dev/sda2              none          swap      defaults              0      0
/dev/sda3              /home         ext4      defaults,noatime      0      2

Field definitions

Each line in the /etc/fstab file contains the following fields separated by spaces or tabs:

file_system    dir    type    options    dump    pass
file system
The partition or storage device to be mounted.
The mountpoint where <file system> is mounted to.
The file system type of the partition or storage device to be mounted. Many different file systems are supported: ext2, ext3, ext4, btrfs, 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 optical media (CD/DVD).
Mount options of the filesystem to be used. See the mount man page. Please note that some options are specific to filesystems; to discover them see below in the aforementioned mount man page.
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.
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 (unless its type is btrfs, in which case this field should be 0) - 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.

Identifying filesystems

There are different ways to identify filesystems that will be mounted. /etc/fstab does support several methods: kernel name descriptor, label or UUID, and GPT labels and UUID for GPT disks. UUID must be privileged over kernel name descriptors and labels. See Persistent block device naming for more explanations. It is recommended to read that article first before continuing with this article.

In this section, we will describe how to mount filesystems using all the mount methods available via examples. The output of the commands lsblk -f and blkid used in the following examples are available in the article Persistent block device naming. If you have not read that article yet, please read it now.

Kernel name descriptors

Run lsblk -f to list the partitions and prefix the values in the NAME column with /dev/.

# <file system> <dir> <type> <options>                                                                                            <dump> <pass>
/dev/sda1       /boot vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0      2
/dev/sda2       /     ext4   rw,relatime,discard,data=ordered                                                                     0      1
/dev/sda3       /home ext4   rw,relatime,discard,data=ordered                                                                     0      2
/dev/sda4       none  swap   defaults                                                                                             0      0


Run lsblk -f to list the partitions, and prefix the values in the LABEL column with LABEL=:

# <file system> <dir> <type> <options>                                                                                            <dump> <pass>
LABEL=EFI       /boot vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0      2
LABEL=SYSTEM    /     ext4   rw,relatime,discard,data=ordered                                                                     0      1
LABEL=DATA      /home ext4   rw,relatime,discard,data=ordered                                                                     0      2
LABEL=SWAP      none  swap   defaults                                                                                             0      0
Note: If any of your fields contains spaces, see #Filepath spaces.


Run lsblk -f to list the partitions, and prefix the values in the UUID column with UUID=:

# <file system>                           <dir> <type> <options>                                                                                            <dump> <pass>
UUID=CBB6-24F2                            /boot vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0      2
UUID=0a3407de-014b-458b-b5c1-848e92a327a3 /     ext4   rw,relatime,discard,data=ordered                                                                     0      1
UUID=b411dc99-f0a0-4c87-9e05-184977be8539 /home ext4   rw,relatime,discard,data=ordered                                                                     0      2
UUID=f9fe0b69-a280-415d-a03a-a32752370dee none  swap   defaults                                                                                             0      0
Tip: If you would like to return just the UUID of a specific partition: $ lsblk -no UUID /dev/sda2

GPT labels

Run blkid to list the partitions, and use the PARTLABEL values without the quotes:

# <file system>                      <dir> <type> <options>                                                                                            <dump> <pass>
PARTLABEL=EFI\040SYSTEM\040PARTITION /boot vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0      2
PARTLABEL=GNU/LINUX                  /     ext4   rw,relatime,discard,data=ordered                                                                     0      1
PARTLABEL=HOME                       /home ext4   rw,relatime,discard,data=ordered                                                                     0      2
PARTLABEL=SWAP                       none  swap   defaults                                                                                             0      0
Note: If any of your fields contains spaces, see #Filepath spaces.


Run blkid to list the partitions, and use the PARTUUID values without the quotes:

# <file system>                               <dir> <type> <options>                                                                                            <dump> <pass>
PARTUUID=d0d0d110-0a71-4ed6-936a-304969ea36af /boot vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0      2
PARTUUID=98a81274-10f7-40db-872a-03df048df366 /     ext4   rw,relatime,discard,data=ordered                                                                     0      1
PARTUUID=7280201c-fc5d-40f2-a9b2-466611d3d49e /home ext4   rw,relatime,discard,data=ordered                                                                     0      2
PARTUUID=039b6c1c-7553-4455-9537-1befbc9fbc5b none  swap   defaults                                                                                             0      0

Tips and tricks

Automount with systemd

If you have a large /home partition, it might be better to allow services that do not depend on /home to start while /home is checked by fsck. This can be achieved by adding the following options to the /etc/fstab entry of your /home partition:


This will fsck and mount /home when it is first accessed, and the kernel will buffer all file access to /home until it is ready.

Note: This will make your /home filesystem type autofs, which is ignored by mlocate by default. The speedup of automounting /home may not be more than a second or two, depending on your system, so this trick may not be worth it.

The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the noauto,x-systemd.automount parameters. In addition, you can use the x-systemd.device-timeout=# option to specify a timeout in case the network resource is not available.

Note: If you intend to use the exec flag with automount, you should remove the user flag for it to work properly as found in the course of a Fedora Bug Report

If you have encrypted filesystems with keyfiles, you can also add the noauto parameter to the corresponding entries in /etc/crypttab. systemd will then not open the encrypted device on boot, but instead wait until it is actually accessed and then automatically open it with the specified keyfile before mounting it. This might save a few seconds on boot if you are using an encrypted RAID device for example, because systemd does not have to wait for the device to become available. For example:

data /dev/md0 /root/key noauto

You may also specify an idle timeout for a mount with the x-systemd.idle-timeout flag. For example:


This will make systemd unmount the mount after it has been idle for 1 minute.

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. For example:

/dev/sdg1        /media/backup    jfs    defaults,nofail,x-systemd.device-timeout=1    0  2

The nofail option is best combined with the x-systemd.device-timeout option. This is because the default device timeout is 90 seconds, so a disconnected external device with only nofail will make your boot take 90 seconds longer, unless you reconfigure the timeout as shown. Make sure not to set the timeout to 0, as this translates to infinite timeout.

If your external device requires another systemd unit to be loaded (for example the network for a network share) you can use x-systemd.requires=x combined with x-systemd.automountto postpone automounting until after the unit is available. For example:

//host/share        /net/share        cifs        noauto,nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=10,workgroup=workgroup,credentials=/foo/credentials        0 0

Filepath spaces

Since spaces are used in fstab to delimit fields, if any field (PARTLABEL, LABEL or the mount point) contains spaces, these spaces must be replaced by escape characters \ followed by the 3 digit octal code 040:

UUID=47FA-4071     /home/username/Camera\040Pictures   vfat  defaults,noatime       0  0
/dev/sda7          /media/100\040GB\040(Storage)       ext4  defaults,noatime,user  0  2

atime options

Below atime options can impact drive performance.

  • The strictatime option updates the access time of the files every time they are accessed. This is more purposeful when Linux is used for servers; it does not have much value for desktop use. The drawback about the strictatime option is that even reading a file from the page cache (reading from memory instead of the drive) will still result in a write!
  • The noatime option fully disables writing file access times to the drive every time you read a file. This works well for almost all applications, except for those that need to know if a file has been read since the last time it was modified. The write time information to a file will continue to be updated anytime the file is written to with this option enabled.
  • The nodiratime option disables the writing of file access times only for directories while other files still get access times written.
Note: noatime already includes nodiratime. You do not need to specify both.
  • relatime updates the access time only if the previous access time was earlier than the current modify or change time. In addition, since Linux 2.6.30, the access time is always updated if the previous access time was more than 24 hours old. This option is used when the defaults option, atime option (which means to use the kernel default, which is relatime; see man 8 mount and wikipedia:Stat (system call)#Criticism of atime) or no options at all are specified.
  • lazytime (since kernel 4.0) updates times to in-memory(RAM) version of the file inode and causes updates to on-disk timestamps only when (1) the file inode needs to be updated for some change unrelated to file timestamps(e.g., the file is modified), (2) a sync to disk occurs, (3) the inode is evicted from memory or (4) if the file is accessed and over 24 hours has passed since the previous access(i.e., the atime is more than 24 hours old). lazytime solves POSIX and time-dependent applications' compatibility issues yet significantly reduces writes to disk since all time changes are maintained in system RAM until forced to disk. Particularly useful for filesystems on SSD(s), as is noatime, because of the reduced number of writes to disk.

When using Mutt or other applications that need to know if a file has been read since the last time it was modified, the noatime option should not be used; using the relatime or lazytime option is acceptable and still provides a performance improvement. For kernels prior to 4.0, the best compromise might be to use the relatime option since programs like Mutt will continue to work, but you will still have a performance boost as the access times will not be updated within 24 hours since the last modification.

Writing to FAT32 as Normal User

To write on a FAT32 partition, you must make a few changes to your /etc/fstab file.

/dev/sdxY    /mnt/some_folder  vfat   user,rw,umask=000              0  0

The user flag means that any user (even non-root) can mount and unmount the partition /dev/sdX. rw gives read-write access; umask option removes selected rights - for example umask=111 remove executable rights. The problem is that this entry removes executable rights from directories too, so we must correct it by dmask=000. See also Umask.

Without these options, all files will be executable. You can use the option showexec instead of the umask and dmask options, which shows all Windows executables (com, exe, bat) in executable colours.

For example, if your FAT32 partition is on /dev/sda9, and you wish to mount it to /mnt/fat32, then you would use:

/dev/sda9    /mnt/fat32        vfat   user,rw,umask=111,dmask=000    0  0

Now, any user can mount it with:

$ mount /mnt/fat32

And unmount it with:

$ umount /mnt/fat32

Remounting the root partition

If for some reason the root partition has been improperly mounted read only, remount the root partition with read-write access with the following command:

# mount -o remount,rw /

bind mounts

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: unfinished section (Discuss in Talk:Fstab#)
Note: Binding a directory to a different location is not recognised by almost any program, so for instance careless commands like rm -r * will also erase any content from the original location. So softlinks should be the preferable way in most cases. If you need permission to a directory on a Btrfs and softlinks are not sufficient its subvolumes faciliate extended capabilities like mount options compared to bind mounting

Sometimes programs or users cannot access one specific directory due to insufficient permissions. One feasable possibility to give the program access to this directory is bind mounting it to a location the program can access. If a program has permission to access directory bar but not to directory foo, under some circumstances the access can be granted without any permission hassle by adding an entry to /etc/fstab:

/<path to foo>         /<path to bar>     none     bind     0 0

See also