Skip to main content

Storage Management

Hands-On Lab

 

Photo of Rob Marti

Rob Marti

Linux Training Architect I in Content

Length

01:00:00

Difficulty

Intermediate

In this lab, we’re going to go over managing and formatting partitions. Having a solid understanding of how to use these tools is a fundamental component of a Linux sysadmin career.

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.

Storage Management

Introduction

In this lab, we’re going to go over managing and formatting partitions. Having a solid understanding of how to use these tools is a fundamental component of a Linux sysadmin career.

Scenario

There are two disks advertised to this server. You've been tasked with setting one up with a GPT partition table and allocating 2GB to a single partition. The other needs to be a MBR partition with a 2GB partition.

Once those partitions have been created, format the /dev/xvdf1 disk with XFS and mount it persistently on /mnt/gptxfs. Format the /dev/xvdg1 disk as ext4 and mount it on /mnt/mbrext4. Ensure it does not mount automatically when the server boots up.

Get logged in

Use the credentials and server IP in the hands-on lab overview page to log into our lab server. Once we're in, we can get moving.

Create a 2GB GPT Partition on /dev/xvdf

We need to use gdisk /dev/xvdf to create our partition. Become root first:

[user@host]$ sudo -i
[root@host]# gdisk
  • Enter n to create a new partition.
  • Accept the default for the partition number.
  • Accept the default for the starting sector.
  • For the ending sector we type +2G to create a 2 Gigabyte partition.
  • Accept the default partition type.
  • Enter w to write the partition information

Once all that is complete, run partprobe to finalize these settings.

[root@host]# partprobe

Create a 2GB MBR Partition on /dev/xvdg

We need to use fdisk to create this partition:

[root@host]# `fdisk /dev/xvdg`
  • Enter n to create a new partition.
  • Accept the default for the partition number.
  • Accept the default for the starting sector.
  • For the ending sector we type +2G to create a 2 Gigabyte partition.
  • Enter w to write the partition information

Once all that is complete, run partprobe again.

Format the GPT Partition with XFS and Mount the Device on /mnt/gptxfs Persistently

To format the partition, we'll run mkfs.xfs:

[root@host]# mkfs.xfs /dev/xvdf1

Getting It Ready for Mounting

We need the UUID of the partition at /dev/xvdf1, and we can get it with this:

[root@host]# blkid

Copy it, then edit (with your text editor of choice) the /etc/fstab file and make a new line for it that looks something like:

UUID="&ltTHE_UUID_WE_COPIED>" /mnt/gptxfs xfs defaults 0 0

Create a Mount Point

We need to create the mount point that we specified in fstab:

[root@host]# mkdir /mnt/gptxfs

Now we can run a quick mount -a, which will mount everything that's described in fstab. To check, run mount with no options, and this partition should be listed in the output.

Format the MBR Partition with ext4 and Mount the Device on /mnt/mbrext4

Now we've got to do this all for the other partition we created, with some small differences.

The mkfs command isn't quite the same. Use this: mkfs.ext4 /dev/xvdg1. We're mounting it in a different spot, and it also needs to be created: mkdir /mnt/mbrext4. This won't be getting mounted at boot, so no fstab entry, just a mount command: mount /dev/xvdg1 /mnt/mbrext4.

Conclusion

We can run mount again with no options, and see that we've completed our objectives. We formatted a couple of partitions exactly as someone wanted them, created mount points for them, and set one up to mount at boot. Congratulations!