Donnerstag, 20. Mai 2010

/etc/fstab

Field definitions

/etc/fstab contains the following fields separated by a space or tab:

					

  • - defines the storage device (i.e. /dev/sda1).
  • - tells the mount command where it should mount the to.
  • - 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.
  • - 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).
  • - 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 entry.
  • fsck reads the 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 value 0 will not be checked by the fsck utility.

Example

Here is an example /etc/fstab using kernel naming (/dev/sdx) descriptors:

#                                    

none /dev/pts devpts defaults 0 0
none /dev/shm tmpfs defaults 0 0

/dev/cdrom /media/cd iso9660 ro,user,noauto,unhide 0 0
/dev/dvd /media/dvd udf ro,user,noauto,unhide 0 0
/dev/fd0 /media/fl auto user,noauto 0 0

/dev/sda2 / ext4 defaults,noatime 0 1
/dev/sda6 /home ext4 defaults,noatime 0 2
/dev/sda7 swap swap defaults 0 0

Defining filesystems

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

Kernel naming

You can get kernel naming descriptors using fdisk:

# 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 (mkfs.*) when you create a filesystem. blkid 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 /etc/fstab using the UUID identifiers:

#                                    

none /dev/pts devpts defaults 0 0
none /dev/shm tmpfs defaults 0 0

/dev/cdrom /media/cd iso9660 ro,user,noauto,unhide 0 0
/dev/dvd /media/dvd udf ro,user,noauto,unhide 0 0
/dev/fd0 /media/fl auto user,noauto 0 0

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 gparted to label partitions or you can use e2label 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|USB} before you can label with a gparted-like application or for ext partitions you can use e2label.

e2label /dev/ Arch_Linux

Labels can be up to 16 characters long. Technically labeling can have spaces too, however there is no way to have your fstab 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 fstab, here is an example:

#                                    

none /dev/pts devpts defaults 0 0
none /dev/shm tmpfs defaults 0 0

/dev/cdrom /media/cd iso9660 ro,user,noauto,unhide 0 0
/dev/dvd /media/dvd udf ro,user,noauto,unhide 0 0
/dev/fd0 /media/fl auto user,noauto 0 0

LABEL=Arch_Linux / ext4 defaults,noatime 0 1
LABEL=Arch_Swap swap swap defaults 0 0

Tips

Some tips.

atime options

The use of noatime, nodiratime or relatime 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. This was more purposeful when Linux was being used for servers and doesn't have much use for desktop use. This works good for almost all applications but Mutt that needs this information. For mutt, you should only use the relatime option.