Virt-manager: Difference between revisions

From NixOS Wiki
imported>Neubeki
m Add networking section to clear up why virbr0 is not accessible after enabling virt-manager and libvirtd
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
The [https://virt-manager.org/ virt-manager] application is a GUI for managing local and remote virtual machines through libvirt. It primarily targets KVM VMs, but also manages Xen and LXC (linux containers).
== Requisites ==
== Requisites ==
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.
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.
Line 5: Line 7:


=== NixOS ===
=== NixOS ===
Before 23.11:
<syntaxhighlight lang="nix">
virtualisation.libvirtd.enable = true;
programs.dconf.enable = true; # virt-manager requires dconf to remember settings
environment.systemPackages = with pkgs; [ virt-manager ];
</syntaxhighlight>


After 23.11:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
virtualisation.libvirtd.enable = true;
virtualisation.libvirtd.enable = true;
programs.virt-manager.enable = true;
programs.virt-manager.enable = true;
</syntaxhighlight>
</syntaxhighlight>
See [https://github.com/NixOS/nixpkgs/pull/261474 relevant merge request]


You may get the following error:


You will get a warning when you open it for the first time:
<code>authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'</code>


<code>Could not detect a default hypervisor. Make sure the appropriate QEMU/KVM virtualization packages are installed to manage virtualization on this host.
To resolve, add the user to the <code>libvirtd</code> group:


A virtualization connection can be manually added via File->Add Connection</code>
<syntaxhighlight lang="nix">
{
  users.users.<myuser>.extraGroups = [ "libvirtd" ];
}
</syntaxhighlight>


To resolve:
=== 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 (may require sudo):  


<pre>
<code>virsh net-start default</code>
File (in the menu bar) -> Add connection


HyperVisor = QEMU/KVM
Or autostart:
Autoconnect = checkmark


Connect
<code>virsh net-autostart default</code>
</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:
By default this will enable the <code>virbr0</code> virtual network bridge.
<syntaxhighlight lang="nix">
dconf.settings = {
  "org/virt-manager/virt-manager/connections" = {
    autoconnect = ["qemu:///system"];
    uris = ["qemu:///system"];
  };
};
</syntaxhighlight>


You may get the following error:
===Display===
The default Video may not allow different resolutions, `Virtio` will allow for more.


<code>authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'</code>
===Windows Guest===
See [https://github.com/virtio-win/virtio-win-guest-tools-installer Virtio-win guest tools] for additional drivers for both paravirtual and emulated hardware


To resolve, add the user to the <code>libvirtd</code> group:
===Guest Agent===
When running NixOS as a guest, enable the [https://wiki.qemu.org/Features/GuestAgent QEMU guest agent] with:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
   users.users.<myuser>.extraGroups = [ "libvirtd" ];
   services.qemuGuest.enable = true;
  services.spice-vdagentd.enable = true; # enable copy and paste between host and guest
}
}
</syntaxhighlight>
</syntaxhighlight>


=== Networking ===
The host must [https://wiki.libvirt.org/Qemu_guest_agent.html#setting-qemu-ga-up provide the needed virtio serial port] under the special name <code>org.qemu.guest_agent.0</code>.
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>.  
 
By default this will enable the <code>virbr0</code> virtual network bridge.


=== 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";
  };
[[Category:Virtualization]]
[[Category:Virtualization]]

Latest revision as of 14:44, 10 November 2024

The virt-manager application is a GUI for managing local and remote virtual machines through libvirt. It primarily targets KVM VMs, but also manages Xen and LXC (linux containers).

Requisites

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.

Installation

NixOS

virtualisation.libvirtd.enable = true;
programs.virt-manager.enable = true;

You may get the following error:

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

To resolve, add the user to the libvirtd group:

{
  users.users.<myuser>.extraGroups = [ "libvirtd" ];
}

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 (may require sudo):

virsh net-start default

Or autostart:

virsh net-autostart default

By default this will enable the virbr0 virtual network bridge.

Display

The default Video may not allow different resolutions, `Virtio` will allow for more.

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";
 };