/etc/fstab

The /etc/fstab file is an essential configuration file in Unix and Linux systems that contains information about disk drives and partitions, including where they should be mounted and with what options. The fstab file is read by the mount command to determine which filesystems to mount at boot time.

Structure of /etc/fstab

Each line in the /etc/fstab file represents a filesystem and follows this format:

<file system> <mount point> <type> <options> <dump> <pass>
  • <file system>: The device or filesystem to mount (e.g., /dev/sda1, UUID=xxxx, LABEL=xxxx).

  • <mount point>: The directory where the filesystem will be mounted (e.g., /, /home, /mnt/data).

  • <type>: The type of filesystem (e.g., ext4, vfat, ntfs).

  • <options>: Mount options (e.g., defaults, ro, rw, noexec, nosuid).

  • <dump>: Used by the dump command to determine if the filesystem needs to be dumped (backup). Usually 0 or 1.

  • <pass>: Used by the fsck command to determine the order in which filesystems should be checked at boot time. 0 means the filesystem is not checked, 1 means the filesystem is checked first, and 2 means the filesystem is checked after the filesystems with 1.

Example of /etc/fstab

Here is an example of a typical /etc/fstab file:

# <file system>  <mount point>  <type>  <options>         <dump>  <pass>
UUID=a1b2c3d4    /              ext4    defaults          1       1
UUID=e5f6g7h8    /home          ext4    defaults          1       2
UUID=i9j0k1l2    /data          ext4    defaults          0       2
/dev/cdrom       /media/cdrom   iso9660 ro,user,noauto    0       0
tmpfs            /tmp           tmpfs   defaults,noatime  0       0

Detailed Explanation of Fields

<file system>

  • Device File: Directly references the device file, e.g., /dev/sda1.

  • UUID: Universally Unique Identifier, e.g., UUID=a1b2c3d4-e5f6-7890-1234-56789abcdef0.

  • LABEL: Volume label, e.g., LABEL=MyData.

  • Special Filesystems: For temporary filesystems, tmpfs is used.

<mount point>

  • The directory where the filesystem will be mounted.

  • Common mount points include /, /home, /var, /mnt, and /media.

<type>

  • Specifies the filesystem type, such as ext4, vfat, ntfs, iso9660, xfs, btrfs, etc.

<options>

  • defaults: Default mount options (rw, suid, dev, exec, auto, nouser, async).

  • rw: Read-write.

  • ro: Read-only.

  • noexec: Do not allow execution of binaries.

  • nosuid: Do not allow set-user-identifier or set-group-identifier bits.

  • user: Allow a normal user to mount.

  • noauto: Do not mount automatically at boot.

  • relatime: Update inode access times relative to modify or change time.

  • others: Depending on the filesystem, options like noatime, nodiratime, sync, async, etc.

<dump>

  • Usually 0 (no dump) or 1 (needs to be dumped).

<pass>

  • 0: Do not check.

  • 1: Check first (typically the root filesystem).

  • 2: Check after filesystems with 1.

Practical Examples

Mounting a Root Filesystem

UUID=a1b2c3d4 / ext4 defaults 1 1
  • Mounts the root filesystem (/) with default options, dumps it, and checks it first.

Mounting a Home Directory

UUID=e5f6g7h8 /home ext4 defaults 1 2
  • Mounts the /home directory with default options, dumps it, and checks it after the root filesystem.

Mounting a Data Partition

UUID=i9j0k1l2 /data ext4 defaults 0 2
  • Mounts /data with default options, does not dump it, and checks it after the root filesystem.

Mounting a CD-ROM

/dev/cdrom /media/cdrom iso9660 ro,user,noauto 0 0
  • Mounts a CD-ROM with read-only access, allows users to mount it, and does not mount it automatically at boot.

Mounting a Temporary Filesystem

tmpfs /tmp tmpfs defaults,noatime 0 0
  • Mounts a temporary filesystem (tmpfs) at /tmp with no access time updates.

Summary

The /etc/fstab file is a critical configuration file for managing filesystem mounts in Unix and Linux systems. It provides a structured way to define which filesystems to mount, where to mount them, and with what options. Understanding how to configure /etc/fstab is essential for system administration, ensuring that filesystems are properly mounted and accessible as required.

Last updated