Although the scenario described below is for a Linux server virtualized on a VMware ESXi box, I am sure you will find that the process described can be used on any virtualization host.
When you're running a Windows server on VMware, expanding a disk is usually trivial. Not so when the server is Linux based. If the server also is installed on an IDE disk controller, things get even worse.
This is a guide I made a while back, and it's got lots of images. Perhaps more than needed, but it saves me some typing, so why not. In my guide, I used a Moodle server that was downloaded from Bitnami, as a virtual appliance. The disk was partitioned without LVM, the process would be a little different with LVM.
I started by checking free space on the server, using the df command.
As you can see, there is no shortage of disk space on this server, but if you've ever run a Moodle server for a school district or the like, you will know that disk space needs to be plentiful. So I want to expand the disk.
After shutting down the server, I can see that it is not possible to alter the size of the disk in VMware, the disk size field is greyed out. This can happen if you have existing snapshots of the machine, or as in this case, it's an IDE disk.
In order to expand a disk that cannot be expanded, I need to create a new, bigger disk, and copy the original to the new disk. I also have to remove all existing snapshots, or else I will not be able to remove the old disk after completing the process.
I add a new disk to the VM with desired capacity, using the same disk controller.
I then download the latest version of Clonezilla, and mount the ISO file to the machine. Clonezilla is a disk imaging software that lets me copy the content of the old disk to the new.
I have to make sure the VM will boot from the CDROM, so from the Options tab, under Boot options, I choose to force the VM into it's BIOS setup page on the next boot.
When I now power up the VM, it goes straight to the BIOS setup, and I configure the boot settings to boot from the CDROM first.
I then exit the BIOS, saving changes, and let the VM boot to the Clonezilla CD. The Clonezilla boot has many prompts during the boot, if one is not mentioned here, choose the default option by pressing Enter. The first non-default choice will be to use device-device mode cloning. There is no need to work with image files, as we have both disks connected and are able to copy directly from one disk to the other.
The next prompt I'll show you, is the choice between beginner and advanced mode of operation. You might be tempted to choose advanced here. After all, when a systems administrators like myself reach such a choice, we always want the advanced stuff available to us, as nobody would understand the advanced options better than us. But trust me, for the operation we are about to do, beginner mode is all we need.
Next important choice is to use a local disk to local disk cloning.
We choose the old, smaller disk as source for the cloning process, and the new, bigger disk as the target.
We also confirm that we do want to copy the boot loader from the old disk to the new.
After this the cloning process will start. This will take some time, depending on how much data you got on your old disk, as well as your VMware server and it's disk system. I was running this on my ESXi test server, with a single SATA disk system. As the first image indicates, I got just over 1.5 GB of data, and the whole process took a couple of minutes.
Clonezilla uses the partclone utility, that only copies sectors that actually have data stored, so you might find it useful for cloning VMs on ESXi for other purposes as well.
When the cloning is done, please take notice if any errors have occurred.
Choose to poweroff the machine when the option is given to you, and you're done with Clonezilla. When the VM is shut down, remove the old disk, without deleting it. We still don't know if we will succeed, so keeping your options open is good.
Next, we want to change the remaining disk to IDE port 0:0.
You might want to remove the CD from the VM and try to boot it now, to check if the cloning went well. However, you will not see any change in free space, as the partitions are still the same size as they where on the old disk. We need to expand the desired partition using Gnome Partition Editor, which is available from the link in a Live-CD configuration. Download the ISO file and attach it to your VM.
The GParted Live CD also has a few prompts during boot, just press Enter on all of them, until you arrive at the desktop, where you will find the GParted program running, showing the current layout of your disk.
In this example, we can see that the swap partition is behind the main partition that we want to expand, so it needs to be moved to the end of the disk. If you're lucky, the swap partition might be the first partition, so that this is not needed.
In order to move the swap partition, we just delete it, and recreate it at a later stage.
When the swap partition is out of the way, we choose to resize the main partition. Leave enough space at the end of the disk for a new swap partition.
Create the new swap partition on the unallocated space left over.
Review your changes, this is what it looked like on my Moodle server.
If you're happy with what you have done, press "Apply" to commit the changes. The operation might take some time, depending on the operations being done. Remember that moving a partition might take even longer than copying, so keep your changes to a minimum, and try to expand partitions without moving them.
When you're done with GParted, shut down the VM by dbl-clicking the Exit icon.
Remove the GParted CD from the VM.
Boot your VM and check if you got the desired space available.
If everything is OK, proceed to delete the old disk file from your VMware server. Done.