Grant McWilliams

Tech Virtualization Xen Howtos Resize Disk Image used as Xen DomU hard drive

Resize Disk Image used as Xen DomU hard drive

Scenario: In the Dom0 (Host) you have a file that you export to the DomU (Guest) and it appears as an entire hard drive and you want to make it larger.

Example- Dom0: /srv/xen/diskimage.img -> DomU: /dev/xvda

 

If you're using diskimages for your DomU drives you may need to increase their size if any of the DomU partitions become full.

Resize the Xen Diskimage in Dom0

1. Create a backup of the diskimage from Dom0

2. Shutdown the DomU

3. Add extra space to the diskimage using dd. This will add 1GB to the DomU image. Adjust count=  depending on how much you want to add. If you want a sparse file use seek= to define the entire disk size.

dd if=/dev/zero bs=1M count=1024  >> ./diskimage.img

or if you want a sparse file

dd if=/dev/zero bs=1 count=0 seek=1G  >> ./diskimage.img

4. Boot the domU

Your disk should now be larger. You will need to use traditional tools inside the DomU to make the partitions and filesystems larger.

Following are examples for Partitions and LVM.

 

Expanding DomU Partitions from within DomU

In this example we're using /dev/xvda as the example DomU device name, change this depending on your setup. Note this tutorial only works for resizing the last partition on the diskimage drive.

1. Start the DomU and log in as root

2. Start fdisk /dev/xvda

3. Delete the last partition and recreate it with the start cylinder being identical as before and the ending cylinder being the default (end of disk)

4. Exit fdisk

5. You may have to reboot the DomU before going on.

5. Resize the filesystem on the partition - resize2fs /dev/xvda1

 

That's really it! You can only hot resize if the Filesystem is getting larger. If you need to shrink it then you'll have to take the Volume offline first. Isn't this easier than dealing with partitions that are too small?

If the partition you want to resize is in the middle of the DomU drive you're in a bit of a pickle. For example if you want to resize / you have problems.

  • /boot - /dev/xvda1
  • / - /dev/xvda2
  • /var - /dev/xvda3

This is the primary reason to using LVM. The solution to this problem isn't very elegant. You basically need to make another disk image and attatch it to the DomU in exactly the same manner as you attached /dev/xvda. The new drive should appear as /dev/xvdb if that's the way we entered it in the DomU config. Once it's done you need to restart DomU, fdisk and format the drive. Once formatted you can mount it and copy all of /var over, change /etc/fstab to map /var to /dev/xvdb1 and reboot the DomU again. Once rebooted you can delete /dev/xvda3 and resize /dev/xvda2.

This process is really no different than if you had a real server but you don't have to install a physical hard drive. I think this shows why LVM is such an improvement over physical partitions.

 

 

Tech Virtualization Xen Howtos Resize Disk Image used as Xen DomU hard drive