RHCSA Rapid Track
In this exercise, you will create and format a partition for use as swap space, format it as swap, and activate it persistently.
Outcomes
You should be able to create a partition and a swap space on a disk using the GPT partitioning scheme.
Log in as the student user on workstation using student as the password.
On workstation, run the lab storage-swap start command.
This command runs a start script that determines if the servera machine is reachable on the network.
It also prepares the second disk on servera for the exercise.
[student@workstation ~]$lab storage-swap start
Use the ssh command to log in to
serveraas thestudentuser. The systems are configured to use SSH keys for authentication, therefore a password is not required.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$Use the sudo -i command to switch to the
rootuser. If prompted, usestudentas the password.[student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Use the parted command to inspect the
/dev/vdbdisk.[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 dataNotice that the disk already has a partition table and uses the GPT partitioning scheme. Also, a 1 GB partition already exists.
Add a new partition that is 500 MB in size for use as swap space. Set the partition type to
linux-swap.Use parted to create the partition. Because the disk uses the GPT partitioning scheme, you need to give a name to the partition. Call it
myswap.[root@servera ~]#parted /dev/vdb mkpart myswap linux-swap \1001MB 1501MBInformation: You may need to update /etc/fstab.Notice in the previous command that the start position, 1001 MB, is the end of the existing first partition. This way parted makes sure 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.
Verify your work by listing the partitions on
/dev/vdb.[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 swapThe size of the new partition is not exactly 500 MB. This is because parted has to align the partition with the disk layout.
Run the udevadm settle command. This command waits for the system to register the new partition and returns when it is done.
[root@servera ~]#udevadm settle
Initialize the newly created partition as 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 newly created swap space.
Use the swapon --show command to show that creating and initializing swap space does not yet enable it for use.
[root@servera ~]#swapon --showEnable the newly created swap space.
[root@servera ~]#swapon /dev/vdb2Verify that the newly created 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
Configure the new swap space to be enabled at system boot.
Use the lsblk command with the
--fsoption to discover the UUID of the/dev/vdb2device.[root@servera ~]#lsblk --fs /dev/vdb2NAME FSTYPE LABEL UUID MOUNTPOINT vdb2 swapcb7f71ca-ee82-430e-ad4b-7dda12632328The UUID in the previous output is probably different on your system.
Add an entry to
/etc/fstab. In the following command, replace the UUID with the one you discovered from the previous step....output omitted... UUID=cb7f71ca-ee82-430e-ad4b-7dda12632328 swap swap defaults 0 0Update
systemdfor the system to register the new/etc/fstabconfiguration.[root@servera ~]#systemctl daemon-reloadEnable the swap space using the entry just added to
/etc/fstab.[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
servera. After the server has rebooted, log in and verify that the swap space is enabled. When done, log off fromservera.Reboot
servera.[root@servera ~]#systemctl rebootConnection to servera closed by remote host. Connection to servera closed.[student@workstation ~]$Wait a few minutes for
serverato reboot and log in as thestudentuser.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$Verify that the swap space is enabled.
[root@servera ~]#swapon --showNAME TYPE SIZE USED PRIO /dev/vdb2 partition 476M 0B -2Log off from
servera.[student@servera ~]$exitlogout Connection to servera closed.[student@workstation ~]$