User Tools

Site Tools



Check cpu for virtualization support

egrep 'vmx|svm' /proc/cpuinfo

Install (on Ubuntu 9.10)

sudo apt-get install kvm libvirt-bin virt-manager virt-viewer
sudo adduser $USER libvirtd 
# make sure current user is in libvirtd group. log out and back in if necessary

Creating a VM

With Ubuntu already installed

If you want to create an Ubuntu VM you can use a shortcut (found here: Install

sudo apt-get install ubuntu-vm-builder

and create, for example, a Lucid VM by typing:

sudo ubuntu-vm-builder kvm lucid --addpkg vim --addpkg openssh-server --addpkg man --mem 1024

Available hypervisors: esxi xen kvm vmw6 vmserver

Available OS suites: dapper gutsy hardy intrepid jaunty karmic

You can specify disk, swap and memory size, network settings (use the –help flag for more details).

Oh, and a tiny but important detail: default user and password on the new KVM: ubuntu/ubuntu You might want to add additional users, then remove the default user.

Lucid KVM, 64bit

sudo vmbuilder kvm ubuntu --arch=amd64 --suite=lucid --addpkg vim --addpkg openssh-server --addpkg man --mem 1024 --rootsize=2048

Trusty KVM, 64bit

There is currently a bug which causes KVM building to fail under trusty (14.04). It is easily fixed by explicitly adding the parameter “–addpkg linux-image-generic” to the command:

ubuntu-vm-builder kvm trusty --rootsize=5120 --addpkg vim --addpkg openssh-server --addpkg man --addpkg ntp --addpkg linux-image-generic --arch=amd64

Empty disk Images

qemu-img create -f raw disk.img 2G  # file format can be raw,qcow2,vmdk  etc.. 


The obvious way

* Create a tar.gz from your vmware image

tar xfvzS my_image.tar.gz  my_image.img 

Real Snapshots with rebasing

Note: For some reason this does not work with the virt-manager in Ubuntu 9.10 . Although it works fine when starting the image from the commandline using “kvm -hda my_image.qcow2”

* Create a base image. Raw images dont work, you need a qcow2 image for that. To convert raw to qcow2 use

kvm-img convert -c -f raw -O qcow2 my_image.img my_converted_image_base.qcow2 

* Create a new sliver

kvm-img create -f qcow2 -b current_image.qcow2 new_image.qcow2 

* Make the Virtual Machine start with new_image.qcow2 as disk


Mounting a KVM Image on the host

sudo modprobe nbd # load kernel module
sudo qemu-nbd -c /dev/nbd0 windows2003.img # connect image to device nbd0
sudo cfdisk -P s /dev/nbd0 # show partitions
sudo mount /dev/nbd0p1 /mnt/my_mountpoint # mount partition 1
#disconnect image
sudo umount /mnt/my_moutnpoint
sudo qemu-nbd -d /dev/nbd0

Passing an USB Device to the Guest

Written for Ubuntu 10.04 .

* First you need to reconfigure apparmor, so it allows read-write access to the hosts USB - Devices. This can be done by

vim /etc/apparmor.d/abstractions/libvirt-qemu
# Now find the  line: /sys/devices/*/*/usb[0-9]*/** r
# and replace it by: /sys/devices/*/*/usb[0-9]*/** rw   
# but be aware that this grants read/write access to the hosts usb devices. so be careful (or add a more specific rule if you want to)
sudo service apparmor reload  # reload apparmor

* Now open virt-manager –> Add Hardware –> Physical Host Device –> USB –> Select Device . Done.

Resizing a (system) disk

First turn off the VM and resize the disk image on the VM host

sudo qemu-img resize image.qcow2 +10G

Make sure virt-manager knows about the changed disk size: go to “Storage” and Refresh (not sure if really necessary, but cant hurt..)

Next boot the VM, log in and increase the size of the partition. This is done by deleting the old partition and re-creating it with the same start, but a larger size:

sudo fdisk /dev/vda
#sudo fdisk --compatibility=dos /dev/vda # in case you want to start at sector 63
# or on newer fdisk versions: 
#sudo fdisk -c=dos /dev/vda # in case you want to start at sector 63
p # print partition table and memorize start sector etc.
d # delete partition 1
n # new partition, primary, 1, start sector = same as sector from print , end sector = default -> maximum size)
w # write new partition table
sudo reboot # reboot immediately to make sure nothing bad happens..

Now you can resize the file system:

sudo resize2fs /dev/vda1 

Reclaim unused space

Convert qcow2 to VMWare

qemu-img convert -f qcow2 file.qcow2 -O vmdk file.vmdk


Windows install hangs at "Windows is starting up"

When the Windows Install asks you to hit F6 for additional drivers, you hit F5 instead. The install will give you the option to select Standard PC or other. Pick Standard PC and the install will continue.

Improving Disk Performance

WARNING: This seems to be no longer true for Ubuntu 10.04. At least I am not seeing any performance gain (quite the contrary).

One effective (but 'unsafe') way to improve disk-performance is to enable the writeback cache in the disk-driver:

sudo virsh stop guest_name
sudo virsh edit guest_name   # <-- add cache='writeback' in the driver section
sudo virsh start guest_name

The relevant part in the xml (in /etc/libvirt/qemu) should look like this:

<disk type='file' device='disk'>
    <driver name='qemu' type='qcow2' cache='writeback'/>
    <source file='/var/vms/vm2/ubuntu-kvm/tmphAUcOB.qcow2'/>
    <target dev='hda' bus='ide'/>

For details see

virtualisation.txt · Last modified: 2017/07/27 12:58 by hkoller