Difference between revisions of "Fstab"

From ArchWiki
Jump to: navigation, search
m (tmpfs)
(tmpfs)
Line 156: Line 156:
 
To use tmpfs for /var/run and /var/run, simply symlink them to /run:
 
To use tmpfs for /var/run and /var/run, simply symlink them to /run:
  
{{Cli|# ln -s /run/lock /var/lock
+
{{Cli|<nowiki># ln -s /run/lock /var/lock
# ln -s /run /var/run}}
+
# ln -s /run /var/run</nowiki>}}
  
 
You may or may not want to specify the size here, but you should leave the mode part alone in these cases, to make sure that they have the correct permissions. In the above example, /tmp will be set to half your total ram, and the other 2 will be set to 10 mb each.
 
You may or may not want to specify the size here, but you should leave the mode part alone in these cases, to make sure that they have the correct permissions. In the above example, /tmp will be set to half your total ram, and the other 2 will be set to 10 mb each.

Revision as of 02:50, 17 May 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

The Template:Filename file contains static filesystem information. It defines how storage devices and partitions are to be initialized and integrated into the overall system.

Example

Here is an example Template:Filename using kernel naming (/dev/sdx) descriptors:

# <file system>        <dir>         <type>    <options>             <dump> <pass>
devpts                 /dev/pts      devpts    defaults              0      0
shm                    /dev/shm      tmpfs     nodev,nosuid          0      0
 
/dev/sda2              /             ext4      defaults,noatime      0      1
/dev/sda6              /home         ext4      defaults,noatime      0      2
/dev/sda7              swap          swap      defaults              0      0

Here is another example using more mount options and the LABEL= method of identifying mountable devices.

devpts                 /dev/pts      devpts    defaults              0      0
shm                    /dev/shm      tmpfs     nodev,nosuid          0      0

LABEL=BOOT      /boot           ext2 defaults              0 2
LABEL=ROOT      /               ext4 defaults,noatime      0 1
LABEL=USR       /usr            ext4 defaults,noatime      0 2
LABEL=VAR       /var            ext4 defaults,noatime      0 2
LABEL=OPT       /opt            ext4 defaults,noatime      0 2
LABEL=HOME      /home           ext4 defaults,noatime      0 2

Field definitions

Template:Filename contains the following fields separated by a space or tab:

<file system>	<dir>	<type>	<options>	<dump>	<pass>
  • <file systems> - defines the storage device (i.e. Template:Filename).
  • <dir> - tells the mount command where it should mount the <file system> to.
  • <type> - defines the file system type of the device or partition to be mounted. Many different file systems are supported. Some examples are: ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap, and auto. The 'auto' type lets the mount command to attempt to guess what type of file system is used, this is useful for removable devices such as cdroms and dvds.
  • <options> - define particular options for filesystems. Some options relate only to the filesystem itself. Some of the more common options are:
  • auto - File system will mount automatically at boot, or when the command 'mount -a' is issued.
  • noauto - The filesystem is mounted only when you tell it to.
  • exec - Allow the execution binaries that are on that partition (default).
  • noexec - Do not allow binaries to be executed on the filesystem.
  • ro - Mount the filesystem read only
  • rw - Mount the filesystem read-write
  • sync - I/O should be done synchronously
  • async - I/O should be done asynchronously
  • flush - specific option for FAT to flush data more often, thus making copy dialogs or progress bars to stays up until things are on the disk
  • user - Permit any user to mount the filesystem (implies noexec,nosuid,nodev unless overridden.)
  • nouser - Only allow root to mount the filesystem. (default)
  • defaults - Default mount settings (equivalent to rw,suid,dev,exec,auto,nouser,async).
  • suid - Allow the operation of suid, and sgid bits. They are mostly used to allow users on a computer system to execute binary executables with temporarily elevated privileges in order to perform a specific task.
  • nosuid - Block the operation of suid, and sgid bits.
  • noatime - Do not update inode access times on the filesystem. Can help performance (see atime options).
  • nodiratime - Do not update directory inode access times on the filesystem. Can help performance (see atime options).
  • 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 atime options).
  • <dump> - Is used by the dump utility to decide when to make a backup. When installed (not installed by a standard installation of Arch Linux), dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system, if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the <dump> entry.
  • <pass> fsck reads the <pass> number and determines in which order the file systems should be checked. Possible entries are 0, 1, and 2. The root file system should have the highest priority, 1, all other file systems you want to have checked should get a 2. File systems with a <pass> value 0 will not be checked by the fsck utility.

Defining filesystems

You can define the filesystems in the Template:Filename configuration in three different ways: by kernel naming descriptors, by UUID, or by labels. The advantage of using UUIDs or labels is that they are not dependent on disk order. This is useful if you change your storage device order in the BIOS, you switch storage device cabling, or because some BIOS's may occasionally change the order of storage devices.

Kernel naming

You can get kernel naming descriptors using Template:Codeline:

# fdisk -l
...
  
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2550    20482843+   b  W95 FAT32
/dev/sda2            2551        5100    20482875   83  Linux
/dev/sda3            5101        7650    20482875   83  Linux
/dev/sda4            7651      121601   915311407+   5  Extended
/dev/sda5            7651       10200    20482843+  83  Linux
/dev/sda6           10201       17849    61440561   83  Linux
/dev/sda7           17850       18104     2048256   82  Linux swap / Solaris
/dev/sda8           18105       18113       72261   83  Linux
/dev/sda9           18114      121601   831267328+   7  HPFS/NTFS

UUIDs

UUIDs are generated by the make-filesystem utilities (Template:Codeline) when you create a filesystem. Template:Codeline will show you the UUIDs of mounted devices and partitions:

# blkid
/dev/sda1: UUID="76E4F702E4F6C401" LABEL="vista" TYPE="ntfs"
/dev/sda2: LABEL="Root" UUID="24f28fc6-717e-4bcd-a5f7-32b959024e26" TYPE="ext4"
/dev/sda6: LABEL="Home" UUID="03ec5dd3-45c0-4f95-a363-61ff321a09ff" TYPE="ext4" 
/dev/sda7: LABEL="swap" UUID="4209c845-f495-4c43-8a03-5363dd433153" TYPE="swap"
/dev/sda10: UUID="0ea7a93f-537c-4868-9201-0dc090c050e4" TYPE="crypto_LUKS"
/dev/mapper/sda10: UUID="d3560bbb-b5d5-46c5-a7a8-434c885217c7" UUID_SUB="425ab275-d520-4636-8d16-55fb2b957971" TYPE="btrfs"

An example Template:Filename using the UUID identifiers:

# <file system>        <dir>         <type>    <options>             <dump> <pass>
none                   /dev/pts      devpts    defaults                0      0
none                   /dev/shm      tmpfs     defaults                0      0
 
UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26 /     ext4 defaults,noatime  0      1
UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff /home ext4 defaults,noatime  0      2
UUID=4209c845-f495-4c43-8a03-5363dd433153 swap  swap defaults          0      0

Labels

The device or partition is required to be labeled first. To do this, you can use common applications like Template:Package Official to label partitions or you can use Template:Codeline to label ext2, ext3, and ext4 partitions. Keep in mind that not all file system have labeling support (e.g. FAT file systems).

A device or partition must not be mounted before attempting to label them. Initially you will need to boot from a Live(CD/DVD/USB) before you can label with a Template:Package Official-like application or for ext partitions you can use Template:Codeline.

e2label /dev/<disk-or-partition> Arch_Linux

Labels can be up to 16 characters long. Technically labeling can have spaces too, however there is no way to have your Template:Filename or GRUB configuration file (for that matter) be able to recognize them by that label if you do.

Labels should be unambiguous, meaning that each label should be original to prevent any possible conflicts. To enter labels into your Template:Filename, here is an example:

# <file system>        <dir>         <type>    <options>             <dump> <pass>
devpts                 /dev/pts      devpts    defaults              0      0
shm                    /dev/shm      tmpfs     nodev,nosuid          0      0
 
LABEL=Arch_Linux       /             ext4      defaults,noatime        0      1
LABEL=Arch_Swap        swap          swap      defaults                0      0

Tips

atime options

The use of Template:Codeline, Template:Codeline or Template:Codeline can help disk performance for ext2, ext3, and ext4 filesystems. Linux by default keeps a record (writes to the disk) every times it reads from the disk Template:Codeline. 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 Template:Codeline 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 Template:Codeline 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 Template:Codeline option. Using the Template:Codeline option enables the writing of file access times only when the file is being modified (unlike Template:Codeline where the file access time will never be changed and will be older than the modification time). The Template:Codeline 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 Template:Codeline 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.

Note: Template:Codeline already includes Template:Codeline. You don't need to specify both options.

tmpfs

tmpfs is a temporary filesystem that resides in memory and/or your swap partition(s), depending on how much you fill it up etc. This may be a good way of speeding up some parts of the system, and to automatically clear some files on reboot.

Some directories where tmpfs can be used are /tmp, /var/lock and /var/run. Do NOT use it on /var/tmp, because that folder is meant for temporary files that are preserved between reboots.

Warning: Some daemons still have files and/or directories installed into /var/lock and /var/run and the /etc/rc.d/ scripts may need to be edited for them to work (example: lighttpd).

By default, a tmpfs partition is 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, tmpfs partitions don't claim any memory before it's actually used.

To use tmpfs for /tmp add this lines to /etc/fstab:

tmpfs /tmp      tmpfs defaults,nodev,nosuid,mode=1777                 0 0

To use tmpfs for /var/run and /var/run, simply symlink them to /run:

Template:Cli

You may or may not want to specify the size here, but you should leave the mode part alone in these cases, to make sure that they have the correct permissions. In the above example, /tmp will be set to half your total ram, and the other 2 will be set to 10 mb each.

See the mount command man page for more information.

Reboot for the changes to come into effect. Note that while it may be tempting and sometimes useful, you should NOT just run mount -a, since this will make any current content in those locations inaccessible (you may want to keep active lockfiles for example). However, if all of them are empty, it should be safe to run mount -a instead of rebooting. You could also run mount /tmp etc to activate some now and the rest after reboot.

After applying changes, you way want to verify that it's working with df (df -h in this case):

tmpfs                 2.0G   20K  2.0G   1% /tmp

Fixing shutdown error with /var partition

When mounting /var/lock and /var/run as tmpfs, /var will fail to unmount at shutdown if it is a separate partition. This happens because tmpfs filesystems are not unmounted by rc.shutdown.

To fix this, create /etc/rc.d/functions.d/clean_umount and add this to it:

clean_umount() {
    umount /var/lock
    umount /var/run
}
add_hook shutdown_postkillall clean_umount
# vim: set ft=sh :

This will unmount /var/lock and /var/run after all processes and daemons are killed, but before the script attempts to unmount /var.

Dealing with paths that contain spaces

You can use the escape character followed by the 3 digit octal code for space "\040".

/dev/sda7                /home/username/Camera\040Picures   ext4  defaults,noatime       0  2
UUID=7D4500B3071E18B2    /media/100\040GB\040(Storage)      ntfs  defaults,noatime,user  0  0

External drives

External drives that are to be mounted when present but ignored if absent may require the Template:Codeline option. This prevents errors being reported at boot.

/dev/sdg1    /media/backup    jfs    defaults,nofail    0  2

Related

Resources