## shutdown the VM first before resize the virtual disktyla@e32:~$virshshutdownalmalinux8Domain'almalinux8'isbeingshutdown## resize the .qcow2 file on host machinetyla@e32:~$sudoqemu-imgresize/data/kvm/almalinux8.qcow2+4GImageresized.## verify if the virtual size is now 25 GBtyla@e32:~$sudoqemu-imginfo/data/kvm/almalinux8.qcow2image:/data/kvm/almalinux8.qcow2fileformat:qcow2virtualsize:25GiB (26843545600 bytes)disksize:2.63GiBcluster_size:65536Formatspecificinformation:compat:1.1compressiontype:zliblazyrefcounts:truerefcountbits:16corrupt:falseextendedl2:falseChildnode'/file':filename:/data/kvm/almalinux8.qcow2protocoltype:filefilelength:20GiB (21478375424 bytes)disksize:2.63GiB## start the VM tyla@e32:~$virshstartalmalinux8Domain'almalinux8'started## verify if the VM is runningtyla@e32:~$virshlistIdNameState----------------------------9almalinux8running
## start working on the desired disk with fdisk
[root@almalinux8 ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
## type 'p' here to print the current disk layout to double check
## take note of 'Start' column for /dev/vda2
## value is 2099200 here.
Command (m for help): p
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa8460c45
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 41943039 39843840 19G 8e Linux LVM
## type 'd' here to delete the partition /dev/vda2
## note that it does not delete data on the disk but the entry in partition table
Command (m for help): d
## if no input and enter, the default is partition number 2 (/dev/vda2 here)
Partition number (1,2, default 2):
Partition 2 has been deleted.
## type 'n' for new to create new partition
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
## if no input and enter, the default is 'p' for primary partition type
Select (default p):
Using default response p.
## if no input and enter, the default is '2' for second primary partition
Partition number (2-4, default 2):
## if no input and enter, the default should be the same value as before
## value is 2099200 here
First sector (2099200-52428799, default 2099200):
## if no input and enter, the default is the last sector of the disk after resize
Last sector, +sectors or +size{K,M,G,T,P} (2099200-52428799, default 52428799):
Created a new partition 2 of type 'Linux' and of size 24 GiB.
Partition #2 contains a LVM2_member signature.
## !!!CAUTION!!! - type 'N' for No to keep the LVM2_member signature
Do you want to remove the signature? [Y]es/[N]o: N
## type 't' for type to set the partition type
Command (m for help): t
## type '8e' for LVM Hex code for the partition
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
## type 'w' for write to apply the changes to the disk
Command (m for help): w
The partition table has been altered.
Syncing disks.
## check if the vda2 disk partition size
[root@almalinux8 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 24G 0 part
├─almalinux-root 253:0 0 17G 0 lvm /
└─almalinux-swap 253:1 0 2G 0 lvm [SWAP]
## verify the LVM physical volume before resize
[root@almalinux8 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 almalinux lvm2 a-- <19.00g 0
## resize the physical volume with pvresize
[root@almalinux8 ~]# pvresize /dev/vda2
Physical volume "/dev/vda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
## verify the LVM physical volume after resize
[root@almalinux8 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 almalinux lvm2 a-- <24.00g 5.00g
## also verify the LVM volume group for free space
[root@almalinux8 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
almalinux 1 2 0 wz--n- <24.00g 5.00g
## now extend the LVM logical volume with lvextend to extend /dev/almalinux/root
[root@almalinux8 ~]# lvextend -l +100%FREE /dev/almalinux/root
Size of logical volume almalinux/root changed from <17.00 GiB (4351 extents) to <22.00 GiB (5631 extents).
Logical volume almalinux/root successfully resized.
## verify the logical volume size of root
[root@almalinux8 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root almalinux -wi-ao---- <22.00g
swap almalinux -wi-ao---- 2.00g
## also verify it with lsblk
[root@almalinux8 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 24G 0 part
├─almalinux-root 253:0 0 22G 0 lvm /
└─almalinux-swap 253:1 0 2G 0 lvm [SWAP]
## grow the / mount with xfs_growfs because the filesystem is xfs here
## note that resize2fs is used when the filesystem is ext4
[root@almalinux8 ~]# xfs_growfs /
meta-data=/dev/mapper/almalinux-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 5766144
## verify the disk free space at / mount point now
[root@almalinux8 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 870M 0 870M 0% /dev
tmpfs tmpfs 890M 0 890M 0% /dev/shm
tmpfs tmpfs 890M 8.6M 881M 1% /run
tmpfs tmpfs 890M 0 890M 0% /sys/fs/cgroup
/dev/mapper/almalinux-root xfs 22G 2.2G 20G 10% /
/dev/vda1 xfs 1014M 232M 783M 23% /boot
tmpfs tmpfs 178M 0 178M 0% /run/user/1000