Howto: passthrough USB scanner to OpenVZ container/guest

JimBeam

Member
Aug 26, 2010
74
1
6
Just got this working (well, lsusb and sane-find-scanner in the guest report results):
Goal: passthrough a USB scanner (could also be another device) to an OpenVZ guest.
Adjusted from the USB printing howto from OpenVZ: http://wiki.openvz.org/USB_Printing_in_VE as well as some posts on getting Dahdi/Zaptel devices passed through when working with the Asterisk VOIP PABX.
Using a Canon scanner as an example; adjust where required.

Host USB device name
We want our scanner to have a fixed name that we can forward to the guest. We use udev rules to create an extra, fixed name depending on device. I had also set up sane on the host and set up sane rules so the host device is assigned to the scanner. Don't know if this is necessary, I presume it isn't.

Code:
#Use lsusb to find out your own scanner's vendor and product codes
#<vendor>:<product>... and adjust commands accordingly
lsusb
cat >> /lib/udev/rules.d/99-local-installation.rules << "EOF_DOCUMENT"
#make sure the scanner is reachable under the same name (/dev/flatbedscanner) regardless of USB port etc.
#obviously, adjust vendor and product codes
ATTRS{idVendor}=="04a9", ATTRS{idProduct}=="1313", MODE="0664", GROUP="scanner", ENV{libsane_matched}="yes", SYMLINK+="flatbedscanner"
EOF_DOCUMENT

#Restart udev:
/etc/init.d/udev restart
#Unplug the scanner and plug it in again.
#the device should now appear:
ls -al /dev/flatbedscanner

Host passthrough
Assuming we're using vmid 102; adjust as required.
Code:
# stop machine
vzctl stop 102
#pass through scanner, and save into config for vm 102
#which should create /dev/flatbedscanner in the guest
#with read/write access
vzctl set --devnode flatbedscanner:rw --save 102
#check config
cat /etc/pve/openvz/102.conf

Guest device setup
In the guest, we should now have a /dev/flatbedscanner. However, that is not enough for sane as it apparently expects/looks for/dev/usb/..something.
We will make it happy:
Code:
vzctl start 102
vzctl enter 102
# more or less a random bus, presumably good idea to pick one that doesn't exist; adjust other commands accordingly
mkdir -p /dev/bus/usb/001 
# just link the /dev/bus/usb/001/002 device to the device the hosted passed on to us:
ln -s /dev/flatbedscanner /dev/bus/usb/001/002
reboot
#back in host
vzctl enter 102
#now you should see the scanner:
lsusb
#if you have sane installed, try this:
sane-find-scanner
Also, in the guest I set up sane, and assigned /dev/flatbedscanner using udev rules, but I wonder whether this is necessary.

Hope this helps; corrections and confirmations welcome.
 
COOL .. THANKS!! only difference in with promox 2.1 ( I guess.. ) is the command:

vzctl set 103 --devnode quickwebcam:r --save

compared to

vzctl set --devnode quickwebcam:r --save 103 (unless that was a typo),

But i managed to connect my webcam to a container which will be running Motion..

Thanks again..
 
Thanks a lot for sharing this!

In my case i am passing through a hashbuster mirco Bitcoin miner to a OpenVZ container.
Still works in Proxmox 3.1 with "vzctl set 109 --devnode hashbuster:RW, --save"