Extending Xen VM size

Draft of notes so I don’t loose the method.

On CentOS 5.0 from 2005.
Xen vm images in /xenvms
Task: extend the databases vm from 5 G to 56 GB.

This wasn’t hard once I learned how to do it.  However, in this case, there were only two partitions on the device: p1: root and p2: swap.   So, I was able to delete the second partition without any hassle and resize the root partition.  Then I put a new swap partition at the end of the newly sized drive device.

In the virtual machine, comment out the swap partition in /etc/fstab.  You’l be deleting it shortly and won’t have it back before you boot up again.

Shutdown the virtual machine – the guest.

  • On the Xen host, run “xm console databases”
  • log in as root
    {do the commenty-outy thing in /etc/fstab}
  • run shutdown -hP -t 0 now

backup the image file first.
cd /xenvms; cp -a databases.img databases.2010061301.img
I renamed my original for easier manipulation and to avoid accidentally munging my backup with filename completion foo.
mv databases.imb t1.img

grow the img file

dd if=/dev/zero of=t1.img oflag=direct bs=1M seek=57000 count=1
Which means, effectively, “write one 1MB of zeros starting at postion 57,000 MB into the device.”  The effect is to very rapidly move the end of the device out to 58 GB.

Create a loop device to represent the device, then use fdisk, not parted, to delete the original partion and create a new one with a new end point out where you want it.

losetup /dev/loop1 t1.img
fdisk /dev/loop1
Set your units to cyl with ‘u’
Use ‘p’ to print the current partition table.
Note the starting cyl, the partition type and any flags
Delete the swap and root partitions with ‘d’
Create a new root partition with everything the same, but put the end out where you want it.  In this case, it was at 7200 cyl.
Don’t bother with the swap part.  Easier to do in the VM when you have it running again.

Get a loop device for the root partition so you can resize it offline.  You need to know how many bytes into the device to start.  Use fdisk -l -u t1.img to find out.  The -u reports in sectors.  Sectors are 512 bytes.  Example:

fdisk -u -l t1.img

Leave a Reply

You must be logged in to post a comment.