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.
Instructions
Q&A (0)
Notes (0)
Resources (0)
Saving Progress...
Resources
There are no resources for this lesson.
Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.
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
The /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/sdb
because UUIDs remain constant regardless of the state of the system. To find the UUID of your 25GB drive, use:bash
sudo blkid
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:
The /mnt/newvolume path assumes you completed the previous lecture where you created this directory.
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=your-UUID-here /mnt/newvolume ext4 defaults 0 2
Replace 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 likerw
for read-write,ro
for read-only,noexec
to prohibit executable files,nosuid
to block set-user-ID or set-group-ID bits, andnodev
to prevent the use of device files. Multiple options can be combined and are often set todefaults
for standard settings. - Dump (
<dump>
): Used by thedump
backup program to determine whether a filesystem should be backed up. If set to0
, the filesystem is ignored bydump
. Most modern systems set this to0
as they use more advanced backup tools. - Pass (
<pass>
): Dictates the order in which filesystem checks are performed during boot-up byfsck
. A setting of0
means no checks,1
is typically for the root filesystem (and should be unique), and numbers2
or 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 nano
, press 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.