USB passthrough to LXC problem

enry86cami

New Member
May 25, 2023
6
0
1
Hi all,
I installed Virtual Environment 8.1.4 on a notebook. I create a LXC container with home assistant.
Now I'd like to install (network UPS tool) NUT in this container. So I need to pass the UPS USB from the host to the container.

HOST-SIDE:
root@proxmoxea:~# lsusb
Bus 001 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply

root@proxmoxea:/dev/bus/usb/001# ls -l 005
crw-rw-r-- 1 root root 189, 4 Apr 13 19:06 005

I followed this guide:
https://www.schreiners-it.de/proxmox/usb-geraet-in-lxc-container-unter-proxmox-7-1/

so:

root@proxmoxea:/home# sudo nano /etc/pve/lxc/102.conf

arch: amd64
cores: 2
features: nesting=1
hostname: homeassistant
memory: 1024
net0: name=eth0,bridge=vmbr0,firewall=1,gw=192.168.0.1,hwaddr=AA:8D:52:E4:F1:D0,ip=192.168.0.28/24,type=veth
ostype: debian
rootfs: local-lvm:vm-102-disk-0,size=10G
swap: 512
unprivileged: 1
lxc.cgroup.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/bus/usb/001/005 dev/bus/usb none bind,optional,create=file

but I don't have the ttyACM file (or ttyUSB0):

root@proxmoxea:/home# ls -l /dev/tty*
crw-rw-rw- 1 root tty 5, 0 Apr 14 13:24 /dev/tty
crw--w---- 1 root tty 4, 0 Apr 13 19:06 /dev/tty0
crw--w---- 1 root tty 4, 1 Apr 13 19:06 /dev/tty1
crw--w---- 1 root tty 4, 10 Apr 13 19:06 /dev/tty10
crw--w---- 1 root tty 4, 11 Apr 13 19:06 /dev/tty11
crw--w---- 1 root tty 4, 12 Apr 13 19:06 /dev/tty12
crw--w---- 1 root tty 4, 13 Apr 13 19:06 /dev/tty13
crw--w---- 1 root tty 4, 14 Apr 13 19:06 /dev/tty14
crw--w---- 1 root tty 4, 15 Apr 13 19:06 /dev/tty15
crw--w---- 1 root tty 4, 16 Apr 13 19:06 /dev/tty16
crw--w---- 1 root tty 4, 17 Apr 13 19:06 /dev/tty17
crw--w---- 1 root tty 4, 18 Apr 13 19:06 /dev/tty18
crw--w---- 1 root tty 4, 19 Apr 13 19:06 /dev/tty19
crw--w---- 1 root tty 4, 2 Apr 13 19:06 /dev/tty2
crw--w---- 1 root tty 4, 20 Apr 13 19:06 /dev/tty20
crw--w---- 1 root tty 4, 21 Apr 13 19:06 /dev/tty21
crw--w---- 1 root tty 4, 22 Apr 13 19:06 /dev/tty22
crw--w---- 1 root tty 4, 23 Apr 13 19:06 /dev/tty23
crw--w---- 1 root tty 4, 24 Apr 13 19:06 /dev/tty24
crw--w---- 1 root tty 4, 25 Apr 13 19:06 /dev/tty25
crw--w---- 1 root tty 4, 26 Apr 13 19:06 /dev/tty26
crw--w---- 1 root tty 4, 27 Apr 13 19:06 /dev/tty27
crw--w---- 1 root tty 4, 28 Apr 13 19:06 /dev/tty28
crw--w---- 1 root tty 4, 29 Apr 13 19:06 /dev/tty29
crw--w---- 1 root tty 4, 3 Apr 13 19:06 /dev/tty3
crw--w---- 1 root tty 4, 30 Apr 13 19:06 /dev/tty30
crw--w---- 1 root tty 4, 31 Apr 13 19:06 /dev/tty31
crw--w---- 1 root tty 4, 32 Apr 13 19:06 /dev/tty32
crw--w---- 1 root tty 4, 33 Apr 13 19:06 /dev/tty33
crw--w---- 1 root tty 4, 34 Apr 13 19:06 /dev/tty34
crw--w---- 1 root tty 4, 35 Apr 13 19:06 /dev/tty35
crw--w---- 1 root tty 4, 36 Apr 13 19:06 /dev/tty36
crw--w---- 1 root tty 4, 37 Apr 13 19:06 /dev/tty37
crw--w---- 1 root tty 4, 38 Apr 13 19:06 /dev/tty38
crw--w---- 1 root tty 4, 39 Apr 13 19:06 /dev/tty39
crw--w---- 1 root tty 4, 4 Apr 13 19:06 /dev/tty4
crw--w---- 1 root tty 4, 40 Apr 13 19:06 /dev/tty40
crw--w---- 1 root tty 4, 41 Apr 13 19:06 /dev/tty41
crw--w---- 1 root tty 4, 42 Apr 13 19:06 /dev/tty42
crw--w---- 1 root tty 4, 43 Apr 13 19:06 /dev/tty43
crw--w---- 1 root tty 4, 44 Apr 13 19:06 /dev/tty44
crw--w---- 1 root tty 4, 45 Apr 13 19:06 /dev/tty45
crw--w---- 1 root tty 4, 46 Apr 13 19:06 /dev/tty46
crw--w---- 1 root tty 4, 47 Apr 13 19:06 /dev/tty47
crw--w---- 1 root tty 4, 48 Apr 13 19:06 /dev/tty48
crw--w---- 1 root tty 4, 49 Apr 13 19:06 /dev/tty49
crw--w---- 1 root tty 4, 5 Apr 13 19:06 /dev/tty5
crw--w---- 1 root tty 4, 50 Apr 13 19:06 /dev/tty50
crw--w---- 1 root tty 4, 51 Apr 13 19:06 /dev/tty51
crw--w---- 1 root tty 4, 52 Apr 13 19:06 /dev/tty52
crw--w---- 1 root tty 4, 53 Apr 13 19:06 /dev/tty53
crw--w---- 1 root tty 4, 54 Apr 13 19:06 /dev/tty54
crw--w---- 1 root tty 4, 55 Apr 13 19:06 /dev/tty55
crw--w---- 1 root tty 4, 56 Apr 13 19:06 /dev/tty56
crw--w---- 1 root tty 4, 57 Apr 13 19:06 /dev/tty57
crw--w---- 1 root tty 4, 58 Apr 13 19:06 /dev/tty58
crw--w---- 1 root tty 4, 59 Apr 13 19:06 /dev/tty59
crw--w---- 1 root tty 4, 6 Apr 13 19:06 /dev/tty6
crw--w---- 1 root tty 4, 60 Apr 13 19:06 /dev/tty60
crw--w---- 1 root tty 4, 61 Apr 13 19:06 /dev/tty61
crw--w---- 1 root tty 4, 62 Apr 13 19:06 /dev/tty62
crw--w---- 1 root tty 4, 63 Apr 13 19:06 /dev/tty63
crw--w---- 1 root tty 4, 7 Apr 13 19:06 /dev/tty7
crw--w---- 1 root tty 4, 8 Apr 13 19:06 /dev/tty8
crw--w---- 1 root tty 4, 9 Apr 13 19:06 /dev/tty9
crw------- 1 root root 5, 3 Apr 13 19:06 /dev/ttyprintk
crw-rw---- 1 root dialout 4, 64 Apr 13 19:06 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Apr 13 19:06 /dev/ttyS1
crw-rw---- 1 root dialout 4, 74 Apr 13 19:06 /dev/ttyS10
crw-rw---- 1 root dialout 4, 75 Apr 13 19:06 /dev/ttyS11
crw-rw---- 1 root dialout 4, 76 Apr 13 19:06 /dev/ttyS12
crw-rw---- 1 root dialout 4, 77 Apr 13 19:06 /dev/ttyS13
crw-rw---- 1 root dialout 4, 78 Apr 13 19:06 /dev/ttyS14
crw-rw---- 1 root dialout 4, 79 Apr 13 19:06 /dev/ttyS15
crw-rw---- 1 root dialout 4, 80 Apr 13 19:06 /dev/ttyS16
crw-rw---- 1 root dialout 4, 81 Apr 13 19:06 /dev/ttyS17
crw-rw---- 1 root dialout 4, 82 Apr 13 19:06 /dev/ttyS18
crw-rw---- 1 root dialout 4, 83 Apr 13 19:06 /dev/ttyS19
crw-rw---- 1 root dialout 4, 66 Apr 13 19:06 /dev/ttyS2
crw-rw---- 1 root dialout 4, 84 Apr 13 19:06 /dev/ttyS20
crw-rw---- 1 root dialout 4, 85 Apr 13 19:06 /dev/ttyS21
crw-rw---- 1 root dialout 4, 86 Apr 13 19:06 /dev/ttyS22
crw-rw---- 1 root dialout 4, 87 Apr 13 19:06 /dev/ttyS23
crw-rw---- 1 root dialout 4, 88 Apr 13 19:06 /dev/ttyS24
crw-rw---- 1 root dialout 4, 89 Apr 13 19:06 /dev/ttyS25
crw-rw---- 1 root dialout 4, 90 Apr 13 19:06 /dev/ttyS26
crw-rw---- 1 root dialout 4, 91 Apr 13 19:06 /dev/ttyS27
crw-rw---- 1 root dialout 4, 92 Apr 13 19:06 /dev/ttyS28
crw-rw---- 1 root dialout 4, 93 Apr 13 19:06 /dev/ttyS29
crw-rw---- 1 root dialout 4, 67 Apr 13 19:06 /dev/ttyS3
crw-rw---- 1 root dialout 4, 94 Apr 13 19:06 /dev/ttyS30
crw-rw---- 1 root dialout 4, 95 Apr 13 19:06 /dev/ttyS31
crw-rw---- 1 root dialout 4, 68 Apr 13 19:06 /dev/ttyS4
crw-rw---- 1 root dialout 4, 69 Apr 13 19:06 /dev/ttyS5
crw-rw---- 1 root dialout 4, 70 Apr 13 19:06 /dev/ttyS6
crw-rw---- 1 root dialout 4, 71 Apr 13 19:06 /dev/ttyS7
crw-rw---- 1 root dialout 4, 72 Apr 13 19:06 /dev/ttyS8
crw-rw---- 1 root dialout 4, 73 Apr 13 19:06 /dev/ttyS9

I looked also this thread but doesn't work for me:
https://forum.proxmox.com/threads/pass-usb-device-to-lxc.124205/

Can anyone help me?
 
Hi,

you made a little mistake in your config file:

Instead of your code:
lxc.mount.entry: /dev/bus/usb/001/005 dev/bus/usb none bind,optional,create=file

Try this line:
lxc.mount.entry: /dev/bus/usb/001/005 dev/bus/usb/001/005 none bind,optional,create=file

The ttyACM is not relevant in your case.

After you saved the config file. Turn of your container and turn it on again. Try the nut-scanner -U command and you should see your UPS (USV).

The downside for this solution: After a shutdown or restart of the proxmox server, the usb port may be changed, so you need to adjust the config file again.
 
thanks for your reply. I'll try... About the USB port changing after a reboot, I'd like to assign a fixed port, so is there another solution?
 
Now I'd like to install (network UPS tool) NUT in this container. So I need to pass the UPS USB from the host to the container.

HOST-SIDE:
root@proxmoxea:~# lsusb
Bus 001 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply

There's software similar to NUT for American Power Conversion UPSs called apcupsd

It talks to the UPS via /dev/usb/hiddev0 - you might have more luck passing that through instead of the raw USB bus.

Note: I run apcupsd directly on the proxmox host rather than in an LXC, so it can shut the VMs and host down cleanly in case of an extended power outage, so I haven't verified if passing the hiddev0 device through is enough.

Bash:
MachineOfLovingGrace ~ # dmesg | grep 'American Power'
[    1.829442] usb 3-4: Manufacturer: American Power Conversion
[    1.837834] hid-generic 0003:051D:0002.0001: hiddev0,hidraw0: USB HID v1.00 Device [American Power Conversion Back-UPS RS 1500G FW:878.L4 .I USB FW:L4 ] on usb-0000:00:14.0-4/input0  
MachineOfLovingGrace ~ # ls -l /proc/`pidof apcupsd`/fd
total 0
lr-x------ 1 root root 64 May  1 08:28 0 -> /dev/null
lr-x------ 1 root root 64 May  1 08:28 1 -> /dev/null
lr-x------ 1 root root 64 May  1 08:28 2 -> /dev/null
lrwx------ 1 root root 64 May  1 08:28 3 -> /var/log/apcupsd.events
lrwx------ 1 root root 64 May  1 08:28 4 -> socket:[7544]
lrwx------ 1 root root 64 May  1 08:28 5 -> socket:[2715]
lrwx------ 1 root root 64 May  1 08:28 7 -> /dev/usb/hiddev0
l-wx------ 1 root root 64 May  1 08:28 8 -> /var/log/apcupsd.status
 
lxc.cgroup.devices.allow: c 189:* rwm
As per docs that should be:
Code:
lxc.cgroup2.devices.allow: c 189:* rwm

root@proxmoxea:/home# ls -l /dev/tty*
It looks like you are searching in your Proxmox host, I believe you should be searching in the LXC "Homeassistant" CT 102

About the USB port changing after a reboot
You have 2 options for this:

1. Create a udev rule, example here.
2. Pass the whole USB bus/ instead of just bus/port, example here.
 
Hi,

you made a little mistake in your config file:

Instead of your code:
lxc.mount.entry: /dev/bus/usb/001/005 dev/bus/usb none bind,optional,create=file

Try this line:
lxc.mount.entry: /dev/bus/usb/001/005 dev/bus/usb/001/005 none bind,optional,create=file

The ttyACM is not relevant in your case.

After you saved the config file. Turn of your container and turn it on again. Try the nut-scanner -U command and you should see your UPS (USV).

The downside for this solution: After a shutdown or restart of the proxmox server, the usb port may be changed, so you need to adjust the config file again.
with you suggested line (host side):
Code:
lxc.cgroup2.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/bus/usb/001/005 dev/bus/usb/001/005 none bind,optional,create=file

I have this (client side):
Code:
root@utilities:/# ls -l /dev/bus/usb/001/005
crw-rw-r-- 1 nobody nogroup 189, 4 May  3 18:46 /dev/bus/usb/001/005

this is the log of nut container:
Code:
root@utilities:/home/nut# docker compose logs
WARN[0000] /home/nut/docker-compose.yml: `version` is obsolete
nut-upsd  | + '[' -z mypasswd ]
nut-upsd  | + '[' -z  ]
nut-upsd  | + base64
nut-upsd  | + dd 'if=/dev/urandom' 'bs=18' 'count=1'
nut-upsd  | + ADMIN_PASSWORD=gerterHW0+3
nut-upsd  | + cat
nut-upsd  | + cat
nut-upsd  | + cat
nut-upsd  | + cat
nut-upsd  | + chgrp -R nut /etc/nut /dev/bus/usb
nut-upsd  | chgrp: /dev/bus/usb/001/005: Operation not permitted

Is this a permission problem?
 
Last edited:
lxc.cgroup2.devices.allow: c 189:* rwm lxc.mount.entry: /dev/bus/usb/001/005 dev/bus/usb/001/005 none bind,optional,create=file
Instead of mounting the device node into the container,

use the device passthrough feature instead:
Code:
pct set <vmid> --dev0 path=/dev/bus/usb/001/005
This creates a new device node within the container,

nut-upsd | chgrp: /dev/bus/usb/001/005: Operation not permitted
which should fix this error.
 
Instead of mounting the device node into the container,

use the device passthrough feature instead:
Code:
pct set <vmid> --dev0 path=/dev/bus/usb/001/005
This creates a new device node within the container,


which should fix this error.
Not sure i follow .. in prox8.1 setting the: pct set ... do a passthrought like any pci-e in vm.. So we do not have to deal anymore with the id 189* rwm ..
as i quickly check on prox 8.2 and the gui show line to set gid uid. Is the line / lxc.cgroup2.devices.allow: c 189:* rwm / is still needed to a proper pass in 8.1 when using the pct set lxcid ... or it required a change of 3 file to somehow get the guid-cid to set. ? (for unpriviledge container)
 
When using the container device passthrough feature, there is no need to manually specify allow device rules with lxc.cgroup2.devices.allow. This also works with unprivileged containers.

The options uid and gid specify the ids of the device node within the container. If not set, it defaults to uid=0 and gid=0.
Code:
pct set <vmid> --dev0 path=/dev/bus/usb/001/005,uid=0,gid=0
 
When using the container device passthrough feature, there is no need to manually specify allow device rules with lxc.cgroup2.devices.allow. This also works with unprivileged containers.
This is news for me. I personally don't use USB device passthrough to LXC, but would be eager to hear from other users who have managed this with the above pct set <vmid> --dev0 .... command alone (working).
 
This is news for me. I personally don't use USB device passthrough to LXC, but would be eager to hear from other users who have managed this with the above pct set <vmid> --dev0 .... command alone (working).
i got a usb tv tuner working in an unpriv plex lxc and a pci coral tpu in an unpriv frigate lxc with this method (but through the web gui through the resource > add > device passthrough menu). also got the igpu in both with the same method
 
  • Like
Reactions: gfngfn256

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!