Gimme some space, man

Most modern virtualization software lets you add a disk (and hence: disk space!) to your virtual machines while the machine is powered on. That's great - but then the VM's operating system needs to be able to do something with it.

In Linux, that can be quite a chore. Especially if the disk running out of space is your / partition.... In this article, I'll show you what to do about that. And no, it's not scary. Almost.

If you're using LVM on your disk - and most folks using a Red Hat like distribution (RHEL, Fedora, CentOS, and the like) do this by default - then life adding a new disk can be as easy as typing a few commands to the command line (that is if you've been a good little admin and refrained from installing X on your server...)

So: Let's get started! To start out with, do two things:

  1. make a snapshot of your VM (!!)
  2. add the new virtual disk

Now, go to your command prompt (SSH or the console of your server) and log in, the use su to get you a bit more privileges...

Done? Okay. With df -h you can check which mount point - and especially which LVM "partition" needs to be increased in size.

Find the name of your scsci controller (probably scsi0) by doing:
ls /sys/class/scsi_host
Output:host0

Now type the following to send a rescan request (we'll assume that it shows up as /dev/sdb in this example):

echo "- - -" > /sys/class/scsi_host/host0/scan
fdisk -l
fdisk /dev/sdb
n   (create new partition, select start and end cylinders, all free space is selected by default)
w  (save partition table and exit)

Initialise the partition for use as a physical volume in lvm and add it to VolGroup00:

pvcreate /dev/sdb1
vgextend VolGroup00 /dev/sdb1

Extend LogVol00 using all available space on the new disk by simply referring to the new disk's partition:

lvextend /dev/VolGroup00/LogVol00 /dev/sdb1

Alternatively, you can use only parts of the new disk (e.g. by 10G here)

lvextend -L +10G /dev/VolGroup00/LogVol00

alternatively, you can Finally, resize the filesystem (this part normally would require unmounting /, but for ext3 and 2.6 Kernels it works while the partition is mounted)

resize2fs /dev/VolGroup00/LogVol00