Lxc usb problems

Hello!
The installed system debian 10.

uname -a

Linux 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5 (2019-06-19) x86_64 GNU/Linux

installed lxc

dpkg -l|grep lxc

ii liblxc1 1:3.1.0+really3.0.3-8 amd64 Linux Containers userspace tools (library)
ii lxc 1:3.1.0+really3.0.3-8 amd64 Linux Containers userspace tools
ii lxc-templates 3.0.3-1 amd64 Linux Containers userspace tools (templates)
ii lxcfs 3.0.3-2 amd64 FUSE based filesystem for LXC
ii python3-lxc 1:3.0.3-1 amd64 Linux Containers userspace tools (Python3 bindings)

my container
sudo lxc-create -n forPSQL -t debian
and its configuration file

cat /var/lib/lxc/forPSQL/config

lxc.net.0.type = veth
lxc.net.0.flags = up
lxc.net.0.link = br0
lxc.net.0.ipv4.gateway = 10.0.0.1
lxc.net.0.hwaddr = 00:16:3e:6b:c7:5b
lxc.net.0.ipv4.address = 10.0.0.3/24
lxc.apparmor.profile = generated
lxc.apparmor.allow_nesting = 1
lxc.rootfs.path = dir:/var/lib/lxc/forPSQL/rootfs
lxc.include = /usr/share/lxc/config/debian.common.conf
lxc.tty.max = 4
lxc.uts.name = forPSQL
lxc.arch = amd64
lxc.pty.max = 1024

before connecting the flash drive on the host

lsusb|nl

 1	Bus 009 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 2	Bus 004 Device 002: ID 04f2:b40e Chicony Electronics Co., Ltd HP Truevision HD camera
 3	Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 4	Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 5	Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 6	Bus 006 Device 002: ID 0bda:b001 Realtek Semiconductor Corp. 
 7	Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 8	Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
 9	Bus 005 Device 017: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
10	Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
11	Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
12	Bus 002 Device 002: ID 04f2:0833 Chicony Electronics Co., Ltd KU-0833 Keyboard
13	Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

before connecting the flash drive on the container

lsusb|nl

 1	Bus 009 Device 001: ID 1d6b:0001  
 2	Bus 004 Device 002: ID 04f2:b40e  
 3	Bus 004 Device 001: ID 1d6b:0002  
 4	Bus 008 Device 001: ID 1d6b:0001  
 5	Bus 001 Device 001: ID 1d6b:0002  
 6	Bus 006 Device 002: ID 0bda:b001  
 7	Bus 006 Device 001: ID 1d6b:0001  
 8	Bus 007 Device 001: ID 1d6b:0003  
 9	Bus 005 Device 017: ID 093a:2510  
10	Bus 005 Device 001: ID 1d6b:0002  
11	Bus 003 Device 001: ID 1d6b:0003  
12	Bus 002 Device 002: ID 04f2:0833  
13	Bus 002 Device 001: ID 1d6b:0002  

inserted the flash drive into the usb port
after connecting the flash drive on the host

lsusb|nl

 1	Bus 009 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 2	Bus 004 Device 002: ID 04f2:b40e Chicony Electronics Co., Ltd HP Truevision HD camera
 3	Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 4	Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 5	Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 6	Bus 006 Device 002: ID 0bda:b001 Realtek Semiconductor Corp. 
 7	Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 8	Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
 9	Bus 005 Device 017: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
10	Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
11	Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
12	Bus 002 Device 002: ID 04f2:0833 Chicony Electronics Co., Ltd KU-0833 Keyboard
13	Bus 002 Device 006: ID 13fe:4300 Kingston Technology Company Inc. 
14	Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

after connecting the flash drive on the container

lsusb|nl

 1	Bus 009 Device 001: ID 1d6b:0001  
 2	Bus 004 Device 002: ID 04f2:b40e  
 3	Bus 004 Device 001: ID 1d6b:0002  
 4	Bus 008 Device 001: ID 1d6b:0001  
 5	Bus 001 Device 001: ID 1d6b:0002  
 6	Bus 006 Device 002: ID 0bda:b001  
 7	Bus 006 Device 001: ID 1d6b:0001  
 8	Bus 007 Device 001: ID 1d6b:0003  
 9	Bus 005 Device 017: ID 093a:2510  
10	Bus 005 Device 001: ID 1d6b:0002  
11	Bus 003 Device 001: ID 1d6b:0003  
12	Bus 002 Device 002: ID 04f2:0833  
13	Bus 002 Device 006: ID 13fe:4300  
14	Bus 002 Device 001: ID 1d6b:0002  

Who knows why these things happen? How can I work with a flash drive in a container.

Hi,

how exactly do you connect the flash drive with the container ?

Can you please write down the steps how to reproduce this ?

Thank you !

  1. I opened mate-terminal

  2. opened two bookmarks (the first tab for host, the second tab for container)

  3. the first tab
    host:# lsusb|nl
    1 Bus 009 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    2 Bus 004 Device 002: ID 04f2:b40e Chicony Electronics Co., Ltd HP Truevision HD camera
    3 Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    4 Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    5 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    6 Bus 006 Device 002: ID 0bda:b001 Realtek Semiconductor Corp.
    7 Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    8 Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    9 Bus 005 Device 017: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
    10 Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    11 Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    12 Bus 002 Device 002: ID 04f2:0833 Chicony Electronics Co., Ltd KU-0833 Keyboard
    13 Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

  4. the second tab
    container:# lsusb|nl
    1 Bus 009 Device 001: ID 1d6b:0001
    2 Bus 004 Device 002: ID 04f2:b40e
    3 Bus 004 Device 001: ID 1d6b:0002
    4 Bus 008 Device 001: ID 1d6b:0001
    5 Bus 001 Device 001: ID 1d6b:0002
    6 Bus 006 Device 002: ID 0bda:b001
    7 Bus 006 Device 001: ID 1d6b:0001
    8 Bus 007 Device 001: ID 1d6b:0003
    9 Bus 005 Device 017: ID 093a:2510
    10 Bus 005 Device 001: ID 1d6b:0002
    11 Bus 003 Device 001: ID 1d6b:0003
    12 Bus 002 Device 002: ID 04f2:0833
    13 Bus 002 Device 001: ID 1d6b:0002

  5. physically installed the flash drive in the laptop port

  6. the first tab
    host:# lsusb|nl
    1 Bus 009 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    2 Bus 004 Device 002: ID 04f2:b40e Chicony Electronics Co., Ltd HP Truevision HD camera
    3 Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    4 Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    5 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    6 Bus 006 Device 002: ID 0bda:b001 Realtek Semiconductor Corp.
    7 Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    8 Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    9 Bus 005 Device 017: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
    10 Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    11 Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    12 Bus 002 Device 002: ID 04f2:0833 Chicony Electronics Co., Ltd KU-0833 Keyboard
    13 Bus 002 Device 006: ID 13fe:4300 Kingston Technology Company Inc.
    14 Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

  7. the second tab
    container:# lsusb|nl
    1 Bus 009 Device 001: ID 1d6b:0001
    2 Bus 004 Device 002: ID 04f2:b40e
    3 Bus 004 Device 001: ID 1d6b:0002
    4 Bus 008 Device 001: ID 1d6b:0001
    5 Bus 001 Device 001: ID 1d6b:0002
    6 Bus 006 Device 002: ID 0bda:b001
    7 Bus 006 Device 001: ID 1d6b:0001
    8 Bus 007 Device 001: ID 1d6b:0003
    9 Bus 005 Device 017: ID 093a:2510
    10 Bus 005 Device 001: ID 1d6b:0002
    11 Bus 003 Device 001: ID 1d6b:0003
    12 Bus 002 Device 002: ID 04f2:0833
    13 Bus 002 Device 006: ID 13fe:4300
    14 Bus 002 Device 001: ID 1d6b:0002

  8. the second tab
    container:# ls -alh /dev/
    итого 4,0K
    drwxr-xr-x 7 root root 520 сен 12 11:44 .
    drwxr-xr-x 20 root root 4,0K сен 12 11:44 …
    crw–w---- 1 root tty 136, 2 сен 12 11:45 console
    lrwxrwxrwx 1 root root 11 сен 12 11:44 core -> /proc/kcore
    lrwxrwxrwx 1 root root 13 сен 12 11:44 fd -> /proc/self/fd
    crw-rw-rw- 1 root root 1, 7 сен 12 11:44 full
    drwxr-xr-x 2 root root 0 сен 12 11:44 hugepages
    lrwxrwxrwx 1 root root 12 сен 12 11:44 initctl -> /run/initctl
    lrwxrwxrwx 1 root root 28 сен 12 11:44 log -> /run/systemd/journal/dev-log
    drwxr-xr-x 4 root root 80 сен 12 11:44 .lxc
    drwxrwxrwt 2 root root 40 сен 12 11:44 mqueue
    crw-rw-rw- 1 root root 1, 3 сен 12 11:44 null
    crw-rw-rw- 1 root root 5, 2 сен 15 20:32 ptmx
    drwxr-xr-x 2 root root 0 сен 12 11:44 pts
    crw-rw-rw- 1 root root 1, 8 сен 12 11:44 random
    drwxrwxrwt 2 root root 40 сен 12 11:44 shm
    lrwxrwxrwx 1 root root 15 сен 12 11:44 stderr -> /proc/self/fd/2
    lrwxrwxrwx 1 root root 15 сен 12 11:44 stdin -> /proc/self/fd/0
    lrwxrwxrwx 1 root root 15 сен 12 11:44 stdout -> /proc/self/fd/1
    crw-rw-rw- 1 root root 5, 0 сен 15 20:30 tty
    crw–w---- 1 root tty 136, 0 сен 12 11:44 tty1
    crw–w---- 1 root tty 136, 1 сен 12 11:44 tty2
    crw–w---- 1 root tty 136, 2 сен 12 11:44 tty3
    crw–w---- 1 root tty 136, 3 сен 12 11:44 tty4
    crw-rw-rw- 1 root root 1, 9 сен 12 11:44 urandom
    crw-rw-rw- 1 root root 1, 5 сен 12 11:44 zero

the problem is that the container sees all devices simultaneously with the host, but not fully and can not work with them

Hi,

ok so i assume you run the container in priviliged mode, to be able to see changes in /dev

But if i understand you right, you do not assign the usb device to the container by something like

lxc config device add ....

https://lxd.readthedocs.io/en/latest/containers/#type-usb

I think to see the entry in /dev might/will? not be enough to actually use it.

Please try to add the usb device by command to the container ( see the link above )

yes, i run the container in privileged mode

lxc config device add …
bash: lxc: command not found

ls /usr/bin/lxc*
/usr/bin/lxc-attach /usr/bin/lxc-checkconfig /usr/bin/lxc-console /usr/bin/lxc-destroy /usr/bin/lxc-freeze /usr/bin/lxc-ls /usr/bin/lxc-start /usr/bin/lxc-unshare /usr/bin/lxc-wait
/usr/bin/lxc-autostart /usr/bin/lxc-checkpoint /usr/bin/lxc-copy /usr/bin/lxc-device /usr/bin/lxcfs /usr/bin/lxc-monitor /usr/bin/lxc-stop /usr/bin/lxc-update-config
/usr/bin/lxc-cgroup /usr/bin/lxc-config /usr/bin/lxc-create /usr/bin/lxc-execute /usr/bin/lxc-info /usr/bin/lxc-snapshot /usr/bin/lxc-unfreeze /usr/bin/lxc-usernsexec

#lxc-device add -n forPSQL Kingston usb vendorid=13fe productid=4300
lxc-device: forPSQL: tools/lxc_device.c: main: 172 Failed to add Kingston to forPSQL

sorry, my fault, thats lxc, not lxd…

I am currently starting to learn about lxc, so i am not of big help here.

But did you already try something like this ? :

https://unix.stackexchange.com/questions/137931/usb-passthrough-for-lxc-containers#137936