Libvirt: Difference between revisions
imported>IgorM m Fixed syntax highlighting |
imported>Onny Restructuring and setup example |
||
| Line 1: | Line 1: | ||
[https://libvirt.org libvirt] is a toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes). It does so by providing a common API to different virtualization backends. | |||
== Setup == | |||
Enable libvirt daemon | |||
== | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
services.libvirtd = { | |||
enable = true; | |||
qemu = { | |||
package = pkgs.qemu_kvm; | |||
runAsRoot = true; | |||
swtpm.enable = true; | |||
ovmf = { | |||
enable = true; | |||
packages = [(pkgs.unstable.OVMF.override { | |||
secureBoot = true; | |||
tpmSupport = true; | |||
}).fd]; | |||
}; | |||
}; | |||
}; | |||
</nowiki>}} | |||
To enable local user access to libvirt, for example by using <code>virt-manager</code> or <code>gnome-boxes</code>, add yourself to the <code>libvirtd</code> group | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
users.users.myuser = { | |||
extraGroups = [ "libvirtd" ]; | |||
}; | |||
</nowiki>}} | |||
== Configuration == | |||
=== Nested virtualization === | |||
If you would like to enable nested virtualization for your guests to run KVM hypervisors inside them, you should enable it as follows: {{nixos:option|boot.extraModprobeConfig}}, for example: | If you would like to enable nested virtualization for your guests to run KVM hypervisors inside them, you should enable it as follows: {{nixos:option|boot.extraModprobeConfig}}, for example: | ||
< | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
boot.extraModprobeConfig = "options kvm_intel nested=1"; | boot.extraModprobeConfig = "options kvm_intel nested=1"; | ||
</ | </nowiki>}} | ||
=== | === UEFI with OVMF === | ||
Enable UEFI firmware support, following Qemu configuration for your local user is required | |||
{{file|~/.config/libvirt/qemu.conf|nix|<nowiki> | |||
# Adapted from /var/lib/libvirt/qemu.conf | # Adapted from /var/lib/libvirt/qemu.conf | ||
# Note that AAVMF and OVMF are for Aarch64 and x86 respectively | # Note that AAVMF and OVMF are for Aarch64 and x86 respectively | ||
nvram = [ "/run/libvirt/nix-ovmf/AAVMF_CODE.fd:/run/libvirt/nix-ovmf/AAVMF_VARS.fd", "/run/libvirt/nix-ovmf/OVMF_CODE.fd:/run/libvirt/nix-ovmf/OVMF_VARS.fd" ] | nvram = [ "/run/libvirt/nix-ovmf/AAVMF_CODE.fd:/run/libvirt/nix-ovmf/AAVMF_VARS.fd", "/run/libvirt/nix-ovmf/OVMF_CODE.fd:/run/libvirt/nix-ovmf/OVMF_VARS.fd" ] | ||
</ | </nowiki>}} | ||
See [https://ostechnix.com/enable-uefi-support-for-kvm-virtual-machines-in-linux/ this tutorial] on how to run a guest machine in UEFI mode using <code>virt-manager</code>. | |||
== | == Clients == | ||
NixOS provides some packages that can make use of libvirt or are useful with libvirt. | NixOS provides some packages that can make use of libvirt or are useful with libvirt. | ||