/etc/fstab
The /etc/fstab
file is a configuration file on Unix-like operating systems that contains information about different filesystems and partitions and their respective mount points. It is crucial for automating the process of mounting partitions and filesystems at boot time.
Structure of /etc/fstab
/etc/fstab
The file typically contains lines with the following fields:
Device: The device or partition to be mounted.
Mount Point: The directory where the device or partition will be mounted.
Filesystem Type: The type of filesystem on the device or partition (e.g.,
ext4
,xfs
,swap
,nfs
).Options: Mount options (e.g.,
defaults
,ro
,rw
,noatime
).Dump: Used by the
dump
utility to decide if a filesystem should be backed up (usually set to0
or1
).Pass: Used by
fsck
to determine the order in which filesystems should be checked at boot time (usually0
,1
, or2
).
Example /etc/fstab
/etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=123e4567-e89b-12d3-a456-426655440000 / ext4 defaults,noatime 0 1
UUID=123e4567-e89b-12d3-a456-426655440001 /home ext4 defaults 0 2
UUID=123e4567-e89b-12d3-a456-426655440002 none swap sw 0 0
UUID=123e4567-e89b-12d3-a456-426655440003 /mnt/data ext4 defaults 0 2
192.168.1.100:/export/nfs /mnt/nfs nfs defaults 0 0
Fields Explained
Device
Can be specified by the device file (e.g.,
/dev/sda1
), UUID (e.g.,UUID=123e4567-e89b-12d3-a456-426655440000
), or LABEL (e.g.,LABEL=root
).
Mount Point
The directory where the filesystem will be mounted. For swap space, use
none
.
Filesystem Type
Common types include
ext4
,xfs
,btrfs
,nfs
,vfat
,ntfs
, andswap
.
Options
defaults
: Uses the default options (rw
,suid
,dev
,exec
,auto
,nouser
,async
).ro
: Mounts the filesystem as read-only.rw
: Mounts the filesystem as read-write.noatime
: Prevents the system from updating the access time on files.auto
: Automatically mounts the filesystem at boot.noauto
: Does not mount the filesystem at boot.user
: Allows a non-root user to mount the filesystem.
Dump
0
: Do not dump.1
: Dump this filesystem.
Pass
0
: Do not check.1
: Check this filesystem first.2
: Check this filesystem after those with a1
.
Common Use Cases
Mounting a Local Disk Partition
/dev/sda1 / ext4 defaults 0 1
Mounting a Swap Partition
/dev/sda2 none swap sw 0 0
Mounting a Network Filesystem (NFS)
192.168.1.100:/export/nfs /mnt/nfs nfs defaults 0 0
Mounting a Filesystem by UUID
UUID=123e4567-e89b-12d3-a456-426655440000 /home ext4 defaults 0 2
Managing /etc/fstab
/etc/fstab
Adding a New Entry
Edit
/etc/fstab
sudo nano /etc/fstab
Add the new entry:
UUID=123e4567-e89b-12d3-a456-426655440004 /mnt/newdisk ext4 defaults 0 2
Create the mount point:
sudo mkdir -p /mnt/newdisk
Mount all filesystems:
sudo mount -a
Conclusion
The /etc/fstab
file is an essential configuration file for defining how and where disk partitions, network shares, and other filesystems are mounted. Understanding its structure and options allows for effective management of system storage, ensuring that filesystems are correctly mounted at boot time or on demand.
Last updated