How to KVM
Advantages of KVM
1. Open source solution, enough said.
2. Supports 64 bit hosts / guests as well as multiple CPU (I have used 8 virtual CPU without any issue). In general you want to use a max number of virtual CPU = to the number of physical CPU.
3. IMO, KVM is faster then VMWare and Virtual box, although this is obviously a subjective opinion and I kave no hard objective data to back that claim, your experience may vary.
Disadvantages of KVM
Perhaps the biggest disadvantage is that the the GUI interface (virt-manager) is not as polished. Personally I use KVM on the command line and write a "simple" script (with all the options) to launch a machine. It takes a little more time,
Home page : http://virt-manager.et.redhat.com/
Screen shots : http://virt-manager.et.redhat.com/screenshots.html
1. What is KVM ? "Kernel Based Virtual Machine".2. Will my hardware support KVM ?
To test this open a terminal and enter :
If you see vmx or svm in the output your hardware (CPU) will support KVM. If you get no output with that command you are out of luck.
egrep --color=auto '(vmx|svm)' /proc/cpuinfo
You may need to enable KVM in your BIOS. I have had to do this on my hardware. Unfortunately it is not always obvious how to do this, you may need to use google, read any manual you may have, or like I did, hunt through your BIOS.
How to install KVM
Alternately, you may install from source :
sudo apt-get install kvm qemu bridge-utils uml-utilities
~ Thanks redbrain
You can then either re-boot or :
Then add your user to the kvm group. You may either user the gui or :
where "<user>" is the user you wish to add to kvm. You will need to log out and back in for the group membership to take effect.
sudo usermod -G kvm -a <user>
Make a virtual hard drive
Other options include "raw", see man qemu-img for options.
qemu-img create -f qcow2 /home/user/Ubuntu.img 5G
/sbin/mkfs.ext3 -F /home/user/Ubuntu.img
Use a physical partition
Physical partitions are very easy in KVM. Let us assume you wish to use /dev/sda2 for example :
Not start kvm using the physical partition:
sudo chown root.kvm /dev/sda2
How to bridge your network card
kvm -hda /dev/sda2 ...
First bring down your network:
Next, using any editor (gksu gedit) edit /etc/network/interfaces to add a bridge. You may use either static or dhcp :
sudo /etc/init.d/networking stop
iface lo inet loopback
iface eth0 inet manual
iface br0 inet static
iface lo inet loopback
iface eth0 inet manual
iface br0 inet dhcp
- change "eth0" to your network card.
- This will not work with wireless.
- If you are using a firewall on the host, you may have problems. I find Firestarter (which is a GUI front end) will often break with complex networking.
Now bring your network back up:
Wrapper script for bridged network connections on KVM
sudo /etc/init.d/networking start
Use a wrapper script to automatically bring up a tap when you start a new virtual machine.
Save this script in /usr/bin/kvm-bridge
Set ownership and permissions:
# script to manage tap interface allocation
# for linux kernels >= 2.6.18
# modified by bodhi.zazen from :
# set up a tap interface for qemu
# USERID - uid qemu is being run under.
# generate a random mac address for the qemu nic
# shell script borrowed from user pheldens @ qemu forum
ranmac=$(echo -n DE:AD:BE:EF ; for i in `seq 1 2` ; \
do echo -n `echo ":$RANDOM$RANDOM" | cut -n -c -3` ;done)
# specify which NIC to use - see qemu.org for others
# Set model based on this how-to
iface=`sudo tunctl -b -u $USERID`
# start kvm with our parameters
# echo "Bringing up interface $iface with mac address $ranmac"
# nohup added to allow kvm to run independent of the terminal
nohup kvm -net nic,vlan=0,macaddr=$ranmac -net tap,vlan=0,ifname=$iface $@
# kvm has stopped - no longer using tap interface
sudo tunctl -d $iface &> /dev/null
Usage : Use kvm-bridge in place of kvm, for example ;
sudo chown root.kvm /usr/bn/kvm-bridge
sudo chmod 550 /usr/bin/kvm-bridge
kvm-bridge -cdrom /dev/scd0 -m 512
The KVM console allow you to modify your machine as it is running. To get to the console, place your mouse in the KVM screen and hit "ctrl-alt-2".
To see your options type help. You can also use help <command>
Useful commands include :
sendkey ctrl-alt-f1 => changes to the console in the virtual machine.
sendkey ctrl-alt-f7 => changes back to the normal GUI interface in the virtual machine.
ctrl-alt-1 => returns to the KVM interface.
IMO at this time KVM is best run from the command line. Also, IMO the best soruce of inforation on KVM is "man qemu" (the qemu options all work with kvm).
Useful options include :
-snapshot = run kvm without making changes to your (virtual) hard disk.
-M = Allows you to select a machine (cup) to emulate.
-smp = sets number of CPU.
-m = sets amount or RAM for the virtual machine.
-hda , -hdb, -cdrom = sets hard drive and / or cdrom, you may use a physical partition, hard drive, cdrom, DVD, or a file (Ubuntu.img, ubuntu-desktop.iso) and (I assume) USB devices.
-boot = sets which device to boot from.
-soundhw = set sound card.
-win2k-hack = used with windows 2000 guests.
-std-vga = may increase the resolution of your guests, primarily used by windows guests.
-name = sets a name to your guest.
-nographic, -fullscreen = additional graphic options.
-vnc = start the built in VNC server rather then the standard display. Useful if running kvm without X.
-daemonize = kvm runs detached from your terminal.
-usb = enable usb driver.
-usbdevice = use for usb mouse / tablet etc (on the host).
-tftp , -smb = use built in ftp and samba servers.
-no-apci = Disable ACPI.
-g = set display resolution (see man qemu for details).
Other options : See https://help.ubuntu.com/community/KVM
GUI options. use virt-manager. IMO virt-manager has come a long way, but not all options are available on the GUI interface.
Peace be with you,