Fstab


The fstab file is a system configuration file commonly found at /etc/fstab on Unix and Unix-like computer systems. In Linux, it is part of the util-linux package. The fstab file typically lists all available disk partitions and other types of file systems and data sources that are not necessarily disk-based, and indicates how they are to be initialized or otherwise integrated into the larger file system structure.
The fstab file is read by the mount command, which happens automatically at boot time to determine the overall file system structure, and thereafter when a user executes the mount command to modify that structure. It is the duty of the system administrator to properly create and maintain the fstab file.
While fstab is still used for basic system configuration, for other uses, it has been superseded by automatic mounting mechanisms.
The file has other names on some versions of Unix; for example, it is found at /etc/vfstab on Solaris systems.

Modern use

The fstab file is read by programs that work with disk partitions and other file systems and is not automatically maintained. Instead it is written by the system administrator or sometimes by an operating system installation program. However, some administration tools can automatically build and edit fstab, or act as graphical editors for it, such as the Kfstab graphical configuration utility available for KDE.
Modern Linux systems use udev as an automounter to handle the hot swapping of devices instead of relying on fstab. Programs such as pmount allow ordinary users to mount and unmount filesystems without a corresponding fstab entry; traditional Unix has always allowed privileged users to mount or unmount devices without an fstab entry.

Example

The following is an example of an fstab file on a typical Linux system.

  1. device-spec mount-point fs-type options dump pass
LABEL=/ / ext4 defaults 1 1
/dev/sda6 none swap defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
  1. Removable media
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,ro 0 0
  1. NTFS Windows 7 partition
/dev/sda1 /mnt/Windows ntfs-3g quiet,defaults,locale=en_US.utf8,umask=0,noexec 0 0
  1. Partition shared by Windows and Linux
/dev/sda7 /mnt/shared vfat umask=000 0 0
  1. mounting tmpfs
tmpfs /mnt/tmpfschk tmpfs size=100m 0 0
  1. mounting cifs
//cifs_server_name/ashare /store/pingu cifs credentials=/root/smbpass.txt 0 0
  1. mounting NFS
nfs_server_name:/store /store nfs rw 0 0

The order of records in fstab is important because fsck, mount, and umount sequentially iterate through fstab doing their thing.
Blank lines and comment lines beginning with a "#" are ignored.
The space- or tab-separated fields within each row must appear in a specific order, as follows:
  1. device-spec – The device name, label, UUID, or other means of specifying the partition or data source this entry refers to.
  2. mount-point – Where the contents of the device may be accessed after mounting; for swap partitions or files, this is set to none.
  3. fs-type – The type of file system to be mounted.
  4. options – Options describing various other aspects of the file system, such as whether it is automatically mounted at boot, which users may mount or access it, whether it may be written to or only read from, its size, and so forth; the special option defaults refers to a predetermined set of options depending on the file system type.
  5. dump – A number indicating whether and how often the file system should be backed up by the dump program; a zero indicates the file system will never be automatically backed up.
  6. pass – A number indicating the order in which the fsck program will check the devices for errors at boot time; this is 1 for the root file system and either 2 or 0 for all other devices.
Missing values in the last two fields are interpreted as zeros. If necessary, space characters in the first, second, and fourth fields are indicated by the octal character code \040.

Options common to all filesystems

As the filesystems in /etc/fstab will eventually be mounted using mount it is not surprising that the options field simply contains a comma-separated list of options which will be passed directly to mount when it tries to mount the filesystem.
The options common to all filesystems are:
; auto / noauto
; dev / nodev
; exec / noexec
; rw / ro
; sync / async
; suid / nosuid
; user / users / nouser
; defaults
; owner
; atime / noatime / relatime / strictatime

Filesystem-specific options

There are many options for the specific filesystems supported by mount. Listed below are some of the more commonly used. The full list may be found in the documentation for mount. Note that these are for Linux; traditional UNIX-like systems have generally provided similar functionality but with slightly different syntax.

ext2

; check=
; debug
; sb=n

fat

; check=
; conv=

fat, ntfs

; windows_names
; uid=n, gid=n
; umask=nnn, dmask=nnn, fmask=nnn

Mode Mask Settings

- user file creation
dmask - directory creation
fmask - for files only
More detailed information about the fstab file can be found in the man page about ; for other systems see below.

nfs

; addr=ip

Mounting all filesystems

mount -a
This command will mount all filesystems mentioned in fstab and is used in system script startup during booting. Note that this command will ignore all those entries containing "noauto" in the options section.