Grant McWilliams

Tech Virtualization Xen Howtos Convert Xen disk image to LVM Logical Volume

Convert Xen disk image to LVM Logical Volume

How to move from a tap:aio file to an LVM Logical Volume.

In Xen we can provide virtualized hard drives several different ways. It's not uncommon to create a large empty file using dd and then specify it as the hard drive like this.

 

name = "mailserver"
memory = "1024"
disk = [ 'tap:aio:/srv/xen/mailserver.img,xvda,w', ]
vif = [ 'bridge=xenbr0', ]
bootloader="/usr/bin/pygrub"
vcpus=2
on_reboot = 'restart'
on_crash = 'restart'

In this example /srv/xen/mailserver.img is our file. In a lot of ways LVM is more powerful and faster so moving our test server to LVM makes sense once we've gotten serious about deploying it. Moving from tap:aio to LVM is much easier than you think, here's how.

1. Shutdown domain.

xm shutdown mailserver

2. Create the Logical Volume

You'll need a Logical Volume the same size as your Xen disk file. In this example the Xen disk file is 10GB and I'll assume you already created it. This could easily turn into an LVM tutorial if I don't.

10 GB Disk file: /srv/xen/mailserver.img
10 GB Logical Volume:  /dev/VolGroup00/LogVolMAIL

3. Copy disk file to Logical Volume

dd if=/srv/xen/mailserver.img of=/dev/VolGroup00/LogVolMAIL -bs 1024

4. Edit the Xen domain config file

name = "mailserver"
memory = "1024"
disk = [ 'phy:/dev/VolGroup00/LogVolMAIL,xvda,w', ]
vif = [ 'bridge=xenbr0', ]
bootloader="/usr/bin/pygrub"
vcpus=2
on_reboot = 'restart'
on_crash = 'restart'

5. Restart domain

xm create -c mailserver

 

 

 

Tech Virtualization Xen Howtos Convert Xen disk image to LVM Logical Volume