Linux fstab

File System Table Configuration

Overview

The /etc/fstab file is a system configuration file that contains information about filesystems and their mount points. It defines how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem at boot time.

Key Features:
  • Automatic filesystem mounting at boot
  • Define mount options and parameters
  • Control filesystem checking and backup
  • Support for various filesystem types
Warning: Incorrect fstab entries can prevent your system from booting properly. Always backup the original file and test changes before rebooting.

File Format

Each line in fstab contains six fields separated by whitespace:

device mount_point filesystem_type options dump pass
Field Description Example
Device Device to mount (UUID, LABEL, or device path) /dev/sda1, UUID=abc123
Mount Point Directory where device will be mounted /, /home, /mnt/data
Filesystem Type Type of filesystem ext4, ntfs, swap
Options Mount options (comma-separated) defaults, rw,noatime
Dump Backup operation (0=no, 1=yes) 0, 1
Pass Filesystem check order (0=no check) 0, 1, 2

Example Entries

Basic System Partitions

# Root filesystem
UUID=12345678-1234-1234-1234-123456789abc / ext4 defaults 0 1

# Home partition
UUID=87654321-4321-4321-4321-cba987654321 /home ext4 defaults 0 2

# Swap partition
UUID=abcdef12-3456-7890-abcd-ef1234567890 none swap sw 0 0

External Storage

# External USB drive
LABEL=MyUSB /mnt/usb ntfs defaults,uid=1000,gid=1000 0 0

# Network share
//server/share /mnt/network cifs username=user,password=pass 0 0

Temporary Filesystems

# tmpfs for /tmp
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

# proc filesystem
proc /proc proc defaults 0 0

Common Mount Options

Option Description
defaults Use default options (rw, suid, dev, exec, auto, nouser, async)
rw / ro Mount read-write / read-only
noatime Don't update access times (improves performance)
user / nouser Allow / disallow ordinary users to mount
auto / noauto Mount automatically / manually at boot
exec / noexec Allow / disallow execution of binaries
suid / nosuid Allow / disallow suid and sgid bits
dev / nodev Allow / disallow device files

Working with fstab

Editing fstab Safely

# Backup original file
sudo cp /etc/fstab /etc/fstab.backup

# Edit the file
sudo nano /etc/fstab

# Test configuration without rebooting
sudo mount -a

Finding Device Information

# List UUIDs
sudo blkid

# List filesystem information
lsblk -f

# Show mounted filesystems
df -h

Testing and Validation

# Test all fstab entries
sudo mount -a

# Test specific entry
sudo mount /mnt/data

# Check for errors
sudo mount -av

Practical Examples

1. Adding a New Hard Drive

# Find the new drive
sudo fdisk -l
sudo blkid

# Create mount point
sudo mkdir /mnt/storage

# Add to fstab
UUID=new-drive-uuid /mnt/storage ext4 defaults 0 2

2. Setting up Swap File

# Create swap file
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile

# Add to fstab
/swapfile none swap sw 0 0

3. Network File System (NFS)

# Install NFS client
sudo apt install nfs-common

# Add NFS mount to fstab
server.example.com:/path/to/share /mnt/nfs nfs defaults 0 0

Troubleshooting

Common Issues:
  • Boot failure: Incorrect fstab entries can prevent booting
  • Mount errors: Check device paths and filesystem types
  • Permission issues: Verify mount options and ownership
  • Network mounts: Ensure network connectivity and credentials

Recovery from Boot Issues

# Boot into recovery mode
# Mount root filesystem as read-write
mount -o remount,rw /

# Restore backup
cp /etc/fstab.backup /etc/fstab

# Or edit problematic entries
nano /etc/fstab

Related Commands

Mount Operations:
  • mount - Mount filesystems
  • umount - Unmount filesystems
  • findmnt - Find mounted filesystems
Disk Management:
  • lsblk - List block devices
  • blkid - Locate/print block device attributes
  • mkfs - Build filesystems

Frequently Asked Questions

The fstab file (/etc/fstab) is a system configuration file that contains information about filesystems and their mount points, used for automatic mounting at boot time. It defines how disk partitions and other storage devices should be integrated into the filesystem hierarchy.

Always backup the original file first with sudo cp /etc/fstab /etc/fstab.backup, then edit with sudo privileges. Test changes with mount -a before rebooting to avoid boot issues.

Use UUIDs instead of device names (like /dev/sda1) because device names can change between boots, especially when adding or removing drives. UUIDs are persistent and unique identifiers for each filesystem.

The dump field (0 or 1) determines if the filesystem should be backed up by the dump utility. The pass field controls the order of filesystem checks at boot: 1 for root filesystem, 2 for other filesystems, 0 to skip checking.

Boot into recovery mode or single-user mode, mount the root filesystem as read-write with mount -o remount,rw /, then either restore your backup or edit the problematic entries in /etc/fstab.