Red Hat System Administration II
Create and extend a physical volume, volume group, logical volume, and an XFS file system. You also persistently mount the logical volume file system.
Outcomes
Create physical volumes, volume groups, and logical volumes with LVM tools.
Create file systems on logical volumes and persistently mount them.
Extend the volume group to include an additional physical volume.
Resize the logical volume when the file system is still mounted and in use.
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-manage
Instructions
Log in to the
serveramachine as thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Create the physical device partition on the
/dev/vdbstorage device.Create two partitions of 256 MiB each and set to the Linux LVM type. Use the
firstandsecondnames for these partitions.[root@servera ~]#
parted /dev/vdb mklabel gptInformation: You may need to update /etc/fstab. [root@servera ~]#parted /dev/vdb mkpart first 1MiB 258MiBInformation: You may need to update /etc/fstab. [root@servera ~]#parted /dev/vdb set 1 lvm onInformation: You may need to update /etc/fstab. [root@servera ~]#parted /dev/vdb mkpart second 258MiB 514MiBInformation: You may need to update /etc/fstab. [root@servera ~]#parted /dev/vdb set 2 lvm onInformation: You may need to update /etc/fstab.Register the new partitions with the kernel.
[root@servera ~]#
udevadm settleList the partitions on the
/dev/vdbstorage device. In theNumbercolumn, the1and2values correspond to the/dev/vdb1and/dev/vdb2device partitions. TheFlagscolumn indicates the partition type.[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 271MB 269MB first lvm 2 271MB 539MB 268MB second lvm
Label the two new partitions as physical volumes.
[root@servera ~]#
pvcreate /dev/vdb1 /dev/vdb2Physical volume "/dev/vdb1" successfully created. Physical volume "/dev/vdb2" successfully created. Creating devices file /etc/lvm/devices/system.devicesCreate the
servera_groupvolume group by using the two new PVs.[root@servera ~]#
vgcreate servera_group /dev/vdb1 /dev/vdb2Volume group "servera_group" successfully createdCreate the
servera_volumelogical volume with a size of 400 MiB. This command creates the/dev/servera_group/servera_volumeLV without a file system.[root@servera ~]#
lvcreate -n servera_volume -L 400M servera_groupLogical volume "servera_volume" created.Format the newly created LV and mount it persistently.
Format the
servera_volumeLV with theXFSfile system.[root@servera ~]#
mkfs -t xfs /dev/servera_group/servera_volume...output omitted...Create the
/datadirectory as a mount point.[root@servera ~]#
mkdir /dataTo persistently mount the newly created file system, add the following content in the
/etc/fstabfile:/dev/servera_group/servera_volume /data xfs defaults 0 0
Mount the
servera_volumeLV.[root@servera ~]#
mount /data
Verify that the mounted file system is accessible, and display the status information of the LVM.
Verify that you can copy files to the
/datadirectory.[root@servera ~]#
cp -a /etc/*.conf /data[root@servera ~]#ls /data | wc -l32View the PV status information. The output shows that the PV uses the
servera_groupVG. The PV has a size of 256 MiB and a physical extent size of 4 MiB.The VG contains 63 PEs, of which 27 PEs are available for allocation, and 36 PEs are currently allocated to LVs. Use the following calculation for allocating the volume size in MiBs:
Total 252 MiB (63 PEs x 4 MiB)
Free 108 MiB (27 PEs x 4 MiB)
Allocated 144 MiB (36 PEs x 4 MiB)
[root@servera ~]#
pvdisplay /dev/vdb2--- Physical volume --- PV Name /dev/vdb2 VG Name servera_group PV Size 256.00 MiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 63 Free PE 27 Allocated PE 36 PV UUID FKKFYJ-wJiR-1jt2-sfy3-yjPy-TylN-LG92jjView the VG status information of the
servera_groupVG. The output shows a VG size of508MiB with a PE size of4MiB. The available size from the VG is108MiB.[root@servera ~]#
vgdisplay servera_group--- Volume group --- VG Name servera_group System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 508.00 MiB PE Size 4.00 MiB Total PE 127 Alloc PE / Size 100 / 400.00 MiB Free PE / Size 27 / 108.00 MiB VG UUID g0ahyT-90J5-iGic-nnb5-G6T9-tLdK-dX8c9MView the status information for the
servera_volumeLV. The output shows the VG name for creating the LV. It also shows an LV size of400MiB and an LE size of100.[root@servera ~]#
lvdisplay /dev/servera_group/servera_volume--- Logical volume --- LV Path /dev/servera_group/servera_volume LV Name servera_volume VG Name servera_group LV UUID 93MfUt-esgT-B5HM-r1p5-DVZH-n5cn-J5e2tw LV Write Access read/write LV Creation host, time servera.lab.example.com, 2022-04-11 03:25:12 -0400 LV Status available # open 1 LV Size 400.00 MiB Current LE 100 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0View the free disk space in human-readable units. The output shows the total size of
395MiB with the available size of372MiB.[root@servera ~]#
df -h /dataFilesystem Size Used Avail Use% Mounted on /dev/mapper/servera_group-servera_volume 395M 24M 372M 6% /data
Create the physical resource on the
/dev/vdbstorage device.Create an additional partition of 512 MiB and set it to the Linux LVM type. Use the
thirdname for this partition.[root@servera ~]#
parted /dev/vdb mkpart third 514MiB 1026MiB[root@servera ~]#parted /dev/vdb set 3 lvm onRegister the new partition with the kernel.
[root@servera ~]#
udevadm settleAdd the new partition as a PV.
[root@servera ~]#
pvcreate /dev/vdb3Physical volume "/dev/vdb3" successfully created.
Using the newly created disk space, extend the file system on the
servera_volumeto be a total size of 700 MiB.Extend the
servera_groupVG by using the new/dev/vdb3PV.[root@servera ~]#
vgextend servera_group /dev/vdb3Volume group "servera_group" successfully extendedExtend the existing
servera_volumeLV to 700 MiB.[root@servera ~]#
lvextend -L 700M /dev/servera_group/servera_volumeSize of logical volume servera_group/servera_volume changed from 400.00 MiB (100 extents) to 700.00 MiB (175 extents). Logical volume servera_group/servera_volume successfully resized.Extend the XFS file system by using the free space on the LV.
[root@servera ~]#
xfs_growfs /data...output omitted... data blocks changed from 102400 to 179200
Verify that the LV size is extended, and that the contents are still present in the volume.
Verify the size of the extended LV by using the
lvdisplaycommand.[root@servera ~]#
lvdisplay /dev/servera_group/servera_volume--- Logical volume --- LV Path /dev/servera_group/servera_volume LV Name servera_volume VG Name servera_group LV UUID mLQhsD-hyL0-KC2B-2nug-o2Nc-0znS-Q428fK LV Write Access read/write LV Creation host, time servera.lab.example.com, 2022-04-12 06:04:12 -0400 LV Status available # open 1 LV Size 700.00 MiB Current LE 175 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0Verify the new file-system size. Verify that the previously copied files are still present.
[root@servera ~]#
df -h /dataFilesystem Size Used Avail Use% Mounted on /dev/mapper/servera_group-servera_volume 695M 26M 670M 4% /data [root@servera ~]#ls /data | wc -l32
Return to the
workstationmachine as thestudentuser.[root@servera ~]#
exitlogout [student@servera ~]$exitlogout Connection to servera closed.