Sometimes we get a disk utilization situations and needs to increase disk space. In the VMware environment, this can be done on the fly at VMware level. VM assigned disk can be increased in size without any downtime. But, you need to take care of increasing space at OS level within VM. In such a scenario we often think, how to increase disk size in Linux when VMware disk size is increased? or how to increase mount point size when vdisk size is increased? or steps for expanding LVM partitions in VMware Linux guest? or how to rescan disk when vdisk expanded? We are going to see steps to achieve this without any downtime.
In our example here, we have one disk
/dev/sdd assigned to VM of 1GB. It is part of volume group vg01 and mount point
/mydrive is carved out of it. Now, we will increase the size of the disk to 2GB at VMware level and then will add up this space in the mount point
If you re using the whole disk in LVM without any fdisk partitioning, then skip step 1 and step 3.
fdisk -l output snippet showing disk
/dev/sdd of 1GB size. We have created a single primary partition on it /dev/sdd1 which in turn forms vg01 as stated earlier. Always make sure you have data backup in place of the disk you are working on.
Now, change disk size at VMware level. We are increasing it by 1 more GB so the final size is 2GB now. At this stage disk need to be re-scanned in Linux so that kernel identifies this size change. Re-scan disk using below command :
Make sure you use the correct disk name in command (before rescan). You can match your SCSI number (X:X:X:X) with VMware disk using this method.
Note : Sending “– – -” to /sys/class/scsi_host/hostX/scan is scanning SCSI host adapters for new disks on every channel (first -), every target (second -), and every device i.e. disk/lun (third -) i.e. CTD format. This will only help to scan when new devices are attached to the system. It will not help us to re-scan already identified devices.
That’s why we have to send “1” to /sys/class/block/XYZ/device/rescan to respective SCSI block device to refresh device information like the size. So this will be helpful here since our device is already identified by the kernel but we want the kernel to re-read its new size and update itself accordingly.
Now, kernel re-scan disk and fetch its new size. You can see new size is being shown in your
fdisk -l output.
At this stage, our kernel know the new size of the disk but our partition (
/dev/sdd1) is still of old 1GB size. This left us no choice but to delete this partition and re-create it again with full size. Make a note here your data is safe and make sure your (old & new) partition is marked as Linux LVM using hex code
8e or else your will mess up the whole configuration.
Delete and re-create partition using
fdisk console as below:
fdisk prompt commands are highlighted in the above output. Now you can see the new partition
/dev/sdd1 is of 2GB size. But this partition table is not yet written to disk. Use w command at
fdisk prompt to write table.
You may see the warning and error like above. If yes, you can use
partprobe -s and you should be good. If you still below error with
partprobe then you need to reboot your system (which is sad ).
Now rest of the part should be tackled by LVM. You need to resize PV so that LVM identifies this new space. This can be done with
As new PV size is learned by LVM you should see free/extra space available in VG.
You can see our VG now have 2GB space! Now you can use this space to create new lvol in this VG or extend existing lvol using LVM commands. Further you can extend filesystem online which is sitting on logical volumes.
You can observe all lvol in this VG will be unaffected by this activity and data is still there as it was previously.