Here is an example doing it with an iSCSI drive on a KVM virtual machine because this procedure applies to any modern Linux OS that runs LVM2, not just CentOS on VMware. I did this on a test virtual machine, starting with /dev/sda
and /dev/sda1
both at 64G in size:
root@xi:~# lsblk /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 64G 0 disk
+-sda1 8:1 0 64G 0 part
+-vg-root 254:0 0 22.4G 0 lvm /
+-vg-swap 254:1 0 952M 0 lvm [SWAP]
+-vg-tmp 254:2 0 952M 0 lvm /tmp
+-vg-var 254:3 0 7.5G 0 lvm /var
root@xi:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 vg lvm2 a-- <63.99g <32.33g
I went to my storage subsystem and expanded the disk by 8GB. Now we can tell the kernel to rescan the device as you mentioned (though my device was found under /sys/class/scsi_disk
instead).
root@xi:~# echo 1 > /sys/class/scsi_disk/0\:0\:0\:0/device/rescan
root@xi:~# lsblk /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 72G 0 disk
+-sda1 8:1 0 64G 0 part
+-vg-root 254:0 0 22.4G 0 lvm /
+-vg-swap 254:1 0 952M 0 lvm [SWAP]
+-vg-tmp 254:2 0 952M 0 lvm /tmp
+-vg-var 254:3 0 7.5G 0 lvm /var
We can now see that lsblk
now shows a larger drive, but the partition is still the original size. We need to resize the partition to fill the expanded space using a partitioning tool. To do this with fdisk
, you have to erase the partition and create a new one starting at the same block, but that is kind of scary to do. An easier way is to use parted resizepart
, like this:
root@xi:~# parted /dev/sda resizepart 1 100%
Information: You may need to update /etc/fstab.
root@xi:~# lsblk /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 72G 0 disk
+-sda1 8:1 0 72G 0 part
+-vg-root 254:0 0 22.4G 0 lvm /
+-vg-swap 254:1 0 952M 0 lvm [SWAP]
+-vg-tmp 254:2 0 952M 0 lvm /tmp
+-vg-var 254:3 0 7.5G 0 lvm /var
The parted
program resized the partition on the disk, but the kernel may not know about the change yet. Run partprobe
to make sure the kernel updates its table in memory:
root@xi:~# partprobe /dev/sda
After we know the partition has been resized and the kernel knows about it, we can finally extend the physical volume. The pvresize
command automatically extends the physical volume to fill all of the free space:
root@xi:~# pvresize /dev/sda1
Physical volume "/dev/sda1" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
root@xi:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 vg lvm2 a-- 71.99g 40.33g