WiFi card passed to LXD container results in failure, Please help me!

I am encountering an issue attaching a usb wireless nic to a lxd container.
I’m tired of it, Who can help me! Thanks!

My laptop:

  • ManjaroLinux 19.0.2
  • LXD 4.0 installed via snap
  • User account yuanfh in sudo and lxd group

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 04ca:0061 Lite-On Technology Corp. USB Optical Mouse
Bus 001 Device 003: ID 8087:0a2a Intel Corp.
Bus 001 Device 002: ID 5986:069e Acer, Inc HD Webcam
Bus 001 Device 005: ID 0bda:8812 Realtek Semiconductor Corp. RTL8812AU 802.11a/b/g/n/ac 2T2R DB WLAN Adapter

$ iw dev
phy#1
" "Interface wlp0s20f0u2
ifindex 4
wdev 0x100000001
addr 00:13:ef:f1:04:05
type managed
txpower 12.00 dBm
phy#0
Unnamed/non-netdev interface
wdev 0x2
addr 84:ef:18:f5:7b:d4
type P2P-device
txpower 0.00 dBm
Interface wlp3s0
ifindex 3
wdev 0x1
addr 84:ef:18:f5:7b:d4
ssid CU_te5d
type managed
channel 7 (2442 MHz), width: 20 MHz, center1: 2442 MHz
txpower 22.00 dBm
multicast TXQ:
qsz-byt qsz-pkt flows drops marks overlmt hashcoltx-bytes tx-packets
0 0 0 0 0 0 0 00

$ lxc launch images:kali/current/amd64 k1
$ lxc launch ubuntu:18.04 u1

$ lxc config device add k1 wlan0 nic nictype=physical parent=wlp0s20f0u2 name=wlan0

Error: Failed to start device “wlan0”: Failed to attach interface: wlp0s20f0u2 to wlan0: attaching specified netdev to the container failed

$ lxc config device add u1 wlan0 nic nictype=physical parent=wlp0s20f0u2 name=wlan0

Error: Failed to start device “wlan0”: Failed to attach interface: wlp0s20f0u2 to wlan0: attaching specified netdev to the container failed

$ lxc stop k1
$ lxc config device add k1 wlan0 nic nictype=physical parent=wlp0s20f0u2 name=wlan0

Device wlan0 added to k1

$ lxc start k1

Error: Failed to run: /snap/lxd/current/bin/lxd forkstart k1 /var/snap/lxd/common/lxd/containers /var/snap/lxd/common/lxd/logs/k1/lxc.conf:
Try lxc info --show-log k1 for more info

$ lxc info --show-log k1
Name: k1
Location: none
Remote: unix://
Architecture: x86_64
Created: 2020/04/09 07:52 UTC
Status: Stopped
Type: container
Profiles: default

Log:

lxc k1 20200409075628.634 ERROR cgfsng - cgroups/cgfsng.c:mkdir_eexist_on_last:1143 - File exists - Failed to create directory “/sys/fs/cgroup/cpuset//lxc.monitor.k1”
lxc k1 20200409075628.636 ERROR cgfsng - cgroups/cgfsng.c:mkdir_eexist_on_last:1143 - File exists - Failed to create directory “/sys/fs/cgroup/cpuset//lxc.payload.k1”
lxc k1 20200409075628.639 WARN cgfsng - cgroups/cgfsng.c:fchowmodat:1455 - No such file or directory - Failed to fchownat(17, memory.oom.group, 1000000000, 0, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW )
lxc k1 20200409075628.705 ERROR network - network.c:lxc_network_move_created_netdev_priv:3129 - Operation not permitted - Failed to move network device “wlp0s20f0u2” with ifindex 4 to network namespace 4108
lxc k1 20200409075628.705 ERROR start - start.c:lxc_spawn:1746 - Failed to create the network
lxc k1 20200409075628.709 WARN network - network.c:lxc_delete_network_priv:3213 - Failed to rename interface with index 0 from “eth0” to its initial name “veth1266d3fd”
lxc k1 20200409075628.714 ERROR lxccontainer - lxccontainer.c:wait_on_daemonized_start:852 - Received container state “ABORTING” instead of “RUNNING”
lxc k1 20200409075628.714 ERROR start - start.c:__lxc_start:1948 - Failed to spawn container “k1”
lxc k1 20200409075628.714 WARN start - start.c:lxc_abort:1025 - No such process - Failed to send SIGKILL via pidfd 30 for process 4108
lxc 20200409075628.889 WARN commands - commands.c:lxc_cmd_rsp_recv:122 - Connection reset by peer - Failed to receive response for command “get_state”

Hi @yuanfh!

Have a look at this guide,

I think the bit that is missing, is to get the device not to be used by the host.
Give it a try according to the guide and please report back (even if it works out of the box).

I was following your document, but I don’t know why it failed. I had the same error on the ubuntu 20.04 host.
Is there something wrong with my wireless card? or driver?But I can use it in both the host and the virtualbox VMs.

$ cat /etc/NetworkManager/NetworkManager.conf

# Configuration file for NetworkManager.
# See “man 5 NetworkManager.conf” for details.
[keyfile]
unmanaged-devices=mac:00:13:ef:f1:04:05;interface-name:wlp0s20f0u2

$ rfkill list

0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
2: phy1: Wireless LAN
Soft blocked: no
Hard blocked: no

But type is still not unmanaged !!

$ iw dev
phy#1
Interface wlp0s20f0u2
ifindex 11
wdev 0x100000001
addr 00:13:ef:f1:04:05
type managed
txpower 12.00 dBm

Thank you very much!

But I still failed. I think this problem may have something to do with NIC and drivers. Are there any important steps missing from your documentation? I have been operating according to your document in many different environments and the result is the same error report!

My next job must realize this function, can you help me solve this problem? Or do I need to provide more configuration and log information?

That’s a different type of managed. iw is not part of the NetworkManager suite, therefore that managed does not mean managed by NetworkManager.

I see you are using the RTL8812AU. Isn’t that the one that does not work out of the box and you need to install DKMS drivers?

Luckily, I happen to have one of those. I went through the steps and installed a DKMS driver, and managed to replicated the issue that you are facing.

According to the following,

You get a better error message when you stop the container, add the nic (it gets added successfully since there is no check), and when you start the container you get:

lxc mykali 20200410173713.876 ERROR    network - network.c:lxc_network_move_created_netdev_priv:3126 - Operation not permitted - Failed to move network device "wlx0xxxxxxxxxx" with ifindex 12 to network namespace 104055

There’s a bug report for this, apparently it has been a regression that was supposed to be fixed.

Here is the fix, support for nl80211 adapters,

This post says that they got a workaround to specify the physical interface (in that case, phy2) simply by installing the iw utility. They use Debian, most likely not the snap.

@stgraber, should there be a bug report for this?

I’m looking at adding iw to the snap now, we’ll see if that helps.

Change done and edge, beta and candidate snaps are being built with it.

https://code.launchpad.net/~ubuntu-lxc/+snap/lxd-latest-edge
https://code.launchpad.net/~ubuntu-lxc/+snap/lxd-latest-beta
https://code.launchpad.net/~ubuntu-lxc/+snap/lxd-latest-candidate/

I have tested latest/candidate (build 14503), and verified that iw is in /snap/lxd/14503/bin/iw.

I got the same error,

  1. Failure to move network device to the network namespace, if using the wlx… name.
  2. Unable to add the appropriate phy0 device (Parent device ‘phy0’ doesn’t exist).
lxc mykali 20200410213638.205 ERROR    network - network.c:lxc_network_move_created_netdev_priv:3126 - Operation not permitted - Failed to move network device wlx0xxxxxxxxxx with ifindex 7 to network namespace 94448

Probably the iw binary is not related to this issue.

According to https://github.com/lxc/lxc/issues/3105 it appears that the issue is related to the regression that probably still exists.

@yuanfh, are you able to test with LXD 3.0? The bug report at https://github.com/lxc/lxc/issues/3105 mentions that this has been working on LXD prior to version 3.15. The last available version to get now, is LXD 3.0.x, either as a DEB package from Ubuntu 18.04, or a snap package from the channel 3.0/stable (see snap info lxd)… Unfortunately, I cannot downgrade LXD to test.

I tested on Ubuntu 20.04 with LXD 3.0.4 (snap package, tracking 3.0/stable).
It did not work either. Specifically,

lxc start mycontainer would work, but lxc list shows

+--------+-------+------+------+------------+-----------+
|  NAME  | STATE | IPV4 | IPV6 |    TYPE    | SNAPSHOTS |
+--------+-------+------+------+------------+-----------+
| mykali | ERROR |      |      | PERSISTENT | 0         |
+--------+-------+------+------+------------+-----------+

The container logfile still shows

lxc mykali 20200411001227.333 ERROR    network - network.c:lxc_network_move_created_netdev_priv:2613 - Operation not permitted - Failed to move network device "wlx0xxxxxxxxxx" to network namespace 5719