Configure /etc/fstab to Persistently Mount a File System

30 minutes
  • 7 Learning Objectives

About this Hands-on Lab

Learning to create file systems and persistently mount them across reboots is an essential skill for Linux administrators. In this lab, we format two new system disks and create filesystems on the newly-created disk partitions. Then we create the directories for the mount points and configure `/etc/fstab` to persistently mount the file systems so they are available on system startup.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log in to the Lab Server and Gain `root` Access
# sudo -i
Format `xvdb`

List the available system disks and format /dev/xvdb. Enter n for new partition, p for primary, and take the defaults. Type w to write the changes to the system.

# lsblk
# fdisk /dev/xvdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xae23de7b.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-4194303, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): 
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
Create the File System and Directory for `dbadmin`
# mkfs.xfs /dev/xvdb1
# mkdir /dbadmin
Configure `xvdb1` to Be Persistently Mounted

Configure /etc/fstab to persistently mount the /dbadmin file system as read-only. Mount the file system, verify it mounted successfully, and test creating a file in that directory.

# blkid /dev/xvdb1
# vim /etc/fstab    
    UUID:<YOURDEVICESUUID>      /dbadmin    xfs ro,defaults 0   0
# mount -a
# df -h
# cd /dbadmin
# touch test
 touch: cannot touch ‘test’: Read-only file system
Format `xvdc`

List the available system disks and format /dev/xvdc. Enter n for new partition, p for primary, and take the defaults. Type w to write the changes to the system.

# lsblk
# fdisk /dev/xvdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xae23de7b.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-4194303, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): 
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
Create the File System and Directory for `www`
# mkfs.xfs /dev/xvdc1
# mkdir /www
Configure `xvdc1` to Be Persistently Mounted

Configure /etc/fstab to persistently mount the /www file system. Mount the file system and verify it mounted successfully.

# blkid /dev/xvdc1
# vim /etc/fstab    
    UUID:<YOURDEVICESUUID>      /www    xfs defaults    0   0
# mount -a
# df -h

Additional Resources

The database team at ABC Company has requested that a 2 GB, read-only file system be created and mounted as /dbadmin. The web team has also requested that a 2 GB file system be created and mounted as /www.

To complete this lab, create the /dbadmin directory and persistently mount it as read-only. Then create and persistently mount the /www directory with the default options.

Please use the lab environment since the Cloud Playground isn't configured for this exercise. Good luck!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?