Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
workshop:libvirt_kvm [2010-06-22 23:09] xro |
workshop:libvirt_kvm [2015-09-16 12:41] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Workshop zu libVirt & KVM ====== | + | ====== Workshop libVirt & KVM ====== |
| - | gehalten von Christian Pointner | + | |
| - | ===== tipps ===== | + | * by Christian Pointner |
| - | * [[http://www.libvirt.org]] | + | * workshop notes by Michael Prokop |
| + | |||
| + | ===== Ressources ===== | ||
| + | |||
| + | * [[http://www.libvirt.org/]] | ||
| * man kvm | * man kvm | ||
| - | ===== libvirt example ===== | + | ===== 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> | <file> | ||
| - | <domain type='kvm' id='7'> | + | cd /dev/shm |
| - | <name>kvm-vnc</name> | + | wget http://download.grml.org/grml-small_2010.04.iso |
| - | <uuid>c4809964-9be7-4d66-2957-3a88743e2ac6</uuid> | + | ISO=/dev/shm/grml-small_2010.04.iso |
| + | cat > grml.xml << EOF | ||
| + | <domain type='kvm'> | ||
| + | <name>grml-kvm</name> | ||
| <memory>262144</memory> | <memory>262144</memory> | ||
| <currentMemory>262144</currentMemory> | <currentMemory>262144</currentMemory> | ||
| <vcpu>1</vcpu> | <vcpu>1</vcpu> | ||
| <os> | <os> | ||
| - | <type arch='i686' machine='pc-0.12'>hvm</type> | + | <type arch='x86_64' machine='pc'>hvm</type> |
| <boot dev='cdrom'/> | <boot dev='cdrom'/> | ||
| </os> | </os> | ||
| Line 30: | Line 70: | ||
| <devices> | <devices> | ||
| <emulator>/usr/bin/kvm</emulator> | <emulator>/usr/bin/kvm</emulator> | ||
| - | <disk type='block' device='disk'> | + | <disk type='file' device='cdrom'> |
| - | <driver cache='none'/> | + | |
| - | <source dev='/home/equinox/Desktop/disks/kvm-graphic.img'/> | + | |
| - | <target dev='vda' bus='virtio'/> | + | |
| - | <alias name='virtio-disk0'/> | + | |
| - | <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> | + | |
| - | </disk> | + | |
| - | <disk type='file' device='cdrom'> | + | |
| <driver name='qemu'/> | <driver name='qemu'/> | ||
| - | <source file='/home/equinox/Downloads/grml-small_2010.04.iso'/> | + | <source file='/grml/isos/grml-small_2010.04.iso'/> |
| <target dev='hdc' bus='ide'/> | <target dev='hdc' bus='ide'/> | ||
| <readonly/> | <readonly/> | ||
| Line 47: | Line 80: | ||
| <controller type='ide' index='0'> | <controller type='ide' index='0'> | ||
| <alias name='ide0'/> | <alias name='ide0'/> | ||
| - | <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> | ||
| </controller> | </controller> | ||
| <interface type='bridge'> | <interface type='bridge'> | ||
| - | <mac address='52:54:00:64:ab:1d'/> | + | <source bridge='vnet'/> |
| - | <source bridge='lan'/> | + | |
| - | <target dev='vnet1'/> | + | |
| <model type='virtio'/> | <model type='virtio'/> | ||
| <alias name='net0'/> | <alias name='net0'/> | ||
| - | <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> | ||
| </interface> | </interface> | ||
| <serial type='pty'> | <serial type='pty'> | ||
| <source path='/dev/pts/9'/> | <source path='/dev/pts/9'/> | ||
| <target port='0'/> | <target port='0'/> | ||
| - | <alias name='serial0'/> | + | <alias name='serial0'/>` |
| </serial> | </serial> | ||
| - | <console type='pty' tty='/dev/pts/9'> | + | <console type='pty'> |
| - | <source path='/dev/pts/9'/> | + | |
| - | <target port='0'/> | + | |
| - | <alias name='serial0'/> | + | |
| </console> | </console> | ||
| <input type='mouse' bus='ps2'/> | <input type='mouse' bus='ps2'/> | ||
| - | <graphics type='vnc' port='5904' autoport='no'/> | + | <graphics type='vnc' autoport='yes'/> |
| - | <video> | + | |
| - | <model type='cirrus' vram='9216' heads='1'/> | + | |
| - | <alias name='video0'/> | + | |
| - | <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> | + | |
| - | </video> | + | |
| </devices> | </devices> | ||
| </domain> | </domain> | ||
| + | EOF | ||
| </file> | </file> | ||
| - | ===== ifaces example ===== | ||
| <file> | <file> | ||
| - | # This file describes the network interfaces available on your system | + | sudo virsh [--connect qemu:///system] |
| - | # and how to activate them. For more information, see interfaces(5). | + | </file> |
| - | # The loopback network interface | + | Inside virsh then define and start grml instance: |
| - | auto lo | + | |
| - | iface lo inet loopback | + | |
| - | # The primary network interface | + | <file> |
| - | # bridge for kvm | + | virsh # define grml.xml |
| - | auto eth0 | + | virsh # start grml-kvm |
| - | iface eth0 inet manual | + | </file> |
| - | auto lan | + | List VNC port: |
| - | iface lan inet dhcp | + | |
| - | bridge_ports eth0 | + | <file> |
| + | virsh # vncdisplay grml-kvm | ||
| + | :0 | ||
| </file> | </file> | ||
| - | ===== grub2 example ===== | + | List all defined instances: |
| <file> | <file> | ||
| - | GRUB_CMDLINE_LINUX_DEFAULT="quiet" | + | virsh # list --all |
| - | GRUB_CMDLINE_LINUX="quiet console=ttyS0,115200n8" | + | Id Name State |
| + | ---------------------------------- | ||
| + | 14 grml-kvm running | ||
| + | </file> | ||
| - | # Uncomment to disable graphical terminal (grub-pc only) | + | List assigned serial console: |
| - | #GRUB_TERMINAL=console | + | |
| - | GRUB_TERMINAL=serial | + | <file> |
| - | GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1" | + | 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> | </file> | ||
| ---- | ---- | ||
| + | |||
| {{tag>workshop}} | {{tag>workshop}} | ||
realraum Graz, Brockmanngasse 15, 8010 Graz, realraum - Verein für Technik in Kultur und Gesellschaft