Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access vm #81

Open
mamaart opened this issue Feb 13, 2025 · 0 comments
Open

Can't access vm #81

mamaart opened this issue Feb 13, 2025 · 0 comments

Comments

@mamaart
Copy link

mamaart commented Feb 13, 2025

I am trying to setup VM's on some headless servers.

I am using a qcow2 file that I generated from another nixos configuration, but I also tested this with the latest qcow2 file from debian.

My flake.nix file is here:

{
  description = "NixOS configuration of the server";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
    NixVirt = {
      url = "https://flakehub.com/f/AshleyYakeley/NixVirt/*.tar.gz";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {nixpkgs, NixVirt, ...}: 
  {
    nixosConfigurations.srv1 = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
      	NixVirt.nixosModules.default
	{
          virtualisation.libvirt = {
            enable = true;
	    verbose = true;
            connections."qemu:///session" = {
	      domains = [
                {
                  definition = NixVirt.lib.domain.writeXML (NixVirt.lib.domain.templates.linux
                    {
                      name = "vm1";
                      uuid = "35ccc185-f1c6-453e-aa1f-c10624e075ce";
                      storage_vol = "/home/martin/nixos.qcow2"; 
		      virtio_video = true; # I'd prefer this with false (I think).
		      virtio_drive = true;
		      #devices = {
		      #  graphics = {
		      #    type = "vnc";
		      #    port = "-1";
		      #    autoport = "yes";
		      #    listen = {
		      #      type = "adress";
		      #      address = "0.0.0.0";
		      #    };
		      #  };
		      #};
		      #serial = {
		      #  type = "pty";
		      #  target = { port = "0"; };
		      #};
		      #console = {
		      #  type = "pty";
		      #  target = {
		      #    type = "serial";
		      #    port = "0";
		      #  };
		      #};
                    }
		  );
		  active = true;
                }
              ];
	      networks = [
	        {
		  definition = NixVirt.lib.network.writeXML (NixVirt.lib.network.templates.bridge
		    {
		      uuid = "0d952b33-8824-41a5-b100-cd4e4844687f";
		      subnet_byte = 71;
		    }
		  );
		  active = true;
		}
	      ];
            };
          };
	}
      ];
    };
  };
}

If the virtio_video is true then I get a systemd error when running nixos-rebuild switch --flake .

warning: the following units failed: nixvirt.service
× nixvirt.service - Configure libvirt objects
     Loaded: loaded (/etc/systemd/system/nixvirt.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Thu 2025-02-13 15:16:39 CET; 301ms ago
 Invocation: 483d7cf7a777445e96817f1003510f76
    Process: 11611 ExecStart=/nix/store/5hdm2larimdp9b2i4ccbj22rmrpk6kva-unit-script-nixvirt-start/bin/nixvirt-start (code=exited, status=1/FAILURE)
   Main PID: 11611 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
         IO: 8K read, 0B written
   Mem peak: 19M
        CPU: 206ms

Feb 13 15:16:38 srv1 nixvirt-start[11612]: [delete, /domain/devices/video/model[2]]
Feb 13 15:16:38 srv1 nixvirt-start[11612]: domain 35ccc185-f1c6-453e-aa1f-c10624e075ce: deactivate
Feb 13 15:16:39 srv1 nixvirt-start[11612]: Defining pool volumes
Feb 13 15:16:39 srv1 nixvirt-start[11612]: Setting activation state
Feb 13 15:16:39 srv1 nixvirt-start[11612]: domain 35ccc185-f1c6-453e-aa1f-c10624e075ce: activate
Feb 13 15:16:39 srv1 nixvirt-start[11612]: NixVirt: libvirt error: internal error: process exited while connecting to monitor: 2025-02-13T14:16:39.355240Z qemu-system-x86_64: egl: eglGetDisplay failed: EGL_SUCCESS
Feb 13 15:16:39 srv1 nixvirt-start[11612]: 2025-02-13T14:16:39.356055Z qemu-system-x86_64: egl: render node init failed
Feb 13 15:16:39 srv1 systemd[1]: nixvirt.service: Main process exited, code=exited, status=1/FAILURE
Feb 13 15:16:39 srv1 systemd[1]: nixvirt.service: Failed with result 'exit-code'.
Feb 13 15:16:39 srv1 systemd[1]: Failed to start Configure libvirt objects.
warning: error(s) occurred while switching to the new configuration

I think the problem is that I didn't install xorg or wayland. And i also shouldn't depend on this to run libvirt.

So. I change virtio_video to false and then it installs without errors.

If i run virsh list I can see that the vm is running. But I cannot access it.
I tried to virsh console vm1 but I get the error

error: internal error: cannot find character device <null>

I tried to setup VNC graphics, but it didn't seem to have any effect.

devices = {
  graphics = {
    type = "vnc";
    port = "-1";
    autoport = "yes";
    listen = {
      type = "adress";
      address = "0.0.0.0";
    };
  };
};

I also tried to SSH into the VM. but I could not find the IP of the VM.

I tried with NMAP but I don't think it got any IP from the DHCP server.

ip -br a
...
virbr0           UP             192.168.71.1/24
...
martin@srv1:~/ > nmap -sn '192.168.71.*'
Starting Nmap 7.95 ( https://nmap.org ) at 2025-02-13 15:36 CET
Nmap scan report for 192.168.71.1
Host is up (0.00082s latency).
Nmap done: 256 IP addresses (1 host up) scanned in 2.81 seconds

I also have a copy from the output of virsh edit --domain vm1

<domain type='kvm'>
  <name>vm1</name>
  <uuid>35ccc185-f1c6-453e-aa1f-c10624e075ce</uuid>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-9.1'>hvm</type>
    <boot dev='cdrom'/>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-passthrough' check='none' migratable='on'/>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/nix/store/j19kcb0288krhkgkvz33lr4ajqmfs3kh-qemu-9.1.2/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none' discard='unmap'/>
      <source file='/home/martin/deb.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='sdc' bus='sata'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='2'/>
    </disk>
    <controller type='usb' index='0' model='qemu-xhci'>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
    </controller>
    <controller type='sata' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pcie-root'/>
    <controller type='pci' index='1' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='1' port='0x10'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
    </controller>
    <controller type='pci' index='2' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='2' port='0x11'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
    </controller>
    <controller type='pci' index='3' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='3' port='0x12'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
    </controller>
    <controller type='pci' index='4' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='4' port='0x13'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
    </controller>
    <controller type='pci' index='5' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='5' port='0x14'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
    </controller>
    <controller type='pci' index='6' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='6' port='0x15'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
    </controller>
    <controller type='pci' index='7' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='7' port='0x16'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:21:82:82'/>
      <source bridge='virbr0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <channel type='unix'>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>
    </channel>
    <input type='tablet' bus='usb'>
      <address type='usb' bus='0' port='2'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice'>
      <listen type='none'/>
      <image compression='off'/>
      <gl enable='no'/>
    </graphics>
    <sound model='ich9'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
    </sound>
    <audio id='1' type='spice'/>
    <video>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
    </video>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='3'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='4'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='1.1'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='1.2'/>
    </redirdev>
    <hub type='usb'>
      <address type='usb' bus='0' port='1'/>
    </hub>
    <watchdog model='itco' action='reset'/>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='random'>/dev/urandom</backend>
      <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
    </rng>
  </devices>
</domain>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant