HowTo: Resize an EXT4-formatted Linux LVM Volume in a virtual machine

by Wolfram Saringer  (2011-02-17)
last change: 2011-02-17

1. Resize the volume using VMWare VM-Manager. The size field is greyed out if there are any snapshots defined... you'll have to delete them.

2. Start the virtual machine.

3. Use cfdisk to create a new logical partition in the free space of the virtual disk. Use type 8e - Linux LVM. Note: fdisk did not see the free space on the device. The new partition is /deb/sda6 in this example.

4. REBOOT the virtual machine. In our tests the change to the partition table was not visible after exiting cfdisk.
# reboot

5. Create a physical volume:
# pvcreate /dev/sda6
  Physical volume "/dev/sda6" successfully created

6. Use lvdisplay to look up the name of the volume group currently in use:
# lvdisplay
  --- Logical volume ---
  LV Name                /dev/mongo1/root
  VG Name                mongo1
  LV UUID                wi9dRo-fS0C-xSCd-fbei-el9R-vpVi-0QEiIR
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                9,29 GiB
  Current LE             2379
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:0

7. Add the physical volume to the volume group found in the field 'VG Name':
# vgextend mongo1 /dev/sda6
  Volume group "mongo1" successfully extended

8. Now you can try to extend the existing logical volume (as named in field 'LV Name' above). If the given size increase (20GB in this example) is more than is available in the disk group, the error message will indicate the number of blocks available:
# lvextend -L +20G /dev/mapper/mongo1-root
  Extending logical volume root to 29,29 GiB
  Insufficient free space: 5120 extents needed, but only 5119 available

Retry with the number of blocks taken from this error message:
# lvextend -l +5119 /dev/mapper/mongo1-root
  Extending logical volume root to 29,00 GiB
  Logical volume root successfully resized

9. Resize the filesystem (sorry for the german output -- this is the only command that used the locale setting...):
# resize2fs /dev/mapper/mongo1-root
resize2fs 1.41.11 (14-Mar-2010)
Das Dateisystem auf /dev/mapper/mongo1-root ist auf / eingehängt; Online-Grössenveränderung nötig
old desc_blocks = 1, new_desc_blocks = 2
Führe eine Online-Grössenänderung von /dev/mapper/mongo1-root auf 5241856 (4k) Blöcke durch.
Das Dateisystem auf /dev/mapper/mongo1-root ist nun 5241856 Blöcke gross.

all articles represent the sole opinion of their respective author. all content comes without any warranty for correctnes, despite due diligence.