Jump to content

Virt-manager: Difference between revisions

From Official NixOS Wiki
Remove 23.11pre options.
Unable to find 'efi' firmware
 
(11 intermediate revisions by 9 users not shown)
Line 1: Line 1:
Virt-manager is a GUI for managing local and remote virtual machines.
[https://virt-manager.org/ 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).


== Requisites ==
== Prequisites ==
Even though Virt-manager (using the KVM hypervisor) is able to take advantage of virtualisation capabilities without any UEFI/BIOS configuration, best performances demand that 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.
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 ==
== Installation ==
In your configuration file add:
{{File|3=virtualisation.libvirtd.enable = true;
programs.virt-manager.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}{{Note|<br/><br /><code>authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'</code>


=== NixOS ===
To resolve, add your user to the libvirtd group:


<syntaxhighlight lang="nix">
{{File|3={
virtualisation.libvirtd.enable = true;
  users.users.<myuser>.extraGroups = [ "libvirtd" ];
programs.virt-manager.enable = true;
}|name=/etc/nixos/configuration.nix|lang=nix}}|leading=After rebuild, you may get the following error:}}
</syntaxhighlight>


You will get a warning when you open it for the first time:
=== Networking ===
To use the default libvirt network, you will need to install the <code>dnsmasq</code> package. This is required for DNS and DCHP functionality within the network:


<code>Could not detect a default hypervisor. Make sure the appropriate QEMU/KVM virtualization packages are installed to manage virtualization on this host.
{{File|3=environment.systemPackages = with pkgs; [
  dnsmasq
];|name=/etc/nixos/configuration.nix|lang=nix}}


A virtualization connection can be manually added via File->Add Connection</code>
The default network starts off inactive, you must enable it 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">
# 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:
{{File|3=networking.firewall.trustedInterfaces = [ "virbr0" ];|name=/etc/nixos/configuration.nix|lang=nix}}


To resolve:
=== Display ===
The default video may not allow different resolutions and is limited. It is recommended to use Virtio instead.


<pre>
For information on how to use Virtio with your VM's, [https://wiki.libvirt.org/Virtio.html you can read up on Virtio on the libvirt wiki].
File (in the menu bar) -> Add connection


HyperVisor = QEMU/KVM
=== Shared folders ===
Autoconnect = checkmark
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 <code>pkgs.virtiofsd</code> to <code>virtualisation.libvirtd.qemu.vhostUserPackages</code>:


Connect
</pre>
The same can also be achieved declaratively by setting the corresponding dconf settings with home-manager. If you want to do this instead of the imperative configuration described above, add the following snippet to your home-manager configuration:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
dconf.settings = {
virtualisation.libvirtd = {
   "org/virt-manager/virt-manager/connections" = {
   enable = true;
    autoconnect = ["qemu:///system"];
  qemu.vhostUserPackages = with pkgs; [ virtiofsd ];
    uris = ["qemu:///system"];
  };
};
};
</syntaxhighlight>
</syntaxhighlight>
You may get the following error:
<code>authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'</code>
To resolve, add the user to the <code>libvirtd</code> group:
<syntaxhighlight lang="nix">
{
  users.users.<myuser>.extraGroups = [ "libvirtd" ];
}
</syntaxhighlight>
=== Networking ===
The default network starts off as being inactive, you must enable it before it is accessible.
This can be done by running the following command:
<code>virsh net-start default</code>
Or autostart:
<code>virsh net-autostart default</code>
By default this will enable the <code>virbr0</code> virtual network bridge.
===Display===
The default Video may not allow different resolutions, `Virtio` will allow for more.


===Windows Guest===
===Windows Guest===
Line 76: Line 53:
{
{
   services.qemuGuest.enable = true;
   services.qemuGuest.enable = true;
  services.spice-vdagentd.enable = true;  # enable copy and paste between host and guest
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 88: Line 66:
     name = "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:
<code>Error:  Error starting domain: operation failed: Unable to find 'efi' firmware that is compatible with the current configuration</code>
Solution:
# Delete old generations:  <code>nix-collect-garbage -d</code>
# Find where the EFI boot loaded file is located:  <code>find /nix/store/ -maxdepth 1 -type d -name "*qemu*"  |  xargs -I {} find "{}" -type f -name "edk2-x86_64-secure-code.fd"</code>  Find the dir holding the latest qemu.  The directory should be something like: <code>xbfjilai721rzd9rf9dhhpv03xza4xp4-qemu-9.1.3</code>.  Take a note of this directory name.
# Open VM in virt-manager, go to XML and within the <code><os ...></code> tag:
## Edit <code><loader ...></code> with the above directory name
## Edit <code><nvram ...></code> with the above directory name.
[[Category:Virtualization]]
[[Category:Virtualization]]

Latest revision as of 12:05, 9 February 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:

❄︎ /etc/nixos/configuration.nix
virtualisation.libvirtd.enable = true;
programs.virt-manager.enable = true;
After rebuild, you may get the following error:

authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'

To resolve, add your user to the libvirtd group:

❄︎ /etc/nixos/configuration.nix
{
  users.users.<myuser>.extraGroups = [ "libvirtd" ];
}

Networking

To use the default libvirt network, you will need to install the dnsmasq package. This is required for DNS and DCHP functionality within the network:

❄︎ /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [ 
  dnsmasq 
];

The default network starts off inactive, you must enable it 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:

❄︎ /etc/nixos/configuration.nix
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 VM's, 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 ];
};

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:

  1. Delete old generations: nix-collect-garbage -d
  2. 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.
  3. Open VM in virt-manager, go to XML and within the <os ...> tag:
    1. Edit <loader ...> with the above directory name
    2. Edit <nvram ...> with the above directory name.