Tuesday, August 14, 2012

Make use of a resized disc in a virtualized Ubuntu (LVM)

In Ubuntu 12.04 running as a guest in VirtualBox on a Windows host, I needed extended disk space.
Resiszing the disc was easy:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"  modifyhd Ubuntu.vdi --resize 16000

But how make the guest system effectively use the additional space, if the disc is used with LVM? It took me some time to understand that several steps are needed due to the layered architecture of LVM. Execute following steps as root
  1. Create a new logical partition with fdisk and give it type 8e (sda is the device name under which Ubuntu recognizes the disk)
    fdisk /dev/sda
    
  2. Create a physical volume from the new partition (sda6 is the device name for the new partition)
    pvcreate /dev/sda6
    
  3. Add the new physical volume to a volume group (ubuntu is its name, you can find it out with vgdisplay)
    vgextend ubuntu /dev/sda6
  4. Extend the logical volume with the space now available (/dev/mapper/ubuntu-root is the path of the logical volume)
    lvextend /dev/mapper/ubuntu-root /dev/sda6
  5. Make the file system aware of its new dimension
    sudo resize2fs /dev/mapper/ubuntu-root

5 comments:

  1. Thanks Michael, you just ended a quite frustrating evening :-)

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Fantastic guide. I was having a bit of a nightmare trying to resize my disk. This worked perfectly, many thanks!

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Thanks! This works great. In my case, I had also increased the size of /dev/sda2 using gparted beforehand - not sure if that step is necessary. It's also worth noting that a reboot of the VM is necessary between steps 1 and 2 (I'm using Ubuntu 14).

    ReplyDelete