Linux KVM: Use software RAID as VM-guest disk

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Linux KVM: Use software RAID as VM-guest disk

Post by ^rooker »

Here's a short description about how to add a physical device's software-RAID partition directly as virtio disk, available to VM-guests.

Introduction:
I wanted to have one virtual machine guest accessing a certain software RAID partition, formatted on ext4 - exclusively.

I've tried adding that device to the KVM's storage pool, using virt-manager, but I failed. It always mounted the device and sold it to the guests as dir. That's not what I wanted.

Luckily, I found a post on Ronald Ever's blog, about adding a physical device using libvirt. I think this is currently not yet possible with virt-manager, so as Ronald says:
You have to do it by hand.
But don't be afraid: It's actually really easy. If you're able to edit a textfile, you're ready to play!

First: Stop the virtual machine guest you're planning to add the disk to.

Then, add the disk:
The XML block you have to add to "/etc/libvirt/qemu/<vm_guest>.xml" looks somewhat like this:

Code: Select all

<disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/md0'/>
      <target dev='vdb1' bus='virtio'/>
</disk>
The only thing that's missing in Ronald's HowTo is, that the XML file should be edited using "virsh" - and not directly:

Code: Select all

$ virsh edit <vm_guest>
This opens the configuration XML of the <vm_guest> in your favorite editor. Now add the above XML block and adapt it to fit your environment.

Then restart libvirt:

Code: Select all

$ /etc/init.d/libvirt-bin restart
Now, you should have the software RAID device available as "/dev/vdb1" on your virtual guest machine.

Have fun! :)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply