In this lab, you 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 servera machine 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 ~]#
Create the physical device partition on the /dev/vdb storage device.
Create two partitions of 256 MiB each and set to the Linux LVM type.
Use the first and second names 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/vdb storage device.
In the Number column, the 1 and 2 values correspond to the /dev/vdb1 and /dev/vdb2 device partitions.
The Flags column indicates the partition type.
[root@servera ~]# parted /dev/vdb print
Model: 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 lvmLabel the two new partitions as physical volumes.
[root@servera ~]# pvcreate /dev/vdb1 /dev/vdb2
Physical volume "/dev/vdb1" successfully created.
Physical volume "/dev/vdb2" successfully created.
Creating devices file /etc/lvm/devices/system.devicesCreate the servera_group volume group by using the two new PVs.
[root@servera ~]# vgcreate servera_group /dev/vdb1 /dev/vdb2
Volume group "servera_group" successfully createdCreate the servera_volume logical volume with a size of 400 MiB.
This command creates the /dev/servera_group/servera_volume LV without a file system.
[root@servera ~]# lvcreate -n servera_volume -L 400M servera_group
Logical volume "servera_volume" created.Format the newly created LV and mount it persistently.
Format the servera_volume LV with the XFS file system.
[root@servera ~]# mkfs -t xfs /dev/servera_group/servera_volume
...output omitted...Create the /data directory as a mount point.
[root@servera ~]# mkdir /dataTo persistently mount the newly created file system, add the following content in the /etc/fstab file:
/dev/servera_group/servera_volume /data xfs defaults 0 0
Mount the servera_volume LV.
[root@servera ~]# mount /dataVerify that the mounted file system is accessible, and display the status information of the LVM.
Verify that you can copy files to the /data directory.
[root@servera ~]#cp -a /etc/*.conf /data[root@servera ~]#ls /data | wc -l32
View the PV status information.
The output shows that the PV uses the servera_group VG.
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_group VG.
The output shows a VG size of 508 MiB with a PE size of 4 MiB.
The available size from the VG is 108 MiB.
[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_volume LV.
The output shows the VG name for creating the LV.
It also shows an LV size of 400 MiB and an LE size of 100.
[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 395 MiB with the available size of 372 MiB.
[root@servera ~]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/servera_group-servera_volume 395M 24M 372M 6% /dataCreate the physical resource on the /dev/vdb storage device.
Create an additional partition of 512 MiB and set it to the Linux LVM type.
Use the third name for this partition.
[root@servera ~]#parted /dev/vdb mkpart third 514MiB 1026MiB[root@servera ~]#parted /dev/vdb set 3 lvm on
Register the new partition with the kernel.
[root@servera ~]# udevadm settleAdd the new partition as a PV.
[root@servera ~]# pvcreate /dev/vdb3
Physical volume "/dev/vdb3" successfully created.Using the newly created disk space, extend the file system on the servera_volume to be a total size of 700 MiB.
Extend the servera_group VG by using the new /dev/vdb3 PV.
[root@servera ~]# vgextend servera_group /dev/vdb3
Volume group "servera_group" successfully extendedExtend the existing servera_volume LV to 700 MiB.
[root@servera ~]# lvextend -L 700M /dev/servera_group/servera_volume
Size 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 179200Verify 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 lvdisplay command.
[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 workstation machine as the student user.
[root@servera ~]#exitlogout [student@servera ~]$exitlogout Connection to servera closed.
This concludes the section.