Mounting Drives Permanently With /etc/fstab
A Linux drive mounts perfectly when you click it in the desktop.
Then you reboot.
It disappears.
For servers, backup disks, data volumes and application storage, that is usually not what you want. The normal way to make a filesystem mount automatically at boot is to define it in:
/etc/fstab
But /etc/fstab is also one of those files where a small mistake can create a surprisingly large startup problem.
The safe order is:
identify the device → test the mount manually → use a stable identifier → add the fstab entry → validate it → mount without rebooting → only then restart.
What Is /etc/fstab?
fstab stands for filesystem table.
It tells Linux which filesystems should be mounted, where they should appear and which mount options should be used.
A typical line looks like:
UUID=1234-ABCD /srv/data ext4 defaults 0 2
Broadly, the six fields are:
device mount-point filesystem options dump fsck-order
Each part matters.
Do Not Use /dev/sdb1 Unless You Have a Good Reason
A device path such as:
/dev/sdb1
may look permanent.
It is not necessarily.
Drive enumeration can change after:
- adding storage
- removing storage
- changing controller order
- kernel updates
- moving devices between ports
Today your data disk might be:
/dev/sdb1
Tomorrow it could become:
/dev/sdc1
That is why persistent mounts should usually use something more stable such as:
- UUID
- filesystem label
- PARTUUID
For ordinary filesystems, UUID is usually the simplest choice.
Step 1: Identify the Drive
Start with:
lsblk -f
This shows useful information such as:
- device
- filesystem type
- label
- UUID
- current mount point
Example:
NAME FSTYPE FSVER LABEL UUID MOUNTPOINTS
sda
└─sda1 ext4 1.0 a1b2c3d4-e5f6-7890-abcd-1234567890ab /
sdb
└─sdb1 ext4 1.0 DATA 7d3fdc42-93b2-49fb-a871-82c4497398ef
Here the second disk is:
/dev/sdb1
with UUID:
7d3fdc42-93b2-49fb-a871-82c4497398ef
You can also use:
blkid
for detailed filesystem identifiers.
Step 2: Confirm the Filesystem
Do not assume every Linux data disk is ext4.
Possible types include:
- ext4
- XFS
- Btrfs
- NTFS
- exFAT
- FAT32
The filesystem type in /etc/fstab needs to match the actual filesystem.
For example:
ext4
is not interchangeable with:
xfs
Use:
lsblk -f
or:
blkid
to confirm it.
Step 3: Create the Mount Point
Decide where the filesystem should appear.
Common choices include:
/mnt/data
or:
/srv/data
For permanent application or server data, I often prefer something under:
/srv
For example:
sudo mkdir -p /srv/data
The directory becomes the mount point.
Anything already stored inside that directory will be hidden while another filesystem is mounted over it, so check first:
ls -la /srv/data
Do not mount over a directory containing important existing data unless you understand the consequence.
Step 4: Test the Mount Manually First
Before editing /etc/fstab, prove that the filesystem can mount successfully.
For an ext4 filesystem:
sudo mount /dev/sdb1 /srv/data
Then check:
df -hT /srv/data
and:
ls -la /srv/data
If that fails, solve the actual mount problem before making it automatic.
An fstab entry does not fix:
- corrupt filesystem
- unsupported filesystem driver
- wrong device
- bad permissions
- hardware failure
It simply automates a mount that should already work.
Step 5: Get the UUID
Use:
blkid /dev/sdb1
You may see:
/dev/sdb1: UUID="7d3fdc42-93b2-49fb-a871-82c4497398ef" TYPE="ext4"
Copy the UUID carefully.
A typo here is one of the easiest ways to create a failed boot-time mount.
Step 6: Back Up /etc/fstab
Before editing:
sudo cp /etc/fstab /etc/fstab.backup
Or timestamp it:
sudo cp /etc/fstab "/etc/fstab.backup-$(date +%F-%H%M)"
That gives you a quick rollback if needed.
Step 7: Edit /etc/fstab
Open it using your preferred editor:
sudo nano /etc/fstab
Add something such as:
UUID=7d3fdc42-93b2-49fb-a871-82c4497398ef /srv/data ext4 defaults 0 2
Do not add random mount options copied from another filesystem or server.
For an ordinary Linux data partition, defaults is usually a reasonable starting point.
What Do the Last Two Numbers Mean?
In:
UUID=... /srv/data ext4 defaults 0 2
the final fields are:
0
Traditionally controls the old dump backup utility.
Most modern systems use:
0
2
Controls filesystem-check ordering at boot.
Common convention:
1
for the root filesystem.
2
for other local filesystems.
0
means do not automatically check through this mechanism.
Do not blindly copy the root filesystem's 1 onto every disk.
Step 8: Validate Before Rebooting
This is probably the most important habit in the article.
Run:
sudo findmnt --verify
This checks /etc/fstab for problems.
Then unmount your manual test:
sudo umount /srv/data
and ask Linux to mount everything defined in fstab:
sudo mount -a
If there are no errors, check:
findmnt /srv/data
and:
df -hT /srv/data
If the drive mounted correctly through:
mount -a
you now have much stronger evidence that the entry is valid.
Do not make:
save file → reboot immediately
your normal workflow.
What If mount -a Returns an Error?
Stop.
Read the message.
Common causes include:
- wrong UUID
- wrong filesystem type
- missing mount point
- invalid option
- missing filesystem helper/package
Fix the error and run:
sudo mount -a
again.
Do not reboot hoping Linux will somehow behave differently.
Use nofail Carefully
For a secondary disk that should not make the server fail to boot if it is unavailable, you may see:
nofail
For example:
UUID=... /srv/archive ext4 defaults,nofail 0 2
This tells the system not to treat failure to mount that filesystem as fatal to boot.
That can be useful for:
- removable drives
- non-critical archive disks
- optional storage
But it can be dangerous for a critical application filesystem.
Suppose a database is expected under:
/srv/database
but the drive fails to mount.
With nofail, the server may boot and the application may start writing into the empty local directory underneath.
Now you have data written onto the wrong filesystem.
So ask:
Should this server really continue normally if this disk is missing?
If the answer is no, nofail may not be appropriate.
x-systemd.automount Can Improve Some Mounts
On systemd-based Linux distributions, another useful option is:
x-systemd.automount
For example:
UUID=... /srv/archive ext4 defaults,x-systemd.automount 0 2
Instead of mounting the filesystem immediately during boot, systemd can create an automount point and mount it when accessed.
This can be useful for:
- slower storage
- network mounts
- filesystems not required immediately during startup
It is not automatically better for every disk.
For a core application filesystem that must be present before a service starts, a normal boot-time mount may be preferable.
Network Mounts Need Different Treatment
An NFS or SMB share is not the same as a local SSD.
The network may not be available when boot begins.
For network filesystems, options often need to account for that.
Examples can include:
_netdev
and, on systemd systems:
x-systemd.automount
For example, an NFS mount might look conceptually like:
server:/exports/data /srv/network-data nfs defaults,_netdev,x-systemd.automount 0 0
Do not copy this blindly.
Network mounts need to be designed around:
- authentication
- DNS
- network readiness
- failure behaviour
- application dependencies
NTFS and exFAT Need Appropriate Filesystem Support
If you are mounting a Windows-formatted external disk, you may see:
ntfs
or:
exfat
The system needs the relevant filesystem support.
Also think about ownership and permissions.
A mount that succeeds but leaves every file owned unexpectedly can be just as problematic as one that fails.
Test manually first.
Labels Can Be Easier to Read Than UUIDs
Instead of:
UUID=7d3fdc42-93b2-49fb-a871-82c4497398ef
you can sometimes use:
LABEL=DATA
That makes fstab easier to read.
But labels must be:
- unique
- managed deliberately
Two filesystems both labelled:
DATA
create ambiguity.
UUIDs are less human-friendly but generally safer against accidental duplication.
What About USB Drives?
You can put a USB drive in /etc/fstab.
But think carefully about what happens when it is disconnected.
For an optional USB backup disk, something like:
nofail
may be sensible.
For a permanently attached storage device, a normal UUID-based mount may work perfectly.
The important point is that boot behaviour should match the hardware's real role.
Check Permissions After Mounting
A successful mount can still leave an application unable to access the data.
Check:
ls -ld /srv/data
and the files inside it.
For Linux-native filesystems such as ext4, ownership and permissions normally belong to the filesystem itself.
You may need to adjust them using:
chown
or:
chmod
but do not recursively change permissions until you understand what the intended ownership should be.
A mount problem and a permissions problem are different things.
Mounting Over an Existing Directory Can Hide Files
Suppose:
/srv/data
already contains:
important.txt
Then you mount another filesystem onto:
/srv/data
important.txt appears to disappear.
It has not necessarily been deleted.
It is hidden underneath the mounted filesystem.
If you unmount:
sudo umount /srv/data
the original directory contents become visible again.
This behaviour surprises a lot of people.
Always inspect the mount point before using it.
Check Which Filesystem Is Actually Mounted
Use:
findmnt /srv/data
or:
mount | grep /srv/data
findmnt is usually clearer.
It can show:
- source device
- target path
- filesystem type
- options
That helps prevent the dangerous assumption:
“The directory exists, so the external disk must be mounted.”
A directory existing proves nothing about whether a separate filesystem is currently mounted there.
A Critical Server Safety Check
Before starting an application that depends on a separate mount, verify the mount exists.
For example:
mountpoint -q /srv/database || {
echo "Database filesystem is not mounted" >&2
exit 1
}
That can be built into operational scripts or service dependencies.
It is much safer than allowing an application to silently write onto / because the intended data volume failed to mount.
If a Mount Suddenly Stops Working After Reboot
Check:
systemctl --failed
and:
journalctl -b
Search for mount-related errors.
Also run:
findmnt --verify
and:
blkid
Check that:
- device still exists
- UUID has not changed
- filesystem is healthy
- mount point exists
A cloned or reformatted filesystem may have a different UUID from the one stored in /etc/fstab.
Do Not Repair a Filesystem While It Is Mounted Read-Write
If the mount fails because the filesystem itself is damaged, you may need tools such as:
fsck
for applicable filesystem types.
Do not casually run filesystem repair against a mounted read-write filesystem.
The correct repair procedure depends on:
- filesystem
- root/non-root volume
- server role
At that point, treat it as a filesystem-recovery task rather than an fstab task.
The Safe /etc/fstab Workflow
For a permanent local disk:
- Identify it:
lsblk -f
- Confirm filesystem and UUID.
- Create the mount point:
sudo mkdir -p /srv/data
- Test manually:
sudo mount /dev/sdb1 /srv/data
- Confirm the data is correct.
- Back up
/etc/fstab. - Add the UUID-based entry.
- Validate:
sudo findmnt --verify
- Test without rebooting:
sudo umount /srv/data
sudo mount -a
- Confirm:
findmnt /srv/data
- Only then reboot if you want to verify full startup behaviour.
That process is much safer than:
edit fstab → cross fingers → reboot.
A Useful Example
You add a new 2 TB ext4 disk.
lsblk -f reports:
/dev/sdb1
UUID=2bf95db6-2ff3-4ef7-a339-b4ccbc2eab71
You want it at:
/srv/files
Create the mount point:
sudo mkdir -p /srv/files
Test:
sudo mount /dev/sdb1 /srv/files
Then add:
UUID=2bf95db6-2ff3-4ef7-a339-b4ccbc2eab71 /srv/files ext4 defaults 0 2
Validate:
sudo findmnt --verify
Test:
sudo umount /srv/files
sudo mount -a
findmnt /srv/files
If that succeeds, you now have a properly tested persistent mount.
How Hamilton Group Can Help
Hamilton Group can help businesses manage Linux storage safely, including:
/etc/fstab- Linux servers
- storage expansion
- filesystem mounts
- NFS and SMB
- disk replacement
- backups
- server monitoring
- storage troubleshooting
For production systems, the goal is not simply to make a disk appear after reboot. It is to ensure that the correct filesystem mounts reliably, application dependencies are understood and a missing disk cannot silently redirect important data onto the wrong volume.
Visit hgmssp.com or call 01423 438 953.
0 comments
- Be the first to comment.