Creating Permanent Mounts with /etc/fstab
Full-Access Members Only
Sorry, this lesson is only available to Server Academy Full-Access members. Become a Full-Access member now and get instant access to this and many more premium courses. Click the button below and get instant access now.
There are no resources for this lesson.
In this lesson, we will explore how to create permanent mounts in Linux using the
/etc/fstab file. This is an essential skill for managing Linux systems, particularly in server environments, where stable and reliable access to different storage volumes is crucial. We'll specifically focus on making the mount of our 25GB disk (
sdb) permanent on our "Ubuntu Server" VM.
Understanding the /etc/fstab File
/etc/fstab file in Linux is used to define how disk partitions, various other storage devices, or remote file systems should be mounted into the filesystem. Each line in the
fstab file represents a device or partition and its associated mount point, along with other mount options. Making an entry in this file ensures that the device is mounted automatically at every system startup.
Steps to Create a Permanent Mount
- Identify the UUID of the Device: Using UUIDs (Universally Unique Identifiers) is preferable over device names like
/dev/sdbbecause UUIDs remain constant regardless of the state of the system. To find the UUID of your 25GB drive, use:bash
Locate the line for
/dev/sdb and note down its UUID. In my example it is the following:
/dev/sdb: UUID="5e43d35b-acb2-4f7e-a02e-b53b1fe7233a" BLOCK_SIZE="4096" TYPE="ext4"
So I will copy the UUID for future use.
Backup the Existing fstab File: Before editing the
fstab file, it's a good practice to create a backup. This way, if something goes wrong, you can restore the original state.
sudo cp /etc/fstab /etc/fstab.backup
Edit the fstab File: Open the
fstab file with a text editor. For beginners,
nano is a user-friendly option:
sudo nano /etc/fstab
Add Your Mount Entry: In the
fstab file, add a line for the new drive. The format should be as follows:
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=your-UUID-here /mnt/newvolume ext4 defaults 0 2
your-UUID-here with the actual UUID, and make sure the mount point (
/mnt/newvolume) and the filesystem type (
ext4) are correct.
You might be wondering what options, dump and pass are used for in the fstab file:
- Options (
<options>): This field defines how the filesystem is mounted. It includes parameters like
noexecto prohibit executable files,
nosuidto block set-user-ID or set-group-ID bits, and
nodevto prevent the use of device files. Multiple options can be combined and are often set to
defaultsfor standard settings.
- Dump (
<dump>): Used by the
dumpbackup program to determine whether a filesystem should be backed up. If set to
0, the filesystem is ignored by
dump. Most modern systems set this to
0as they use more advanced backup tools.
- Pass (
<pass>): Dictates the order in which filesystem checks are performed during boot-up by
fsck. A setting of
0means no checks,
1is typically for the root filesystem (and should be unique), and numbers
2or higher are for other filesystems, dictating the sequence of checks.
Save the fstab File: After adding the new line, save and exit the editor. In
Ctrl + O,
Enter, and then
Ctrl + X to do this.
Test the Configuration: To ensure there are no errors in the
fstab entry, test it by mounting all filesystems:
sudo mount -a
If there are no error messages, your entry is likely correct.
Reboot and Verify: Reboot the system to ensure the new mount works correctly:
sudo reboot now
Server Academy Members Only
Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.