Last week I was asked whether ESXi could run the KVM hypervisor as a Virtual Machine (often referred to as Nested Virtualization). I personally have not used KVM before or run it on top of ESXi, but I have heard of many folks successfully virtualizing KVM as a Virtual Machine on top of ESXi. I figure since I have already written several articles on Nesting VMware ESXi, Microsoft Hyper-V and Xen on top of ESXi, I might as well also take a look at KVM!

Disclaimer: Nested Virtualization is not supported by VMware, please use at your own risk.

As mentioned already, I have not used KVM before and one thing I wanted to understand before trying to run it as a Virtual Machine is what the difference is between Qemu and KVM as I have heard both these terms used in-conjunction before. I found this post to be quite helpful in helping me understand the differences between Qemu, KQemu and KVM. I recommend a read if you are new to Qemu or KVM like I am.

From the article above, we now see that you can run either Qemu as a standalone system or KVM which is an accelerator that runs on top of Qemu. With this, I will now demonstrate how you can run Qemu as well as KVM as Virtual Machine on top of ESXi. In the example below, I have selected the latest Ubuntu release (14.04.1) to run both Qemu and KVM.

To be able to run either Qemu or KVM on top of ESXi, you just need to create a Virtual Machine running Virtual Hardware 10 and enable the (VHV) Hardware Assisted Virtualization feature which available in the vSphere Web Client as seen in the screenshot below:

qemu-and-kvm-on-esxi-0
To validate that you have properly enable VHV, you run the following command:

egrep '(vmx|svm)' /proc/cpuinfo

You should see some output when running the command, else it was not properly enabled as seen in the screenshot below:

qemu-and-kvm-on-esxi-1
Another command you can also run to check if the VM has been properly configure is the following:

kvm-ok

You should also see a message stating that KVM acceleration is possible:

qemu-and-kvm-on-esxi-2
Installing/Running Qemu on Ubuntu VM

Step 1 - Install Qemu by running the following command:

sudo apt-get -y install qemu

Step 2 - Download and extract a simple Linux Qemu image by running the following two commands :

wget http://wiki.qemu.org/download/linux-0.2.img.bz2
bunzip2 linux-0.2.img.bz2

Note: You can also find other Qemu images here.

Step 3 - Launch the Linux image by running the following command:

qemu-system-x86_64 linux-0.2.img -curses

qemu-and-kvm-on-esxi-3

Installing/Running KVM on Ubuntu VM

Step 1 - Install KVM by running the following command:

sudo apt-get install qemu-kvm libvirt-bin

Step 2 - Install bridge networking components by running the following command:

sudo apt-get install bridge-utils

Step 3 - Add a bridge interface by running the following command:

sudo brctl addbr br0

Step 4 - Append the following configuration to /etc/networking/interfaces:

Step 5 - Restart the networking service by running the following command:

sudo /etc/init.d/networking restart

Step 6 - Next, we will need to create a VM which is based on an XML file. Here is what my VM definition looks like:

Step 7 - You will need to make some changes to the XML file such as the location of the Ubuntu ISO (which is required to boot the VM) as well as the lP Address of the VNC service for console access to VM and lastly the UUID identifier of the VM which can be generated by running 'uuid' command.

Step 8 - Before we can create our VM, we will need to create the Image file by running the following command:

qemu-img create -f qcow2 /home/lamw/alice.img 5G

Step 9 - We are now ready to initialize and boot up our VM by running the following command:

virsh --connect qemu:///system create alice.xml

Step 10 - We can get information about the VM we just created by running the following command:

virsh --connect qemu:///system dominfo alice

qemu-and-kvm-on-esxi-4
Step 11 - Lastly, we can connect to the VM console using a VNC client and if you modified the XML definition of the VM to listen on the public address of your Ubuntu host VM, then you should be able to see the installer of ISO bootup (in my case, it's Ubuntu Desktop Edition) as seen in the screenshot below:

qemu-and-kvm-on-esxi-5
Note: The instructions have been modified from this site here http://xmodulo.com/2014/02/use-kvm-command-line-debian-ubuntu.html There were a couple of errors that I ran into and hence re-writing

Additional Resources:

  • https://gmplib.org/~tege/qemu.html

 

3 thoughts on “How to run Qemu & KVM on ESXi?

  1. You can check virt-manager it’s a pretty simple (compared to VMware) GUI, but it can be handy. sudo apt-get install virt-manager

  2. Very helpful post! I was looking to get KVM support on my GNS3 VM after moving it to ESXi from VMware Workstation. Your configuration from the vsphere web client was spot on!

  3. Dear William,
    This blog was very informative one. I came across once thought of running ESXI over any other hypervisor.
    Is it currently support in vmware ?

    Regards,
    Atul

Thanks for the comment!