Red Hat Certified System Administrator RHCSA · Free Practice Question Easy
Question 25
On ServerB, use /dev/sdb to create a new 1G swap partition that takes effect automatically at boot start.
-
A
Pass
-
B
Fail
Reveal correct answer
Correct answer: A
Explanation
Step-by-Step Guide
Check Current Memory and Swap Usage
Command:
- # free -m
Explanation:
This command displays memory and swap usage in megabytes, allowing you to check existing swap space. Monitoringfree -mbefore and after setup helps verify the addition of new swap space.
Open the
fdiskUtility to Partition/dev/sdbCommand:
- # fdisk /dev/sdb
Explanation:
fdiskis a command-line utility for disk partitioning. Opening it with/dev/sdballows you to create, modify, and manage partitions on that specific disk.
Create a New Partition in
fdiskFollow these
fdiskprompts:m: Display help (optional).n: Start creating a new partition.p: Specify a primary partition.4(or press Enter): Accept the default partition number or specify4.Press Enter: Accept the default first sector.
+1G: Define the size of the partition (1GB).
Explanation:
Creating a 1GB partition here ensures the new swap space is ready to be configured and formatted.
Set Partition Type to Linux Swap
Command sequence in
fdisk:t: Change the partition type.4(partition number): Choose the partition you created.l: List available partition types.82: Select82for Linux Swap.Explanation: Setting the type as Linux Swap is crucial for the system to recognize and use it as swap space.
Save Changes and Exit
fdiskCommand in
fdisk:- w
Explanation:
Thewcommand writes the changes to the disk and exitsfdisk. At this point, the new partition is created but not yet formatted or mounted as swap.
Inform the Kernel of Partition Changes
Command:
- # partprobe
Explanation:
partprobenotifies the kernel of the new partition table without requiring a reboot. This ensures the kernel recognizes the new partition immediately.
Format the Partition as Swap
Command:
- # mkswap /dev/sdb4
Explanation:
This command formats/dev/sdb4as swap space, making it ready for use as a swap partition.mkswapassigns a unique identifier (UUID) to the swap partition.
Get the UUID of the New Swap Partition
Command:
- # blkid /dev/sdb4
Explanation:
The UUID is a unique identifier for the partition. Using the UUID instead of the device path (/dev/sdb4) in/etc/fstabensures that the system consistently recognizes the swap partition, even if device names change.
Add the Swap Partition to
/etc/fstabCommand:
- # vim /etc/fstab
Entry to Add in
/etc/fstab:- UUID=<UUID> swap swap defaults 0 0
Explanation:
Adding the swap partition entry in/etc/fstabmakes it persistent, enabling the swap space to be activated automatically at boot. Replace<UUID>with the actual UUID from theblkidcommand.
Activate the Swap Partition Immediately
Command:
- # swapon /dev/sdb4
Explanation:
swaponactivates the newly created swap partition, making it available for immediate use without needing a reboot.
Verify the New Swap Space
Commands:
- # free -m
- # swapon --show
Explanation:
These commands show the active swap space, confirming that the new 1GB swap partition is in use.free -mshows memory and swap usage in megabytes, whileswapon --showprovides detailed information on all active swap areas.
Check Block Device Information (Optional)
Command:
- # lsblk
Explanation:
lsblkdisplays all block devices, showing the swap partition with its size, type, and mount point. This visual confirmation ensures the partition is correctly set up and recognized by the system.
Additional Notes and Tips:
Partprobe Utility:
partprobehelps avoid the need for a system reboot after partition changes. This is especially useful when creating or modifying partitions in environments where downtime is minimized.UUID vs. Device Path in
/etc/fstab:
Using the UUID (fromblkid) instead of the device path (/dev/sdb4) ensures the system recognizes the swap partition reliably, even if device names change due to hardware reordering.Exam Tip:
Practice the complete process of creating, formatting, and activating swap partitions. Ensure familiarity with commands likefdisk,mkswap,swapon, andfstabentries, as these are commonly tested.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
