Can't Run MicroVM in Foreground If it has Network Interface

I am trying to set up my first imperative MicroVM. I build it and start the SystemD service and I get no errors. The name of the vm is “test”. Then, in an attempt to bring the VM to the foreground, I use “microvm -r test” and it gives me this error:

microvm@test: -netdev tap,id=test-eth0,ifname=test-eth0,script=no,downscript=no: could not configure /dev/net/tun (test-eth0): Device or resource busy

I also notice that on the host machine, this interface does not have the IP address that I assigned it. Here is my config file for the microvm:

{
  pkgs,
  config,
  lib,
  ...
}:

{
  system.stateVersion = "24.11";
  networking.hostName = "test";
  microvm.hypervisor = "qemu";

  networking.useNetworkd = true;
  systemd.network = {
    enable = true;

    networks = {
      "00-00-test" = {
        matchConfig = {
          Type = "ether";
        };
        address = [
          "2001:4830:c903:1011:f::1/64"
        ];
        routes = [
          {
            Gateway = "2001:4830:c903::1";
          }
        ];
      };
    };
  };

  microvm.interfaces = [
    {
      type = "tap";
      id = "test-eth0";
      mac = "02:00:00:00:00:01";
    }
  ];

}

The error message indicates that the network interface seems to have been already opened. Perhaps do first systemctl stop microvm@test

I figured out the answer myself. My issue was do to a misunderstanding of the microvm UI.

The microvm help menu says

-r Run a MicroVM in foreground

I took that to mean “take an existing microvm and move it into the foreground.” What it really means is “create a new microvm and run it in the foreground.”

I had a microvm called “test” already running in the background. I ran the command microvm -r test to try to attach it. What this did is basically make a duplicate “test” VM which used the same flake output for its configuration. This meant that both VMs started fighting over the same network interfaces and chaos ensued.

The only way that I know of to visibly see an existing VM is to SSH into it.