Show pageDiscussionOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Workshop libVirt & KVM ====== * by Christian Pointner * workshop notes by Michael Prokop ===== Ressources ===== * [[http://www.libvirt.org/]] * man kvm ===== Software ===== Required software packages: <file> apt-get install libvirt-bin qemu-kvm qemu-utils </file> Graphical user interface: <file> apt-get install virt-manager </file> Kernel 2.6.32 and according libvirt highly recommended, e.g. Debian/squeeze and Debian/lenny with backports works fine. ===== ifaces example ===== <file> # 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 </file> ===== Simple demo setup with Grml ISO ===== <file> 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 <domain type='kvm'> <name>grml-kvm</name> <memory>262144</memory> <currentMemory>262144</currentMemory> <vcpu>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='cdrom'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='cdrom'> <driver name='qemu'/> <source file='/grml/isos/grml-small_2010.04.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <alias name='ide0-1-0'/> <address type='drive' controller='0' bus='1' unit='0'/> </disk> <controller type='ide' index='0'> <alias name='ide0'/> </controller> <interface type='bridge'> <source bridge='vnet'/> <model type='virtio'/> <alias name='net0'/> </interface> <serial type='pty'> <source path='/dev/pts/9'/> <target port='0'/> <alias name='serial0'/>` </serial> <console type='pty'> </console> <input type='mouse' bus='ps2'/> <graphics type='vnc' autoport='yes'/> </devices> </domain> EOF </file> <file> sudo virsh [--connect qemu:///system] </file> Inside virsh then define and start grml instance: <file> virsh # define grml.xml virsh # start grml-kvm </file> List VNC port: <file> virsh # vncdisplay grml-kvm :0 </file> List all defined instances: <file> virsh # list --all Id Name State ---------------------------------- 14 grml-kvm running </file> List assigned serial console: <file> virsh # ttyconsole grml-kvm /dev/pts/8 </file> Connect via serial console (choose the "Serial" boot menu entry under additional entries for "grml-small" in the bootsplash to automatically enable serial console): <file> sudo -u libvirt-qemu cu -l /dev/pts/8 </file> Connect via VNC: <file> vncviewer localhost:5900 </file> 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: <file> define $FOO dumpxml $FOO </file> Autostart setup: <file> autostart $HOST net-auostart default net-autostart --disable default autostart --disable $HOST </file> Ballooning: <file> setmem $HOST 256000 <currentMemory> <= <memory> -> but can be overriden via setmaxmem </file> Overbooking of CPU: <file> <vcpu>16</vcpu> </file> 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 <disk> ... </disk> environment): <file> "<driver cache='none'/>" </file> ===== Serial console access (guest) ===== Adjust Grub2 configuration /etc/default/grub: <file> GRUB_CMDLINE_LINUX="console=ttyS0,115200n8" GRUB_SERIAL_COMMAND="serial --speed=1152200 --unit=0 --word=8 --parity=no --stop=1" </file> Adjust /etc/inittab for serial console access: <file> T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100 </file> ==== Tips ==== Convert file config in the native guest configuration format named by format to a domain XML format: <file> virsh [--connect qemu:///system domxml-to-native] domxml-to-native qemu-argv /dev/shm/grml.xml </file> virsh like console access to kvm/qemu: <file> kvm [...] -monitor stdio </file> Block device: <file> qemu-img create -f qcow2 block.img 1G <disk type='block' device='disk'> <driver cache='none'/> <source dev='/dev/shm/block.img'/> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> </disk> </file> ---- {{tag>workshop}} /srv/dokuwiki/data/pages/workshop/libvirt_kvm.txt Last modified: 2025-11-09 09:25by 127.0.0.1