linux:apps:kvm:kvm
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| linux:apps:kvm:kvm [2025/10/21 20:15] – created - external edit 127.0.0.1 | linux:apps:kvm:kvm [2026/09/15 20:16] (current) – [KVM] oscar | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ---- | ---- | ||
| + | * [[linux: | ||
| + | * [[linux: | ||
| + | * [[linux: | ||
| + | * [[linux: | ||
| - | ===== Installation ===== | ||
| - | Install all the required for the installation of Qemu, KVM hypervisor, and Libvirt | ||
| - | # apt install qemu-system libvirt-daemon-system qemu-utils virt-manager | ||
| - | |||
| - | * qemu-system: | ||
| - | * virt-manager: | ||
| - | * libvirt-daemon-system: | ||
| - | * qemu-utils: Various utilities e.g. for manipulating disk images | ||
| - | * virtinst: Allows to create Virtual Machines (VMs) from the command-line. | ||
| - | |||
| - | Verify that the virtualization daemon, libvritd-daemon, | ||
| - | < | ||
| - | # systemctl status libvirtd | ||
| - | |||
| - | Output: | ||
| - | |||
| - | ● libvirtd.service - Virtualization daemon | ||
| - | | ||
| - | | ||
| - | TriggeredBy: | ||
| - | ● libvirtd-admin.socket | ||
| - | ● libvirtd.socket | ||
| - | Docs: man: | ||
| - | | ||
| - | Main PID: 7999 (libvirtd) | ||
| - | Tasks: 19 (limit: 32768) | ||
| - | | ||
| - | CPU: 188ms | ||
| - | | ||
| - | | ||
| - | Aug 06 10:57:02 pcwerkkamer systemd[1]: Starting libvirtd.service - Virtualization daemon... | ||
| - | Aug 06 10:57:02 pcwerkkamer systemd[1]: Started libvirtd.service - Virtualization daemon. | ||
| - | </ | ||
| - | Check if libvirtd service will start automatically at boot time. | ||
| - | < | ||
| - | # systemctl is-enabled libvirtd | ||
| - | |||
| - | Output: | ||
| - | enabled | ||
| - | </ | ||
| - | If disabled run the following command to have it boot automatically: | ||
| - | # systemctl enable --now libvirtd | ||
| - | |||
| - | Use the following command to determine whether the KVM modules are loaded: | ||
| - | < | ||
| - | $ lsmod | grep -i kvm | ||
| - | kvm_intel | ||
| - | kvm 1142784 | ||
| - | irqbypass | ||
| - | </ | ||
| - | ===== Configuration ===== | ||
| - | === User priviliges === | ||
| - | In order to manage virtual machines as a regular user, that user needs to be added to the libvirt group: | ||
| - | |||
| - | # adduser < | ||
| - | | ||
| - | # usermod -aG libvirt,kvm < | ||
| - | |||
| - | === User-specific and system-wide VMs === | ||
| - | By default, if virsh is run as a normal user it will connect to libvirt using: **qemu: | ||
| - | |||
| - | To manage the system set of VMs (i.e., VMs belonging to root) virsh should be run as root or with: **qemu: | ||
| - | |||
| - | $ virsh --connect qemu:/// | ||
| - | |||
| - | To avoid having to use the --connect flag on every command, the URI string can be set in the LIBVIRT_DEFAULT_URI environment variable: | ||
| - | |||
| - | $ export LIBVIRT_DEFAULT_URI=' | ||
| - | |||
| - | ===== Libvirt default network ===== | ||
| - | If you use libvirt to manage your VMs, libvirt provides a NATed bridged network named " | ||
| - | < | ||
| - | 3: virbr0: < | ||
| - | link/ether 52: | ||
| - | inet 192.168.122.1/ | ||
| - | | ||
| - | </ | ||
| - | This network is available only for the system domains (that is VMs created by root or using the " | ||
| - | virsh --connect=qemu:/// | ||
| - | |||
| - | To make the default network start automatically use: | ||
| - | |||
| - | virsh --connect=qemu:/// | ||
| - | |||
| - | ===== Change XML configuration ===== | ||
| - | Extract the xml from an existing qcow2 image by: | ||
| - | virsh dumpxml Windows-11 > Windows-11.xml | ||
| - | Edit and modify the tags in the XML file. | ||
| - | Undefine the XML config from the old vm to prevent an error because of a duplicate UUID: | ||
| - | virsh undefine --nvram Windows-11 | ||
| - | or | ||
| - | virsh undefine Windows-11 | ||
| - | Import / define the new XML file: | ||
| - | virsh define Windows-11.xml | ||
| - | Of course you will have to stop and start the vm for the changes to take effect: | ||
| - | virsh destroy name_of_vm | ||
| - | virsh start name_of_vm | ||
| - | |||
| - | |||
| - | ===== Error Access ISO files, etc. ===== | ||
| - | Directory, that libvirt is using for storing/ | ||
| - | |||
| - | $ sudo su -s /bin/bash libvirt-qemu | ||
| - | |||
| - | If you can't ls with an account that does have access yields a result with a permission line that contains a dot such as drwxrwxr-x. meaning extended ACL permissions. | ||
| - | |||
| - | === Fix 1: === | ||
| - | Put the iso or image into one of the pool directories of libvirt manager. E.g. / | ||
| - | Or any other paths that have full r others rights. | ||
| - | |||
| - | ===== Convert VirtualBox to KVM ===== | ||
| - | qemu-img convert -f vdi -O qcow2 virtualbox-name.vdi kvm-name.qcow2 | ||
| - | ===== Shrink KVM qcow2 image ===== | ||
| - | qemu-img convert -O qcow2 source.qcow2 shrunk.qcow2 | ||
| - | ===== Make SATA disk available in Windows Client ===== | ||
| - | To make a SATA disk partition available in a Windows VM add the disk to the domain’s xml config file by hand. First find the id of the partition that you want to add. Rather than using /dev/sda you should use / | ||
| - | |||
| - | ls -l / | ||
| - | |||
| - | Now edit the /// | ||
| - | < | ||
| - | # nano / | ||
| - | |||
| - | or | ||
| - | |||
| - | virsh edit ${YOUR_VM} | ||
| - | ---------------------------------------------- | ||
| - | <disk type=' | ||
| - | <driver name=' | ||
| - | <source dev='/ | ||
| - | <target dev=' | ||
| - | </ | ||
| - | </ | ||
| - | This will make the host’s partition available in the guest as /dev/vdb (D:). After changing a domain’s config by hand, you have to reload the config by hand. Log in to your host and issue this command: | ||
| - | |||
| - | # virsh define / | ||
| - | | ||
| - | Domain YOUR_VM defined from / | ||
| - | | ||
| ===== Links ===== | ===== Links ===== | ||
| * [[https:// | * [[https:// | ||
linux/apps/kvm/kvm.1761077756.txt.gz · Last modified: by 127.0.0.1
