In this lab, you 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 parted command.
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 serverb machine has several unused disks.
On the first unused disk, create a GPT partition label and a 2 GB GPT partition named backup.
Because it is difficult to set an exact size, a size between 1.8 GB and 2.2 GB is acceptable.
Configure the backup partition to host an XFS file system.
Log in to serverb as the student user and switch to the root user.
[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 disk
Confirm that the /dev/vdb disk 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 gpt
Information: You may need to update /etc/fstab.Create the 2 GB backup partition with an xfs file-system type.
Start the partition at sector 2048.
[root@serverb ~]# parted /dev/vdb mkpart backup xfs 2048s 2GB
Information: You may need to update /etc/fstab.Confirm the creation of the backup partition.
[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 backup
Run the udevadm settle command.
This command waits for the system to detect the new partition and to create the /dev/vdb1 device file.
[root@serverb ~]# udevadm settleFormat the 2 GB backup partition with an XFS file system and persistently mount it to the /backup directory.
Format the /dev/vbd1 partition.
[root@serverb ~]# mkfs.xfs /dev/vdb1
meta-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 /backup mount point.
[root@serverb ~]# mkdir /backupBefore adding the new file system to the /etc/fstab file, 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-140f97c6757d
Edit the /etc/fstab file and define the new file system.
[root@serverb ~]#vim /etc/fstab...output omitted...UUID=f74ed805-b1fc-401a-a5ee-140f97c6757d/backup xfs defaults 0 0
Force the systemd daemon to reread the /etc/fstab file.
[root@serverb ~]# systemctl daemon-reloadManually mount the /backup directory 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 swap1 and swap2 names.
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/vdb disk.
In the next step, you use that value as the start of the swap1 partition.
[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 backup
Create the first 512 MB GPT partition named swap1.
Set its type to linux-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 2512M
Information: You may need to update /etc/fstab.Create the second 512 MB GPT partition named swap2.
Set its type to linux-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 3024M
Information: 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 swap
Run the udevadm settle command.
The command waits for the system to register the new partitions and to create the device files.
[root@serverb ~]# udevadm settleInitialize the two 512 MB partitions as swap spaces, and configure them to activate at boot.
Set the swap space on the swap2 partition to be preferred over the other.
Note that 512 MB is approximately equivalent to 488 MiB.
Use the mkswap command 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 the mkswap output, then use the lsblk --fs command 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-dfaaf736b942
Edit the /etc/fstab file and define the new swap spaces.
To set the swap space on the swap2 partition to be preferred over the swap1 partition, give the swap2 partition a higher priority with the pri option.
[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 0
Force the systemd daemon to reread the /etc/fstab file.
[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 serverb machine.
Confirm that the system automatically mounts the first partition to the /backup directory.
Also, confirm that the system activates the two swap spaces.
Reboot serverb.
[root@serverb ~]# systemctl reboot
Connection to serverb closed by remote host.
Connection to serverb closed.
[student@workstation ~]$Wait for serverb to boot, and then log in as the student user.
[student@workstation ~]$ ssh student@serverb
...output omitted...
[student@serverb ~]$Verify that the system automatically mounts the /dev/vdb1 partition to the /backup directory.
[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 20
Return to the workstation machine as the student user.
[student@serverb ~]$ exit
logout
Connection to serverb closed.
[student@workstation ~]$This concludes the section.