Today i’m gonna giving a tutorial how to expand logical volume Management (or so called LVM) in centOS 7 especially when it run under virtual machine (mine is in ESXi). In conclusion It’s not hard as you think it is. Let’s start
VM Storage configuration
Power off the desire machine you want to extend.
Edit your VM setting by right click on the vm and choose edit settings.
Go to Hardware Tab and chose the Hard Drive and resize it by changing the value in the provision size (you can do this on the fly but if the addition space isn’t there, you can scan the scsi_disk (i’ll tell about it later)).
when you done resizing you Virtual machine hard drive , power up the virtual machine and login into it.
Check existing space and partition name
[this is where the fun begin ] note : you can do it from terminal inside the machine or using 3rd party ssh software like putty or whatever terminal tool suitable for you.
run this command first to check you space:
df -h
and run this command to find the volume you want to resize :
fdisk -l
and look into your partition name (mine was /dev/sda)
Scanning newly added free space storage
next, run this command :
fdisk /dev/sda
press p to check out if the additional space were added to the hard drive.
If your system still not detecting any addition space you insert earlier. You can use this method : force re-scan the scsi disk with this command :
Note : the “2:0:0:0” path maybe different on the system you installed, so there’s no guarantee will have the same path as mine.
Adding the free space into LVM
now you can create new partition using the additional space you’ve got after scanning the scsi_disk by using fdisk command and then press n. After that press t to change partition table to “8e”.
Note : if the fdisk command show “there’s no free sector available” you can force create new partition using this command : fdisk -c=dos -u /dev/sda. Just enter until it’s done and show like picture above
now press p to take a look if the new partition already created in the system.
and press w to write change it and reboot the system the apply the setting.
run the vgdisplay command to see current Volume group status.
now you can extend your volume group using this command :
vgextend <VG Name> <Newly Created Partition>
in my case is vgextend centos /dev/sda4
as you can see on the picture above, the Free size is increase from 16 / 64.00 MiB to 12815 / 50.06. which is you successfully added the new partition to the current volume group.
run the lvdisplay command to show the current logical volume status. In this case , i want to increase the root partition, so i only display the current status of root logical volume.
15. The next step is to increase the logical volume size of the /dev/centos/root by using this command :
lvextend <lv path> <newly created partition>
in my case is like this :
the last step is to resize the file system so that it can take advantage of the additional space added in volume group before.
Note : usually resize2fs command was using the resize the file system, but in centOS 7 , the command change into xfs_growfs
you can check with command df -h to make sure the additional space was added to the system (mine is growing from 250 GB to 300 GB)
Result
Before
After
and Voila!!. You have more space in your system.