Virt-manager: Difference between revisions
m Add a note to let the user know that using a symlink as source does not work. |
→Networking: libvirt provides for dnsmasq now |
||
| (One intermediate revision by one other user not shown) | |||
| Line 18: | Line 18: | ||
=== Networking === | === Networking === | ||
The [[libvirt]] package [https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/li/libvirt/package.nix#L84-L87 wraps <code>libvirtd</code> with <code>dnsmasq</code>], which provides for DNS and DCHP functionality within the network. The default network starts off inactive, and must be enabled before it is accessible. This can be done by running the following command:<syntaxhighlight lang="console"># virsh net-start default</syntaxhighlight>And if you would like to enable it automatically at boot:<syntaxhighlight lang="console"> | |||
The default network starts off inactive, | |||
# virsh net-autostart default | # virsh net-autostart default | ||
</syntaxhighlight>By default, this will enable a virtual network bridge under the name <code>virbr0</code>. You may need to allow it through your firewall filter like so: | </syntaxhighlight>By default, this will enable a virtual network bridge under the name <code>virbr0</code>. You may need to allow it through your firewall filter like so: | ||
| Line 32: | Line 26: | ||
The default video may not allow different resolutions and is limited. It is recommended to use Virtio instead. | The default video may not allow different resolutions and is limited. It is recommended to use Virtio instead. | ||
For information on how to use Virtio with your | For information on how to use Virtio with your VMs, [https://wiki.libvirt.org/Virtio.html you can read up on Virtio on the libvirt wiki]. | ||
=== Shared folders === | === Shared folders === | ||
| Line 43: | Line 37: | ||
}; | }; | ||
</syntaxhighlight>{{Note|Shared folders do not work when the source folder is a symlink.}} | </syntaxhighlight>{{Note|Shared folders do not work when the source folder is a symlink.}} | ||
{{Note|You still need to mount the shared folder in the VM e.g.: <code>sudo mount -t virtiofs <Target path> <mount path></code> }} | |||
===Windows Guest=== | ===Windows Guest=== | ||
Latest revision as of 10:31, 9 November 2026
Virt-manager (a.k.a. Virtual Machine Manager) is a GUI application for managing local and remote virtual machines through libvirt. It primarily targets KVM VMs, but also manages Xen and LXC (Linux Containers).
Prequisites
Though Virt-manager (using the KVM hypervisor) is able to take advantage of virtualisation capabilities without any UEFI/BIOS configuration, best performance demands that the host have Vt-x and Vt-d (Intel) or AMD-V and AMD-Vi (AMD) enabled.
These settings can usually be found under the UEFI/BIOS settings.
Installation
In your configuration file add:
virtualisation.libvirtd.enable = true;
programs.virt-manager.enable = true;
authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'
To resolve, add your user to the libvirtd group:
{
users.users.<myuser>.extraGroups = [ "libvirtd" ];
}
Networking
The libvirt package wraps libvirtd with dnsmasq, which provides for DNS and DCHP functionality within the network. The default network starts off inactive, and must be enabled before it is accessible. This can be done by running the following command:
# virsh net-start default
And if you would like to enable it automatically at boot:
# virsh net-autostart default
By default, this will enable a virtual network bridge under the name virbr0. You may need to allow it through your firewall filter like so:
networking.firewall.trustedInterfaces = [ "virbr0" ];
Display
The default video may not allow different resolutions and is limited. It is recommended to use Virtio instead.
For information on how to use Virtio with your VMs, you can read up on Virtio on the libvirt wiki.
Shared folders
To be able to share a folder with a guest, you will need 'virtiofsd'. The recommended way to solve this problem is now to add pkgs.virtiofsd to virtualisation.libvirtd.qemu.vhostUserPackages:
virtualisation.libvirtd = {
enable = true;
qemu.vhostUserPackages = with pkgs; [ virtiofsd ];
};
sudo mount -t virtiofs <Target path> <mount path> Windows Guest
See Virtio-win guest tools for additional drivers for both paravirtual and emulated hardware
Guest Agent
When running NixOS as a guest, enable the QEMU guest agent with:
{
services.qemuGuest.enable = true;
services.spice-vdagentd.enable = true; # enable copy and paste between host and guest
}
The host must provide the needed virtio serial port under the special name org.qemu.guest_agent.0.
Wayland
In order to run on Wayland, virt-manager must be ran under XWayland with $ GDK_BACKEND=x11 virt-manager or a gdk cursor must be set. An example of setting a gdk cursor with home-manager is as follows:
home.pointerCursor = {
gtk.enable = true;
package = pkgs.vanilla-dmz;
name = "Vanilla-DMZ";
};
Troubleshooting
Unable to find 'efi' firmware
The following guide is to fix the following error which will occur when starting a virtual machine after NixOS upgrade:
Error: Error starting domain: operation failed: Unable to find 'efi' firmware that is compatible with the current configuration
Solution:
- Delete old generations:
nix-collect-garbage -d - Find where the EFI boot loaded file is located:
find /nix/store/ -maxdepth 1 -type d -name "*qemu*" | xargs -I {} find "{}" -type f -name "edk2-x86_64-secure-code.fd"Find the dir holding the latest qemu. The directory should be something like:xbfjilai721rzd9rf9dhhpv03xza4xp4-qemu-9.1.3. Take a note of this directory name. - Open VM in virt-manager, go to XML and within the
<os ...>tag:- Edit
<loader ...>with the above directory name - Edit
<nvram ...>with the above directory name.
- Edit