Introduction / Purpose
The fstab file (/etc/fstab) is a key configuration file in Linux that defines how the system should mount partitions and removable media at boot. Proper fstab configuration allows disks to be automatically mounted, avoids manual mounting after each reboot, and sets access parameters. In this guide, you will learn the basic fstab syntax, how to add new entries for various filesystem types, and how to avoid common errors.
Prerequisites / Preparation
Before you begin, ensure you have:
- Superuser access (
sudoprivileges). - Basic understanding of terms: disk partition, mount point, filesystem.
- A backup of your current fstab (in case of errors):
sudo cp /etc/fstab /etc/fstab.backup - Utilities installed for working with different filesystems (e.g.,
ntfs-3gfor NTFS,cifs-utilsfor SMB).
Step 1: Understand the fstab Line Structure
Each line in fstab describes one partition or device and consists of six fields, separated by spaces or tabs:
<device> <mount_point> <fs_type> <options> <dump> <pass>
Field explanations:
<device>— How to identify the partition. It is recommended to use UUID (unique identifier) or LABEL (volume label). Examples:UUID=1234-ABCDLABEL=MyData/dev/sda1(not recommended, as device names can change).
<mount_point>— The directory where the partition will be mounted. It must exist (create it beforehand if needed).<fs_type>— The filesystem type. Common values:ext4,ext3,ext2— for Linux partitions.ntfs— for Windows partitions (use thentfs-3gdriver).vfat— for FAT32.swap— for swap partitions.nfs,cifs— for network drives.auto— automatic detection (not always reliable).
<options>— A comma-separated list of mount options without spaces. Most common:defaults— a set of standard options:rw,suid,dev,exec,auto,nouser,async.noatime— do not update file access time (improves performance).nodiratime— same for directories.uid=1000,gid=1000— set owner and group (for FAT/NTFS).dmask=022,fmask=133— permission masks for directories and files.noauto— do not mount automatically at boot (only on command)._netdev— wait for network connection (for NFS/SMB).
<dump>— Used by thedumputility. Usually0(do not dump).<pass>— The order in which the filesystem is checked at boot (fsck).0— do not check.1— for the root partition (/).2— for other partitions.
Example line:
UUID=1234-ABCD / ext4 defaults,noatime 0 1
Step 2: Determine the UUID of the Target Partition
UUID is the most reliable way to identify partitions. To find the UUID:
- Run the command:
sudo blkid - Find the desired partition in the output. Example:
/dev/sda1: UUID="1234-ABCD" TYPE="ext4" PARTUUID="..." /dev/sdb1: UUID="5678-EFGH" TYPE="ntfs" PARTUUID="..." - Copy the
UUIDvalue (in quotes) for use in fstab.
💡 Tip: If a partition does not appear in
blkid, it may not contain a filesystem or is not connected. Ensure the disk is properly connected.
Step 3: Add a New Entry to fstab
- Open the
/etc/fstabfile in a text editor with superuser privileges (e.g.,nanoorvim):sudo nano /etc/fstab - Add a new line at the end of the file, following the format from Step 1. Ensure that:
- Fields are separated by spaces or tabs (do not mix!).
- The mount point exists (create it if needed:
sudo mkdir -p /mnt/mydisk).
- Save the file and close the editor.
Examples for different filesystem types:
- ext4 (system or user Linux partition):
UUID=1234-ABCD / ext4 defaults,noatime,errors=remount-ro 0 1
Theerrors=remount-rooption will remount the partition as read-only on errors. - NTFS (secondary Windows partition):
UUID=5678-EFGH /mnt/ntfs ntfs-3g defaults,uid=1000,gid=1000,dmask=022,fmask=133 0 0
Replaceuid=1000,gid=1000with your own IDs (find them viaid -uandid -g). - Swap (swap partition):
UUID=9012-IJKL none swap sw 0 0 - NFS network drive:
nfs-server:/share /mnt/nfs nfs defaults,_netdev 0 0_netdevensures mounting waits for the network to be ready. - USB drive FAT32:
UUID=MNOP-QRST /mnt/usb vfat defaults,utf8,uid=1000,gid=1000 0 0
Step 4: Check Syntax and Test Mounting
Do not reboot immediately! First, check the syntax and ensure the new entries work:
- Run the command to check all fstab entries:
sudo mount -a- If the output is empty and the return code is
0— the syntax is correct, and all partitions are mounted (or were already mounted). - If errors appear (e.g.,
wrong fs typeorno such device), go back to fstab and fix the entry.
- If the output is empty and the return code is
- Ensure the partition is mounted:
mount | grep /mount_point
Or:df -hT /mount_point
The output should show your partition with the correct filesystem type. - Check permissions (especially for NTFS/FAT):
ls -ld /mount_point
The owner should be theuidspecified in the options (usually your user).
Step 5: Reboot the System or Apply Changes
If mount -a succeeded:
- Option 1: Reboot the system to test automatic mounting at boot:
After booting, check again withsudo rebootdf -h. - Option 2: If you want to apply changes without rebooting, mount the specific partition:
sudo mount /mount_point
Verifying the Result
After rebooting or manual mounting, ensure that:
- The partition appears in the output of
df -hormount. - Files on the partition are accessible for reading/writing (depending on options).
- For a swap partition, check:
sudo swapon --show(should be listed).
If the partition did not mount automatically, check:
- The UUID is correct (run
blkidagain). - The mount point exists.
- There are no typos in fstab (especially in options).
Troubleshooting
1. System does not boot after editing fstab
Symptom: Boot stops with Failed to mount /... or drops to emergency mode.
Solution:
- Boot into recovery mode or use a LiveCD.
- Unmount the problematic partition if needed:
sudo umount /mount_point. - Edit fstab, commenting out the problematic line (add
#at the beginning). - Reboot and fix the entry, comparing with the examples.
2. Error wrong fs type, bad option, bad superblock
Cause: Incorrect filesystem type, options, or corrupted superblock. Solution:
- Check the filesystem type via
sudo blkidand correct the third field. - Simplify options: start with
defaults. - For NTFS, ensure
ntfs-3gis installed:sudo apt install ntfs-3g(Debian/Ubuntu) orsudo yum install ntfs-3g(RHEL/Fedora).
3. Partition mounts but access is root-only
Cause: For filesystems that do not support Linux permissions (FAT, NTFS), uid/gid are not set.
Solution: Add uid=1000,gid=1000 to the options (substitute your own IDs). For NTFS, you can also use umask=022 for shared permissions.
4. Network drive does not mount at boot
Cause: Network is not yet ready.
Solution: Add the _netdev option to the options field. You can also increase the timeout in the systemd unit (but that is an advanced setting).
5. Error mount: /mount_point: special device /dev/sdX1 does not exist.
Cause: The device name has changed (e.g., /dev/sda1 → /dev/sdb1).
Solution: Use UUID instead of the /dev/sdX path. This solves the problem in 99% of cases.
⚠️ Important: Always back up
/etc/fstabbefore editing. One mistake can make the system unbootable.
You are now confident with fstab! For more complex scenarios (such as conditional mounting or encryption), explore advanced options in man mount and man fstab.