Introduction
In this lab, you will gain hands-on experience managing storage partitions and swap space on Red Hat Enterprise Linux (RHEL) systems. You will learn to create and persistently mount XFS partitions, as well as configure and activate swap partitions with varying priorities. The lab uses the LabEx VM environment with available storage devices, allowing you to practice these essential system administration skills.
You will begin by inspecting available disks, then proceed to create and manage partitions, including setting up GPT partition tables where necessary. The lab emphasizes ensuring persistent mounts and swap activation, providing a comprehensive understanding of disk management in a RHEL environment.
Inspect the available practice disk
In this step, you will inspect the available storage devices on your LabEx VM. The LabEx environment provides one additional storage device for partitioning practice, but its device name can vary between VM instances.
First, switch to the root user to perform disk management operations. You are currently logged in as the labex user with sudo privileges.
sudo su -
Now, examine the available block devices on the system using the lsblk command:
lsblk
You should see output similar to this, showing the system disk and one extra disk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 253:0 0 40G 0 disk
├─vda1 253:1 0 1M 0 part
├─vda2 253:2 0 100M 0 part /boot/efi
└─vda3 253:3 0 39.9G 0 part /
nvme1n1 259:0 0 40G 0 disk
Next, identify the extra practice disk and define reusable shell variables for the remaining steps. The PRACTICE_DISK variable stores the disk device, and PART_PREFIX handles the partition naming difference between devices such as /dev/vdb1 and /dev/nvme1n1p1.
export ROOT_PARTITION="$(findmnt -n -o SOURCE /)"
export ROOT_DISK="/dev/$(lsblk -no PKNAME "$ROOT_PARTITION")"
export PRACTICE_DISK="$(lsblk -dpno NAME,TYPE | awk -v root="$ROOT_DISK" '$2=="disk" && $1 != root {print $1; exit}')"
if [[ "$PRACTICE_DISK" =~ [0-9]$ ]]; then
export PART_PREFIX="${PRACTICE_DISK}p"
else
export PART_PREFIX="${PRACTICE_DISK}"
fi
echo "Practice disk: $PRACTICE_DISK"
echo "Partition prefix: $PART_PREFIX"
You should see output similar to this. Your device name may be /dev/vdb, /dev/nvme0n1, or /dev/nvme1n1.
Practice disk: /dev/nvme1n1
Partition prefix: /dev/nvme1n1p
Use the lsblk command with the -f option to display filesystem information for the practice disk:
lsblk -f "$PRACTICE_DISK"
You should see output similar to this, indicating that the practice disk is a new, unformatted disk:
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
nvme1n1
Next, use the parted command to get more detailed information about the disk, including its partition table:
parted "$PRACTICE_DISK" print
The output should show that there is no partition table on the practice disk yet. The model and device name will match your VM instance:
Error: /dev/nvme1n1: unrecognised disk label
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
This confirms that the extra practice disk is ready for partitioning. The error message is normal for a disk that has not been initialized with a partition table yet.
Create an XFS partition on the practice disk and mount it persistently
In this step, you will create a new partition on the practice disk, format it with the XFS file system, and configure it to mount persistently.
The commands below assume you are still in the same root shell from Step 1, so the PRACTICE_DISK and PART_PREFIX variables are still available. You will create a 1 GB primary partition on that disk and specify the file system type as XFS. Starting at sector 2048s is a common alignment choice.
First, create a partition table on the uninitialized disk. Use parted in interactive mode to create the partition table and partition:
parted "$PRACTICE_DISK"
GNU Parted 3.5
Using /dev/nvme1n1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel msdos
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? xfs
Start? 2048s
End? 1001MB
(parted) quit
Information: You may need to update /etc/fstab.
Note: The mklabel msdos command creates an MBR (Master Boot Record) partition table on the disk. This is required before you can create any partitions. After creating the partition table, you can proceed with mkpart to create the actual partition. Because the partition starts at sector 2048s, setting the end position to 1001MB results in a partition size of approximately 1 GB. When you quit parted, you will see an informational message about updating /etc/fstab, which is normal.
To verify that the partition has been created, print the partition table for the practice disk:
parted "$PRACTICE_DISK" print
You should see output similar to this, showing your newly created primary partition:
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1001MB 1000MB primary
After creating a new partition, run udevadm settle so the kernel registers the new partition device, such as /dev/vdb1 or /dev/nvme1n1p1.
udevadm settle
Now that the partition is created, format it with the XFS file system:
mkfs.xfs "${PART_PREFIX}1"
The output will show details about the XFS file system creation:
meta-data=/dev/nvme1n1p1 isize=512 agcount=4, agsize=61056 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1 nrext64=0
data = bsize=4096 blocks=244224, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
To make the file system accessible, create a mount point directory. You will mount this partition to /archive.
mkdir -p /archive
For persistent mounting, add an entry to /etc/fstab. Use the partition UUID because device names such as /dev/vdb1 or /dev/nvme1n1p1 can vary between environments.
Discover the UUID of the first partition:
lsblk --fs "${PART_PREFIX}1"
Note down the UUID from the output. It will look something like 881e856c-37b1-41e3-b009-ad526e46d987.
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
nvme1n1p1 xfs 2ee03827-6acf-4543-9a21-0fd031250b45
Now, open the /etc/fstab file using nano and add a new line for your partition. Replace YOUR_UUID_HERE with the actual UUID you just found.
nano /etc/fstab
Add the following line to the end of the file:
UUID=YOUR_UUID_HERE /archive xfs defaults 0 0
Save the file by pressing Ctrl+X, then Y to confirm, and Enter to write to the file.
After modifying /etc/fstab, tell systemd to reload its configuration so it recognizes the new entry.
systemctl daemon-reload
Finally, mount the new file system using the entry in /etc/fstab.
mount /archive
Verify that the new file system is mounted correctly:
mount | grep /archive
You should see output similar to this, confirming the successful mount:
/dev/nvme1n1p1 on /archive type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
Create and activate a swap partition on the practice disk
In this step, you will create a swap partition on the practice disk. Swap space is a portion of a hard disk drive (HDD) or solid-state drive (SSD) used for temporary storage when the system runs out of physical RAM. It acts as an overflow for RAM, allowing the system to continue operating even when memory is scarce, though at a slower speed.
First, inspect the current partition table on the practice disk to determine where to create the new swap partition.
parted "$PRACTICE_DISK" print
You should see the existing XFS partition (${PART_PREFIX}1) that you created in the previous step:
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1001MB 1000MB primary xfs
Now, add a new primary partition of 500 MB for use as swap space. The new partition starts immediately after the existing first partition, so it begins at 1001MB and ends at 1501MB.
Use parted in non-interactive mode to create this partition:
parted "$PRACTICE_DISK" mkpart primary linux-swap 1001MB 1501MB
You might see the Information: You may need to update /etc/fstab. message again.
Verify your work by listing the partitions on the practice disk:
parted "$PRACTICE_DISK" print
You should now see two partitions, with the second one being your new swap partition:
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1001MB 1000MB primary xfs
2 1001MB 1501MB 499MB primary swap
As before, run udevadm settle to ensure the system registers the new partition and creates its device file, such as /dev/vdb2 or /dev/nvme1n1p2.
udevadm settle
Now, format the second partition as swap space using the mkswap command:
mkswap "${PART_PREFIX}2"
The output will show details about the swap space creation, including its size and a generated UUID:
Setting up swapspace version 1, size = 476 MiB (499118080 bytes)
no label, UUID=4379b167-ab39-4c83-bf7c-b28fbdb38725
To configure the new swap space to activate persistently, add an entry to /etc/fstab. First, discover the UUID of the second partition:
lsblk -o UUID "${PART_PREFIX}2"
Note down the UUID from the output. It will be similar to 4379b167-ab39-4c83-bf7c-b28fbdb38725.
UUID
4379b167-ab39-4c83-bf7c-b28fbdb38725
Open /etc/fstab using nano and add a new line for your swap partition. Replace YOUR_SWAP_UUID_HERE with the actual UUID you just found.
nano /etc/fstab
Add the following line to the end of the file:
UUID=YOUR_SWAP_UUID_HERE swap swap defaults 0 0
Save the file by pressing Ctrl+X, then Y to confirm, and Enter to write to the file.
After modifying /etc/fstab, reload the systemd daemon to recognize the new entry:
systemctl daemon-reload
Finally, enable the swap space using swapon -a:
swapon -a
Verify that the new swap space is enabled:
swapon --show
You should see output similar to this, confirming your new swap partition is active:
NAME TYPE SIZE USED PRIO
/dev/nvme1n1p2 partition 476M 0B -2
The output shows your newly created swap partition is active and ready to use.
Create additional partitions on the practice disk
In this step, you will create additional partitions on the practice disk. Since you have created one XFS partition and one swap partition using the MBR (msdos) partition table, you still have space available for more partitions. You will now create a third partition that demonstrates managing larger partitions.
First, check the current partition table and available space on the practice disk:
parted "$PRACTICE_DISK" print
You should see the two partitions you created earlier:
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1001MB 1000MB primary xfs
2 1001MB 1501MB 500MB primary linux-swap
Now, you will create a third partition of 2 GB for additional storage. This partition will start at 1501MB (the end of the swap partition) and end at 3501MB (1501MB + 2000MB).
parted "$PRACTICE_DISK" mkpart primary xfs 1501MB 3501MB
You might see the Information: You may need to update /etc/fstab. message.
Verify the creation of the third partition:
parted "$PRACTICE_DISK" print
You should now see three partitions:
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1001MB 1000MB primary xfs
2 1001MB 1501MB 500MB primary linux-swap
3 1501MB 3501MB 2000MB primary
Run udevadm settle to ensure the system detects the new partition:
udevadm settle
Format the third partition and mount it persistently
In this step, you will format the third partition (${PART_PREFIX}3) with the XFS file system and configure it for persistent mounting at /backup.
First, format the third partition with the XFS file system:
mkfs.xfs "${PART_PREFIX}3"
The output will show details about the XFS file system creation:
meta-data=/dev/nvme1n1p3 isize=512 agcount=4, agsize=122880 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=491520, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Now, create a mount point directory for this partition. You will mount it to /backup.
mkdir -p /backup
To ensure the file system mounts automatically, add an entry to /etc/fstab. First, find the UUID of the third partition.
lsblk -o UUID "${PART_PREFIX}3"
Note down the UUID from the output. It will be a unique identifier like f74ed805-b1fc-401a-a5ee-140f97c6757d.
UUID
f74ed805-b1fc-401a-a5ee-140f97c6757d
Open the /etc/fstab file using nano and add the new entry. Replace YOUR_UUID_HERE with the actual UUID you found.
nano /etc/fstab
Add the following line to the end of the file:
UUID=YOUR_UUID_HERE /backup xfs defaults 0 0
Save the file (Ctrl+X, Y, Enter).
After modifying /etc/fstab, reload the systemd daemon to apply the changes.
systemctl daemon-reload
Finally, manually mount the /backup directory to verify that the configuration is correct.
mount /backup
Confirm that the mount is successful by checking the mount command output:
mount | grep /backup
You should see output similar to this:
/dev/nvme1n1p3 on /backup type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
Create additional swap partitions on the practice disk with priorities
In this step, you will create one additional swap partition on the practice disk and learn about partition table limitations. You will also learn how to assign priorities to swap partitions. When multiple swap partitions are active, the system uses the one with the highest priority first.
Understanding Partition Table Limitations:
The current setup uses an MBR (msdos) partition table, which has a limitation of only 4 primary partitions. After you create the fourth partition in this step, you cannot create additional primary partitions without converting to GPT or using extended partitions.
First, check the current partition table on the practice disk:
parted "$PRACTICE_DISK" print
You should see the four partitions you created so far:
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1001MB 1000MB primary xfs
2 1001MB 1501MB 500MB primary linux-swap
3 1501MB 3501MB 2000MB primary xfs
Now, create the fourth partition as a 512 MB swap partition. It will start at 3501MB (the end of the third partition) and end at 4013MB (3501MB + 512MB).
parted "$PRACTICE_DISK" mkpart primary linux-swap 3501MB 4013MB
You might see the Information: You may need to update /etc/fstab. message.
Note about MBR limitations: At this point, you have reached the 4-partition limit for MBR partition tables. Attempting to create a fifth primary partition would result in an error: Error: Can't create any more partitions.
Display the partition table to verify your work:
parted "$PRACTICE_DISK" print
You should now see four partitions:
Model: Amazon Elastic Block Store (nvme)
Disk /dev/nvme1n1: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1001MB 1000MB primary xfs
2 1001MB 1501MB 500MB primary linux-swap
3 1501MB 3501MB 2000MB primary xfs
4 3501MB 4013MB 512MB primary linux-swap
Run udevadm settle to ensure the system registers the new partition and creates its device file, such as /dev/vdb4 or /dev/nvme1n1p4.
udevadm settle
Now, initialize the new partition as swap space using the mkswap command. Note down the UUID for the fourth partition, as you will need it for /etc/fstab.
mkswap "${PART_PREFIX}4"
Example output for the fourth partition:
Setting up swapspace version 1, size = 488 MiB (511705088 bytes)
no label, UUID=87976166-4697-47b7-86d1-73a02f0fc803
To configure this swap space to activate with a specific priority, you need to add an entry to the /etc/fstab file. A higher pri (priority) value indicates a higher preference. You will set a higher priority for the new swap partition.
Open /etc/fstab using nano:
nano /etc/fstab
Add the following line to the end of the file, replacing the UUID with the one you noted down:
UUID=UUID_OF_PARTITION4 swap swap pri=10 0 0
Explanation of pri option:
pri=10: Assigns a priority of 10 to the fourth partition. This is higher than the default priority (-2) of the second partition, so the system will prefer the fourth partition first.
Save the file (Ctrl+X, Y, Enter).
Reload the systemd daemon to recognize the new /etc/fstab entry.
systemctl daemon-reload
Activate the new swap space using swapon -a.
swapon -a
Verify the correct activation and priority of the swap spaces using swapon --show:
swapon --show
You should see output showing all active swap partitions with their priorities. The second partition will have default priority -2, while the fourth partition will have the priority you assigned (10).
NAME TYPE SIZE USED PRIO
/dev/nvme1n1p2 partition 476M 0B -2
/dev/nvme1n1p4 partition 488M 0B 10
Learning Note: In a production environment, if you needed more than 4 partitions, you would either:
- Convert to GPT partition table (supports up to 128 partitions)
- Use extended partitions with logical partitions within them
- Use LVM (Logical Volume Manager) for more flexible storage management
Verify persistent mount configuration without reboot
In this final step, you will test the persistent mount configuration without actually rebooting the system, since a reboot would disconnect you from the LabEx environment. Instead, you will use various commands to simulate and verify that your configurations would work correctly after a restart.
First, let's verify that all your mount entries are correctly configured in /etc/fstab. Display the contents of /etc/fstab to review your entries:
cat /etc/fstab
You should see your entries for the XFS partitions and swap spaces similar to this:
## ... existing system entries ...
UUID=your-archive-uuid /archive xfs defaults 0 0
UUID=your-swap-low-uuid swap swap defaults 0 0
UUID=your-backup-uuid /backup xfs defaults 0 0
UUID=your-swap-high-uuid swap swap pri=10 0 0
Now, let's test the mount configuration by unmounting and remounting the file systems to ensure they work correctly:
First, unmount the /archive directory:
umount /archive
Verify it's unmounted:
mount | grep /archive
This should return no output.
Now remount it using the /etc/fstab entry:
mount /archive
Verify it's mounted again:
mount | grep /archive
You should see:
/dev/nvme1n1p1 on /archive type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
Repeat the same process for /backup:
umount /backup
mount /backup
mount | grep /backup
You should see:
/dev/nvme1n1p3 on /backup type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
For swap spaces, let's test by turning them off and on again. First, turn off all swap:
swapoff -a
Verify no swap is active:
swapon --show
This should show only any system swap that might exist, but not your custom swap partitions.
Now turn on all swap using /etc/fstab:
swapon -a
Verify all swap spaces are active with correct priorities:
swapon --show
You should see output similar to this, with your custom swap partitions active and the higher-priority one preferred:
NAME TYPE SIZE USED PRIO
/dev/nvme1n1p2 partition 476M 0B -2
/dev/nvme1n1p4 partition 488M 0B 10
Finally, let's test that systemd can process all your /etc/fstab entries without errors:
systemctl daemon-reload
This should complete without any error messages.
You can also use the findmnt command to verify that the kernel would be able to mount all file systems defined in /etc/fstab:
findmnt --verify
This command checks /etc/fstab for potential issues. Because this lab intentionally defines two swap entries, findmnt --verify may print a warning that the swap target appears more than once. That warning is expected for this lab, but the command should not report parse errors or hard errors.
Display a final summary of all your work:
echo "=== Final Storage Configuration Summary ==="
echo "Partition tables:"
parted "$PRACTICE_DISK" print
echo ""
echo "Mounted filesystems:"
mount | grep -E "/archive|/backup"
echo ""
echo "Active swap spaces:"
swapon --show
echo ""
echo "fstab entries for persistence:"
grep -E "archive|backup|swap" /etc/fstab
echo ""
echo "UUID verification:"
echo "Device UUIDs:"
lsblk -f "${PART_PREFIX}"{1,2,3,4}
This concludes the lab on managing storage partitions and swap space. You have successfully created and configured multiple partitions with different file systems, set up persistent mounts, and configured swap spaces with priorities, all without requiring a system reboot.
Summary
In this lab, participants learned to manage storage partitions and swap space on a RHEL 9 system within the LabEx VM environment. The lab began with identifying the extra practice disk in the current VM and understanding its current state before proceeding with partitioning tasks.
Participants worked with that practice disk, creating an MBR partition table, then creating multiple partitions: an XFS partition for mounting at /archive, a swap partition, another XFS partition for mounting at /backup, and an additional swap partition with priority configuration. The lab also demonstrates the limitations of MBR partition tables (4 primary partition limit) and provides insights into alternatives like GPT for scenarios requiring more partitions.
A crucial aspect of the lab was ensuring persistent configuration through proper /etc/fstab entries and testing the configuration without requiring a system reboot (which would disconnect the LabEx environment). The lab concluded with comprehensive verification procedures to confirm that all mounts and swap spaces would activate correctly, providing hands-on experience with essential RHEL storage management skills in a practical, cloud-based learning environment.



