C
C
cyber punk2016-06-29 10:31:37
LXC
cyber punk, 2016-06-29 10:31:37

How to forward a USB printer to an LXD container?

Before that, I used LXC containers on ubuntu 14.04, where I wrote printer forwarding in the configuration file in the form:

lxc.cgroup.devices.allow = c 189:* rwm
lxc.mount.entry = /dev/bus/usb/003 dev/bus/usb/003 none bind,optional,create=dir
lxc.mount.entry = /dev/usb/lp0 dev/usb/lp0 none bind,optional,create=file

How to forward (in this case a printer, but not the essence, in a similar way, I think other devices can be forwarded) using LXD?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cyber-punk, 2016-07-13
@cyber punk

The final solution has been found!
It turned out to forward, install and force the HP LaserJet 1000 printer (win-printer) to print from the LXD container.
So, for the standard, we take the config from Ubuntu 14.04 on which everything worked and try to do the same, but in LXD.
To forward a USB printer to an LXD container (in my example I use an HP LaserJet 1000 printer, the container is pre-deployed based on Ubuntu 16.04 and is called "print"), you need to do the following:
To do this, on the host, enter lsusb

[email protected]:~# lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 0bda:8197 Realtek Semiconductor Corp. RTL8187B Wireless Adapter
Bus 001 Device 003: ID 5986:0102 Acer, Inc Crystal Eye Webcam
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 03f0:0517 Hewlett-Packard LaserJet 1000
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

The printer is connected to Bus 003 Device 002.
Let's go to the container:
[email protected]:~# lxc exec print -- bash
[email protected]:~# lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 0bda:8197 Realtek Semiconductor Corp. RTL8187B Wireless Adapter
Bus 001 Device 003: ID 5986:0102 Acer, Inc Crystal Eye Webcam
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 03f0:0517 Hewlett-Packard LaserJet 1000
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

In my case, usbutils support and HP printer support, via hplip, are already installed.
For those who do not have it installed, you need to run in the container:
In the previous steps, we found out that the printer is connected to Bus 003 Device 002 on the host.
Now you need to find out who owns and with what rights the device files on the host, as well as the digital identifier of the gid group.
To do this, we will execute:
[email protected]:~# ll /dev/bus/usb/003
итого 0
drwxr-xr-x 2 root root       80 Июл 14 21:00 ./
drwxr-xr-x 6 root root      120 Июл 14 21:00 ../
crw-rw-r-- 1 root root 189, 256 Июл 14 21:00 001
crw-rw-r-- 1 root lp   189, 257 Июл 15 10:56 002

The information we are interested in is file 002, which is a char device owned by the root user and the lp group. The permissions of this file are 0664.
Now let's find out the numerical identifier of the lp group:
[email protected]:~# cat /etc/group | egrep lp
lp:x:7:

The numeric group ID is 7.
And finally, let's create these devices in the container. To do this, we will execute:
[email protected]:~# lxc config device add print lj1000 unix-char path=/dev/bus/usb/003/002 mode=0664 gid=7
Device lj1000 added to print
[email protected]:~# lxc config device add print lp0 unix-char path=/dev/usb/lp0 gid=7
Device lp0 added to print

(By default, the unix-char device is created with permissions 0660, so setting mode=0660 in the second command can be omitted)
We act according to the instructions displayed by the installation script.
Upon completion, the script will offer to print a test page, we agree and jump with happiness about the successful transfer of the printer to the LXD container.
To add container autostart after reboot, run:
[email protected]:~# lxc config set print boot.autostart true
[email protected]:~# lxc config set print boot.autostart.delay 5

This will automatically start the container 5 seconds after the host is rebooted.
The only problem you may encounter is device numbering on the bus after plugging the USB cable into another port or into the same port for a short period of time, but that's another story. As a tip, I can say that you can bind a device to the bus (provided it is connected to the same USB port) using the serial number of the device and such a wonderful thing as udev.
Thank you all for your attention!!!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question