3

I am fairly new to LXD Conatiners. I have a Host ubuntu 16.04 machine running which has a single container :

root@ubuntu-blade1:/etc/udev/rules.d# lxc list
+-------------+---------+----------------------+------+------------+-----------+
|    NAME     |  STATE  |         IPV4         | IPV6 |    TYPE    | SNAPSHOTS |
+-------------+---------+----------------------+------+------------+-----------+
| nish-ubuntu | RUNNING | 10.20.186.185 (eth0) |      | PERSISTENT | 0         |
+-------------+---------+----------------------+------+------------+-----------+
root@ubuntu-blade1:/etc/udev/rules.d# 

I have a attached USB device to the main host system :

Disk /dev/sde: 14.7 GiB, 15795748864 bytes, 30851072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0527cd14

The lsusb output is as follows :

root@ubuntu-blade1:/etc/udev/rules.d# lsusb
Bus 002 Device 005: ID 8564:1000 Transcend Information, Inc. JetFlash
Bus 002 Device 004: ID 0424:2512 Standard Microsystems Corp. USB 2.0 Hub
Bus 002 Device 003: ID 0424:2512 Standard Microsystems Corp. USB 2.0 Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 005: ID 0624:0251 Avocent Corp. Virtual Mass Storage
Bus 001 Device 004: ID 0624:0249 Avocent Corp. Virtual Keyboard/Mouse
Bus 001 Device 003: ID 0624:0248 Avocent Corp. Virtual Hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Now i need to detect/attach the usb (/dev/sde ) inside the container. I am having a little context of udev and seen a couple of stack question on same issue but none have a clear procedure to do so. Can someone please guide ?

4

This question is quite old, but I stumbled upon the same use case today and I found a solution so easy that probably it wasn't available 7 months ago.

At this link one can find more information, but essentially it is this way:

let's say we have a modem device (AT commands) on /dev/ttyUSB2 and a container "xenial1", one can add ttyUSB2 to the container with the following command:

$ lxc config device add xenial1 ttyUSB2 unix-char path=/dev/ttyUSB2

it does not matter whether the container is running or not

This configuration is permanently saved in the container's default profile:

$ lxc config show xenial1
architecture: x86_64
config:
  security.privileged: "true"
  volatile.base_image: <numbers>
  volatile.eth0.hwaddr: xx:xx:xx:xx:xx:xx
  volatile.idmap.base: "0"
  volatile.idmap.next: '[]'
  volatile.last_state.idmap: '[]'
  volatile.last_state.power: RUNNING
devices:
  root:
    path: /
    type: disk
  ttyUSB1:
    path: /dev/ttyUSB1
    type: unix-char
  ttyUSB2:
    path: /dev/ttyUSB2
    type: unix-char
ephemeral: false
profiles:
- default

In order to delete a device, use "remove" command in place of "add".

NOTE: my container is "privileged", so this solution might not work on unpriviledged containers

| improve this answer | |
  • 1
    okay, i found a tool called "USB-Redirector" , which can do so without caring privalaged vs unprivileged container (incentivespro.com/usb-redirector.html), it runs in client-server mode . I think i did tried adding it via add command as well but didn't worked out.. maybe coz it was a unprivileged container – Nishant Singh Feb 18 '17 at 19:34
3

if you are using an unpriviliged container, you might also set the right permissions for that device... i expierienced, that this was the case, when i tryed to use a webcam in a container... maybe this also helps here...

lxc config device add containerName yourNameForTheDevice unix-char path=/path/to/device

lxc config device set containerName yourNameForTheDevice mode 666

also be aware of the fact, that usb-passthrough only works with lxd 2.5 or higher, as Stephan Graber writes at https://stgraber.org/ (scroll down to USB devices in containers). so maybe you also need to add the repository from the lxd-developers.... at this moment, the "normal" ubuntu-xenial repositorys only has lxd-version 2.0.9

check wich version you have with

dpkg -l lxd

take a look at this page and consider using that repository: https://launchpad.net/~ubuntu-lxc/+archive/ubuntu/lxd-stable

if you do so, you could update it to version 2.15

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.