https://wiki.archlinux.org/api.php?action=feedcontributions&user=Thibit&feedformat=atomArchWiki - User contributions [en]2024-03-29T10:09:47ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Fstab&diff=213121Fstab2012-07-16T02:55:45Z<p>Thibit: Correct atime option links</p>
<hr />
<div>{{Lowercase_title}}<br />
[[Category:File systems]]<br />
[[Category:Boot process]]<br />
[[es:Fstab]]<br />
[[it:Fstab]]<br />
[[ru:Fstab]]<br />
[[zh-CN:Fstab]]<br />
[[zh-TW:Fstab]]<br />
{{Article summary start}}<br />
{{Article summary text|This article explains how to configure and use fstab.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|udev}}<br />
{{Article summary end}}<br />
<br />
The {{ic|/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.<br />
<br />
== File example ==<br />
<br />
A simple {{ic|/etc/fstab}}, using kernel name descriptors:<br />
{{hc|/etc/fstab|<br />
# <file system> <dir> <type> <options> <dump> <pass><br />
tmpfs /tmp tmpfs nodev,nosuid 0 0<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 />
<br />
== Field definitions ==<br />
The {{ic|/etc/fstab}} file contains the following fields separated by a space or tab:<br />
<br />
<file system> <dir> <type> <options> <dump> <pass><br />
<br />
* '''<file system>''' - the partition or storage device to be mounted.<br />
* '''<dir>''' - the mountpoint where <file system> is mounted to.<br />
* '''<type>''' - the file system type of the partition or storage device to be mounted. Many different file systems are supported: {{ic|ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap}} and {{ic|auto}}. The {{ic|auto}} type lets the mount command guess what type of file system is used. This is useful for removable devices such as cdroms and dvds.<br />
* '''<options>''' - the options of the filesystem to be used. Note that some options are filesystem specific. Some of the most common options are:<br />
<br />
:* {{ic|auto}} - Mount automatically at boot, or when the command {{ic|mount -a}} is issued.<br />
:* {{ic|noauto}} - Mount only when you tell it to.<br />
:* {{ic|exec}} - Allow execution of binaries on the filesystem.<br />
:* {{ic|noexec}} - Disallow execution of binaries on the filesystem.<br />
:* {{ic|ro}} - Mount the filesystem read-only.<br />
:* {{ic|rw}} - Mount the filesystem read-write.<br />
:* {{ic|user}} - Allow any user to mount the filesystem. This automatically implies {{ic|noexec, nosuid, nodev}}, unless overridden.<br />
:* {{ic|users}} - Allow any user in the users group to mount the filesystem.<br />
:* {{ic|nouser}} - Allow only root to mount the filesystem.<br />
:* {{ic|owner}} - Allow the owner of device to mount.<br />
:* {{ic|sync}} - I/O should be done synchronously.<br />
:* {{ic|async}} - I/O should be done asynchronously.<br />
:* {{ic|dev}} - Interpret block special devices on the filesystem.<br />
:* {{ic|nodev}} - Don't interpret block special devices on the filesystem.<br />
:* {{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.<br />
:* {{ic|nosuid}} - Block the operation of suid, and sgid bits.<br />
:* {{ic|noatime}} - Don't update inode access times on the filesystem. Can help performance (see [[#atime_options|atime options]]).<br />
:* {{ic|nodiratime}} - Do not update directory inode access times on the filesystem. Can help performance (see [[#atime_options|atime options]]).<br />
:* {{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]]).<br />
:* {{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.<br />
:* {{ic|defaults}} - the default mount options for the filesystem to be used. The default options for {{ic|ext3}} are: {{ic|rw, suid, dev, exec, auto, nouser, async}}.<br />
<br />
* '''<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.<br />
<br />
* '''<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.<br />
<br />
== Identifying filesystems ==<br />
<br />
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 disks order. This is useful if the storage device order in the BIOS is changed, or if you switch the storage device cabling. Also, sometimes the BIOS may occasionally change the order of storage devices. Read more about this in the [[Persistent_block_device_naming|persistent block device naming]] article.<br />
<br />
=== Kernel name ===<br />
<br />
You can get the kernel name descriptors using {{ic|fdisk -l}}. The kernel names are listed in the first row:<br />
<br />
{{hc|# fdisk -l|<nowiki><br />
...<br />
Device Boot Start End Blocks Id System<br />
/dev/sda1 * 1 2550 20482843+ b W95 FAT32<br />
/dev/sda2 2551 5100 20482875 83 Linux<br />
/dev/sda3 5101 7650 20482875 83 Linux<br />
/dev/sda4 7651 121601 915311407+ 5 Extended<br />
/dev/sda5 7651 10200 20482843+ 83 Linux<br />
/dev/sda6 10201 17849 61440561 83 Linux<br />
/dev/sda7 17850 18104 2048256 82 Linux swap / Solaris<br />
/dev/sda8 18105 18113 72261 83 Linux<br />
/dev/sda9 18114 121601 831267328+ 7 HPFS/NTFS<br />
...</nowiki>}}<br />
<br />
See the [[Fstab#File_example|file example]].<br />
<br />
=== Label ===<br />
<br />
In order to use labels, the devices or partitions must have unambiguous labels. Labels should be unambiguous to prevent any possible conflicts - each label should be unique. To label a device or partition, see [[Persistent_block_device_naming|this]] article. To list all devices and partitions with their labels, you can use the command {{ic|blkid}}. In {{ic|/etc/fstab}} you prefix the device label with {{ic|LABEL<nowiki>=</nowiki>}} :<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
<br />
tmpfs /tmp tmpfs nodev,nosuid 0 0<br />
<br />
LABEL=Arch_Linux / ext4 defaults,noatime 0 1<br />
LABEL=Arch_Swap none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
=== UUID ===<br />
<br />
All partitions and devices have a unique UUID. They are generated by the make-filesystem utilities ({{ic|mkfs.*}}) when you create the filesystem. To list all devices and partitions with their UUID, you can also use {{ic|blkid}}. In {{ic|/etc/fstab}} you prefix the device UUID with {{ic|UUID<nowiki>=</nowiki>}} :<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
# <file system> <dir> <type> <options> <dump> <pass><br />
<br />
tmpfs /tmp tmpfs nodev,nosuid 0 0<br />
<br />
UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26 / ext4 defaults,noatime 0 1<br />
UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff /home ext4 defaults,noatime 0 2<br />
UUID=4209c845-f495-4c43-8a03-5363dd433153 none swap defaults 0 0<br />
</nowiki>}}<br />
<br />
== Tips and tricks ==<br />
<br />
=== Swap UUID ===<br />
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|blkid}} command. Here are some steps to assign a UUID to your swap:<br />
<br />
Identify the swap partition:<br />
# swapon -s<br />
<br />
Disable the swap:<br />
# swapoff /dev/sda7<br />
<br />
Recreate the swap with a new UUID assigned to it:<br />
# mkswap -U random /dev/sda7<br />
<br />
Activate the swap:<br />
# swapon /dev/sda7<br />
<br />
=== Filepath spaces ===<br />
<br />
You can use the escape character "\" followed by the 3 digit octal code "040" to emulate spaces in a path:<br />
<br />
{{hc|/etc/fstab|<nowiki>.....<br />
/dev/sda7 /home/username/Camera\040Pictures ext4 defaults,noatime 0 2<br />
UUID=7D4500B3071E18B2 /media/100\040GB\040(Storage) ntfs defaults,noatime,user 0 0<br />
.....</nowiki>}}<br />
<br />
===External devices===<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.<br />
{{hc|/etc/fstab|<nowiki>.....<br />
/dev/sdg1 /media/backup jfs defaults,nofail 0 2<br />
.....</nowiki>}}<br />
<br />
=== atime options ===<br />
<br />
The use of {{ic|noatime}}, {{ic|nodiratime}} or {{ic|relatime}} can help disk performance for ext2, ext3, and ext4 filesystems. Linux by default keeps a record (writes to the disk) every time it reads from the disk {{ic|atime}}. This was more purposeful when Linux was being used for servers; it doesn't have much value for desktop use. The worst thing about the default {{ic|atime}} option is that even reading a file from the page cache (reading from memory instead of the disk) will still result in a disk write! Using the {{ic|noatime}} option fully disables writing file access times to the disk every time you read a file. This works well for almost all applications, except for a rare few like [[Mutt]] that need the such information. For mutt, you should only use the {{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.<br />
<br />
{{Note|{{ic|noatime}} already includes {{ic|nodiratime}}. You do not need to specify both options.[http://lwn.net/Articles/244941/ ]}}<br />
<br />
===tmpfs===<br />
[[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.<br />
<br />
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.<br />
<br />
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.<br />
<br />
To use tmpfs for {{ic|/tmp}}, add this line to {{ic|/etc/fstab}}:<br />
{{hc|/etc/fstab|tmpfs /tmp tmpfs nodev,nosuid 0 0}}<br />
<br />
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:<br />
{{hc|/etc/fstab|2=tmpfs /tmp tmpfs nodev,nosuid,size=2G 0 0}}<br />
<br />
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. [[#Other_resources|More info]].<br />
{{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}}<br />
<br />
See the '''mount''' command man page for more information. One useful mount option in the man page is the '''default''' option, understand that at least.<br />
<br />
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).<br />
<br />
After applying changes, you may want to verify that they took effect by looking at {{ic|/proc/mounts}} and using {{ic|findmnt}}:<br />
{{hc|<nowiki>$ findmnt --target /tmp</nowiki>|<nowiki>TARGET SOURCE FSTYPE OPTIONS<br />
/tmp tmpfs tmpfs rw,nosuid,nodev,relatime</nowiki>}}<br />
<br />
To use tmpfs for {{ic|/var/lock}} and {{ic|/var/run}}, you can simply symlink them to {{ic|/run}}, or even better, bind mount them. Make sure to close anything important before doing this, because you will have to reboot, and daemons may not stop cleanly.<br />
<br />
{{bc|<nowiki># ln -sf /run/lock /var/lock<br />
# ln -sf /run /var/run<br />
# reboot</nowiki>}}<br />
<br />
{{Note|Package {{pkg|filesystem}} provides the symlinking as version 2012.6-2. See [http://www.archlinux.org/news/filesystem-upgrade-manual-intervention-required-1/ the news].}}<br />
{{Warning|Some daemons still have files and/or directories installed into {{ic|/var/lock}} and {{ic|/var/run}}, and the {{ic|/etc/rc.d/}} scripts may need to be edited for them to work.}}<br />
<br />
=== Writing to FAT32 as Normal User ===<br />
To write on a FAT32 partition, you must make a few changes to your {{ic|/etc/fstab}} file.<br />
/dev/hdX /mnt/Y 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/hdX}}. {{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}}.<br />
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.<br />
<br />
For example, if your FAT32 partition is on {{ic|/dev/hda9}}, and you wish to mount it to {{ic|/mnt/fat32}}, then you would use:<br />
/dev/hda9 /mnt/fat32 vfat user,rw,umask=111,dmask=000 0 0<br />
<br />
==Related==<br />
* [[Persistent block device naming]]<br />
* [[NTFS Write Support]]<br />
* [[Firefox Ramdisk]]<br />
* [[Using tmpfs for /var/*]]<br />
* [[Boot Debugging]]<br />
<br />
==See also==<br />
*[[Wikipedia:Fstab]]<br />
*[http://www.tuxfiles.org/linuxhelp/fstab.html tuxfiles]<br />
*[http://www.kernel.org/pub/linux/docs/device-list/devices.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)</div>Thibit