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 21:04] – xro | workshop:libvirt_kvm [2025-11-09 09:25] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Workshop | + | ====== Workshop libVirt & KVM ====== |
| - | gehalten von Christian Pointner | + | |
| - | ===== libvirt example ===== | + | * by Christian Pointner |
| + | * workshop notes by Michael Prokop | ||
| + | |||
| + | ===== Ressources ===== | ||
| + | |||
| + | * [[http:// | ||
| + | * 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, | ||
| + | |||
| + | ===== ifaces | ||
| + | < | ||
| + | # This file describes the network interfaces available on your system | ||
| + | # and how to activate them. For more information, | ||
| + | |||
| + | # 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 ===== | ||
| < | < | ||
| - | <domain type=' | + | cd /dev/shm |
| - | < | + | wget http:// |
| - | < | + | ISO=/ |
| + | cat > grml.xml << EOF | ||
| + | <domain type=' | ||
| + | < | ||
| < | < | ||
| < | < | ||
| < | < | ||
| <os> | <os> | ||
| - | <type arch='i686' machine=' | + | <type arch='x86_64' machine=' |
| <boot dev=' | <boot dev=' | ||
| </os> | </os> | ||
| Line 25: | Line 70: | ||
| < | < | ||
| < | < | ||
| - | | + | <disk type=' |
| - | <driver cache=' | + | |
| - | <source dev='/ | + | |
| - | <target dev=' | + | |
| - | <alias name=' | + | |
| - | <address type=' | + | |
| - | </ | + | |
| - | | + | |
| <driver name=' | <driver name=' | ||
| - | <source file='/ | + | <source file='/ |
| <target dev=' | <target dev=' | ||
| < | < | ||
| Line 42: | Line 80: | ||
| < | < | ||
| <alias name=' | <alias name=' | ||
| - | <address type=' | ||
| </ | </ | ||
| < | < | ||
| - | | + | <source bridge=' |
| - | | + | |
| - | <target dev=' | + | |
| <model type=' | <model type=' | ||
| <alias name=' | <alias name=' | ||
| - | <address type=' | ||
| </ | </ | ||
| <serial type=' | <serial type=' | ||
| <source path='/ | <source path='/ | ||
| <target port=' | <target port=' | ||
| - | <alias name=' | + | <alias name=' |
| </ | </ | ||
| - | <console type=' | + | <console type=' |
| - | <source path='/ | + | |
| - | <target port=' | + | |
| - | <alias name=' | + | |
| </ | </ | ||
| <input type=' | <input type=' | ||
| - | < | + | < |
| - | < | + | |
| - | <model type=' | + | |
| - | <alias name=' | + | |
| - | <address type=' | + | |
| - | </video> | + | |
| </ | </ | ||
| </ | </ | ||
| + | EOF | ||
| </ | </ | ||
| - | ===== ifaces example ===== | ||
| < | < | ||
| - | # This file describes the network interfaces available on your system | + | sudo virsh [--connect qemu:///system] |
| - | # and how to activate them. For more information, | + | </ |
| - | # The loopback network interface | + | Inside virsh then define and start grml instance: |
| - | auto lo | + | |
| - | iface lo inet loopback | + | |
| - | # The primary network interface | + | < |
| - | # bridge for kvm | + | virsh # define grml.xml |
| - | auto eth0 | + | virsh # start grml-kvm |
| - | iface eth0 inet manual | + | </ |
| - | auto lan | + | List VNC port: |
| - | iface lan inet dhcp | + | |
| - | | + | < |
| + | virsh # vncdisplay grml-kvm | ||
| + | :0 | ||
| </ | </ | ||
| - | ===== grub2 example ===== | + | List all defined instances: |
| < | < | ||
| - | GRUB_CMDLINE_LINUX_DEFAULT=" | + | virsh # list --all |
| - | GRUB_CMDLINE_LINUX=" | + | Id Name |
| + | ---------------------------------- | ||
| + | 14 grml-kvm | ||
| + | </ | ||
| - | # Uncomment | + | List assigned serial console: |
| - | # | + | |
| - | GRUB_TERMINAL=serial | + | < |
| - | GRUB_SERIAL_COMMAND=" | + | virsh # ttyconsole grml-kvm |
| + | / | ||
| + | </ | ||
| + | |||
| + | Connect via serial console (choose the " | ||
| + | |||
| + | < | ||
| + | sudo -u libvirt-qemu cu -l / | ||
| + | </ | ||
| + | |||
| + | Connect via VNC: | ||
| + | |||
| + | < | ||
| + | vncviewer localhost: | ||
| + | </ | ||
| + | |||
| + | 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 / | ||
| + | |||
| + | Verify defined configuration: | ||
| + | |||
| + | < | ||
| + | define $FOO | ||
| + | dumpxml $FOO | ||
| + | </ | ||
| + | |||
| + | Autostart setup: | ||
| + | |||
| + | < | ||
| + | autostart $HOST | ||
| + | net-auostart default | ||
| + | net-autostart --disable | ||
| + | autostart | ||
| + | </ | ||
| + | |||
| + | Ballooning: | ||
| + | |||
| + | < | ||
| + | setmem $HOST 256000 | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Overbooking of CPU: | ||
| + | |||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | 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 < | ||
| + | |||
| + | < | ||
| + | "< | ||
| + | </ | ||
| + | |||
| + | ===== Serial | ||
| + | |||
| + | Adjust Grub2 configuration / | ||
| + | |||
| + | < | ||
| + | GRUB_CMDLINE_LINUX=" | ||
| + | GRUB_SERIAL_COMMAND=" | ||
| + | </ | ||
| + | |||
| + | Adjust / | ||
| + | |||
| + | < | ||
| + | T0: | ||
| + | </ | ||
| + | |||
| + | ==== Tips ==== | ||
| + | |||
| + | Convert file config in the native guest configuration format named by format to a domain XML format: | ||
| + | |||
| + | < | ||
| + | virsh [--connect qemu:/// | ||
| + | </ | ||
| + | |||
| + | virsh like console access to kvm/qemu: | ||
| + | |||
| + | < | ||
| + | kvm [...] -monitor stdio | ||
| + | </ | ||
| + | |||
| + | Block device: | ||
| + | |||
| + | < | ||
| + | qemu-img create -f qcow2 block.img 1G | ||
| + | |||
| + | <disk type=' | ||
| + | <driver cache=' | ||
| + | <source dev='/ | ||
| + | <target dev=' | ||
| + | <alias name=' | ||
| + | </ | ||
| </ | </ | ||
| ---- | ---- | ||
| + | |||
| {{tag> | {{tag> | ||