There are many products out there, for many different variety of use cases. In this post, I’m just going to write-up a mini How-To for virtualization on Ubuntu Linux, using KVM. This is all supposed to be so straight-forward, but sadly, it was far from a no-brainer. So I hope this little guide will be useful to some people.
This is written for Ubuntu 12.04. 12.10 should be just around the corner. But seeing that 12.04 is marked as LTS (long term support), it will probably stick around longer and many people are likely to stay with it.
Setting Up KVM In Ubuntu
First, get a root shell. Ubuntu, like Mac OS X, tries to hide root away from the regular user. But it’s easy to get back the root shell:
$ sudo -s
You’ll be prompted for your user password. Next, check that your system has hardware virtualization support.
$ egrep '(vmx|svm)' --color=always /proc/cpuinfo
Check that vmx or svm appears in the output.
Note: Despite vmx appearing in mine, the BIOS actually had virtualization disabled. Check your BIOS settings to ensure that it is indeed enabled. You’ll probably learn your BIOS might have disabled virtualization anyway when you later try to create a virtual machine and receive a warning about hardware virtualization not being available.
There are a few software packages you’ll need to install.
$ apt-get install ubuntu-virt-server virt-manager python-vm-builder kvm-ipxe bridge-utils
Now, check that kvm is really working by running this command:
$ virsh -c qemu:///system list
Make sure that there is no error from the above command.
The software installation above would have added your user account into the libvirtd group. That change will not be effected in your current login session. You need to logout and login again.
If you plan to run your virtualized guests in bridged networking mode, you’ll probably want to disable bridge firewall. Ubuntu enables it by default, and it does make things a little troublesome if you’re not prepared for it.
$ echo 0 > /proc/sys/net/bridge/bridge-nf-call-arptables $ echo 0 > /proc/sys/net/bridge/bridge-nf-call-ip6tables $ echo 0 > /proc/sys/net/bridge/bridge-nf-call-iptables
You should also be able to achieve the same thing by setting up /etc/sysctl.conf. For some reason, settings in /etc/sysctl.conf were not being applied in my system after a reboot. (I’m sure this is something that can be sorted out, but I haven’t had time to look into that.)
The GUI for the virtualization manager is called virt-manager. Or you can search for Virtual Machine Manager from the dashboard. In principle, virt-manager is not very different from others like VMware, so if you’re familiar with those, you should have no trouble figuring out virt-manager.
If you’ve created a guest and want it to run automatically whenever your system boots, you can add this into /etc/rc.local:
virsh start guest-name
Note that you can actually configure in the GUI to have the guest autostart too. But seeing that there are other bridging configuration (like the above, and more stuffs) that I needed to configure, and the order they get executed mattered, I decided to go with the rc.local approach.