Sometimes it would be useful to extend certain volumes on VMWare or other VMs on the guest machine due to development requirements. In this tutorial, the logical volume on Rocky Linux 9 guest machine will be extended on VMWare.
Generally speaking, there are 2 steps to do so: first the spaces need to be added from host machine using the VM software, so that spaces would be allocated onto the VM machine files. Once it is done, futher operations are needed in the guest machine to allocate those unused spaces onto the volumes needed.
Operation on VM Software
VMWare
Before doing any operations on the gust machine, shut it down first. Then we need to add spaces onto it through VMWare setting. It is quiet easy to do so but actually the space is not directly added to the logical volume we intended to add. But this is basis for extending the spaces on logical volumes.
KVM
The operation on kvm is a bit complicated than VMWare, but it could be done by just running one line of code.
qemu-img resize vmdisk.img +10G
Operation on Guest Machine
There are many commands involved in checking spaces, adding/modifying spaces in logical volume, group volume and physical volume lvelve.
In this tutorial, running lsblk
would show the following results.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 9.8G 0 rom
nvme0n1 259:0 0 200G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
└─nvme0n1p2 259:2 0 119G 0 part
├─rl-root 253:0 0 70G 0 lvm /
├─rl-swap 253:1 0 11.9G 0 lvm [SWAP]
└─rl-home 253:2 0 37.1G 0 lvm /home
physical volume related commands pvs pvdisplay to check out the info.
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/nvme0n1p2 rl lvm2 a-- <119.00g 0
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/nvme0n1p2
VG Name rl
PV Size <119.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 30463
Free PE 0
Allocated PE 30463
PV UUID ------------------------------------
commands for logic volume are lvs
, lvdisplay
, volume group are vgs
, vgdisplay
.
To modify the disk space, growpart
needs to be installed on system.
[root@localhost ~]# dnf whatprovides growpart
cloud-utils-growpart-0.33-1.el9.x86_64 : Script for growing a partition
Repo : appstream
Matched from:
Filename : /usr/bin/growpart
[root@localhost ~]# dnf install -y cloud-utils-growpart
Running the growpart command as follows would show the changes info but not actually process the request. The arguments are based on the results from pvdisplay
physical volume name.
[root@localhost ~]# growpart /dev/nvme0n1 2 -N
CHANGE: partition=2 start=2099200 old: size=249559040 end=251658239 new: size=417331167 end=419430366
# === old sfdisk -d ===
label: dos
label-id: 0x64436e11
device: /dev/nvme0n1
unit: sectors
sector-size: 512
/dev/nvme0n1p1 : start= 2048, size= 2097152, type=83, bootable
/dev/nvme0n1p2 : start= 2099200, size= 249559040, type=8e
# === new sfdisk -d ===
label: dos
label-id: 0x64436e11
device: /dev/nvme0n1
unit: sectors
sector-size: 512
/dev/nvme0n1p1 : start= 2048, size= 2097152, type=83, bootable
/dev/nvme0n1p2 : start= 2099200, size= 417331167, type=8e
Running growpart /dev/nvme0n1 2
will make the changes to the physical volume, but the extra space is not added to the volume.
After running growpart
command, pvresize
command needs to be executed.
[root@localhost ~]# pvresize /dev/nvme0n1p2
Physical volume "/dev/nvme0n1p2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Now it is time to add the spaces to the logical volume, first running lvdisplay
to get the LV Path
, normally the path is /dev/rl/root
. After that, using the following lvextend
command to take advantages of all the available free spaces.
[root@localhost ~]# lvextend -r -l +100%FREE /dev/rl/root
Size of logical volume rl/root changed from 70.00 GiB (17920 extents) to 150.00 GiB (38400 extents).
File system xfs found on rl/root mounted at /.
Extending file system xfs to 150.00 GiB (161061273600 bytes) on rl/root...
xfs_growfs /dev/rl/root
meta-data=/dev/mapper/rl-root isize=512 agcount=4, agsize=4587520 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1 nrext64=0
data = bsize=4096 blocks=18350080, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 18350080 to 39321600
xfs_growfs done
Extended file system xfs on rl/root.
Logical volume rl/root successfully resized.
Running lsblk
would show the following results, the rl-root space has been changed to 150G.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 9.8G 0 rom
nvme0n1 259:0 0 200G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
└─nvme0n1p2 259:2 0 199G 0 part
├─rl-root 253:0 0 150G 0 lvm /
├─rl-swap 253:1 0 11.9G 0 lvm [SWAP]
└─rl-home 253:2 0 37.1G 0 lvm /home
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 4.7G 13M 4.7G 1% /run
/dev/mapper/rl-root 150G 71G 80G 47% /
/dev/mapper/rl-home 38G 1.3G 36G 4% /home
/dev/nvme0n1p1 960M 406M 555M 43% /boot
vmhgfs-fuse 3.7T 1.7T 2.0T 47% /mnt/hgfs
tmpfs 2.4G 56K 2.4G 1% /run/user/42
tmpfs 2.4G 36K 2.4G 1% /run/user/0
Conclusion
In this article, the process for adding spaces to logical volumes has been provided, there are a few commands to run and it doesn’t take a lot of time for them to be executed. In this way, you could fine tune the space for your VM to perform in an optimal condition.
Leave a Reply