Difference between revisions of "Fstab"

From ArchWiki
Jump to: navigation, search
m (dev name in text had 'hd...' instead of 'sd...', as used in examples.)
m (atime options: improve wording (re-apply the only sensible part of the last edit))
 
(129 intermediate revisions by 42 users not shown)
Line 2: Line 2:
 
[[Category:File systems]]
 
[[Category:File systems]]
 
[[Category:Boot process]]
 
[[Category:Boot process]]
 +
[[ar:Fstab]]
 
[[es:Fstab]]
 
[[es:Fstab]]
 +
[[hu:Fstab]]
 
[[it:Fstab]]
 
[[it:Fstab]]
 +
[[ja:Fstab]]
 
[[ro:Fstab]]
 
[[ro:Fstab]]
 
[[ru:Fstab]]
 
[[ru:Fstab]]
 
[[zh-CN:Fstab]]
 
[[zh-CN:Fstab]]
 
[[zh-TW:Fstab]]
 
[[zh-TW:Fstab]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|This article explains how to configure and use fstab.}}
+
{{Related|Persistent block device naming}}
{{Article summary heading|Related}}
+
{{Related|File systems}}
{{Article summary wiki|Persistent block device naming}}
+
{{Related|Mount}}
{{Article summary wiki|NTFS Write Support}}
+
{{Related|tmpfs}}
{{Article summary wiki|Firefox Ramdisk}}
+
{{Related|swap}}
{{Article summary wiki|Boot Debugging}}
+
{{Related articles end}}
{{Article summary wiki|udev}}
+
{{Article summary end}}
+
  
The [[Wikipedia:Fstab|/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 {{ic|mount}} command to determine which options to use when mounting a specific device or partition.
+
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.
  
== File example ==
+
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.
  
A simple {{ic|/etc/fstab}}, using kernel name descriptors:
+
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.
  
{{hc|/etc/fstab|
+
== Usage ==
# <file system>        <dir>        <type>    <options>            <dump> <pass>
+
  
tmpfs                  /tmp          tmpfs    nodev,nosuid          0      0
+
A simple {{ic|/etc/fstab}}, using kernel name descriptors:
  
 +
{{hc|/etc/fstab|
 +
# <device>            <dir>        <type>    <options>            <dump> <fsck>
 
/dev/sda1              /            ext4      defaults,noatime      0      1
 
/dev/sda1              /            ext4      defaults,noatime      0      1
 
/dev/sda2              none          swap      defaults              0      0
 
/dev/sda2              none          swap      defaults              0      0
 
/dev/sda3              /home        ext4      defaults,noatime      0      2}}
 
/dev/sda3              /home        ext4      defaults,noatime      0      2}}
  
== Field definitions ==
+
* {{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.
 +
* {{ic|<fsck>}} sets the order for filesystem checks at boot time; see {{man|8|fsck}}.
  
The {{ic|/etc/fstab}} file contains the following fields separated by a space or tab:
+
{{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).}}
 +
{{Note|If the root file system is [[btrfs]], the fsck order should be set to {{ic|0}} instead of {{ic|1}}.}}
  
  <file system>        <dir>        <type>    <options>            <dump> <pass>
+
See {{man|5|fstab|DESCRIPTION}} for details.
  
* '''<file system>''' - the partition or storage device to be mounted.
+
== Identifying filesystems ==
* '''<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: {{ic|ext2}}, {{ic|ext3}}, {{ic|ext4}}, {{ic|reiserfs}}, {{ic|xfs}}, {{ic|jfs}}, {{ic|smbfs}}, {{ic|iso9660}}, {{ic|vfat}}, {{ic|ntfs}}, {{ic|swap}} and {{ic|auto}}. The {{ic|auto}} type lets the mount command guess what type of file system is used. This is useful for optical media (CD/DVD).
+
* '''<options>''' - mount options of the filesystem to be used. Note that some [http://linux.die.net/man/8/mount mount options] are filesystem specific. Some of the most common options are:
+
  
:* {{ic|auto}} - Mount automatically at boot, or when the command {{ic|mount -a}} is issued.
+
There are different ways to identify filesystems that will be mounted. {{ic|/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.
:* {{ic|noauto}} - Mount only when you tell it to.
+
:* {{ic|exec}} - Allow execution of binaries on the filesystem.
+
:* {{ic|noexec}} - Disallow execution of binaries on the filesystem.
+
:* {{ic|ro}} - Mount the filesystem read-only.
+
:* {{ic|rw}} - Mount the filesystem read-write.
+
:* {{ic|user}} - Allow any user to mount the filesystem. This automatically implies {{ic|noexec}}, {{ic|nosuid}}, {{ic|nodev}}, unless overridden.
+
:* {{ic|users}} - Allow any user in the users group to mount the filesystem.
+
:* {{ic|nouser}} - Allow only root to mount the filesystem.
+
:* {{ic|owner}} - Allow the owner of device to mount.
+
:* {{ic|sync}} - I/O should be done synchronously.
+
:* {{ic|async}} - I/O should be done asynchronously.
+
:* {{ic|dev}} - Interpret block special devices on the filesystem.
+
:* {{ic|nodev}} - Don't interpret block special devices on the filesystem.
+
:* {{ic|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.
+
:* {{ic|nosuid}} - Block the operation of suid, and sgid bits.
+
:* {{ic|noatime}} - Don't update inode access times on the filesystem. Can help performance (see [[#atime_options|atime options]]).
+
:* {{ic|nodiratime}} - Do not update directory inode access times on the filesystem. Can help performance (see [[#atime_options|atime options]]).
+
:* {{ic|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 [[fstab#atime_options|atime options]]).
+
:* {{ic|flush}} - The {{ic|vfat}} option to flush data more often, thus making copy dialogs or progress bars to stay up until all data is written.
+
:* {{ic|defaults}} - the default mount options for the filesystem to be used. The default options for {{ic|ext4}} are: {{ic|rw}}, {{ic|suid}}, {{ic|dev}}, {{ic|exec}}, {{ic|auto}}, {{ic|nouser}}, {{ic|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.
+
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]]. If you have not read that article yet, please read it now.
  
* '''<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.
+
=== Kernel name descriptors ===
  
== Identifying filesystems ==
+
Run {{ic|lsblk -f}} to list the partitions and prefix the values in the ''NAME'' column with {{ic|/dev/}}.
  
There are three ways to identify a partition or storage device in {{ic|/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 order in which the drives are (physically) connected to the machine. 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.
+
{{hc|/etc/fstab|<nowiki>
 +
# <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
 +
</nowiki>}}
  
To list basic information about the partitions, run:
+
=== Labels ===
  
{{hc|$ lsblk -f|
+
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''LABEL'' column with {{ic|1=LABEL=}}:
NAME  FSTYPE LABEL     UUID                                MOUNTPOINT
+
sda                                                         
+
├─sda1 ext4  Arch_Linux 978e3e81-8048-4ae1-8a06-aa727458e8ff /
+
├─sda2 ntfs  Windows    6C1093E61093B594                   
+
└─sda3 ext4  Storage    f838b24e-3a66-4d02-86f4-a2e73e454336 /media/Storage
+
sdb                                                         
+
├─sdb1 ntfs  Games      9E68F00568EFD9D3                   
+
└─sdb2 ext4  Backup    14d50a6c-e083-42f2-b9c4-bc8bae38d274 /media/Backup
+
sdc                                                         
+
└─sdc1 vfat  Camera    47FA-4071                            /media/Camera}}
+
  
=== Kernel name ===
+
{{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>}}
  
Run {{ic|lsblk -f}} to list the partitions, and prefix them with {{ic|/dev}}.
+
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}
  
See the [[#File_example|example]].
+
=== UUIDs ===
  
=== Label ===
+
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''UUID'' column with {{ic|1=UUID=}}:
  
{{Note|Each label should be unique, to prevent any possible conflicts.}}
+
{{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>}}
  
To label a device or partition, see [[Persistent_block_device_naming|this]] article. You can also install and use {{Pkg|gparted}}, but renaming the root partition would have to be done from a "live" Linux distribution (Parted Magic, Ubuntu, etc) because the partition needs to be unmounted first.
+
{{Tip|If you would like to return just the UUID of a specific partition:
 +
$ lsblk -no UUID /dev/sda2}}
  
Run {{ic|lsblk -f}} to list the partitions, and prefix them with {{ic|1=LABEL=}} :
+
=== GPT labels ===
 +
Run {{ic|blkid}} to list the partitions, and use the ''PARTLABEL'' values without the quotes:
  
{{hc|/etc/fstab|2=
+
{{hc|/etc/fstab|<nowiki>
# <file system>       <dir>         <type>   <options>             <dump> <pass>
+
# <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>}}
  
tmpfs                  /tmp          tmpfs    nodev,nosuid          0      0
+
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}
+
LABEL=Arch_Linux      /            ext4      defaults,noatime      0      1
+
LABEL=Arch_Swap        none          swap      defaults              0      0}}
+
  
=== UUID ===
+
=== GPT UUIDs ===
  
All partitions and devices have a unique UUID. They are generated by filesystem utilities (e.g. {{ic|mkfs.*}}) when you create or format a partition.
+
Run {{ic|blkid}} to list the partitions, and use the ''PARTUUID'' values without the quotes:
  
Run {{ic|lsblk -f}} to list the partitions, and prefix them with {{ic|1=UUID=}} :
+
{{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>}}
  
{{Tip|If you would like to return just the UUID of a specific partition:
+
== Tips and tricks ==
$ lsblk -no UUID /dev/sda2
+
}}
+
  
{{hc|/etc/fstab|2=
+
=== Automount with systemd ===
# <file system>                            <dir>    <type>    <options>            <dump> <pass>
+
  
tmpfs                                      /tmp      tmpfs    nodev,nosuid          0      0
+
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:
  
UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26 /        ext4      defaults,noatime      0      1
+
  noauto,x-systemd.automount
UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff  /home    ext4      defaults,noatime      0      2
+
UUID=4209c845-f495-4c43-8a03-5363dd433153  none      swap      defaults              0      0}}
+
  
== Tips and tricks ==
+
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.
  
=== Swap UUID ===
+
{{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.}}
  
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 {{ic|lsblk -f}} command. Here are some steps to assign a UUID to your swap:
+
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.
  
Identify the swap partition:
+
{{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]}}
  
# swapon -s
+
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:
  
Disable the swap:
+
{{hc|/etc/crypttab|
 +
data /dev/md0 /root/key noauto}}
  
  # swapoff /dev/sda7
+
You may also specify an idle timeout for a mount with the {{ic|x-systemd.idle-timeout}} flag. For example:
  
Recreate the swap with a new UUID assigned to it:
+
noauto,x-systemd.automount,x-systemd.idle-timeout=1min
  
# mkswap -U random /dev/sda7
+
This will make systemd unmount the mount after it has been idle for 1 minute.
  
Activate the swap:
+
=== External devices ===
  
# swapon /dev/sda7
+
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:
  
=== Filepath spaces ===
+
{{hc|/etc/fstab|2=
 +
/dev/sdg1        /media/backup    jfs    defaults,nofail,x-systemd.device-timeout=1    0  2}}
  
If any mountpoint contains spaces, use the escape character {{ic|\}} followed by the 3 digit octal code {{ic|040}} to emulate them:
+
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=
 
{{hc|/etc/fstab|2=
UUID=47FA-4071    /home/username/Camera<font color="grey">\040</font>Pictures  vfat  defaults,noatime      0  0
+
//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}}
/dev/sda7          /media/100<font color="grey">\040</font>GB<font color="grey">\040</font>(Storage)      ext4  defaults,noatime,user  0 2}}
+
  
=== External devices ===
+
=== Filepath spaces ===
  
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.
+
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|
+
{{hc|/etc/fstab|2=
/dev/sdg1        /media/backup    jfs    defaults,nofail    0  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 ===
 
=== atime options ===
  
The use of {{ic|noatime}}, {{ic|nodiratime}} or {{ic|relatime}} can improve drive performance. Linux by default uses {{ic|atime}}, which keeps a record (writes to the drive) every time it reads anything. This is more purposeful when Linux is used for servers; it doesn't have much value for desktop use. The worst thing about the default {{ic|atime}} option is that even reading a file from the page cache (reading from memory instead of the drive) will still result in a write! Using 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 a rare few like [[Mutt]] that need the such information. For mutt, you should only use the {{ic|relatime}} option. Using the {{ic|relatime}} option enables the writing of file access times only when the file is being modified (unlike {{ic|noatime}} where the file access time will never be changed and will be older than the modification time). The {{ic|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 {{ic|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.
+
Below atime options can impact drive performance.
  
{{Note|{{ic|noatime}} already includes {{ic|nodiratime}}. You do not need to specify both.[http://lwn.net/Articles/244941/ ]}}
+
* 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!
  
=== tmpfs ===
+
* 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.
  
[[Wikipedia: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.
+
* 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].}}
  
Some directories where tmpfs is commonly used are [http://www.pathname.com/fhs/2.2/fhs-3.15.html /tmp], [http://www.pathname.com/fhs/2.2/fhs-5.9.html /var/lock] and [http://www.pathname.com/fhs/2.2/fhs-5.13.html /var/run]. Do NOT use it on [http://www.pathname.com/fhs/2.2/fhs-5.15.html /var/tmp], because that folder is meant for temporary files that are preserved across reboots. Arch uses a tmpfs {{ic|/run}} directory, with {{ic|/var/run}} and {{ic|/var/lock}} simply existing as symlinks for compatibility. It is also used for {{ic|/tmp}} in the default {{ic|/etc/fstab}}.
+
* {{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.
  
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 do not consume any memory until it is actually needed.
+
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.
  
To use tmpfs for {{ic|/tmp}}, add this line to {{ic|/etc/fstab}}:
+
Since kernel 4.0 there is another related option:
  
{{hc|/etc/fstab|
+
* {{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.
tmpfs  /tmp        tmpfs  nodev,nosuid                  0  0}}
+
: {{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.}}
  
You may or may not want to specify the size here, but you should leave the {{ic|mode}} option alone in these cases to ensure that they have the correct permissions (1777). In the example above, {{ic|/tmp}} will be set to use up to half of your total RAM. To explicitly set a maximum size, use the {{ic|size}} mount option:
+
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.
  
{{hc|/etc/fstab|2=
+
=== Writing to FAT32 as Normal User ===
tmpfs  /tmp        tmpfs  nodev,nosuid,size=2G          0  0}}
+
  
Here is a more advanced example showing how to add tmpfs mounts for users. This is useful for websites, mysql tmp files, {{ic|~/.vim/}}, and more. It's important to try and get the ideal mount options for what you are trying to accomplish. The goal is to have as secure settings as possible to prevent abuse. Limiting the size, and specifying uid and gid + mode is very secure. [[#See_also|More info]].
+
To write on a FAT32 partition, you must make a few changes to your {{ic|/etc/fstab}} file.
  
 
{{hc|/etc/fstab|2=
 
{{hc|/etc/fstab|2=
tmpfs  /www/cache   tmpfs rw,size=1G,nr_inodes=5k,noexec,nodev,nosuid,uid=648,gid=648,mode=1700  0  0}}
+
/dev/sdxY   /mnt/some_folder vfat  '''user''',rw,umask=000              0  0}}
  
See the {{ic|mount}} command man page for more information. One useful mount option in the man page is the {{ic|default}} option. At least understand that.
+
The {{ic|user}} flag means that any user (even non-root) can mount and unmount the partition {{ic|/dev/sdX}}. {{ic|rw}} gives read-write access;
 +
{{ic|umask}} option removes selected rights - for example {{ic|1=umask=111}} remove executable rights. The problem is that this entry removes executable rights from directories too, so we must correct it by {{ic|1=dmask=000}}. See also [[Umask]].
  
Reboot for the changes to take effect. Note that although it may be tempting to simply run {{ic|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 {{ic|mount -a}} instead of rebooting (or mount them individually).
+
Without these options, all files will be executable. You can use the option {{ic|showexec}} instead of the umask and dmask options, which shows all Windows executables (com, exe, bat) in executable colours.
  
After applying changes, you may want to verify that they took effect by looking at {{ic|/proc/mounts}} and using {{ic|findmnt}}:
+
For example, if your FAT32 partition is on {{ic|/dev/sda9}}, and you wish to mount it to {{ic|/mnt/fat32}}, then you would use:
  
{{hc|$ findmnt --target /tmp|
+
{{hc|/etc/fstab|2=
TARGET SOURCE FSTYPE OPTIONS
+
/dev/sda9    /mnt/fat32        vfat   '''user''',rw,umask=111,dmask=000    0  0}}
/tmp   tmpfs  tmpfs  rw,nosuid,nodev,relatime}}
+
  
==== Usage ====
+
Now, any user can mount it with:
  
Generally, I/O intensive tasks and programs that run frequent read/write operations can benefit from using a tmpfs folder. Some applications can even receive a substantial gain by offloading some (or all) of their data onto the shared memory. For example, [[Firefox_Ramdisk|relocating the Firefox profile into RAM]] shows a significant improvement in performance.
+
$ mount /mnt/fat32
  
===== Improving compile times =====
+
And unmount it with:
  
{{Note|The tmpfs folder ({{ic|/tmp}}, in this case) needs to be mounted without {{ic|noexec}}, else it will prevent build scripts or utilities from being executed. Also, as stated [[#tmpfs|above]], the default size is half of the available RAM. You may run out of space.}}
+
$ umount /mnt/fat32
  
You can run [[makepkg]] with a tmpfs folder for the build directory (which is also a setting in {{ic|/etc/makepkg.conf}}):
+
=== Remounting the root partition ===
  
$ BUILDDIR=/tmp/makepkg makepkg
+
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:
  
=== Writing to FAT32 as Normal User ===
+
# mount -o remount,rw /
  
To write on a FAT32 partition, you must make a few changes to your {{ic|/etc/fstab}} file.
+
=== bind mounts ===
  
{{hc|/etc/fstab|2=
+
{{Expansion|unfinished section}}
/dev/sdxY    /mnt/some_folder  vfat  user,rw,umask=000              0  0}}
+
  
The {{ic|user}} flag means that any user (even non-root) can mount and unmount the partition {{ic|/dev/sdX}}. {{ic|rw}} gives read-write access; {{ic|umask}} option removes selected rights - for example {{ic|1=umask=111}} remove executable rights. The problem is that this entry removes executable rights from directories too, so we must correct it by {{ic|1=dmask=000}}.
+
{{Note|Binding a directory to a different location is not recognised by almost any program, so for instance careless commands like {{ic|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 [[Btrfs#Subvolumes|subvolumes]] faciliate extended capabilities like mount options compared to bind mounting}}
And why using these options? Without these options all files will be executable. You can use the option {{ic|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 {{ic|/dev/sda9}}, and you wish to mount it to {{ic|/mnt/fat32}}, then you would use:
+
  
 +
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 {{ic|/etc/fstab}}:
 
{{hc|/etc/fstab|2=
 
{{hc|/etc/fstab|2=
/dev/sda9    /mnt/fat32        vfat  user,rw,umask=111,dmask=000    0 0}}
+
/<path to foo>        /<path to bar>    none    bind    0 0}}
  
 
== See also ==
 
== See also ==
  
*[http://www.kernel.org/pub/linux/docs/lanana/device-list/devices-2.6.txt Full device listing including block device]
+
* [http://www.kernel.org/pub/linux/docs/lanana/device-list/devices-2.6.txt Full device listing including block device]
*[http://www.pathname.com/fhs/2.2/index.html Filesystem Hierarchy Standard]
+
* [http://www.pathname.com/fhs/2.2/index.html Filesystem Hierarchy Standard]
*[http://www.askapache.com/web-hosting/super-speed-secrets.html 30x Faster Web-Site Speed] (Detailed tmpfs)
+
* [http://www.askapache.com/web-hosting/super-speed-secrets.html 30x Faster Web-Site Speed] (Detailed tmpfs)
 +
* [[Samba#Add Share to /etc/fstab|Adding Samba shares to /etc/fstab]]

Latest revision as of 19:51, 7 August 2016

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.
  • <fsck> sets the order for filesystem checks at boot time; see fsck(8).
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.

See fstab(5) for details.

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/.

/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.

Writing to FAT32 as Normal User

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

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

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

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

See also