====== Workshop libVirt & KVM ====== * by Christian Pointner * workshop notes by Michael Prokop ===== Ressources ===== * [[http://www.libvirt.org/]] * man kvm ===== Software ===== Required software packages: apt-get install libvirt-bin qemu-kvm qemu-utils Graphical user interface: apt-get install virt-manager Kernel 2.6.32 and according libvirt highly recommended, e.g. Debian/squeeze and Debian/lenny with backports works fine. ===== ifaces example ===== # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # bridge for kvm auto eth0 iface eth0 inet manual auto vnet iface vnet inet dhcp bridge_ports eth0 ===== Simple demo setup with Grml ISO ===== cd /dev/shm wget http://download.grml.org/grml-small_2010.04.iso ISO=/dev/shm/grml-small_2010.04.iso cat > grml.xml << EOF grml-kvm 262144 262144 1 hvm destroy restart restart /usr/bin/kvm
` EOF sudo virsh [--connect qemu:///system] Inside virsh then define and start grml instance: virsh # define grml.xml virsh # start grml-kvm List VNC port: virsh # vncdisplay grml-kvm :0 List all defined instances: virsh # list --all Id Name State ---------------------------------- 14 grml-kvm running List assigned serial console: virsh # ttyconsole grml-kvm /dev/pts/8 Connect via serial console (choose the "Serial" boot menu entry under additional entries for "grml-small" in the bootsplash to automatically enable serial console): sudo -u libvirt-qemu cu -l /dev/pts/8 Connect via VNC: vncviewer localhost:5900 Possible falltraps while setup: * i686 vs. x86_64 as arch type * missing any defined block devices * missing bridge configuration as defined in config, example for /etc/network/interfaces see above Verify defined configuration: define $FOO dumpxml $FOO Autostart setup: autostart $HOST net-auostart default net-autostart --disable default autostart --disable $HOST Ballooning: setmem $HOST 256000 <= -> but can be overriden via setmaxmem Overbooking of CPU: 16 Tip: Disable caching in the virtualised instance so just the internal system (the system running inside the virtual machine) uses the caches (add this line inside every ... environment): "" ===== Serial console access (guest) ===== Adjust Grub2 configuration /etc/default/grub: GRUB_CMDLINE_LINUX="console=ttyS0,115200n8" GRUB_SERIAL_COMMAND="serial --speed=1152200 --unit=0 --word=8 --parity=no --stop=1" Adjust /etc/inittab for serial console access: T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100 ==== Tips ==== Convert file config in the native guest configuration format named by format to a domain XML format: virsh [--connect qemu:///system domxml-to-native] domxml-to-native qemu-argv /dev/shm/grml.xml virsh like console access to kvm/qemu: kvm [...] -monitor stdio Block device: qemu-img create -f qcow2 block.img 1G ---- {{tag>workshop}}