Technical

Proxmox LXC USB Passthrough Device Name Colon: Fix It With a Systemd Override

Proxmox LXC USB Passthrough Device Name Colon: Fix It With a Systemd Override

Proxmox LXC USB passthrough device name colon is a pain because systemd escapes colons in device names, so your container can’t find the device after a reboot. The fix is a systemd override that creates a stable symlink without the colon.

Closeup of smart usb port multiplier with inserted memory card connected to modern thin netbook while placed on wooden t

Why the colon breaks passthrough

LXC passes USB devices by their path under /dev/bus/usb. A device name like Bus 001 Device 005: ID 0781:5583 SanDisk Corp. includes a colon in the ID, but the actual device node is just /dev/bus/usb/001/005. When you add a passthrough line in the container config, you might reference the device by its full name with the colon, and LXC tries to match that string. systemd escapes colons in unit names and device paths, so the match fails. The device works when you hotplug it manually, but after a reboot the container starts before the device is ready, or the name changes, and the passthrough silently fails.

The working config

First, find the device’s vendor and product ID with lsusb. Then add a line to the container config file, usually at /etc/pve/lxc/<CTID>.conf:

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

That’s the straightforward way, but it relies on the bus and device numbers staying the same. They don’t. Plug the device into a different port and it’s 002/003. Reboot and it might be 001/004. So you need a stable symlink.

Modern cellphone in transparent cover with closeup of charging input and mobile phone white charger cable usb connector

Systemd override for a stable symlink

Create a udev rule to make a symlink with a name that has no colon. Put this in /etc/udev/rules.d/99-usb-symlink.rules:

SUBSYSTEM=="usb", ATTR{idVendor}=="0781", ATTR{idProduct}=="5583", SYMLINK+="usb-sandisk"

Then reload udev and replug the device. Now you have /dev/usb-sandisk. But the container still needs the device node inside its namespace. LXC can mount the symlink target, but if the symlink points to a path with a colon (like the original device name), the same escaping problem happens. Instead, use a systemd override to create a bind mount inside the container at boot.

Create a systemd unit override for the container service. For container 100, the service is pve-container@100.service. Create the directory and override file:

mkdir -p /etc/systemd/system/pve-container@100.service.d
cat > /etc/systemd/system/pve-container@100.service.d/usb-passthrough.conf <<EOF
[Service]
ExecStartPre=/bin/sh -c 'mkdir -p /var/lib/lxc/100/rootfs/dev/bus/usb/001 && cp /dev/usb-sandisk /var/lib/lxc/100/rootfs/dev/bus/usb/001/005'
EOF

This copies the device node into the container’s rootfs before the container starts. It’s ugly but it works. The device node is just a file, so copying it gives the container access. You’ll need to adjust the container ID and the target path.

My take

This is a stupid problem that shouldn’t exist. The whole point of LXC is to share the host’s kernel, so passing a USB device should be a one-liner. But systemd’s escaping rules and LXC’s path matching make it a mess. The systemd override is a hack, but it’s a hack that survives reboots, which is more than the official docs give you. If you’re doing this for a printer or a scanner, consider a VM instead. USB passthrough in QEMU is way more mature. But if you’re stuck with LXC, this gets the job done.

Related: needrestart false positive: why it triggers on Proxmox and in LXC containers

Leave a comment

Comments are reviewed before they appear. Your email is never published.