Linux - FSTAB (file systems table)

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix > Linux - Disk (storage devices)

1 - About

When a Linux system is newly-installed, all the disk partitions defined and/or created during the installation are configured to be automatically mounted whenever the system boots.

However, what happens when additional disk drives are added to a system after the installation is done? The answer is “nothing” because the system was not configured to mount them automatically. However, this is easily changed.

The answer lies in the /etc/fstab file. This file is used to control what file systems are mounted when the system boots, as well as to supply default values for other file systems that may be mounted manually from time to time.

Advertising

3 - Management

3.1 - /etc/fstab format

To get the structure for your system,

man fstab

See fstab

3.2 - Example

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

# device name   mount point     fs-type      options                 dump-freq pass-num
LABEL=/         /               ext3         defaults                1         1
/dev/hda6       swap            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
 
# Removable media
/dev/cdrom      /mount/cdrom    udf,iso9660  noauto,owner,kudzu,ro   0         0
/dev/fd0        /mount/floppy   auto         noauto,owner,kudzu      0         0
 
# NTFS Windows XP partition
/dev/hda1       /mnt/WinXP      ntfs-3g      quiet,defaults,locale=en_US.utf8,umask=0    0 0
 
# Partition shared by Windows and Linux
/dev/hda7       /mnt/shared     vfat         umask=000               0         0
 
# mounting tmpfs
tmpfs           /mnt/tmpfschk   tmpfs        size=100m               0         0
 
# mounting cifs
//pingu/ashare  /store/pingu    cifs         credentials=/root/smbpass.txt 0   0
 
# mounting NFS
pingu:/store    /store          nfs          rw                      0         0
 
# with UUID
UUID=11fa2c88-c408-484e-b449-89b6505c6db5 /datadrive              ext4    defaults,nofail  1  2

Each line represents one file system and contains the following fields:

  • File system specifier — For disk-based file systems:
    • either a device file or a device label specification (see name)
    • or a UUID (blkid)
  • Mount point — Except for swap partitions, this field specifies the mount point (a directory) to be used when the file system is mounted
  • File system type — The type of file system present on the specified device (note that auto may be specified to select automatic detection of the file system to be mounted, which is handy for removable media units such as diskette drives)
  • Mount options — A comma-separated list of options that can be used to control mount's behavior
    • defaults
    • nofail: the system will not fail to boot if the disk is not present
  • Dump frequency — If the dump backup utility is used, the number in this field will control dump's handling of the specified file system
  • File system check order — Controls the order in which the file system checker fsck checks the integrity of the file systems
Advertising

3.3 - Read

The proper way to read records from fstab is to use the routines getmntent(3) or libmount.

cat /etc/fstab

3.4 - Verification

To verify that the changes are correct, you can perform a mount command for all disk

mount -a

Or for one disk

mount /dev/sda2
mount: can't find /dev/sda2 in /etc/fstab or /etc/mtab