Monday, May 11, 2009

How to increase Virtual Machine (VM) Size:

In my first post I’ll explain how to increase the size of a virtual machine on VMware ESX Server. I’ve been working with virtual servers for the past 3-4 years and they are getting more and more popular each year. There’s no network administrator who have never used VMware player or at least heard of it.

On this particular case I’m dealing with VMware ESX Server as it is one of the best and complete solutions regarding virtualization. As you may know the ESX platform runs over Linux and we are going to need root access to perform a few commands on the Linux shell.

First Step:

Before doing anything, if the machine you want to change disk size is running Windows you should check the disk for errors first. For this job you only need to open a cmd prompt and type:

chkdsk /F

This will schedule a disk check for the next time you boot Windows. Do this for all your disk drivers or partitions. You may want to just check the disk without using /f option but this will not fix any error because the disk is probably mounted and in use by the O.S.

Second Step:

Now that you know your disk is free of errors let’s put the VM down for a while. For this job you can either use Virtual Infrastructure Client to access the VM desktop or just use any kind of remote desktop view in case you have it enabled in your machine. Just perform a simple shutdown action and wait until the process is completed.

Third Step:

Make sure you have a backup of your files before doing the next 2 steps. I take no responsibility for data losses.

Now we want access to the ESX server shell. For this you can either use SSH client like Putty (Windows) or just sit in front of the server itself. Once you’re in use the following command to change a VM size.

vmkfstools <options> <device_or_VMFS_volume>[:<file>]

For example if you want to increase a VM to 35gb disk size which is stored in serverA.vmdk. (By default VMs are stored in /vmfs)

# vmkfstools -X 35g /vmfs/volumes/serverA.vmdk

Tip: You can also want to reduce the VM size but there are a few more steps you have to do before doing so. Check this link for a tutorial on how to do it.

Attention: Be sure you have enough disk space left on your server before trying to increase the VM size.

Fourth Step:

It’s time to turn on your VM again but before we do that we need a software to dynamically change a partition size. I recommend using Gparted Live CD which can be obtained on this address.

Use the .Iso as the cdrom drive and make your server is able to boot from it. You can see how to do it here.

As soon as it finishes the boot process you just need to open gparted tool and resize the partition sliding the bar to the top right part, i.e. till you don’t have any free space left. Click apply and wait for the process to finish. Should only take seconds to a few minutes.

Once the resizing step finishes, remove the Iso file from the cdrom connector and reboot the machine. Check the disk size to ensure it changed.

That’s it folks. Just make a comment if you need any help or fix anything i wrote here.

No comments: