https://wiki.archlinux.org/api.php?action=feedcontributions&user=Pob&feedformat=atomArchWiki - User contributions [en]2024-03-28T12:19:55ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Fstab&diff=412945Fstab2015-12-20T22:17:34Z<p>Pob: /* External devices */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:File systems]]<br />
[[Category:Boot process]]<br />
[[ar:Fstab]]<br />
[[es:Fstab]]<br />
[[hu:Fstab]]<br />
[[it:Fstab]]<br />
[[ja:Fstab]]<br />
[[ro:Fstab]]<br />
[[ru:Fstab]]<br />
[[zh-CN:Fstab]]<br />
[[zh-TW:Fstab]]<br />
{{Related articles start}}<br />
{{Related|Persistent block device naming}}<br />
{{Related|File systems}}<br />
{{Related|Mount}}<br />
{{Related|tmpfs}}<br />
{{Related articles end}}<br />
<br />
The [[Wikipedia:Fstab|/etc/fstab]] file can be used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem.<br />
<br />
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 {{ic|man 5 systemd.mount}} for details.<br />
<br />
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.<br />
<br />
== File example ==<br />
<br />
A simple {{ic|/etc/fstab}}, using kernel name descriptors:<br />
<br />
{{hc|/etc/fstab|<br />
# <file system> <dir> <type> <options> <dump> <pass><br />
/dev/sda1 / ext4 defaults,noatime 0 1<br />
/dev/sda2 none swap defaults 0 0<br />
/dev/sda3 /home ext4 defaults,noatime 0 2}}<br />
<br />
== Field definitions ==<br />
<br />
Each line in the {{ic|/etc/fstab}} file contains the following fields separated by spaces or tabs:<br />
<br />
''file_system'' ''dir'' ''type'' ''options'' ''dump'' ''pass''<br />
<br />
;''file system''<br />
:The partition or storage device to be mounted.<br />
;''dir''<br />
:The mountpoint where <file system> is mounted to.<br />
;''type''<br />
: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|btrfs}}, {{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).<br />
;''options''<br />
:Mount options of the filesystem to be used. See the [http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-INDEPENDENT_MOUNT%20OPTIONS mount man page]. Please note that some options are specific to filesystems; to discover them see below in the aforementioned mount man page.<br />
;''dump''<br />
: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.<br />
;''pass''<br />
: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.<br />
<br />
== Identifying filesystems ==<br />
<br />
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.<br />
<br />
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.<br />
<br />
=== Kernel name descriptors ===<br />
<br />
Run {{ic|lsblk -f}} to list the partitions and prefix the values in the ''NAME'' column with {{ic|/dev/}}.<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
/dev/sda1 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
/dev/sda2 / ext4 rw,relatime,discard,data=ordered 0 1<br />
/dev/sda3 /home ext4 rw,relatime,discard,data=ordered 0 2<br />
/dev/sda4 none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
=== Labels ===<br />
<br />
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''LABEL'' column with {{ic|1=LABEL=}}:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
LABEL=EFI /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
LABEL=SYSTEM / ext4 rw,relatime,discard,data=ordered 0 1<br />
LABEL=DATA /home ext4 rw,relatime,discard,data=ordered 0 2<br />
LABEL=SWAP none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}<br />
<br />
=== UUIDs ===<br />
<br />
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''UUID'' column with {{ic|1=UUID=}}:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
UUID=CBB6-24F2 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
UUID=0a3407de-014b-458b-b5c1-848e92a327a3 / ext4 rw,relatime,discard,data=ordered 0 1<br />
UUID=b411dc99-f0a0-4c87-9e05-184977be8539 /home ext4 rw,relatime,discard,data=ordered 0 2<br />
UUID=f9fe0b69-a280-415d-a03a-a32752370dee none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
{{Tip|If you would like to return just the UUID of a specific partition:<br />
$ lsblk -no UUID /dev/sda2}}<br />
<br />
=== GPT labels ===<br />
Run {{ic|blkid}} to list the partitions, and use the ''PARTLABEL'' values without the quotes:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
PARTLABEL=EFI\040SYSTEM\040PARTITION /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
PARTLABEL=GNU/LINUX / ext4 rw,relatime,discard,data=ordered 0 1<br />
PARTLABEL=HOME /home ext4 rw,relatime,discard,data=ordered 0 2<br />
PARTLABEL=SWAP none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}<br />
<br />
=== GPT UUIDs ===<br />
<br />
Run {{ic|blkid}} to list the partitions, and use the ''PARTUUID'' values without the quotes:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
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<br />
PARTUUID=98a81274-10f7-40db-872a-03df048df366 / ext4 rw,relatime,discard,data=ordered 0 1<br />
PARTUUID=7280201c-fc5d-40f2-a9b2-466611d3d49e /home ext4 rw,relatime,discard,data=ordered 0 2<br />
PARTUUID=039b6c1c-7553-4455-9537-1befbc9fbc5b none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
== Tips and tricks ==<br />
<br />
=== Automount with systemd ===<br />
<br />
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:<br />
<br />
noauto,x-systemd.automount<br />
<br />
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.<br />
<br />
{{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.}}<br />
<br />
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.<br />
<br />
{{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]}}<br />
<br />
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:<br />
<br />
{{hc|/etc/crypttab|<br />
data /dev/md0 /root/key noauto}}<br />
<br />
You may also specify an idle timeout for a mount with the {{ic|x-systemd.idle-timeout}} flag. For example:<br />
<br />
noauto,x-systemd.automount,x-systemd.idle-timeout=1min<br />
<br />
This will make systemd unmount the mount after it has been idle for 1 minute.<br />
<br />
=== External devices ===<br />
<br />
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: <br />
<br />
{{hc|/etc/fstab|2=<br />
/dev/sdg1 /media/backup jfs defaults,nofail,x-systemd.device-timeout=1 0 2}}<br />
<br />
As of systemd 219, 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.<br />
<br />
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:<br />
<br />
{{hc|/etc/fstab|2=<br />
//host/share /net/share cifs noauto,nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-system.device-timeout=10,workgroup=workgroup,credentials=/foo/credentials 0 0}}<br />
<br />
=== Filepath spaces ===<br />
<br />
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}}:<br />
<br />
{{hc|/etc/fstab|2=<br />
UUID=47FA-4071 /home/username/Camera<font color="grey">\040</font>Pictures vfat defaults,noatime 0 0<br />
/dev/sda7 /media/100<font color="grey">\040</font>GB<font color="grey">\040</font>(Storage) ext4 defaults,noatime,user 0 2<br />
}}<br />
<br />
=== atime options ===<br />
<br />
The use of {{ic|noatime}}, {{ic|nodiratime}} or {{ic|relatime}} can impact drive performance.<br />
<br />
* The {{ic|strictatime}} option updates the ''atime'' 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!<br />
<br />
: 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 needs such information. For mutt, you should only use the {{ic|relatime}} option.<br />
<br />
: The {{ic|nodiratime}} option disables the writing of file access times only for directories while other files still get access times written.<br />
: {{Note|{{ic|noatime}} already includes {{ic|nodiratime}}. [http://lwn.net/Articles/244941/ You do not need to specify both].}}<br />
<br />
* {{ic|relatime}} 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 best compromise might be the use this option since programs like [[Mutt]] will continue to work, but you will still have a performance boost as the files will not get access times updated unless they are modified. This option is used when the {{ic|defaults}} keyword option, {{ic|atime}} option (which means to use the kernel default, which is relatime; see {{ic|man 8 mount}} and [http://en.wikipedia.org/wiki/Stat_%28system_call%29#Solutions]) or no options at all are specified in ''fstab'' for a given mount point.<br />
<br />
=== Writing to FAT32 as Normal User ===<br />
<br />
{{Merge|USB Storage Devices#Mounting USB memory|The linked section assumes that the partition on USB storage uses FAT32 or NTFS filesystem, so we have two sections covering the same topic. Either merge everything here or in the linked section.}}<br />
<br />
To write on a FAT32 partition, you must make a few changes to your {{ic|/etc/fstab}} file.<br />
<br />
{{hc|/etc/fstab|2=<br />
/dev/sdxY /mnt/some_folder vfat user,rw,umask=000 0 0}}<br />
<br />
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; <br />
{{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]].<br />
<br />
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.<br />
<br />
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:<br />
<br />
{{hc|/etc/fstab|2=<br />
/dev/sda9 /mnt/fat32 vfat user,rw,umask=111,dmask=000 0 0}}<br />
<br />
=== Remounting the root partition ===<br />
<br />
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:<br />
<br />
# mount -o remount,rw /<br />
<br />
=== bind mounts ===<br />
<br />
{{Expansion|unfinished section}}<br />
<br />
{{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#Sub-volumes|subvolumes]] faciliate extended capabilities like mount options compared to bind mounting}}<br />
<br />
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}}:<br />
{{hc|/etc/fstab|2=<br />
/<path to foo> /<path to bar> none bind 0 0}}<br />
<br />
== See also ==<br />
<br />
* [http://www.kernel.org/pub/linux/docs/lanana/device-list/devices-2.6.txt Full device listing including block device]<br />
* [http://www.pathname.com/fhs/2.2/index.html Filesystem Hierarchy Standard]<br />
* [http://www.askapache.com/web-hosting/super-speed-secrets.html 30x Faster Web-Site Speed] (Detailed tmpfs)<br />
* [[Samba#Add Share to /etc/fstab|Adding Samba shares to /etc/fstab]]</div>Pobhttps://wiki.archlinux.org/index.php?title=Fstab&diff=412943Fstab2015-12-20T22:16:45Z<p>Pob: Added a section detailing using x-systemd.requires= as an fstab option. This is very useful for automounting network shares after the network is up.</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:File systems]]<br />
[[Category:Boot process]]<br />
[[ar:Fstab]]<br />
[[es:Fstab]]<br />
[[hu:Fstab]]<br />
[[it:Fstab]]<br />
[[ja:Fstab]]<br />
[[ro:Fstab]]<br />
[[ru:Fstab]]<br />
[[zh-CN:Fstab]]<br />
[[zh-TW:Fstab]]<br />
{{Related articles start}}<br />
{{Related|Persistent block device naming}}<br />
{{Related|File systems}}<br />
{{Related|Mount}}<br />
{{Related|tmpfs}}<br />
{{Related articles end}}<br />
<br />
The [[Wikipedia:Fstab|/etc/fstab]] file can be used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem.<br />
<br />
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 {{ic|man 5 systemd.mount}} for details.<br />
<br />
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.<br />
<br />
== File example ==<br />
<br />
A simple {{ic|/etc/fstab}}, using kernel name descriptors:<br />
<br />
{{hc|/etc/fstab|<br />
# <file system> <dir> <type> <options> <dump> <pass><br />
/dev/sda1 / ext4 defaults,noatime 0 1<br />
/dev/sda2 none swap defaults 0 0<br />
/dev/sda3 /home ext4 defaults,noatime 0 2}}<br />
<br />
== Field definitions ==<br />
<br />
Each line in the {{ic|/etc/fstab}} file contains the following fields separated by spaces or tabs:<br />
<br />
''file_system'' ''dir'' ''type'' ''options'' ''dump'' ''pass''<br />
<br />
;''file system''<br />
:The partition or storage device to be mounted.<br />
;''dir''<br />
:The mountpoint where <file system> is mounted to.<br />
;''type''<br />
: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|btrfs}}, {{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).<br />
;''options''<br />
:Mount options of the filesystem to be used. See the [http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-INDEPENDENT_MOUNT%20OPTIONS mount man page]. Please note that some options are specific to filesystems; to discover them see below in the aforementioned mount man page.<br />
;''dump''<br />
: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.<br />
;''pass''<br />
: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.<br />
<br />
== Identifying filesystems ==<br />
<br />
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.<br />
<br />
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.<br />
<br />
=== Kernel name descriptors ===<br />
<br />
Run {{ic|lsblk -f}} to list the partitions and prefix the values in the ''NAME'' column with {{ic|/dev/}}.<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
/dev/sda1 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
/dev/sda2 / ext4 rw,relatime,discard,data=ordered 0 1<br />
/dev/sda3 /home ext4 rw,relatime,discard,data=ordered 0 2<br />
/dev/sda4 none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
=== Labels ===<br />
<br />
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''LABEL'' column with {{ic|1=LABEL=}}:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
LABEL=EFI /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
LABEL=SYSTEM / ext4 rw,relatime,discard,data=ordered 0 1<br />
LABEL=DATA /home ext4 rw,relatime,discard,data=ordered 0 2<br />
LABEL=SWAP none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}<br />
<br />
=== UUIDs ===<br />
<br />
Run {{ic|lsblk -f}} to list the partitions, and prefix the values in the ''UUID'' column with {{ic|1=UUID=}}:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
UUID=CBB6-24F2 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
UUID=0a3407de-014b-458b-b5c1-848e92a327a3 / ext4 rw,relatime,discard,data=ordered 0 1<br />
UUID=b411dc99-f0a0-4c87-9e05-184977be8539 /home ext4 rw,relatime,discard,data=ordered 0 2<br />
UUID=f9fe0b69-a280-415d-a03a-a32752370dee none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
{{Tip|If you would like to return just the UUID of a specific partition:<br />
$ lsblk -no UUID /dev/sda2}}<br />
<br />
=== GPT labels ===<br />
Run {{ic|blkid}} to list the partitions, and use the ''PARTLABEL'' values without the quotes:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
PARTLABEL=EFI\040SYSTEM\040PARTITION /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2<br />
PARTLABEL=GNU/LINUX / ext4 rw,relatime,discard,data=ordered 0 1<br />
PARTLABEL=HOME /home ext4 rw,relatime,discard,data=ordered 0 2<br />
PARTLABEL=SWAP none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
{{Note|If any of your fields contains spaces, see [[#Filepath spaces]].}}<br />
<br />
=== GPT UUIDs ===<br />
<br />
Run {{ic|blkid}} to list the partitions, and use the ''PARTUUID'' values without the quotes:<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
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<br />
PARTUUID=98a81274-10f7-40db-872a-03df048df366 / ext4 rw,relatime,discard,data=ordered 0 1<br />
PARTUUID=7280201c-fc5d-40f2-a9b2-466611d3d49e /home ext4 rw,relatime,discard,data=ordered 0 2<br />
PARTUUID=039b6c1c-7553-4455-9537-1befbc9fbc5b none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
== Tips and tricks ==<br />
<br />
=== Automount with systemd ===<br />
<br />
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:<br />
<br />
noauto,x-systemd.automount<br />
<br />
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.<br />
<br />
{{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.}}<br />
<br />
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.<br />
<br />
{{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]}}<br />
<br />
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:<br />
<br />
{{hc|/etc/crypttab|<br />
data /dev/md0 /root/key noauto}}<br />
<br />
You may also specify an idle timeout for a mount with the {{ic|x-systemd.idle-timeout}} flag. For example:<br />
<br />
noauto,x-systemd.automount,x-systemd.idle-timeout=1min<br />
<br />
This will make systemd unmount the mount after it has been idle for 1 minute.<br />
<br />
=== External devices ===<br />
<br />
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: <br />
<br />
{{hc|/etc/fstab|2=<br />
/dev/sdg1 /media/backup jfs defaults,nofail,x-systemd.device-timeout=1 0 2}}<br />
<br />
As of systemd 219, 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.<br />
<br />
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 module is available. For example:<br />
<br />
{{hc|/etc/fstab|2=<br />
//host/share /net/share cifs noauto,nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-system.device-timeout=10,workgroup=workgroup,credentials=/foo/credentials 0 0}}<br />
<br />
=== Filepath spaces ===<br />
<br />
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}}:<br />
<br />
{{hc|/etc/fstab|2=<br />
UUID=47FA-4071 /home/username/Camera<font color="grey">\040</font>Pictures vfat defaults,noatime 0 0<br />
/dev/sda7 /media/100<font color="grey">\040</font>GB<font color="grey">\040</font>(Storage) ext4 defaults,noatime,user 0 2<br />
}}<br />
<br />
=== atime options ===<br />
<br />
The use of {{ic|noatime}}, {{ic|nodiratime}} or {{ic|relatime}} can impact drive performance.<br />
<br />
* The {{ic|strictatime}} option updates the ''atime'' 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!<br />
<br />
: 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 needs such information. For mutt, you should only use the {{ic|relatime}} option.<br />
<br />
: The {{ic|nodiratime}} option disables the writing of file access times only for directories while other files still get access times written.<br />
: {{Note|{{ic|noatime}} already includes {{ic|nodiratime}}. [http://lwn.net/Articles/244941/ You do not need to specify both].}}<br />
<br />
* {{ic|relatime}} 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 best compromise might be the use this option since programs like [[Mutt]] will continue to work, but you will still have a performance boost as the files will not get access times updated unless they are modified. This option is used when the {{ic|defaults}} keyword option, {{ic|atime}} option (which means to use the kernel default, which is relatime; see {{ic|man 8 mount}} and [http://en.wikipedia.org/wiki/Stat_%28system_call%29#Solutions]) or no options at all are specified in ''fstab'' for a given mount point.<br />
<br />
=== Writing to FAT32 as Normal User ===<br />
<br />
{{Merge|USB Storage Devices#Mounting USB memory|The linked section assumes that the partition on USB storage uses FAT32 or NTFS filesystem, so we have two sections covering the same topic. Either merge everything here or in the linked section.}}<br />
<br />
To write on a FAT32 partition, you must make a few changes to your {{ic|/etc/fstab}} file.<br />
<br />
{{hc|/etc/fstab|2=<br />
/dev/sdxY /mnt/some_folder vfat user,rw,umask=000 0 0}}<br />
<br />
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; <br />
{{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]].<br />
<br />
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.<br />
<br />
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:<br />
<br />
{{hc|/etc/fstab|2=<br />
/dev/sda9 /mnt/fat32 vfat user,rw,umask=111,dmask=000 0 0}}<br />
<br />
=== Remounting the root partition ===<br />
<br />
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:<br />
<br />
# mount -o remount,rw /<br />
<br />
=== bind mounts ===<br />
<br />
{{Expansion|unfinished section}}<br />
<br />
{{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#Sub-volumes|subvolumes]] faciliate extended capabilities like mount options compared to bind mounting}}<br />
<br />
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}}:<br />
{{hc|/etc/fstab|2=<br />
/<path to foo> /<path to bar> none bind 0 0}}<br />
<br />
== See also ==<br />
<br />
* [http://www.kernel.org/pub/linux/docs/lanana/device-list/devices-2.6.txt Full device listing including block device]<br />
* [http://www.pathname.com/fhs/2.2/index.html Filesystem Hierarchy Standard]<br />
* [http://www.askapache.com/web-hosting/super-speed-secrets.html 30x Faster Web-Site Speed] (Detailed tmpfs)<br />
* [[Samba#Add Share to /etc/fstab|Adding Samba shares to /etc/fstab]]</div>Pob