LXC USB Printer Server

Giggling3999

Member
Apr 2, 2024
88
6
8
Hi

I'm trying to set up a LXC print/scan container - But I have a problem

I have an LXC - I pass through the device via /dev/bus/usb/005/105 etc

The usb number changes each time that I turn on the printer - I am also unsure if there WAS some way to dynamically map it , does an LXC allow for the device to be passed on creation? i.e. without rebooting the LXC

Is a VM the only way to achieve this?
 
I'll let the experts chime in with specific information, but you might be able to setup udev rules on the host to map the printer to a specific path. Try some searches for udev usb printer mapping, or maybe someone later can provide specific information.
 
Thanks for the input - I'll have a look around

Tearing my bloody hair out trying to get the damn printer to work with usb in the first place!
 
So - I came up with a udev rule that symlink a /dev/printer - I also saw a solution of passing a /dev/serial - But this folder does not exist for me

Code:
nano /etc/udev/rules.d/98-printer.rules

SUBSYSTEMS=="usb", ATTRS{idVendor}=="04f9", ATTRS{idProduct}=="02ce", SYMLINK+="printer", MODE="0777"

I then modify the LXC

Code:
nano /etc/pve/lxc/109.conf 

dev0: /dev/printer,mode=0777

This APPEARS to work - I can see it in the LXC - However - There is IO issues and it can't print/scan - Any help appreciated
Code:
 lsusb

Bus 005 Device 031: ID 04f9:02ce Brother Industries, Ltd DCP-7055W

ls -la /dev

crwxrwxrwx  1 root   root   189, 542 Apr 24 07:03 printer

sane-find scanner

could not open USB device 0x04f9/0x02ce at 005:031: No such device (it may have been disconnected)
 
The problem appears to be that even though it is passed correctly, it is still expecting the bus and device location 005:031 in the above.

If I manually map it to that location - No problem - The problem is doing that - Dynamically
 
The only way I have been able to achieve what I wanted it by passing an entire usb and moving devices around, so that only the printer is on a bus - Although, I suspect it would just share the other devices, also

The bus hub is always device 001 - As far as I am aware - I get the IDs with

Code:
ls -la /dev/bus/usb/005/001 
crw-rw-r-- 1 root root 189, 512 May 10 13:10 /dev/bus/usb/005/001

then I modify my lxc and add the following lines - Passing the entire bus as a directory

Code:
nano /etc/pve/lxc/114.conf

lxc.cgroup2.devices.allow: c 189:512 rwm
lxc.mount.entry: /dev/bus/usb/005 dev/bus/usb/005 none bind,optional,create=dir

This also solves the VM problem that I had - Which is - That a VM with a powered down mapped usb will not start, as it is unable to detect it