Expanding VMware virtual disks can be a complicated task, but by following a few outlined steps, it should become a simple procedure.
One of the most dreadful and critical system error messages you can receive is the infamous "Low on Disk Space" or "Out of Disk Space" message. Adding disk space to physical machines can be a pain, but working with virtualized disks can also be cumbersome. In this TechTip, I'll show you how to easily expand virtual disks in VMware ESX Infrastructure, ESX Server, and Workstation installations.
Back Up!
The first step is to create a backup of your virtual machine to be resized. Choose your favorite backup method and back up the entire directory of the machine you want to expand. Be diligent about backing up because if something goes wrong, you'll be in big trouble; there is no way to revert the drive after you mess with the resizing tools.
If you're running VMware Workstation or VMware ESX Server (free edition), you should already know where you specified your virtual machines to be located. In VMware Infrastructure, you can find the machines in the following location. VMware Infrastructure 3 uses Red Hat Enterprise Linux 3 for its basis, so navigation through the file system is the same as RHEL.
/vmfs/volumes/servername:storage
Remove VMware Snapshots
My first attempt at resizing a Windows 2000 Server installation left me a bit disappointed because it failed. The commands used by VMware to expand the virtual disk completed successfully; however, when I booted up the machine, it failed and complained about snapshots being corrupted. It's impossible to expand a virtual machine if it contains snapshots. This can be a bit disconcerting, but remember: your original machine state and all snapshots are contained in the backup you created. Through VMware's interface, delete all snapshots that you have stored before you move on. Depending on the hardware you're working with, deleting several snapshots can take some time.
Expanding in VMware Workstation and ESX Server
If you're running either VMware Workstation or VMware ESX Server, the free edition, then you'll use the built-in vmware-vdiskmanager command-line utility. My examples are assuming you're running VMware on a Linux host, but if you're running it on a Windows host, the tools are identical. Substitute the correct path to the virtual machines and tools.
# cd /path/to/virtual_machines/machinename
# vmware-vdiskmanager -x 10GB machinename.vmdk
In this example, the disk will be expanded from its original size to a 10 GB disk size. VMware's tool extends the size of the file machinename.vmdk to reflect the new size. Depending on the speed of your hardware, this process could take just a few seconds or quite a long time to complete.
Expanding in VMware Infrastructure 3
The only differences in expanding virtual disks in VMware Infrastructure 3 are the tool and the arguments used on the .vmdk file. Infrastructure's tool is called vmkfstools. Navigate to the virtual machine's directory and issue the commands to extend the disk.
# cd /vmfs/volumes/servername:storage/machinename
# vmkfstools -X 10G machinename.vmdk
Make sure you use a capital "X" instead of lowercase; other than that, the process is the same as in the VMware Workstation and ESX Server example. The size specified is the final size of the virtual drive.
Extending the Guest's Partition
If the virtual installation's guest disk is partitioned, you'll need to use a third-party tool to extend the partition that the OS resides on. You can use expensive tools like Partition Magic, but the open-source tool GParted works wonderfully for this task. You can download a copy of GParted from the project hosted at SourceForge.
You have two choices for booting the utility from within VMware. You can burn the ISO image to a CD and boot it up on the guest OS, or you can use VMware's ability to boot ISO images directly and virtually from the guest CD device settings. To use the second method, edit the virtual machine's CD/DVD hardware device and select the ISO image option. Navigate to the ISO file and then boot up the virtual machine. You may need to edit the virtual machine to boot into the BIOS mode. From here, you can change the boot order to boot from CD-ROM devices before the hard drive no matter which method you choose.
Once you have the guest booted up, you can select to boot GParted up in the default mode. Follow all the standard prompts and you'll be presented with a GUI interface to select which partition you want resized. You can either type in the size or use the GUI to choose the new size. The interface will look very similar to the following image.
Figure 1: GParted's GUI interface allows you to select the partition you want to resize. (Click image to enlarge.)
Once you select the new size of the partition to be resized, make sure to click the Apply button to start the process. Once the utility has completed, you can restart the virtual machine and see that your drive space has increased.
Supported File System Types
GParted supports most file systems right out of the box. Obviously, the most commonly used types are EXT2, EXT3, FAT16, FAT32, NTFS, Reiser, and XFS. A complete list of supported types can be found at the GParted Web site.
If you're running Logical Volume Management (LVM) on your Linux systems, you won't be able to use GParted to extend logical volumes. LVM has its own set of tools that you can use to extend LVM's volume groups and logical volumes. You'll want to look into the two commands vgextend and lvextend.
If you're running NTFS on Windows, you can substitute using GParted if you'd like and use the native Microsoft tool DISKPART. Microsoft's tool cannot resize FAT16 or FAT32 types, though, and can only be used on NTFS.
Extend Away
As you can see, expanding virtual disks in VMware and then extending partitions can be a bit nerve-wracking. A bit more complexity is added when you throw VMware into the mix, but with its own native tools and the open-source tool GParted, you'll find the task very manageable. Just don't forget to back up your virtual machines and to delete VMware's snapshots before attempting to resize your virtual machines.
LATEST COMMENTS
MC Press Online