Saturday, July 20, 2013

HOWTO: add disk to VMware Ubuntu guest without reboot using LVM

SkyHi @ Saturday, July 20, 2013
This howto is mostly built on the great tutorial available at…hout-reboot/. My spot tries to be more Ubuntu and LVM specific. This manual was tested on Ubuntu 9.04 (jaunty) Server edition guest OS.

Add Virtual Hard Disk

add-disk1A new hard disk can be added easily to a running virtual machine in VMWare Infrastructure Web Access by clicking Add Hardware and following the wizard.
Note: I assume that all of the commands given are run under superuser (root) rights. To become root type
sudo su root

Detect new SCSI Disk

The package scsitools provides the script, which does exacly what we need. Install it and run it:
apt-get install scsitools
This should detect the newly added hard disk and make it available in /dev/ – /dev/sdb in the case you are adding a new drive for the first time. The output of fdisk -l should include the newly detected disk.

Format the new disk

Format the newly detected drive using fdisk
fdisk /dev/sdb
    n (for new partition)
    p (for primary partition)
    1 (partition number)
    (keep the other values default)
    w (write changes)
Change the type of the partition to LVM Linux:
fdisk /dev/sdb
    t (change the partition type)
    8e (for Linux LVM)
    w (write changes)


Initialize LVM Physical Volume

pvcreate /dev/sdb1

Add Physical Volume to Volume Group

List the Volume groups available at your machine.
Replace VolGroupName with what you read from the output of the last command.
vgextend VolGroupName /dev/sdb1
You should see the newly aquired free space in the output of

Resize Logical Volumes

After adding some free space to your Volume Group, you can distribute it to the Logical Volumes. The list of Logical Volumes can be obtained by running
Run the following commands for each Logical Volume you want to resize (add space to). Again – replace /dev/VolGroupNa­me/Namewith the Logical Volume name you can read from the output of the last command. The +10G means Add 10 GB
lvextend -L +10G /dev/VolGroupName/Name
The last step is to resize the ext3 filesystem (use different tool is you use different filesystem):
resize2fs /dev/VolGroupName/Name