This action is relevant when you are using the MBR partition table, because this type of partitions has a limitation: 3 main partitions (primary)
We look at the structure
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 6G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 200M 0 part /boot
sda3 8:3 0 5.8G 0 part
├─
centos
-root 253:0 0 5.3G 0 lvm /
└─centos-swap 253:1 0 512M 0 lvm [SWAP]
In this example, the disk sda is equal to 6 Gb
Turn off the machine, expand the disk through virtualization, turn on the machine
Installing the utility growpart (Centos, Rocky Linux)
$ sudo yum -y install cloud-utils-growpart
Installing the utility growpart ( Debian )
$ sudo apt -y install cloud-guest-utils
Expanding partition 3 on disk / dev / sda
$ sudo growpart /dev/sda 3
Let’s see what happened
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 7.8G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 200M 0 part /boot
sda3 8:3 0 7.6G 0 part
├─centos-root 253:0 0 5.3G 0 lvm /
└─centos-swap 253:1 0 512M 0 lvm [SWAP]
Expanding the physical volume
$ sudo pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Checking the size of the physical volume
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 centos lvm2 a-- 7.61g 1.81g
Checking the size of the volume group
$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 7.61g 1.81g
We check the size of the root size, at the same time we look at the path and type of the file system (in this example, xfs)
$ df -hT | grep mapper
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 7.2G 1.7G 5.5G 23% /
Expanding a logical volume
$ sudo lvextend -r -l +100%FREE /dev/mapper/centos-root
Extending the XFS file system
$ sudo xfs_growfs /
Or, we expand the EXT4 file system
$ sudo resize2fs /dev/mapper/centos-root