RHCSA Rapid Track
Resize an existing logical volume, add LVM resources as necessary, and then add a new logical volume with a persistently mounted XFS file system on it.
Outcomes
Resize the
serverb_01_lvlogical volume to 768 MiB.Create the
serverb_02_lvlogical volume with 128 MiB with an XFS file system.Persistently mount the volume on the
/storage/data2directory.
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 lvm-review
Instructions
On the serverb machine, the serverb_01_lv logical volume that is mounted on the /storage/data1 directory is running out of disk space, and must be extended to 768 MiB. You must ensure that the serverb_01_lv LV remains persistently mounted on the /storage/data1 directory.
The serverb_01_lv LV is present on the serverb_01_vg volume group. It has insufficient space to extend the existing logical volume. A 512 MiB partition exists on the /dev/vdb disk. Create a partition with the 512 MiB size on the /dev/vdb disk.
Important
Note especially the specification of the partition size in MiB (220 bytes). If you create the partition in MB (106 bytes), it does not satisfy the evaluation criteria, because 1 MiB = 1.048576 MB.
Although the default unit when using the parted /dev/vdb print command is MB, you can verify the size of the /dev/vdb device partitions in MiB units. Use the parted /dev/vdb unit MiB print command to print the partition sizes in MiB.
Create the serverb_02_lv LV with 128 MiB. Create the XFS file system on the newly created volume. Mount the newly created logical volume on the /storage/data2 directory.
Create a 512 MiB partition on the
/dev/vdbdisk. Initialize this partition as a physical volume, and extend theserverb_01_vgvolume group to use this partition.Log in to the
serverbmachine as thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#Print the partition sizes in MiB to determine where the first partition ends.
[root@serverb ~]#
parted /dev/vdb unit MiB print...output omitted... Number StartEndSize File system Name Flags 1 1.00MiB513MiB512MiB primaryCreate the 512 MiB partition and set the
lvmpartition type.[root@serverb ~]#
parted /dev/vdb mkpart primary 514MiB 1026MiB...output omitted... [root@serverb ~]#parted /dev/vdb set 2 lvm onRegister the new partition with the kernel.
[root@serverb ~]#
udevadm settleInitialize the partition as a PV.
[root@serverb ~]#
pvcreate /dev/vdb2Physical volume "/dev/vdb2" successfully created.Extend the
serverb_01_vgVG by using the new/dev/vdb2PV.[root@serverb ~]#
vgextend serverb_01_vg /dev/vdb2Volume group "serverb_01_vg" successfully extended
Extend the
serverb_01_lvlogical volume to 768 MiB.Extend the
serverb_01_lvLV to 768 MiB.Alternatively, you can also use the
lvcreatecommand-L +512Moption to resize the LV.[root@serverb ~]#
lvextend -L 768M /dev/serverb_01_vg/serverb_01_lvSize of logical volume serverb_01_vg/serverb_01_lv changed from 256.00 MiB (64 extents) to 768.00 MiB (192 extents). Logical volume serverb_01_vg/serverb_01_lv successfully resized.Extend the XFS file system to consume the remaining space on the LV.
[root@serverb ~]#
xfs_growfs /storage/data1meta-data=/dev/mapper/serverb_01_vg-serverb_01_lv isize=512 agcount=4, agsize=16384 blks ...output omitted... data blocks changed from 65536 to 196608Note
The
xfs_growfscommand introduces an extra step to extend the file system. An alternative would be to use thelvextendcommand-roption.
In the existing volume group, create the
serverb_02_lvlogical volume with 128 MiB. Add an XFS file system and mount it persistently on the/storage/data2directory.Create the
serverb_02_lvLV with 128 MiB from theserverb_01_vgVG.[root@serverb ~]#
lvcreate -n serverb_02_lv -L 128M serverb_01_vgLogical volume "serverb_02_lv" created.Create the
xfsfile system on theserverb_02_lvLV.[root@serverb ~]#
mkfs -t xfs /dev/serverb_01_vg/serverb_02_lv...output omitted...Create the
/storage/data2directory as the mount point.[root@serverb ~]#
mkdir /storage/data2Add the following line to the end of the
/etc/fstabfile:/dev/serverb_01_vg/serverb_02_lv /storage/data2 xfs defaults 0 0
Update the
systemddaemon with the new/etc/fstabconfiguration file.[root@serverb ~]#
systemctl daemon-reloadMount the
serverb_02_lvLV.[root@serverb ~]#
mount /storage/data2
Verify that the newly created LV is mounted with the intended size.
Use the
dfcommand to verify theserverb_01_lvLV size.[root@serverb ~]#
df -h /storage/data1Filesystem Size Used Avail Use% Mounted on /dev/mapper/serverb_01_vg-serverb_01_lv 763M 19M 744M 3% /storage/data1Verify the
serverb_02_lvLV size.[root@serverb ~]#
df -h /storage/data2Filesystem Size Used Avail Use% Mounted on /dev/mapper/serverb_01_vg-serverb_02_lv 123M 7.6M 116M 7% /storage/data2Verify the
serverb_01_lvLV details.[root@serverb ~]#
lvdisplay /dev/serverb_01_vg/serverb_01_lv--- Logical volume --- LV Path /dev/serverb_01_vg/serverb_01_lv LV Name serverb_01_lv VG Name serverb_01_vg LV UUID 1pY3DZ-fs1F-mptC-fL32-e8tG-PFBT-bs7LSJ LV Write Access read/write LV Creation host, time serverb.lab.example.com, 2022-05-05 14:40:51 -0400 LV Status available # open 1 LV Size 768.00 MiB Current LE 192 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0Verify the
serverb_02_lvLV details.[root@serverb ~]#
lvdisplay /dev/serverb_01_vg/serverb_02_lv--- Logical volume --- LV Path /dev/serverb_01_vg/serverb_02_lv LV Name serverb_02_lv VG Name serverb_01_vg LV UUID 0aJIb6-Ti2b-jLCk-imB6-rkLx-mUoX-acjkz9 LV Write Access read/write LV Creation host, time serverb.lab.example.com, 2022-05-05 14:45:46 -0400 LV Status available # open 1 LV Size 128.00 MiB Current LE 32 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1