Thursday, August 7, 2014

Connect a Usb device through Vagrant

If you want to list your usb devices do this:
$ VBoxManage list usbhost
Host USB Devices:

<none>
On a pure VirtualBox setup it says nothing. Usb devices won't work in your virtual machine until you don't see something in the list. So, you'll need to do two things to fix this:

  • Install VirtualBox Extension Pack (from here)
  • You have to be (your currently logged in user) in the vboxusers group
    • sudo usermod -a -G vboxusers <username>
    • and you have to logout/login from your session!

When you have done with these steps, run the list usbhost again:
$ VBoxManage list usbhost
Host USB Devices:

UUID:               55d6661d-dd23-487c-8f97-23d4cd4f7378
VendorId:           0x064e (064E)
ProductId:          0x8125 (8125)
Revision:           40.16 (4016)
Port:               4
USB version/speed:  2/2
Manufacturer:       SuYin
Product:            Laptop_Integrated_Webcam_HD
Address:            sysfs:/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.5//device:/dev/vboxusb/001/004
Current State:      Busy

UUID:               e96c6aef-f8a7-4f18-a67e-07776c7d839e
VendorId:           0x0bda (0BDA)
ProductId:          0x0129 (0129)
Revision:           57.96 (5796)
Port:               2
USB version/speed:  2/2
Manufacturer:       Generic
...

In Vagrantfile you have to enable the usb option and add a filter based on the desired Manufacturer and Product:
config.vm.provider "virtualbox" do |vb|
  ...
  vb.customize ["modifyvm", :id, "--usb", "on"]
  vb.customize ["modifyvm", :id, "--usbehci", "on"]
  vb.customize ["usbfilter", "add", "0", 
    "--target", :id, 
    "--name", "This is the identifier",
    "--manufacturer", "SuYin",
    "--product", "Laptop_Integrated_Webcam_HD"]
  ...
end  
You are all set.

Run vagrant up and ssh in your vm with vagrant ssh. In your vm run lsusb and you should see the connected usb device!

2 comments:

  1. I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot!
    USB名入れ

    ReplyDelete
  2. Excellent blog!
    What if I have a Windows host? How can I add the user to vboxusers group?

    ReplyDelete