It’s been a while since I started to use XenClient on my laptop, and I’ve always missed a nice and easy way to resize my VM’s disks not being synchronized. Cause I’m a techie, and we techie’s used to like the idea of being aside the corporate standards and preserve our independence. XenClient is a great match for this BYO concept, and that same feeling impulsed me to investigate how to resize my personnal XenClient VM disks which are not synced on the Datacenter.

So let me share with you how I managed to resize my main personnal VM disk (vhd) from my own single laptop, without needing to SSH.

First thing you will need to do is to open a terminal window from XenClient Receiver. Just go to Receiver for XenClient or press “Ctrl + 0″. Once on your home screen, type “Ctrl + Shift + t”, and your terminal window should pop up asking for your root password (you need to know that, for obvious reasons).

Next step will be to identify your VM virtual disk (vhd). All VM’s disks are located on /storage/disks, but there is a bunch of them with long UUID based names. So, which one is the one I’m looking for?

In your case, it could be easier, if you have little few VM’s or is pretty clear your target disk size. Remember, these are thin-provisioned vhd’s, so the size of the vhd would not reflect the actual size of the disk being seen by the VM but the amount of used space.

 
IDENTIFYING YOUR VM DISK

If you ain’t that lucky, here is what you would need to do:

Go to “/config/vms” (using “cd” command) where you will find a bunch of db files with file name based on VM’s UUID. These files keep VM’s configuration information, and disks are specified within these configuration files. Knowing the VM UUID could be challenging, but my VM’s name is something I can easily remember. So all I need to do is run the following command:

grep -r -l "My VM Name" /config/vms/*.db

The output of such command should be the db file for “My VM Name” VM. Something like this:

/config/vms/b4501705-0232-45da-9d12-9f80e45bd857.db

Now that I have identified the file, let’s dig into it to find the vhd for this Vm’s disk. You can easily type:

vi /config/vms/b4501705-0232-45da-9d12-9f80e45bd857.db

Once edited your file, scroll down to the “disk” section. “0″ subsection will represent your mounted iso, and “1″ will represent your attached disk. So within “1″ subsection you will have the “path” value. It would look something like this:

"1": {
   "path": "\/storage\/disks\/your_vhd_uuid.vhd",

This represents the actual vhd we were looking for. Great, now we are 100% sure this is the disk. Write that down as from Terminal window you won’t be able to copy and paste. You will not need the backslashes, your path would be like:

"/storage/disks/your_vhd_uuid.vhd"

Type “:q + Enter” to leave vi editor.

 
COPYING THE VHD FILE

But now I need to move my vhd file somewhere I can then grab it from my VM to resize the disk. In my case, I will move the vhd file into a NAS. To avoid doing that from an additional computer via SCP or SFTP, I would just mount a CIFS share from XenClient Terminal window as follows:

Create a mounting point:

mkdir /mnt/vhd

(worked for me).

Run:

mount -t cifs -o username=server_user,password=secret //192.168.44.100/share /mnt/vhd

…where server_user and secret will be your credentials to log into your share.

If everything went fine, now you should be able to change to “/mnt/vhd” folder and browse the share content with ls command.

Assuming everything went fine, it’s time to copy the vhd file:

cp /storage/disks/your_vhd_uuid.vhd /mnt/vhd

“your_vhd_uuid.vhd” should be the one you wrote down on a previous step. Now it’s time to wait for it to be copied.

There are other ways to copy your file, as you could mount a USB drive, but this will require again some Linux skills. In this post I will just focus on using a NAS as the storage media to support vhd transition.

 
RESIZING YOUR VHD

For vhd resizing purposes, I will be using “vmtoolkit vhd resizer”. It’s easy and neat. You can download it from http://vmtoolkit.com/files/default.aspx

In my case I will install this tool on another VM, so it would be easier for me. It’s time to run the additional VM and install “vhd resizer”. After the installation, I will recommend to map the shame CIFS share file, now from your Windows VM. It should be something like:

net use z: \\192.168.44.100\share /user:[DomainName\UserName] /persistent:no

If everything mapped correctly, you can now launch “vhd resizer”. You would have to select your source vhd and your destination file. Keep it dynamic and assign the new size. For this I got a screenshot:

vhdresizer

Try to have your destination file on the same share so it would be easier to move back the vhd in XenClient.

So resizer will start dumping your sector from one disk to the other and eventually will finish.

 
MOVING THE RESIZED VHD INTO XENCLIENT

Now it’s time to import your new vhd file into XenClient. Your new vhd should be about the same size as your previous disk.

Moving back into Terminal window on XenClient Receiver (“Ctrl + 0″; + “Alt + Tab” in case your terminal window hid), you will just need to copy your file as follows:

cp /mnt/vhd/your_vhd_uuid_2.vhd /storage/disks

Be sure there is enough space on your physical disk. In case not, remove your previous vhd from “/storage/disks” with “rm” command.

If you still preserve your previous vhd (do it as a best practice, so you will easily move back to your previous disk in case something goes wrong with your resized vhd), rename your file to “old” or anything you feel comfortable to identify it later on. For that purpose use the “mv” command as follows:

mv your_vhd_uuid.vhd your_vhd_uuid_old.vhd

Now, you need to rename your resized vhd. It’s important you rename the resized vhd to the source vhd name, otherwise your VM will not mount the disk later.

mv your_vhd_uuid_2.vhd your_vhd_uuid.vhd

Guess what. TURN YOUR VM ON!!!
Your VM should now be able to boot from the resized disk.

 
EXTEND YOUR VM DISK VOLUME

But I’m afraid we ain’t gone the whole way. If you go to Windows Explorer you will see your C: drive is still the same size as before. You still need to extend your volume to include the new unallocated space. For this purpose, go to Windows Disk Manager and you will see something like this:

(Next screenshots are in Spanish, but you will figure it out)

c_drive

Now right click on C: volume and select “Extend Volume”. Be sure your disk is added specifying the available unallocated new space (it should be done automatically by default). And press “Next”.

extend_volume

 

When finished, YOU CAN SAY NOW IT’S DONE!!!

If you’ve managed to come down the whole path, WELL DONE!!!

Remember to keep a copy of your source vhd as a backup, just in case you need to roll back.

And hope you enjoyed with this post.