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 available storage devices
In this step, you will inspect the available storage devices on your LabEx VM. The LabEx environment provides an additional storage device that you can use for partitioning practice.
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, let's examine the available block devices on the system using the lsblk command:
lsblk
You should see output similar to this, showing various storage devices:
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 /
vdb 253:16 0 40G 0 disk
In this environment, you have access to an additional storage device /dev/vdb that is unpartitioned and ready for use. Let's inspect this device more closely.
Use the lsblk command with the -f option to display filesystem information for /dev/vdb:
lsblk -f /dev/vdb
You should see output similar to this, indicating that /dev/vdb is a new, unformatted disk:
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
vdb
Next, use the parted command to get more detailed information about the disk, including its partition table:
parted /dev/vdb print
The output should show that there is no partition table on /dev/vdb yet:
Error: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
This confirms that /dev/vdb is a fresh disk ready for partitioning. The error message is normal for a disk that hasn't been initialized with a partition table yet.
Create an XFS partition on /dev/vdb and mount it persistently
In this step, you will create a new partition on /dev/vdb, format it with the XFS file system, and configure it to mount persistently.
You will create a 1 GB primary partition on /dev/vdb and specify the file system type as XFS. It's good practice to align partitions to sector boundaries for optimal performance. Starting at sector 2048 is a common alignment.
First, you need to create a partition table on the uninitialized disk. Use parted in interactive mode to create the partition table and partition:
parted /dev/vdb
GNU Parted 3.5
Using /dev/vdb
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 2048, setting the end position to 1001MB will result in a partition size of approximately 1 GB. When you quit parted, you'll see an informational message about updating /etc/fstab, which is normal.
To verify that the partition has been created, use parted to print the partition table for /dev/vdb:
parted /dev/vdb print
You should see output similar to this, showing your newly created primary partition:
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 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, it's crucial to inform the kernel about the changes. The udevadm settle command waits for the system to register the new partition and create its corresponding device file (e.g., /dev/vdb1).
udevadm settle
Now that the partition is created, you need to format it with the XFS file system. This prepares the partition to store data. Use the mkfs.xfs command for this:
mkfs.xfs /dev/vdb1
The output will show details about the XFS file system creation:
meta-data=/dev/vdb1 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, you need to mount it. First, create a mount point directory. You will mount this partition to /archive.
mkdir /archive
For persistent mounting (meaning the file system will automatically mount every time the system boots), you need to add an entry to the /etc/fstab file. It's best practice to use the Universally Unique Identifier (UUID) of the partition in /etc/fstab because device names like /dev/vdb1 can change if new disks are added or removed.
Discover the UUID of /dev/vdb1 using lsblk --fs:
lsblk --fs /dev/vdb1
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
vdb1 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
Explanation of the /etc/fstab entry:
UUID=YOUR_UUID_HERE: Specifies the device to mount using its UUID./archive: The mount point directory.xfs: The file system type.defaults: A common set of mount options (rw, suid, dev, exec, auto, nouser, async).0:dumpoption (0 means no dump).0:fsckorder (0 means no fsck check at boot).
Save the file by pressing Ctrl+X, then Y to confirm, and Enter to write to the file.
After modifying /etc/fstab, you need to 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. The mount /archive command will use the information from /etc/fstab to mount /dev/vdb1 to /archive.
mount /archive
Verify that the new file system is mounted correctly by checking the mount command output and filtering for /archive:
mount | grep /archive
You should see output similar to this, confirming the successful mount:
/dev/vdb1 on /archive type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
Create and activate a swap partition on /dev/vdb
In this step, you will create a swap partition on the /dev/vdb 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, let's inspect the current partition table on /dev/vdb to determine where to create the new swap partition.
parted /dev/vdb print
You should see the existing XFS partition (/dev/vdb1) that you created in the previous step:
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 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, you will add a new primary partition of 500 MB for use as swap space. You will set the partition file-system type to linux-swap. The new partition will start immediately after the existing /dev/vdb1 partition. The end of /dev/vdb1 is at 1001MB. So, the new partition will start at 1001MB and end at 1501MB (1001MB + 500MB).
Use parted in non-interactive mode to create this partition:
parted /dev/vdb 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 /dev/vdb disk:
parted /dev/vdb print
You should now see two partitions, with the second one being your new swap partition:
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 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, after creating a new partition, you must run udevadm settle to ensure the system registers the new partition and creates its device file (/dev/vdb2).
udevadm settle
Now, format the new partition (/dev/vdb2) as swap space using the mkswap command. This command initializes the partition for use as swap.
mkswap /dev/vdb2
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, you need to add an entry to the /etc/fstab file. First, discover the UUID of the /dev/vdb2 device.
lsblk -o UUID /dev/vdb2
Note down the UUID from the output. It will be similar to 4379b167-ab39-4c83-bf7c-b28fbdb38725.
UUID
4379b167-ab39-4c83-bf7c-b28fbdb38725
Open the /etc/fstab file 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
Explanation of the /etc/fstab entry for swap:
UUID=YOUR_SWAP_UUID_HERE: Specifies the device to use as swap.swap: The mount point (for swap, this is alwaysswap).swap: The file system type (for swap, this is alwaysswap).defaults: Standard options for swap.0:dumpoption (0 means no dump).0:fsckorder (0 means no fsck check for swap).
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 the swapon -a command. The -a option tells swapon to enable all swap devices listed in /etc/fstab.
swapon -a
Verify that the new swap space is enabled using swapon --show:
swapon --show
You should see output similar to this, confirming your new swap partition is active:
NAME TYPE SIZE USED PRIO
/dev/vdb2 partition 476M 0B -2
The output shows your newly created swap partition is active and ready to use.
Create additional partitions on /dev/vdb
In this step, you will create additional partitions on /dev/vdb. 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 will demonstrate managing larger partitions.
First, let's check the current partition table and available space on /dev/vdb:
parted /dev/vdb print
You should see the two partitions you created earlier:
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 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 /dev/vdb 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 /dev/vdb print
You should now see three partitions:
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 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 (/dev/vdb3) with XFS file system and configure it for persistent mounting at /backup.
First, format the /dev/vdb3 partition with the XFS file system:
mkfs.xfs /dev/vdb3
The output will show details about the XFS file system creation:
meta-data=/dev/vdb3 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 /backup
To ensure the file system mounts automatically, you need to add an entry to /etc/fstab. First, find the UUID of the /dev/vdb3 partition.
lsblk -o UUID /dev/vdb3
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/vdb3 on /backup type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
Create additional swap partitions on /dev/vdb with priorities
In this step, you will create one additional swap partition on /dev/vdb 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. Since you have already created 4 partitions, you cannot create additional primary partitions without converting to GPT or using extended partitions.
First, check the current partition table on /dev/vdb:
parted /dev/vdb print
You should see the four partitions you created so far:
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 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 /dev/vdb 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 /dev/vdb print
You should now see four partitions:
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 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 (/dev/vdb4).
udevadm settle
Now, initialize the new partition as swap space using the mkswap command. Note down the UUID for /dev/vdb4, as you will need it for /etc/fstab.
mkswap /dev/vdb4
Example output for /dev/vdb4:
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_VDB4 swap swap pri=10 0 0
Explanation of pri option:
pri=10: Assigns a priority of 10 to/dev/vdb4. This is higher than the default priority (-2) of/dev/vdb2, so the system will prefer to use/dev/vdb4before/dev/vdb2.
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 /dev/vdb2 will have default priority (-2), while /dev/vdb4 will have the priority you assigned (10).
NAME TYPE SIZE USED PRIO
/dev/vdb2 partition 476M 0B -2
/dev/vdb4 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-vdb1-uuid /archive xfs defaults 0 0
UUID=your-vdb2-uuid swap swap defaults 0 0
UUID=your-vdb3-uuid /backup xfs defaults 0 0
UUID=your-vdb4-uuid swap swap pri=10 0 0
UUID=your-vdb5-uuid swap swap pri=20 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/vdb1 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/vdb3 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 all your swap partitions active and correct priorities:
NAME TYPE SIZE USED PRIO
/dev/vda2 partition 2G 0B -2
/dev/vdb2 partition 476M 0B -2
/dev/vdc2 partition 244M 0B 10
/dev/vdc3 partition 244M 0B 20
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 and should complete without errors.
Display a final summary of all your work:
echo "=== Final Storage Configuration Summary ==="
echo "Partition tables:"
parted /dev/vdb 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 /dev/vdb* | grep -E "vdb[1-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 inspecting the available storage device (/dev/vdb) and understanding its current state before proceeding with partitioning tasks.
Participants worked with /dev/vdb, 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.



