RHCSA Rapid Track
Create several partitions on a new disk, and format some with file systems and mount them, and activate others as swap spaces.
Outcomes
Display and create partitions with the
partedcommand.Create file systems on partitions and persistently mount them.
Create swap spaces and activate them at boot.
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-review
Instructions
The
serverbmachine has several unused disks. On the first unused disk, create a GPT partition label and a 2 GB GPT partition namedbackup.Because it is difficult to set an exact size, a size between 1.8 GB and 2.2 GB is acceptable.
Configure the
backuppartition to host an XFS file system.Log in to
serverbas thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#Identify the unused disks. The first unused disk,
/dev/vdb, does not have any partitions.[root@serverb ~]#
lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS vda 252:0 0 10G 0 disk ├─vda1 252:1 0 1M 0 part ├─vda2 252:2 0 200M 0 part /boot/efi ├─vda3 252:3 0 500M 0 part /boot └─vda4 252:4 0 9.3G 0 part /vdb252:16 0 5G 0 disk vdc 252:32 0 5G 0 disk vdd 252:48 0 5G 0 diskConfirm that the
/dev/vdbdisk has no label.[root@serverb ~]#
parted /dev/vdb printError: /dev/vdb:unrecognised disk labelModel: Virtio Block Device (virtblk) Disk /dev/vdb: 5369MB Sector size (logical/physical): 512B/512B Partition Table:unknownDisk Flags:Define the GPT partitioning scheme.
[root@serverb ~]#
parted /dev/vdb mklabel gptInformation: You may need to update /etc/fstab.Create the 2 GB
backuppartition with anxfsfile-system type. Start the partition at sector 2048.[root@serverb ~]#
parted /dev/vdb mkpart backup xfs 2048s 2GBInformation: You may need to update /etc/fstab.Confirm the creation of the
backuppartition.[root@serverb ~]#
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 Flags1 1049kB 2000MB 1999MB backupRun the
udevadm settlecommand. This command waits for the system to detect the new partition and to create the/dev/vdb1device file.[root@serverb ~]#
udevadm settle
Format the 2 GB
backuppartition with an XFS file system and persistently mount it to the/backupdirectory by using the UUID.Format the
/dev/vbd1partition.[root@serverb ~]#
mkfs.xfs /dev/vdb1meta-data=/dev/vdb1 isize=512 agcount=4, agsize=121984 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=487936, 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=0Create the
/backupmount point.[root@serverb ~]#
mkdir /backupBefore adding the new file system to the
/etc/fstabfile, retrieve its UUID. The UUID on your system might be different.[root@serverb ~]#
lsblk --fs /dev/vdb1NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS vdb1 xfsf74ed805-b1fc-401a-a5ee-140f97c6757dEdit the
/etc/fstabfile and define the new file system.[root@serverb ~]#
vim /etc/fstab...output omitted...UUID=f74ed805-b1fc-401a-a5ee-140f97c6757d/backup xfs defaults 0 0Force the
systemddaemon to reread the/etc/fstabfile.[root@serverb ~]#
systemctl daemon-reloadManually mount the
/backupdirectory to verify your work. Confirm that the mount is successful.[root@serverb ~]#
mount /backup[root@serverb ~]#mount | grep /backup/dev/vdb1 on /backup type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
On the same disk, create two 512 MB GPT partitions with the
swap1andswap2names.A size between 460 MB and 564 MB is acceptable.
Configure the file-system types of the partitions to host swap spaces.
Retrieve the end position of the first partition by displaying the current partition table on the
/dev/vdbdisk. In the next step, you use that value as the start of theswap1partition.[root@serverb ~]#
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 1049kB2000MB1999MB xfs backupCreate the first 512 MB GPT partition named
swap1. Set its type tolinux-swap. Use the end position of the first partition as the starting point. The end position is 2000 MB + 512 MB = 2512 MB.[root@serverb ~]#
parted /dev/vdb mkpart swap1 linux-swap 2000M 2512MInformation: You may need to update /etc/fstab.Create the second 512 MB GPT partition named
swap2. Set its type tolinux-swap. Use the end position of the previous partition as the starting point:2512M. The end position is 2512 MB + 512 MB = 3024 MB.[root@serverb ~]#
parted /dev/vdb mkpart swap2 linux-swap 2512M 3024MInformation: You may need to update /etc/fstab.Display the partition table to verify your work.
[root@serverb ~]#
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 2000MB 1999MB xfs backup 22000MB 2512MB 513MB swap1 swap32512MB 3024MB 512MB swap2 swapRun the
udevadm settlecommand. The command waits for the system to register the new partitions and to create the device files.[root@serverb ~]#
udevadm settle
Initialize the two 512 MB partitions as swap spaces, and configure them to activate at boot. Set the swap space on the
swap2partition to be preferred over the other. Note that 512 MB is approximately equivalent to 488 MiB.Use the
mkswapcommand to initialize the swap partitions. Note the UUIDs of the two swap spaces, because you use that information in the next step. If you clear themkswapoutput, then use thelsblk --fscommand to retrieve the UUIDs.[root@serverb ~]#
mkswap /dev/vdb2Setting up swapspace version 1, size = 489 MiB (512749568 bytes) no label, UUID=87976166-4697-47b7-86d1-73a02f0fc803[root@serverb ~]#mkswap /dev/vdb3Setting up swapspace version 1, size = 488 MiB (511700992 bytes) no label, UUID=4d9b847b-98e0-4d4e-9ef7-dfaaf736b942Edit the
/etc/fstabfile and define the new swap spaces. To set the swap space on theswap2partition to be preferred over theswap1partition, give theswap2partition a higher priority with theprioption.[root@serverb ~]#
vim /etc/fstab...output omitted... UUID=a3665c6b-4bfb-49b6-a528-74e268b058dd /backup xfs defaults 0 0UUID=87976166-4697-47b7-86d1-73a02f0fc803swap swap pri=10 0 0UUID=4d9b847b-98e0-4d4e-9ef7-dfaaf736b942swap swap pri=20 0 0Force the
systemddaemon to reread the/etc/fstabfile.[root@serverb ~]#
systemctl daemon-reloadActivate the new swap spaces. Verify the correct activation of the swap spaces.
[root@serverb ~]#
swapon -a[root@serverb ~]#swapon --showNAME TYPE SIZE USED PRIO/dev/vdb2partition 489M 0B 10/dev/vdb3partition 488M 0B 20
To verify your work, reboot the
serverbmachine. Confirm that the system automatically mounts the first partition to the/backupdirectory. Also, confirm that the system activates the two swap spaces.Reboot
serverb.[root@serverb ~]#
systemctl rebootConnection to serverb closed by remote host. Connection to serverb closed. [student@workstation ~]$Wait for
serverbto boot, and then log in as thestudentuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$Verify that the system automatically mounts the
/dev/vdb1partition to the/backupdirectory.[student@serverb ~]$
mount | grep /backup/dev/vdb1 on /backup type xfs(rw,relatime,seclabel,attr2,inode64,noquota)Verify that the system activates both swap spaces.
[student@serverb ~]$
swapon --showNAME TYPE SIZE USED PRIO/dev/vdb2partition 489M 0B 10/dev/vdb3partition 488M 0B 20Return to the
workstationmachine as thestudentuser.[student@serverb ~]$
exitlogout Connection to serverb closed. [student@workstation ~]$