Debian Wheezy: Split and resize Xen disk image

On this page

Background

One of my Xen virtual servers needed to have its 400G disk split and resized over the weekend, and I wanted to keep downtime to a minimal. The disk had 240G used, 235G of which was a /backup directory, and the remaining 5G dedicated to a regular Debian Linux installation. I wanted to split the disk into a two disks - a 20GB disk containing the Linux system, and a 300G disk to mount as /backup. Then I could apply my DRBD setup to replicate that 300G backup partition to a separate 2nd backup machine.

I didn't want to end up in a situation of having to copy a load of data on the physical host, and I certainly didn't want the virtual machine down while I did it.

Set up images

The virtual machine has its disk image located in /vm/domains/b1/disk.img and an accompanying swap.img that we don't need to worry about.

Issue:

losetup -a

To locate all used loop devices. In my case, /dev/loop20 was the first free device. Next, I'll set up a loopback device for the image, and then mount it: