Sunday, November 16, 2008

Adding disk space to a Linux VM in VMWare

I had a CentOS 5 VM that just didn't have enought disk space, so I wanted to give it some more. I didn't think it would be too hard, and in the end it wasn't, but it sure took me a while to find all the steps to accomplish it. So here are the ones I found useful. YMMV :)


Host OS: Windows Vista x64 SP1

VMWare Software: VMWare Workstation 6.5

Guest OS: Centos 5 (code equivalent to RHEL5)


1. Power off the VM (have to do this to add a new disk)

2. Create a new virtual disk (this is the easy part)
a. Go into VM->Settings and in the Hardware tab, click the Add... button.
b. Follow the instructions. This is very straightforward. I created a new 8GB disk.

3. Power on the VM and log in as root.

4. I decided to use the LVM subsystem, and that's what these steps address:

a. Create a Physical Volume representing the new disk: pvcreate /dev/sdb
b. Extend the default Volume Group to contain the new PV:
vgextend VolGroup00 /dev/sdb

c. Extend the default Logical Volume to include the newly-acquired space in the VG:
lvextend --size +7.88G /dev/VolGroup00/LogVol00
(The disk is 8GB according to VMWare, but it looks like around 7.88GB to Linux)

d. Extend the device containing the / (root) filesystem to stretch across the entire LV:
resize2fs -p /dev/mapper/VolGroup00-LogVol00

And that's it. I took the defaults on installing CentOS, so my / (root) filesystem is of type ext3, which supports this dynamic resizing.

So in this case, this disk is basically tied to this VM. If you wanted to create a disk that could be used by different VMs, you would certainly go about it differently, but that's a different topic.

1 comment:

Venkat said...

Very useful article and I used it to resize my RHEL4 VM. My RHEL4 VM did not have resize2fs command and I used "ext2online /dev/mapper/VolGroup00-LogVol00 15g" to extend the volume to 15 GB.

Thanks Frank for making my day easier!

-venkat