Skip to main content

Adding a New Hard Disk to a Linux System

Hands-On Lab

 

Photo of Kenny Armstrong

Kenny Armstrong

Linux Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

Linux system administrators need to know how to add a new disk drive to a system, create a file system on that drive, and have it permanently mounted via the /etc/fstab file. This exercise will assist you in your practice of creating a new file system and mounting the file system to a directory, and configuring the system so that this mount persists across reboots.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Adding a New Hard Disk to a Linux System

Linux system administrators need to know how to add a new disk drive to a system, create a file system on that drive, and have it permanently mounted in /etc/fstab file. This lab will assist in the practice of creating a new filesystem, mounting the filesystem to a directory, and then configuring the system so the mount persists across reboots.

Create a New Partition

Before we go mounting any new partition up, we've got to create that partition.

Open up a terminal window and log in using the credentials provided on the lab page, replacing x.x.x.x with the public IP address listed:

$ ssh cloud_user@x.x.x.x

Enter the provided password when prompted.

Next, let's run the lsblk command to verify we have a /dev/xvdg device available. Once we've confirmed that, we'll create a partition on the /dev/xdg disk using fdisk. Note that we'll need to preface these commands with sudo for these commands. This partition we create will span the entire disk:

[cloud_user@host]$ lsblk
[cloud_user@host]$ sudo fdisk /dev/xvdg

After running fdisk, we'll have to perform a few tasks. At the Command (m for help): command, type n to make a new partition, then hit Enter. Our Partition type will be p, primary. Press Enter for Partition number, the First sector, and the Last sector options. This will make fdisk ready to create the partition. Type p at the Command (m for help): to print out what the disk will look like after we commit our changes. If that all looks good, type w and press Enter to write our changes to disk.

Create the Filesystem

Next, we've got to create a filesystem, so we can read and write data. We'll format the partition to the XFS file system with the mkfs.xfs command. Once that is complete, we'll run blkid on the newly created partition to obtain the UUID. We'll have to make a note of this UUID, since we're going to need it later:

[cloud_user@host]$ sudo mkfs.xfs /dev/xvdg1
[cloud_user@host]$ sudo blkid /dev/xvdg1

Mount the New Filesystem and Make It Permanent

We can mount this partition up manually with the mount command, but it won't be a persistent mount; it won't get mounted after something like a reboot.

We're going to edit /etc/fstab and create a new entry for the new disk at the bottom. The format should follow the following (be sure to use your disk's UUID from the previous step):

UUID=YOURUUID /opt xfs defaults 0 0

We can save the file, Then run:

[cloud_user@host]$ sudo mount -a

This will mount everything that's listed in fstab, including our new partition.

And running a quick df -h /opt should show us roughly 5GB available for the /opt directory.

Conclusion

You're all set. Congratulations on completing this lab!