Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| kvm [2019/02/09 09:39] – [Table] admin | kvm [2021/02/14 09:36] (current) – [Edit networks] dani | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== KVM manual ====== | ====== KVM manual ====== | ||
| - | |||
| - | |||
| - | |||
| - | |||
| ===== General ===== | ===== General ===== | ||
| This document shows and describes the most important commands for a KVM environment. | This document shows and describes the most important commands for a KVM environment. | ||
| - | |||
| - | |||
| - | |||
| ===== Host setup ===== | ===== Host setup ===== | ||
| Before you can start with any virtual machine, you have to install the following packages first: | Before you can start with any virtual machine, you have to install the following packages first: | ||
| - | |||
| - | |||
| <code bash> | <code bash> | ||
| dnf -y install virt-install libvirt-daemon-kvm qemu-kvm libvirt-client qemu libvirt-daemon | dnf -y install virt-install libvirt-daemon-kvm qemu-kvm libvirt-client qemu libvirt-daemon | ||
| </ | </ | ||
| - | |||
| It’s not a bad idea, to check, if your host system is virtualisation capable. | It’s not a bad idea, to check, if your host system is virtualisation capable. | ||
| - | |||
| - | |||
| <code bash> | <code bash> | ||
| Line 68: | Line 56: | ||
| LXC: Checking for cgroup ' | LXC: Checking for cgroup ' | ||
| </ | </ | ||
| - | |||
| | **Note: | | **Note: | ||
| - | |||
| ==== Test installation tree ==== | ==== Test installation tree ==== | ||
| - | |||
| <code bash> | <code bash> | ||
| Line 80: | Line 65: | ||
| curl -O http:// | curl -O http:// | ||
| </ | </ | ||
| - | |||
| - | |||
| - | |||
| - | |||
| ===== Environment ===== | ===== Environment ===== | ||
| - | |||
| <code bash> | <code bash> | ||
| virsh dumpxml <domain name> > < | virsh dumpxml <domain name> > < | ||
| </ | </ | ||
| - | |||
| - | |||
| <code bash> | <code bash> | ||
| virsh create < | virsh create < | ||
| </ | </ | ||
| - | |||
| - | |||
| - | |||
| ===== Basic commands ===== | ===== Basic commands ===== | ||
| - | + | * Completely delete a VM:<code bash> | |
| - | + | ||
| - | <code bash> | + | |
| virsh --connect qemu:/// | virsh --connect qemu:/// | ||
| virsh --connect qemu:/// | virsh --connect qemu:/// | ||
| - | </ | + | </ |
| - | + | * Unordered List ItemEdit/ | |
| - | + | ||
| - | | **Note: | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh edit <domain name> | virsh edit <domain name> | ||
| </ | </ | ||
| - | + | * Unordered List ItemList all (also not started VM's):<code bash> | |
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh --connect qemu:/// | virsh --connect qemu:/// | ||
| | | ||
| Line 128: | Line 92: | ||
| | | ||
| </ | </ | ||
| - | + | * Start a console session for a VM:<code bash> | |
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh --connect qemu:/// | virsh --connect qemu:/// | ||
| + | </ | ||
| + | * Setup autostart (when booting the KVM server) for a VM:<code bash> | ||
| + | virsh --connect qemu:/// | ||
| </ | </ | ||
| - | + | | **Note: | |
| ===== Installation of VM’s ===== | ===== Installation of VM’s ===== | ||
| If you want to add a second network interface, you should add it after the '' | If you want to add a second network interface, you should add it after the '' | ||
| - | |||
| ==== Fedora ==== | ==== Fedora ==== | ||
| In this example the new virtual machine or domain (fedora27) will be installed using kickstart. Following features are given: | In this example the new virtual machine or domain (fedora27) will be installed using kickstart. Following features are given: | ||
| - | |||
| * The disk is a logical volume ('' | * The disk is a logical volume ('' | ||
| Line 152: | Line 113: | ||
| * The VM has two network interfaces, one for internal guest/host comunication (the default network), and one for external connections via '' | * The VM has two network interfaces, one for internal guest/host comunication (the default network), and one for external connections via '' | ||
| * The installation tree lifes on a webserver ( http:// | * The installation tree lifes on a webserver ( http:// | ||
| - | |||
| - | |||
| <code bash> | <code bash> | ||
| Line 165: | Line 124: | ||
| virsh --connect qemu:/// | virsh --connect qemu:/// | ||
| </ | </ | ||
| - | |||
| | **Note: | | **Note: | ||
| - | + | | **Info: | |
| - | ||If you want to configure a fix MAC address, use '' | + | |
| - | + | ||
| ==== Centos ==== | ==== Centos ==== | ||
| - | |||
| In this example the new virtual machine or domain (centos7) will be installed using kickstart. Following features are given: | In this example the new virtual machine or domain (centos7) will be installed using kickstart. Following features are given: | ||
| - | |||
| * The disk is a logical volume ('' | * The disk is a logical volume ('' | ||
| Line 183: | Line 136: | ||
| * The VM has one network interfaces for internal guest/host comunication (the default network) only | * The VM has one network interfaces for internal guest/host comunication (the default network) only | ||
| * The installation tree lifes on a webserver ( http:// | * The installation tree lifes on a webserver ( http:// | ||
| - | |||
| - | |||
| <code bash> | <code bash> | ||
| Line 195: | Line 146: | ||
| virsh --connect qemu:/// | virsh --connect qemu:/// | ||
| </ | </ | ||
| - | |||
| - | |||
| - | |||
| - | |||
| ===== Networking ===== | ===== Networking ===== | ||
| - | + | * List all networks:<code bash> | |
| - | + | ||
| - | <code bash> | + | |
| virsh net-list --all | virsh net-list --all | ||
| </ | </ | ||
| - | + | * Attach a network interface to a virtual machine (domain):<code bash> | |
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh attach-interface --domain <vm name> --type bridge --source virbr0 --model virtio --config --live | virsh attach-interface --domain <vm name> --type bridge --source virbr0 --model virtio --config --live | ||
| - | </ | + | </ |
| - | + | ||
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh attach-interface --domain <vm name> --type direct --source enp0s31f6 --model virtio --config --live | virsh attach-interface --domain <vm name> --type direct --source enp0s31f6 --model virtio --config --live | ||
| </ | </ | ||
| + | | **Note: | ||
| - | ||The '' | + | * Unordered List ItemIf |
| - | + | ||
| - | + | ||
| - | If you want to figure out the IP addresss of one or more VM’s, you can use the following command executed on the KVM host. | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| vm=fedora27 | vm=fedora27 | ||
| for mac in `virsh domiflist $vm |grep -o -E " | for mac in `virsh domiflist $vm |grep -o -E " | ||
| Line 233: | Line 165: | ||
| done | done | ||
| </ | </ | ||
| - | |||
| ==== Edit networks ==== | ==== Edit networks ==== | ||
| - | The '' | + | * Unordered List ItemThe |
| - | + | ||
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh net-edit default | virsh net-edit default | ||
| </ | </ | ||
| - | + | * Show the network configuration of a network (here '' | |
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh net-dumpxml default | virsh net-dumpxml default | ||
| - | </ | + | </ |
| - | + | ||
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| < | < | ||
| < | < | ||
| Line 264: | Line 184: | ||
| <bridge name=' | <bridge name=' | ||
| <mac address=' | <mac address=' | ||
| - | <ip address=' | + | <ip address=' |
| < | < | ||
| - | <range start=' | + | <range start=' |
| - | <host mac=' | + | <host mac=' |
| - | <host mac=' | + | <host mac=' |
| - | <host mac=' | + | <host mac=' |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| - | <host mac=' | + | |
| </ | </ | ||
| </ip> | </ip> | ||
| </ | </ | ||
| </ | </ | ||
| - | |||
| |**1**|Network IP and netmask | |**1**|Network IP and netmask | ||
| |**2**|Define a fix IP address for a given MAC address| | |**2**|Define a fix IP address for a given MAC address| | ||
| - | + | * Unordered List ItemAfter | |
| - | After changing anything, you must activate the changed configuration, | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | <code bash> | + | |
| virsh net-destroy default && virsh net-start default | virsh net-destroy default && virsh net-start default | ||
| </ | </ | ||
| - | + | * Delete a vm (host) in a network (here '' | |
| - | + | virsh net-update default delete ip-dhcp-host "< | |
| - | + | </ | |
| - | <code bash> | + | * Add a network configuration (host) live:< |
| - | virsh net-update default delete ip-dhcp-host "< | + | virsh net-update default add ip-dhcp-host "< |
| </ | </ | ||
| - | |||
| - | |||
| - | |||
| - | |||
| ===== Harddisks ===== | ===== Harddisks ===== | ||
| Line 314: | Line 212: | ||
| It’s also possible to add a disk to a running VM. The disk can be a disk image or a LVM volume. It’s possible to resize the disk, but, you have to reboot the client or relaod the kernel disk table ('' | It’s also possible to add a disk to a running VM. The disk can be a disk image or a LVM volume. It’s possible to resize the disk, but, you have to reboot the client or relaod the kernel disk table ('' | ||
| - | + | * Add (persistent) a disk to a VM:<code bash> | |
| - | + | ||
| - | <code bash> | + | |
| virsh attach-disk ds --source / | virsh attach-disk ds --source / | ||
| - | </ | + | </ |
| + | | **Note: | ||
| - | This adds a new disk to the '' | + | ==== Resize (LVM) disk ==== |
| + | * First increase size of the LV on KVM host:< | ||
| + | lvresize -G < | ||
| + | </ | ||
| + | * Configure the size of that domain and disk using '' | ||
| + | virsh blockresize < | ||
| + | </ | ||
| - | ||The disk is a logical volume on the KVM host| | ||