LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 06-05-2016, 04:05 PM   #1
TWfromSWD
LQ Newbie
 
Registered: Jun 2016
Posts: 8

Rep: Reputation: Disabled
usb device access from lxc container


Hi

I want to access a usb device on my host from inside an lxc container. I found a lot of information on the internet but I'm still not quite sure how to do this.

This is the device I need to access from inside the container:
Code:
Bus=01 Lev=02 Prnt=02 Port=03 Cnt=02 Dev#=  5 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=03(HID  ) Sub=00 Prot=ff MxPS=64 #Cfgs=  1
P:  Vendor=6666 ProdID=5555 Rev=01.00
S:  Manufacturer=LA CROSSE TECHNOLOGY
S:  Product=Weather Direct Light Wireless Device
S:  SerialNumber=0123456
C:  #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=30mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
This is a diff of the /dev directory content when unplugged
Code:
2,4d1
< ./hidraw0
< ./usb
< ./usb/hiddev0
85,87d81
< ./char/247:0
< ./char/180:96
< ./char/189:7
262d255
< ./bus/usb/001/008
And this is what I use to mount the device
Code:
lxc.mount.entry = /dev/bus/usb/001 dev/bus/usb/001  none bind,optional,create=dir
lxc.mount.entry = /dev/char dev/char  none bind,optional,create=dir
lxc.mount.entry = /dev/usb dev/usb none bind,optional,create=dir
lxc.mount.entry = /dev/hidraw0 dev/hidraw0  none bind,optional

lxc.cgroup.devices.allow = c 21:39 rwm
lxc.cgroup.devices.allow = c 189:* rwm
But still I can't access the device. Did I miss something?
 
Old 06-08-2016, 08:31 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Generally speaking unprivileged containers can't mount "real" devices, like USB. The UID of the process calling the device inside the container is going to be roughly equivelent to "nobody" when it's translated out of the namespace.
So the fix I normally shoot for is to have a process running on the host to catch a signal from the unpriveledged calling process in the container and mount/provide USB access as a service. In the container it's just another mounted directory, on the host it's a USB stick.
Hope that helps
 
Old 06-08-2016, 12:34 PM   #3
TWfromSWD
LQ Newbie
 
Registered: Jun 2016
Posts: 8

Original Poster
Rep: Reputation: Disabled
The container I'm running is a privileged container, so accessing devices shouldn't be a problem. At least for someone who understands lxc device handling and not for someone like me
 
Old 06-08-2016, 01:09 PM   #4
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Privileged containers?!?!?!?!?
Am I dealing with an individual so possessed of a singular valor that creating privileged containers is a non-issue for you or do you just not know what a huge security hole you're about create? You can use the container to develop in, but you wont deploy in a secure production facility like that. I always try to make my Dev environment as close to the Prod environment as possible (as there so here) but you, my friend, are apparently made of finer stuff than I.

That said, I'd check dmesg on both nodes and see if my Uber-container and my host can help us out a little. We need to see if it is trying to mount the thing and failing or just doesn't know how to try. If it's failing, udev is going to pitch a fit all over dmesg and syslog. If it doesn't know how to ask for it, it's going to fail quietly (no error in dmesg or syslog).
What are you running in this beast anyway?

Last edited by dijetlo; 06-08-2016 at 01:12 PM.
 
Old 06-08-2016, 01:24 PM   #5
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
I checked, people on the internet actually do this stuff (don't let it swell your head, they do a lot of crazy stuff on the internet).
The process is pretty simple, match the udev references, bind the mount point on the guest, add permissions in lxc.conf to allow the device passthrough and it should work.
Take a look at this and this and let me know if you have any questions.
 
Old 06-09-2016, 12:17 AM   #6
TWfromSWD
LQ Newbie
 
Registered: Jun 2016
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dijetlo View Post
What are you running in this beast anyway?
It's a compatibility thing. I'm using the wfrog weather station software with a special plugin to write the data my weather station collects into a mysql database. I'm currently redesigning my setup and so I decided to migrate the wfrog installation, along with some other stuff, to debian jessie. My problem is now, that the wfrog plugin doesn't work on jessie. And since I'm already using lxc on my new installation I decided to move the whole old wfrog wheezy installation into a container till I find a way to make it work on jessie (or till forever, who knows ). This wfrog container has no access to the outside world, except for a temporary internet connection for installing updates. It should only have access to the mysql database on the host to write it's data. So I don't think its a big security issue running it as privileged container.

And now I'm trying to learn how to use lxc property and how to let the wfrog plugin access the usb transceiver to connect with the weather station.
 
Old 06-09-2016, 11:12 AM   #7
TWfromSWD
LQ Newbie
 
Registered: Jun 2016
Posts: 8

Original Poster
Rep: Reputation: Disabled
Fun story: I actually did too much

I reduced my config entries to the following:
Code:
lxc.mount.entry = /dev/bus/usb/001 dev/bus/usb/001  none bind,optional,create=dir

# USB Dongle for weather station
lxc.cgroup.devices.allow = c 189:* rwm
and finally it works
Thanks for the help!
It may be possible to reduce the rights even further...

Now I just have to solve my internet access problem from the other thread

Last edited by TWfromSWD; 06-09-2016 at 11:14 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Internet acces for LXC container TWfromSWD Linux - Networking 3 06-14-2016 01:52 PM
LXC Container Namespaces Cgroup Ahmed83 Linux - Virtualization and Cloud 2 12-06-2015 04:31 AM
[SOLVED] Running ctdb in an LXC container PeterSteele CentOS 5 08-13-2015 07:45 AM
How to use Local ISO for LXC Container? sunveer Linux - Software 0 10-04-2013 04:44 AM
How to end a Linux Container (LXC) from within? Skaperen Linux - Virtualization and Cloud 0 06-14-2011 09:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 01:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration