In this lab, you will extend the logical volume added in the previous practice exercise.
| Resources: | |
|---|---|
| Machines: | serverX |
Outcomes:
A resized logical volume, 700MiB total, called storage in the volume
group shazam, mounted at /storage. Resizing done while
the file system is still mounted and in use. The volume group extended to include an
additional physical volume of 512MiB, giving a total VG size of 1GiB.
Complete Practice: Adding a Logical Volume
Check for Space in the Volume Group
Use vgdisplay to check if the VG has sufficient free space to extend the LV to a total size of 700MiB.
[root@serverX ~]#vgdisplay shazam--- Volume group --- VG Name shazam System ID Format lvm2 ... VG Size 504.00 MiB PE Size 4.00 MiB Total PE 126 Alloc PE / Size 100 / 400.00 MiB Free PE / Size 26 / 104.00 MiB VG UUID OBBAtU-2nBS-4SW1-khmF-yJzi-z7bD-DpCrAV
There is only 104MiB available (26 PEs x 4MiB extents) and we need at least 300MiB to have 700MiB in total. We need to extend the VG.
For later comparison, use df to check current disk free space:
[root@serverX ~]#df -h /storageFilesystem Size Used Avail Use% Mounted on /dev/mapper/shazam-storage 397M 21M 377M 6% /storage
Create the Physical Resources
Use fdisk to create an additional partition of 512MiB and set it to type Linux LVM.
[root@serverX ~]#fdisk /dev/vdb
Note: The following steps omit some output.
Add a new primary partition of 512MiB.
Command (m for help):nPartition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p):EnterUsing default response p Partition number (3,4, default 3):EnterFirst sector (1050624-20971519, default 1050624):EnterUsing default value 1050624 Last sector, +sectors or +size{K,M,G} (1050624-20971519, default 20971519):+512MPartition 3 of type Linux and of size 512 MiB is set
Change the partition type to Linux LVM - 0x8e.
Command (m for help):tPartition number (1-3, default 3):EnterHex code (type L to list all codes):8eChanged type of partition 'Linux' to 'Linux LVM'
Write the changes to the partition table and quit.
Command (m for help): w
The partition table has been altered!Use partprobe to register the new partitions with the kernel.
[root@serverX ~]#partprobe
Create the Physical Volume
Use pvcreate to add the new partition as a PV.
[root@serverX ~]#pvcreate /dev/vdb3Physical volume "/dev/vdb3" successfully created
Extend the Volume Group
Use vgextend to extend the VG named shazam, using
the new /dev/vdb3 PV.
[root@serverX ~]#vgextend shazam /dev/vdb3Volume group "shazam" successfully extended
Use vgdisplay to check the shazam VG free space
again. There should be plenty of free space now.
[root@serverX ~]#vgdisplay shazam--- Volume group --- VG Name shazam System ID Format lvm2 ... VG Size 1012.00 MiB PE Size 4.00 MiB Total PE 253 Alloc PE / Size 100 / 400.00 MiB Free PE / Size 153 / 612.00 MiB VG UUID OBBAtU-2nBS-4SW1-khmF-yJzi-z7bD-DpCrAV
There is now 612MiB available (153 PEs x 4MiB extents); perfect.
Extend the Logical Volume
Use lvextend to extend the existing LV to 700MiB.
[root@serverX ~]#lvextend -L 700M /dev/shazam/storageExtending logical volume storage to 700.00 MiB Logical volume storage successfully resized
In our example, we specified the exact size to make the final LV, but we could also have used:
-L +300M to add the new space using size in MiB.
-l 175 to specify the total number of extents (175 PEs x 4MiB).
-l +75 to add the additional extents needed.
Resize the File System
Use xfs_growfs to extend the XFS file system to the remainder of the free space on the LV.
[root@serverX ~]#xfs_growfs /storagemeta-data=/dev/mapper/shazamstorage isize=256 agcount=4, agsize=25600 blks ...
Verify Content Availability and New File System Size
Use df and ls | wc to review the new file system size and verify the existing files are still present.
[root@serverX ~]#df -h /storageFilesystem Size Used Avail Use% Mounted on /dev/mapper/shazam-storage 697M 21M 677M 3% /storage[root@serverX ~]#ls /storage | wc -l47
The files are still there and the file system is about the size we expect.