KVM Installation
From SemanticLab
Contents |
Installation using libvirt (recommended)
This manual covers the installation of kvm using libvirt under Ubuntu (Lucid).
Terminology:
- KVM Host - corresponds to VMware's dom0 (the host which will hold the guest machines)
- Guest - a virtual machine which resides on the KVM Host
- Management Workstation - the workstation from which you manage your KVM hosts and guests.
KVM Host
- install libvirt and the bridge-utils on the kvm host:
aptitiude install libvirt-bin bridge-utils - modify
/etc/network/interfacesto support bridging (see the example below; replace your ethX interface with brX and add the bridge parameters
The loopback network interface auto lo iface lo inet loopback # The primary network interface auto br0 iface br0 inet static address 137.208.30.31 netmask 255.255.255.0 network 137.208.30.0 gateway 137.208.30.1 bridge_ports eth0 bridge_stp off bridge_maxwait 5 dns-nameservers 137.208.3.3 137.208.8.3 dns-search wu.ac.at
Management Workstation
- install virt-manager on your workstation:
aptitude install virt-manager - start virt-manager and add your kvm host to the manager
- File -> Add Connection -> QEMU/KVM -> Connection: Remote tunnel over SSH
- create a new virtual machine on that host:
- select your kvm host and choose the item "New" in the host's context menu and complete the installation wizard.
Networking
- the version of virt-manager which comes with Ubuntu (Lucid) does not support bridged networking. You have to edit the guest's configuration using virsh to enable bridging. Enter
virsh edit guestnameand modify the network interface section as follows:
<interface type='bridge'> <mac address='your-mac-address'/> <source bridge='br0'/> <target dev='vnet1'/> <model type='virtio'/> </interface>
Replace your-mac-address with the mac address you want to assign to the guest.
Performance Considerations
- ensure that you use paravirtualized disk and network devices:
- open the host and select its info tab
- ensure that all disks are Virtual Disks (otherwise remove the disks and re-add them as Storage -> Virtio Disk)
- use paravirtualized network devices (interface type virtio).
Manual KVM Installation
This section outlines the steps necessary to install a kvm instance. This howto covers the use of kvm and migration from xen as used in the IDIOM project. Therefore, some of these instruction might be too specific for the general audience.
Prepare the host system
- Install an up-to-date kernel (>=2.6.26) with kvm and virtio support.
- add the following virtio drivers to /etc/intitramfs-tools/modules and call update-initramfs -k all -u afterwards.
virtio virtio_pci virtio_ring virtio_net virtio_blk
- Enable bridging at the host machine (Howto):
- If you plan to install the guest OS on a logical volume of the hosts LVM, ensure to format the LV in advance: So the OS installer won't detect it as a raw harddrive and tries create new partitions on it!!!!!!!!!!
Option 1: Install the guests operation system
- Install the operating system on the harddisk (virtio aware distribution)
kvm -drive file=/dev/vg_sol2/xmtokay3_root,if=virtio -m 512 \
-net nic,vlan=0,model=virtio,macaddr={mac-address} \
-net tap,vlan=0,script=/etc/kvm/kvm-ifup -cdrom /root/debian-501-i386-netinst.iso \
-boot d -vnc 127.0.0.1:7
- Install the operating system using debootstrap (virtio aware)
a) Create a LVM volume, format it, and install debian.
lvcreate -L 5G -n xmgila2_root vg_root mkfs.ext3 /dev/mapper/vg_root-xmgila2_root mount /dev/mapper/vg_root-xmgila2_root /media/ debootstrap lenny /media/ http://ftp.at.debian.org/debian/
b) Edit the guest's /etc/fstab
# /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/vda / ext3 errors=remount-ro 0 1
c) Unmount the guest filesystem and start kvm using the host's kernel.
kvm -drive file=/dev/mapper/vg_root-xmgila2_root,if=virtio,boot=on \
-net nic,vlan=0,model=virtio,macaddr=00:16:3E:39:33:7D -net tap,vlan=0 \
-kernel /vmlinuz -initrd /initrd.img -append "root=/dev/vda ro" \
-daemonize \
-vnc localhost:0
Option 2: Move a Xen-Instance to KVM
- shutdown the xen instance
- boot the instance using the kernel at the host machine
kvm -drive file=/dev/mapper/{volume_name},if=virtio,boot=on -m 512 \
-net nic,vlan=0,model=virtio,macaddr={mac-address} -net tap,vlan=0 \
-kernel /vmlinuz -initrd /initrd.img -append "root=/dev/vda ro"
- edit fstab and remove paths to linux-lvm-volumes with /dev/vdX'.
- restart the system - finished :)

