15.2 Resize LVM
The great things from LVM is the fact that we can resize all components within the LVM, like the VG and the LV
Here we will extend our plato-cave LV that we have created. To do this we will have to:
Check available space
Plan how to extend
Extend LV and filesystem
1. Check available space
For us to make a plan on how to resize, we need to check how much space is available on the disk and Volume Group.
Use vgdisplay to check if the VG has sufficient free space to extend the LV to a total size of 500MiB
vgdisplay plato
[root@rhcsa ~]# vgdisplay plato
--- Volume group ---
VG Name plato
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 992.00 MiB
PE Size 4.00 MiB
Total PE 248
Alloc PE / Size 245 / 980.00 MiB
Free PE / Size 3 / 12.00 MiB
VG UUID 44avDc-4ODt-xaeZ-MGAL-tEzx-efEC-c2QWl2
We can see that the plato Volume Group has Free PE / Size 3 / 12.00 MiB 12MB left: this is not enough.
For later comparison, let’s use df to check current free space on the cave Logical Volume:
df -ah /mnt/cave
Result:
[root@rhcsa ~]# df -ah /mnt/cave
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/plato-cave 495M 29M 466M 6% /mnt/cave
And lsblk to see all the available disks and partition space:
lsblk
[root@rhcsa ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 8:0 0 9G 0 disk
├─vda1 8:1 0 1G 0 part /boot
└─vda2 8:2 0 8G 0 part
├─cl-root 253:0 0 6.1G 0 lvm /
├─cl-swap 253:1 0 924M 0 lvm [SWAP]
└─cl-home 253:2 0 1G 0 lvm /home
vdb 8:16 0 10G 0 disk
vdbc 8:32 0 10G 0 disk
├─vdc1 8:33 0 500M 0 part
│ └─plato-cave 253:3 0 500M 0 lvm /mnt/cave
└─vdc2 8:34 0 500M 0 part
├─plato-cave 253:3 0 500M 0 lvm /mnt/cave
└─plato-phaedrus 253:4 0 480M 0 lvm /mnt/phaedrus
sr0 11:0 1 1024M 0 rom
There is still 4G free on the vdc disk.
2. Plan how to extend
The plan, in this case, is to make another partition on the /dev/vdc with the remaining space to add to the Volume Group.
In our case, we will make one extra partition on /dev/vdc of the remaining space, using the fdisk command.
fdisk /dev/vdc
n - new partition
p - primairy partion
[enter] - select logical next number
[enter] - select logical partition start sector
+4G - select all remaining space
t - to label the partion
8e - selects LVM label
w - write partition
Refresh Linux Kernel:
partprobe
Use pvcreate to add the new partition as a PV:
pvcreate /dev/vdb
Result:
[root@rhcsa ~]# pvcreate /dev/vdb3
Physical volume "/dev/vdb3" successfully created.
Next extend the Volume Group with the new pv that we assigned:
vgextend plato /dev/vdb3
Result:
[root@rhcsa ~]# vgextend plato /dev/vdb3
Volume group "plato" successfully extended
Use vgdisplay to check the plato vg free space again. There should be plenty of free space now.
vgdisplay plato
Result:
[root@rhcsa ~]# vgdisplay plato
--- Volume group ---
VG Name plato
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size <4.99 GiB
PE Size 4.00 MiB
Total PE 1277
Alloc PE / Size 245 / 980.00 MiB
Free PE / Size 1032 / 4.03 GiB
VG UUID GjNm0g-UJuq-9VTh-4Gz0-DQ40-0gCQ-zYD2ft
It shows we have Free PE / Size 1032 / 4.03 GiB 4G left.
3. Extend LV and filesystem
We are going to extend the Logical Volume Cave with another 500M and Phaedrus with 700M. We are going to do this in 2 ways.
The long method:
to extend the Logical Volume we will use the lvextend command; it uses the same options of -l for extends and -L by size.
lvextend -L 1000M /dev/plato/cave
Result:
[root@rhcsa ~]# lvextend -L 1000M /dev/plato/cave
Size of logical volume plato/cave changed from 500.00 MiB (125 extents) to 1000.00 MiB (250 extents).
Logical volume plato/cave successfully resized.
-L 1000M Means that the final size of the Logical Volume will be 1000M in total. If you want to resize by 500M, use the + flag -L +500 to add 500.
Now if we check the filesystem size with df:
df -ah /mnt/cave
Result
[root@rhcsa ~]# df -ah /mnt/cave
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/plato-cave 495M 29M 466M 6% /mnt/cave
Notice that the filesystem has not actually grown. We will have to resize the filesystem as well.
We need to use xfs_growfs to extend the XFS file system to use all the space on the Logical Volume:
xfs_growfs /mnt/cave
Result:
[root@rhcsa ~]# xfs_growfs /mnt/cave
meta-data=/dev/mapper/plato-cave isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 128000 to 256000
Now let’s check the filesystem size with df again:
df -ah /mnt/cave
Result
[root@rhcsa ~]# df -ah /mnt/cave
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/plato-cave 995M 33M 963M 4% /mnt/cave
Shorter Method:
now we will extend Phaedrus with 700M:
lvextend -rL +700M /dev/plato/phaedrus
Result:
[root@rhcsa ~]# df -ah /mnt/cave
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/plato-cave 995M 33M 963M 4% /mnt/cave
[root@rhcsa ~]# lvextend -rL +700M /dev/plato/phaedrus
Size of logical volume plato/phaedrus changed from 480.00 MiB (120 extents) to 1.15 GiB (295 extents).
Logical volume plato/phaedrus successfully resized.
resize2fs 1.44.3 (10-July-2018)
Filesystem at /dev/mapper/plato-phaedrus is mounted on /mnt/phaedrus; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 10
The filesystem on /dev/mapper/plato-phaedrus is now 1208320 (1k) blocks long.
By adding -r to the lvextend, it also immediately resized the filesystem. Check with df:
df -ah /mnt/phaedrus
Result:
[root@rhcsa ~]# df -ah /mnt/phaedrus
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/plato-phaedrus 1.2G 2.8M 1.1G 1% /mnt/phaedrus
Let’s check all that we have achieved:
vgdisplay plato
Result:
[root@rhcsa ~]# vgdisplay plato
--- Volume group ---
VG Name plato
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size <4.99 GiB
PE Size 4.00 MiB
Total PE 1277
Alloc PE / Size 545 / <2.13 GiB
Free PE / Size 732 / <2.86 GiB
VG UUID GjNm0g-UJuq-9VTh-4Gz0-DQ40-0gCQ-zYD2ft
And on Logical Volume:
lvdisplay plato
[root@rhcsa ~]# lvdisplay plato
--- Logical volume ---
LV Path /dev/plato/cave
LV Name cave
VG Name plato
LV UUID sdwM7G-OCAU-e5tU-uzyQ-HsjK-tJL5-7zUzNm
LV Write Access read/write
LV Creation host, time rhcsa.greateracademy.local, 2020-08-11 10:14:05 -0400
LV Status available
# open 1
LV Size 1000.00 MiB
Current LE 250
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
--- Logical volume ---
LV Path /dev/plato/phaedrus
LV Name phaedrus
VG Name plato
LV UUID ZmGUDB-6iSs-HM8w-6hyr-S0lR-dIIf-XyeAxf
LV Write Access read/write
LV Creation host, time rhcsa.greateracademy.local, 2020-08-11 10:14:12 -0400
LV Status available
# open 1
LV Size 1.15 GiB
Current LE 295
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4
