RHCSA Rapid Track
Create and format a partition as a swap space, and activate it persistently.
Outcomes
Create a partition and a swap space on a disk by using the GPT partitioning scheme.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start storage-swap
Instructions
Log in to
serveraas thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Inspect the
/dev/vdbdisk. The disk already has a partition table and uses the GPT partitioning scheme. Also, it has an existing 1 GB partition.[root@servera ~]#
parted /dev/vdb printModel: Virtio Block Device (virtblk) Disk /dev/vdb: 5369MB Sector size (logical/physical): 512B/512B Partition Table:gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 1001MB 1000MB dataAdd a new partition of 500 MB for use as a swap space. Set the partition type to
linux-swap.Create the
myswappartition. Because the disk uses the GPT partitioning scheme, you must give a name to the partition. Notice that the start position, 1001 MB, is the end of the existing first partition. Thepartedcommand ensures that the new partition immediately follows the previous one, without any gap. Because the partition starts at the 1001 MB position, the command sets the end position to 1501 MB to get a partition size of 500 MB.[root@servera ~]#
parted /dev/vdb mkpart myswap linux-swap \1001MB 1501MBInformation: You may need to update /etc/fstab.Verify your work by listing the partitions on the
/dev/vdbdisk. The size of the new partition is not exactly 500 MB. The difference in size is because thepartedcommand must align the partition with the disk layout.[root@servera ~]#
parted /dev/vdb printModel: Virtio Block Device (virtblk) Disk /dev/vdb: 5369MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 1001MB 1000MB data2 1001MB 1501MB 499MB myswap swapRun the
udevadm settlecommand. This command waits for the system to register the new partition, and returns when it is done.[root@servera ~]#
udevadm settle
Initialize the new partition as a swap space.
[root@servera ~]#
mkswap /dev/vdb2Setting up swapspace version 1, size = 476 MiB (499118080 bytes) no label, UUID=cb7f71ca-ee82-430e-ad4b-7dda12632328Enable the new swap space.
Verify that creating and initializing the swap space does not yet enable it for use.
[root@servera ~]#
swapon --showEnable the new swap space.
[root@servera ~]#
swapon /dev/vdb2Verify that the new swap space is now available.
[root@servera ~]#
swapon --showNAME TYPE SIZE USED PRIO /dev/vdb2 partition 476M 0B -2Disable the swap space.
[root@servera ~]#
swapoff /dev/vdb2Confirm that the swap space is disabled.
[root@servera ~]#
swapon --show
Enable the new swap space at system boot.
Use the
lsblkcommand with the--fsoption to discover the UUID of the/dev/vdb2device. The UUID in the output is different on your system.[root@servera ~]#
lsblk --fs /dev/vdb2NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS vdb2 swap 1762735cb-a52a-4345-9ed0-e3a68aa8bb97Add an entry to the
/etc/fstabfile. In the following command, replace the UUID with the one that you discovered from the previous step....output omitted... UUID=
762735cb-a52a-4345-9ed0-e3a68aa8bb97swap swap defaults 0 0Update the
systemddaemon for the system to register the new/etc/fstabfile configuration.[root@servera ~]#
systemctl daemon-reloadEnable the swap space by using the entry in the
/etc/fstabfile.[root@servera ~]#
swapon -aVerify that the new swap space is enabled.
[root@servera ~]#
swapon --showNAME TYPE SIZE USED PRIO /dev/vdb2 partition 476M 0B -2
Reboot the
serveramachine. After the server reboots, log in and verify that the swap space is enabled. When done, log out fromservera.Reboot the
serveramachine.[root@servera ~]#
systemctl rebootConnection to servera closed by remote host. Connection to servera closed. [student@workstation ~]$Wait for
serverato reboot and log in as thestudentuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$Verify that the swap space is enabled.
[student@servera ~]#
swapon --showNAME TYPE SIZE USED PRIO /dev/vdb2 partition 476M 0B -2Return to the
workstationmachine as thestudentuser.[student@servera ~]$
exitlogout Connection to servera closed. [student@workstation ~]$