Jason Ruiz

Virtualization, Technology, and Stuff!

KVM: Nested Virtualization Support

This hit me like a sack of bricks, I looked for this before and never found any way of doing it, but I just happened to have found some articles from early last year that showed it was supported. As I’m writing this I’m getting a fully set up UEC cloud going, the proof is in the setup for this as it’ll flat out warn you 2-3 times that you don’t have KVM support, and it hasn’t yet. There are very few steps:

You’ll want to stop libvirtd in some instances, depending on what route you chose. Here we will remove and reinsert the module with nested support.

jason@Desktop:~$ sudo /etc/init.d/libvirt-bin stop
jason@Desktop:~$ sudo modprobe -r kvm_amd
jason@Desktop:~$ sudo modprobe kvm_amd nested=1

Next we will want to either add a new script to apparmor and the bin directory or change the current symlinked /usr/bin/kvm file. Let’s start off with the safe way, by creating separate script. This one I’ve named kvm-nested.

#!/bin/bash
exec /usr/bin/kvm -enable-nesting "$@"

Once that is done, you’ll need to edit the /etc/apparmor.d/abstractions/libvirt-qemu file and add the line below line into it in the section for “the various binaries”.

/usr/bin/kvm-nested rmix,

The one draw back to this method is you will need to manually edit each VM’s xml file to point to that new script /usr/bin/kvm-nested in this line.

<emulator>/usr/bin/kvm-nested</emulator>

The other way which I found more simple was deleting the current kvm symlink to qemu-system-x86_64 and pointing it to the script below.

jason@Desktop:~$ cat /usr/bin/kvm
#!/bin/bash
/usr/bin/qemu-system-x86_64 -enable-nesting "$@"
jason@Desktop:~$ ls -l /usr/bin/kvm
lrwxrwxrwx 1 root root 10 2011-01-21 19:13 /usr/bin/kvm -> /usr/bin/kvm-nested

That really should be it, now to keep testing to see if any issues arise.

7 thoughts on “KVM: Nested Virtualization Support

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>