Difference between revisions of "Fstab"

From ArchWiki
Jump to: navigation, search
(See also)
m (See also: update link to HTTPS)
(317 intermediate revisions by 80 users not shown)
Line 1: Line 1:
[[Category:File systems (English)]]
+
{{Lowercase title}}
[[Category:HOWTOs (English)]]
+
[[Category:File systems]]
{{i18n_links_start}}
+
[[Category:Boot process]]
{{i18n_entry|English|Fstab}}
+
[[ar:Fstab]]
{{i18n_entry|Español|Fstab (Español)}}
+
[[es:Fstab]]
{{i18n_entry|Русский|fstab (Русский)}}
+
[[fr:Fstab]]
{{i18n_entry|简体中文|fstab (简体中文)}}
+
[[hu:Fstab]]
{{i18n_links_end}}
+
[[it:Fstab]]
The {{Filename|/etc/fstab}} file contains static filesystem information.  It defines how storage devices and partitions are to be initialized and integrated into the overall system.
+
[[ja:Fstab]]
 +
[[ro:Fstab]]
 +
[[ru:Fstab]]
 +
[[zh-hans:Fstab]]
 +
[[zh-hant:Fstab]]
 +
{{Related articles start}}
 +
{{Related|Persistent block device naming}}
 +
{{Related|File systems}}
 +
{{Related|tmpfs}}
 +
{{Related|swap}}
 +
{{Related articles end}}
  
==Field definitions==
+
The {{man|5|fstab}} file can be used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem.
  
A entry has the following fields that are separated by a space or tab:
+
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 {{ic|/etc/fstab}} should work out of the box. See {{man|5|systemd.mount}} for details.
  
<file system> <dir> <type> <options> <dump> <pass>
+
The {{ic|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 systems>''' - defines the storage device (i.e. {{Filename|/dev/sda1}}).
+
== Usage ==
* '''<dir>''' - tells the mount command where it should mount the <file system> to.
 
* '''<type>''' - defines the file system type of the device or partition to be mounted. Many different file systems are supported. Some examples are: ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap, and auto. The 'auto' type lets the mount command to attempt to guess what type of file system is used, this is useful for removable devices such as cdroms and dvds.
 
* '''<options>''' - field.  Options define particular options for filesystems.  Some options relate only to the filesystem itself.  Some of the more common options are:
 
  
:* auto - File system will mount automatically at boot, or when the command 'mount -a' is issued.
+
A simple {{ic|/etc/fstab}}, using kernel name descriptors:
:* noauto - The filesystem is mounted only when you tell it to.
 
:* exec - Allow the execution binaries that are on that partition (default).
 
:* noexec - Do not allow binaries to be executed on the filesystem.
 
:* ro - Mount the filesystem read only
 
:* rw - Mount the filesystem read-write
 
:* sync - I/O should be done synchronously
 
:* async - I/O should be done asynchronously
 
:* user - Permit any user to mount the filesystem (implies noexec,nosuid,nodev unless overridden.)
 
:* nouser - Only allow root to mount the filesystem. (default)
 
:* defaults - Default mount settings (equivalent to rw,suid,dev,exec,auto,nouser,async).
 
:* 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 - Do not update inode access times on the filesystem.
 
:* nodiratime - Do not update directory inode access times on the filesystem.
 
:* 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.)
 
* '''<dump>''' - Is used by the dump utility to decide when to make a backup. When installed (not installed by a standard installation of Arch Linux), 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>''' fsck reads the <pass> number and determines in which order the file systems should 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 get a 2.  File systems with a <pass> value 0 will not be checked by the fsck utility.
 
  
== Example ==
+
{{hc|/etc/fstab|
 +
# <device>            <dir>        <type>    <options>            <dump> <fsck>
 +
/dev/sda1              /            ext4      defaults,noatime      0      1
 +
/dev/sda2              none          swap      defaults              0      0
 +
/dev/sda3              /home        ext4      defaults,noatime      0      2}}
  
Here is an example {{Filename|/etc/fstab}} using kernel naming (/dev/sdx) descriptors:
+
* {{ic|<device>}} describes the block special device or remote filesystem to be mounted; see [[#Identifying filesystems]].
 +
* {{ic|<dir>}} describes the [[mount]] directory, {{ic|<type>}} the [[file system]] type, and {{ic|<options>}} the associated mount options; see {{man|8|mount|FILESYSTEM-INDEPENDENT_MOUNT_OPTIONS}}.
 +
* {{ic|<dump>}} is checked by the {{man|8|dump|url=http://linux.die.net/man/8/dump}} utility. This field is usually set to {{ic|0}}, which disables the check.
 +
* {{ic|<fsck>}} sets the order for filesystem checks at boot time; see {{man|8|fsck}}. For the root device it should be {{ic|1}}. For other partitions it should be {{ic|2}}, or {{ic|0}} to disable checking.
  
# <file system>        <dir>        <type>    <options>            <dump> <pass>
+
{{Tip|The {{ic|auto}} type lets the mount command guess what type of file system is used. This is useful for optical media (CD/DVD).}}
none                  /dev/pts      devpts    defaults                0      0
+
{{Note|If the root file system is [[btrfs]], the fsck order should be set to {{ic|0}} instead of {{ic|1}}.}}
none                  /dev/shm      tmpfs    defaults                0      0
 
 
/dev/cdrom            /media/cd    iso9660  ro,user,noauto,unhide  0      0
 
/dev/dvd              /media/dvd    udf      ro,user,noauto,unhide  0      0
 
/dev/fd0              /media/fl    auto      user,noauto            0      0
 
 
/dev/sda2              /            ext4      defaults,noatime        0      1
 
/dev/sda6              /home        ext4      defaults,noatime        0      2
 
/dev/sda7              swap          swap      defaults                0      0
 
  
== Defining filesystems ==
+
All specified devices within {{ic|/etc/fstab}} will be automatically mounted on startup and when the {{ic|-a}} flag is used with {{man|8|mount}} unless the {{ic|noauto}} option is specified. Devices that are listed and not present will result in an error unless the {{ic|nofail}} option is used.
  
You can define the filesystems in the {{Filename|/etc/fstab}} configuration in three different ways: by kernel naming descriptors, by UUID, or by labels.  The advantage of using UUIDs or labels is that they are not dependent on disk order.  This is useful if you change your storage device order in the BIOS, you switch storage device cabling, or because some BIOS's may occasionally change the order of storage devices.
+
See {{man|5|fstab|DESCRIPTION}} for details.
  
=== Kernel naming ===
+
== Identifying filesystems ==
  
You can get kernel naming descriptors using {{Codeline|fdisk}}:
+
There are different ways to identify filesystems that will be mounted in {{ic|/etc/fstab}}: 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.
  
<pre>
+
In this section, we will describe how to mount filesystems using all the mount methods available via examples. The output of the commands {{ic|lsblk -f}} and {{ic|blkid}} used in the following examples are available in the article [[Persistent block device naming]].
# fdisk -l
+
 
...
+
To use kernel name descriptors, use /dev/sd''xy'' in the first column.  
 
+
 
Device Boot     Start        End      Blocks  Id  System
+
=== Kernel name descriptors ===
/dev/sda1  *          1       2550    20482843+  b  W95 FAT32
+
 
/dev/sda2           2551        5100    20482875   83  Linux
+
Run {{ic|lsblk -f}} to list the partitions and prefix the values in the ''NAME'' column with {{ic|/dev/}}.
/dev/sda3           5101        7650    20482875   83  Linux
+
 
/dev/sda4           7651     121601  915311407+  5  Extended
+
{{hc|/etc/fstab|<nowiki>
/dev/sda5            7651      10200    20482843+  83  Linux
+
# <device>     <dir> <type> <options>                                                                                            <dump> <fsck>
/dev/sda6          10201       17849    61440561   83  Linux
+
/dev/sda1       /boot vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0      2
/dev/sda7          17850      18104     2048256   82  Linux swap / Solaris
+
/dev/sda2       /    ext4   rw,relatime,discard,data=ordered                                                                    0      1
/dev/sda8          18105      18113      72261   83  Linux
+
/dev/sda3       /home ext4   rw,relatime,discard,data=ordered                                                                    0      2
/dev/sda9          18114     121601   831267328+  7  HPFS/NTFS
+
/dev/sda4       none  swap  defaults                                                                                            0     0
</pre>
+
</nowiki>}}
 +
 
 +
=== Labels ===
 +
 
 +
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''LABEL'' column with {{ic|1=LABEL=}}:
 +
 
 +
{{hc|/etc/fstab|<nowiki>
 +
# <device>      <dir> <type> <options>                                                                                            <dump> <fsck>
 +
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
 +
</nowiki>}}
 +
 
 +
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}
  
 
=== UUIDs ===
 
=== UUIDs ===
  
UUIDs are generated by the make-filesystem utilities ({{Codeline|mkfs.*}}) when you create a filesystem. {{Codeline|blkid}} will show you the UUIDs of mounted devices and partitions:
+
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''UUID'' column with {{ic|1=UUID=}}:
 +
 
 +
{{hc|/etc/fstab|<nowiki>
 +
# <device>                                <dir> <type> <options>                                                                                            <dump> <fsck>
 +
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
 +
</nowiki>}}
 +
 
 +
{{Tip|If you would like to return just the UUID of a specific partition: {{ic|lsblk -no UUID /dev/sda2}}.}}
 +
 
 +
=== GPT labels ===
 +
Run {{ic|blkid}} to list the partitions, and use the ''PARTLABEL'' values without the quotes:
 +
 
 +
{{hc|/etc/fstab|<nowiki>
 +
# <device>                          <dir> <type> <options>                                                                                            <dump> <fsck>
 +
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
 +
</nowiki>}}
 +
 
 +
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}
 +
 
 +
=== GPT UUIDs ===
 +
 
 +
Run {{ic|blkid}} to list the partitions, and use the ''PARTUUID'' values without the quotes:
 +
 
 +
{{hc|/etc/fstab|<nowiki>
 +
# <device>                                    <dir> <type> <options>                                                                                            <dump> <fsck>
 +
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
 +
</nowiki>}}
 +
 
 +
== Tips and tricks ==
 +
 
 +
=== Automount with systemd ===
 +
 
 +
If you have a large {{ic|/home}} partition, it might be better to allow services that do not depend on {{ic|/home}} to start while {{ic|/home}} is checked by ''fsck''. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition:
 +
 
 +
noauto,x-systemd.automount
 +
 
 +
This will fsck and mount {{ic|/home}} when it is first accessed, and the kernel will buffer all file access to {{ic|/home}} until it is ready.
 +
 
 +
{{Note|This will make your {{ic|/home}} filesystem type {{ic|autofs}}, which is ignored by [[mlocate]] by default. The speedup of automounting {{ic|/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 {{ic|noauto,x-systemd.automount}} parameters. In addition, you can use the {{ic|1=x-systemd.device-timeout=#}} option to specify a timeout in case the network resource is not available.
 +
 
 +
{{Note|1=If you intend to use the {{ic|exec}} flag with automount, you should remove the {{ic|user}} flag for it to work properly as found in the course of a [https://bugzilla.redhat.com/show_bug.cgi?id=769636 Fedora Bug Report]}}
  
<pre>
+
If you have encrypted filesystems with keyfiles, you can also add the {{ic|noauto}} parameter to the corresponding entries in {{ic|/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:
# blkid
 
/dev/sda1: UUID="76E4F702E4F6C401" LABEL="vista" TYPE="ntfs"
 
/dev/sda2: LABEL="Root" UUID="24f28fc6-717e-4bcd-a5f7-32b959024e26" TYPE="ext4"
 
/dev/sda6: LABEL="Home" UUID="03ec5dd3-45c0-4f95-a363-61ff321a09ff" TYPE="ext4"
 
/dev/sda7: LABEL="swap" UUID="4209c845-f495-4c43-8a03-5363dd433153" TYPE="swap"
 
/dev/sda10: UUID="0ea7a93f-537c-4868-9201-0dc090c050e4" TYPE="crypto_LUKS"
 
/dev/mapper/sda10: UUID="d3560bbb-b5d5-46c5-a7a8-434c885217c7" UUID_SUB="425ab275-d520-4636-8d16-55fb2b957971" TYPE="btrfs"
 
</pre>
 
  
An example {{Filename|/etc/fstab}} using the UUID identifiers:
+
{{hc|/etc/crypttab|
 +
data /dev/md0 /root/key noauto}}
  
<pre>
+
You may also specify an idle timeout for a mount with the {{ic|x-systemd.idle-timeout}} flag.  For example:
# <file system>        <dir>        <type>    <options>            <dump> <pass>
 
none                  /dev/pts      devpts    defaults                0      0
 
none                  /dev/shm      tmpfs    defaults                0      0
 
  
/dev/cdrom            /media/cd    iso9660  ro,user,noauto,unhide  0      0
+
noauto,x-systemd.automount,x-systemd.idle-timeout=1min
/dev/dvd              /media/dvd    udf      ro,user,noauto,unhide  0      0
 
/dev/fd0              /media/fl    auto      user,noauto            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 swap  swap defaults          0      0
 
</pre>
 
  
=== Labels ===
+
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 {{ic|nofail}} option. This prevents errors being reported at boot. For example:
 +
 
 +
{{hc|/etc/fstab|2=
 +
/dev/sdg1        /media/backup    jfs    defaults,nofail,x-systemd.device-timeout=1    0  2}}
 +
 
 +
The {{ic|nofail}} option is best combined with the {{ic|x-systemd.device-timeout}} option. This is because the default device timeout is 90 seconds, so a disconnected external device with only {{ic|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 {{ic|1=x-systemd.requires=x}} combined with {{ic|x-systemd.automount}}to postpone automounting until after the unit is available. For example:
 +
 
 +
{{hc|/etc/fstab|2=
 +
//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 {{ic|fstab}} to delimit fields, if any field (''PARTLABEL'', ''LABEL'' or the mount point) contains spaces, these spaces must be replaced by escape characters {{ic|\}} followed by the 3 digit octal code {{ic|040}}:
 +
 
 +
{{hc|/etc/fstab|2=
 +
UUID=47FA-4071    /home/username/Camera<font color="grey">\040</font>Pictures  vfat  defaults,noatime      0  0
 +
/dev/sda7          /media/100<font color="grey">\040</font>GB<font color="grey">\040</font>(Storage)      ext4  defaults,noatime,user  0  2
 +
}}
 +
 
 +
=== atime options ===
 +
 
 +
Below atime options can impact drive performance.
 +
 
 +
* The {{ic|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 {{ic|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 {{ic|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 {{ic|nodiratime}} option disables the writing of file access times only for directories while other files still get access times written.
 +
: {{Note|{{ic|noatime}} implies {{ic|nodiratime}}. [http://lwn.net/Articles/244941/ You do not need to specify both].}}
 +
 
 +
* {{ic|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 {{ic|defaults}} option, {{ic|atime}} option (which means to use the kernel default, which is {{ic|relatime}}; see {{man|8|mount}} and [[wikipedia:Stat (system call)#Criticism of atime]]) or no options at all are specified.
 +
 
 +
When using [[Mutt]] or other applications that need to know if a file has been read since the last time it was modified, the {{ic|noatime}} option should not be used; using the {{ic|relatime}} option is acceptable and still provides a performance improvement.
  
The device or partition will need to be labeled first.  You can use a common application like {{Package Official|gparted}} to label partitions (not all filesystem types support labels however) or you can use {{Codeline|e2label}} to label ext2, ext3, and ext4 partitions.
+
Since kernel 4.0 there is another related option:
  
To label a device or partition it can not be mounted (needs source). Boot from a LiveCD or LiveUSB then you can label by:
+
* {{ic|lazytime}} reduces writes to disk by maintaining changes to inode timestamps (access, modification and creation times) only in memory. The on-disk timestamps are updated only when either (1) the file inode needs to be updated for some change unrelated to file timestamps, (2) a sync to disk occurs, (3) an undeleted inode is evicted from memory or (4) if more than 24 hours passed since the the last time the in-memory copy was written to disk.
 +
: {{Warning|In the event of a system crash, the access and modification times on disk might be out of date by up to 24 hours.}}
  
e2label /dev/sda6 Arch_Linux
+
Note that the {{ic|lazytime}} option works '''in combination''' with the aforementioned {{ic|*atime}} options, not as an alternative. That is {{ic|relatime}} by default, but can be even {{ic|strictatime}} with the same or less cost of disk writes as the plain {{ic|relatime}} option.
  
Labels can be up to 16 characters long.  They can also have spaces too, but there is no way to have your {{Filename|fstab}} file (or [[GRUB]] configuration file for that matter) be able to recognize them by that label if you do.
+
=== Remounting the root partition ===
  
Labels should be un-ambiguous.  That is that each label needs to be unique in order to not cause any conflicts.  Devices and partitions can be labeled and used as identifiers by:
+
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:
  
<pre>
+
# mount -o remount,rw /
# <file system>        <dir>        <type>    <options>            <dump> <pass>
 
none                  /dev/pts      devpts    defaults                0      0
 
none                  /dev/shm      tmpfs    defaults                0      0
 
 
/dev/cdrom            /media/cd    iso9660  ro,user,noauto,unhide  0      0
 
/dev/dvd              /media/dvd    udf      ro,user,noauto,unhide  0      0
 
/dev/fd0              /media/fl    auto      user,noauto            0      0
 
 
LABEL=Arch_Linux      /            ext4      defaults,noatime        0      1
 
LABEL=Arch_Swap        swap          swap      defaults                0      0
 
</pre>
 
  
== Resources ==
+
== See also ==
  
* [[Writing on a FAT32 partition as a normal user]]
+
* [http://www.kernel.org/pub/linux/docs/lanana/device-list/devices-2.6.txt Full device listing including block device]
* [[NTFS Write Support]]
+
* [http://www.pathname.com/fhs/2.2/index.html Filesystem Hierarchy Standard]
* [http://ubuntuforums.org/showthread.php?t=283131 how to fstab]
+
* [https://www.askapache.com/optimize/super-speed-secrets/ 30x Faster Cache and Site Speed with TMPFS]
* [[Persistent block device naming]]
+
* [[Samba#As_mount_entry|Adding Samba shares to /etc/fstab]]

Revision as of 12:59, 28 October 2017

The fstab(5) 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 systemd.mount(5) 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.

Usage

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

/etc/fstab
# <device>             <dir>         <type>    <options>             <dump> <fsck>
/dev/sda1              /             ext4      defaults,noatime      0      1
/dev/sda2              none          swap      defaults              0      0
/dev/sda3              /home         ext4      defaults,noatime      0      2
  • <device> describes the block special device or remote filesystem to be mounted; see #Identifying filesystems.
  • <dir> describes the mount directory, <type> the file system type, and <options> the associated mount options; see mount(8).
  • <dump> is checked by the dump(8) utility. This field is usually set to 0, which disables the check.
  • <fsck> sets the order for filesystem checks at boot time; see fsck(8). For the root device it should be 1. For other partitions it should be 2, or 0 to disable checking.
Tip: The auto type lets the mount command guess what type of file system is used. This is useful for optical media (CD/DVD).
Note: If the root file system is btrfs, the fsck order should be set to 0 instead of 1.

All specified devices within /etc/fstab will be automatically mounted on startup and when the -a flag is used with mount(8) unless the noauto option is specified. Devices that are listed and not present will result in an error unless the nofail option is used.

See fstab(5) for details.

Identifying filesystems

There are different ways to identify filesystems that will be mounted in /etc/fstab: 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.

To use kernel name descriptors, use /dev/sdxy in the first column.

Kernel name descriptors

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

/etc/fstab
# <device>      <dir> <type> <options>                                                                                            <dump> <fsck>
/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

Labels

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

/etc/fstab
# <device>      <dir> <type> <options>                                                                                            <dump> <fsck>
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.

UUIDs

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

/etc/fstab
# <device>                                <dir> <type> <options>                                                                                            <dump> <fsck>
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:

/etc/fstab
# <device>                           <dir> <type> <options>                                                                                            <dump> <fsck>
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.

GPT UUIDs

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

/etc/fstab
# <device>                                    <dir> <type> <options>                                                                                            <dump> <fsck>
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:

noauto,x-systemd.automount

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:

/etc/crypttab
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:

noauto,x-systemd.automount,x-systemd.idle-timeout=1min

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:

/etc/fstab
/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:

/etc/fstab
//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:

/etc/fstab
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 implies 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 mount(8) and wikipedia:Stat (system call)#Criticism of atime) or no options at all are specified.

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 option is acceptable and still provides a performance improvement.

Since kernel 4.0 there is another related option:

  • lazytime reduces writes to disk by maintaining changes to inode timestamps (access, modification and creation times) only in memory. The on-disk timestamps are updated only when either (1) the file inode needs to be updated for some change unrelated to file timestamps, (2) a sync to disk occurs, (3) an undeleted inode is evicted from memory or (4) if more than 24 hours passed since the the last time the in-memory copy was written to disk.
Warning: In the event of a system crash, the access and modification times on disk might be out of date by up to 24 hours.

Note that the lazytime option works in combination with the aforementioned *atime options, not as an alternative. That is relatime by default, but can be even strictatime with the same or less cost of disk writes as the plain relatime option.

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 /

See also