NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.49k stars 12.98k forks source link

Qemu fails to start when told to use bridged networking. #311807

Open TheMuso opened 1 month ago

TheMuso commented 1 month ago

Describe the bug

Qemu fails to start when using quickemu to set up and run a virtual machine configured to use bridged networking. Other than the console output from quickemu itself, qemu does not provide any failure or error messages on the console.

Steps To Reproduce

  1. Set up an ethernet bridge on your system. This can be done with NetworkManager. A guide can be found at https://www.cyberciti.biz/faq/how-to-add-network-bridge-with-nmcli-networkmanager-on-linux/
  2. Use nix-shell to download quickemu: nix-shell -p quickemu
  3. Download and set up a VM configuration: quickget nixos 23.11 minimal
  4. Edit nixos-23.11-minimal.conf and add: network="br0" where br0 is the name of the bridge interface you previously set up.
  5. Attempt to run the VM with: quickemu --vm nixos-23.11-minimal.conf

Expected behavior

Qemu should load and display a window that shows the booting of the virtual machine.

Additional context

When running the virtual machine for the first time, quickemu creates a shell script in the same directory where the downloaded ISO and virtual machine disk image is located. This script can also be used to run qemu, and when doing so, there is no output from qemu to show any failure. I tried editing this script to manually specify the location of the qemu-bridge-helper binary as specified in the qemu manpage, with no change to the result.

Notify maintainers

@fedx-sudo @flexiondotorg

Metadata

[themuso@barton:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.9, NixOS, 24.05 (Uakari), 24.05.20240512.2057814`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/nix/store/vsbi6gfwf2bdamw0d0d9xndb1rrxfnbk-source`
FedX-sudo commented 1 month ago

Hi, thanks for reaching out! I was able to re-create this issue and may have found a partial fix to it (I am getting a new error, but I don't know if it's because I am bad at networking or it's NixOS being wierd). Try adding this to your NixOS config:

  virtualisation.libvirtd = {
    enable = true;
    allowedBridges = [
      "virbr0"
      "br0"
    ];
  };

I was able to isolate at least one of the issues to the way NixOS handles QEMU config, and the fact that QEMU is looking for the /etc/qemu/bridge.conf when in bridge mode, which NixOS defines in the libvird module. It would be very helpful if you could provide more info, a full Qickemu output and more info on how you have configured the bridge would be great!

EDIT: sorry, just saw the guide on bridge networking you followed.

TheMuso commented 1 month ago

This is the output I get when attempting to run a VM. It is the same with and without your suggested Nix configuration change.

[themuso@barton:~/VMs]$ quickemu --vm ./nixos-23.11-minimal.conf 
~/VMs ~/VMs
Quickemu 4.9.4 using /nix/store/rp0r6rfw5imlgz8x9w54n2w3jq8bg37b-qemu-8.2.3/bin/qemu-system-x86_64 v8.2.3
 - Host:     NixOS 24.05 (Uakari) running Linux 6.8 (barton)
 - CPU:      AMD Ryzen 5 2600X Six-Core Processor
 - CPU VM:   1 Socket(s), 2 Core(s), 2 Thread(s), 8G RAM
 - BOOT:     EFI (Linux), OVMF (/nix/store/46gqm6dd7g25jrgcsf9044s0cbg9jnl7-OVMF-202402-fd/FV/OVMF_CODE.fd), SecureBoot (off).
 - Disk:     nixos-23.11-minimal/disk.qcow2 (32G)
             Just created, booting from nixos-23.11-minimal/latest-nixos-minimal-x86_64-linux.iso
 - Boot ISO: nixos-23.11-minimal/latest-nixos-minimal-x86_64-linux.iso
 - Display:  SDL, virtio-vga-gl, GL (on), VirGL (on)
 - Sound:    intel-hda
 - ssh:      On host:  ssh user@localhost -p 22220
 - WebDAV:   On guest: dav://localhost:9843/
 - 9P:       On guest: sudo mount -t 9p -o trans=virtio,version=9p2000.L,msize=104857600 Public-themuso ~/Public
 - Network:  Bridged (br0)
 - Monitor:  On host:  nc -U "nixos-23.11-minimal/nixos-23.11-minimal-monitor.socket"
             or     :  socat -,echo=0,icanon=0 unix-connect:nixos-23.11-minimal/nixos-23.11-minimal-monitor.socket
 - Serial:   On host:  nc -U "nixos-23.11-minimal/nixos-23.11-minimal-serial.socket"
             or     :  socat -,echo=0,icanon=0 unix-connect:nixos-23.11-minimal/nixos-23.11-minimal-serial.socket
cat: nixos-23.11-minimal/nixos-23.11-minimal.pid: No such file or directory
 - Process:  Starting ./nixos-23.11-minimal.conf as nixos-23.11-minimal ()
FedX-sudo commented 1 month ago

That's odd... That's not the output I have with or without the changes whatsoever. I assume you have been able to get VMs to work just fine without bridge networking?

TheMuso commented 1 month ago

Yes, I have.

FedX-sudo commented 1 month ago

Have you tried connecting to the VM in ways other then the graphical console like connecting bia TTY? You can run ps -A | grep nixos to see if the VM is running. Sorry, I don't terribly know what's going on with this issue.

TheMuso commented 1 month ago

Sorry, I should have mentioned that in my initial report. I check for any qemu processes but there are none. It is as ift qemu is a dumb binary that takes any arguments and does nothing.

TheMuso commented 1 month ago

I decided to set up the bridge using systemd-network instead. No difference.

FedX-sudo commented 1 month ago

Hey, sorry for the late response. I am kind of stuck here. @flexiondotorg may know more, but I am not sure how to fix your issue....