In this exercise, you 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 servera as the student user and switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Inspect the /dev/vdb disk.
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 data
Add a new partition of 500 MB for use as a swap space.
Set the partition type to linux-swap.
Create the myswap partition.
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.
The parted command 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/vdb disk.
The size of the new partition is not exactly 500 MB.
The difference in size is because the parted command 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 swap
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 settleInitialize 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-7dda12632328
Enable 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 --show
NAME 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 --showEnable the new swap space at system boot.
Use the lsblk command with the --fs option to discover the UUID of the /dev/vdb2 device.
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-e3a68aa8bb97
Add an entry to the /etc/fstab file.
In the following command, replace the UUID with the one that you discovered from the previous step.
...output omitted...
UUID=762735cb-a52a-4345-9ed0-e3a68aa8bb97 swap swap defaults 0 0Update the systemd daemon for the system to register the new /etc/fstab file configuration.
[root@servera ~]# systemctl daemon-reloadEnable the swap space by using the entry in the /etc/fstab file.
[root@servera ~]# swapon -aVerify that the new swap space is enabled.
[root@servera ~]# swapon --show
NAME TYPE SIZE USED PRIO
/dev/vdb2 partition 476M 0B -2Reboot the servera machine.
After the server reboots, log in and verify that the swap space is enabled.
When done, log out from servera.
Reboot the servera machine.
[root@servera ~]# systemctl reboot
Connection to servera closed by remote host.
Connection to servera closed.
[student@workstation ~]$Wait for servera to reboot and log in as the student user.
[student@workstation ~]$ ssh student@servera
...output omitted...
[student@servera ~]$Verify that the swap space is enabled.
[student@servera ~]# swapon --show
NAME TYPE SIZE USED PRIO
/dev/vdb2 partition 476M 0B -2Return to the workstation machine as the student user.
[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$This concludes the section.