The /etc/fstab
(File System Table) file is used to define how storage devices, partitions, and file systems should be mounted automatically at boot.
Table of Contents
Toggle1. Viewing the /etc/fstab
File
To display the contents of /etc/fstab
:
cat /etc/fstab
or
sudo nano /etc/fstab
2. /etc/fstab
File Format
Each line in /etc/fstab
follows this format:
<DEVICE> <MOUNT_POINT> <FILESYSTEM> <OPTIONS> <DUMP> <FSCK_ORDER>
Column | Description |
---|---|
DEVICE | The disk/partition (e.g., /dev/sdb1 or UUID=xxxx ). |
MOUNT_POINT | Directory where it is mounted (e.g., /mnt/data ). |
FILESYSTEM | File system type (ext4 , xfs , ntfs , vfat , etc.). |
OPTIONS | Mount options (defaults , noexec , ro , etc.). |
DUMP | Backup option (0 = no backup, 1 = backup with dump ). |
FSCK_ORDER | File system check order (0 = no check, 1 = root, 2 = others). |
3. Example /etc/fstab
Entries
Mount an ext4
Partition
UUID=1234abcd-5678 /mnt/data ext4 defaults 0 2
๐น Mounts an ext4
file system at /mnt/data
with default options.
Mount a Swap Partition
UUID=5678efgh-9101 none swap sw 0 0
๐น Enables a swap partition.
Mount a Windows NTFS Partition
UUID=abcd1234-efgh-5678 /mnt/windows ntfs-3g defaults 0 0
๐น Mounts an NTFS partition using ntfs-3g
.
Mount a USB Drive (vFAT)
UUID=9F7A-1D2C /mnt/usb vfat defaults,uid=1000,gid=1000 0 0
๐น Ensures a FAT32 USB drive is mounted with correct permissions.
Mount an NFS Share
192.168.1.100:/shared /mnt/nfs nfs defaults 0 0
๐น Mounts an NFS share from a remote server.
4. Get Partition UUIDs for /etc/fstab
Use blkid
to find UUIDs:
sudo blkid
or
lsblk -o NAME,UUID,MOUNTPOINT
Use these UUIDs in /etc/fstab
instead of /dev/sdX
for reliability.
5. Apply Changes Without Reboot
To reload /etc/fstab
without rebooting:
sudo mount -a
๐น This mounts all file systems listed in /etc/fstab
.
6. Common Mount Options
Option | Description |
---|---|
defaults |
Uses default mount settings (rw, suid, dev, exec, auto, nouser, async ). |
ro |
Mount as read-only. |
rw |
Mount as read-write. |
noexec |
Prevents execution of binaries. |
nosuid |
Ignores SUID bit for security. |
nofail |
Continues boot even if the mount fails. |
uid=1000,gid=1000 |
Sets owner to user ID 1000 (useful for USB drives). |
7. Troubleshooting /etc/fstab
Issues
If a misconfiguration causes boot failure:
- Boot into recovery mode or a live Linux USB.
- Edit
/etc/fstab
:sudo nano /etc/fstab
- Comment out the problematic line by adding
#
at the beginning. - Save and reboot.
To check for errors before rebooting:
sudo mount -a
โ Summary
/etc/fstab
is used for automatic mounting.- Use
blkid
to get UUIDs for reliable mounting. - Mounting options affect performance and security.
- Test changes with
sudo mount -a
before rebooting.