Recently, I am interested in SBC (single-board computer) and need to prepare a Linux development environment because many utilities/tools/packages are ONLY available on Linux (such as cross-compiler). I have 2 Mac mini and 1 MBP, and I want to share the Linux development environment among these computers with minimal efforts. Then, it comes to me to utilize Vagrant and VirtualBox to automate Linux environment setup.

Then, I meet several problems... Here I explain how those problems are solved, and the results are committed to github.

USB SD-Card Reader

Now popular SBCs use SD-card as storage to store Linux or Android, so it's necessary to use dd command to write Linux/Android images onto SD-card. For this purpoase, I select one combo card reader: Digifusion SD2 GO 120 in 1:

However, when the Digifusion card reader is connected to the USB port on my MBP, the card reader is automatically mounted by Mac OSX. Of course I can manually add USB filter with VirtualBox GUI

But I don't like GUI that breaks my idea to automate development environment setup. So, I need to automate it with VBoxManage.

First, it's failed to enable virtual USB controller. You need to install VirtualBox 4.2.18 Oracle VM VirtualBox Extension Pack. After installing extension pack, the --usb on and --usbehci on can work successfully with Vagrantfile:

box.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--usb", "on"]
    vb.customize ["modifyvm", :id, "--usbehci", "on"]

Second, you need to add USB filter with VBoxManage usbfilter command. Before writing the filter, you can observe that Digifusion card reader is treated as mass storage:

$ VBoxManage list usbhost
UUID:               493f68ba-d20c-4830-94dc-db372fdc7236
VendorId:           0x05ac (05AC)
ProductId:          0x8510 (8510)
Revision:           128.37 (12837)
Port:               1
USB version/speed:  0/2
Manufacturer:       Apple Inc.
Product:            FaceTime HD Camera (Built-in)
SerialNumber:       CC2D4K0FFXDN9KE0
Address:            p=0x8510;v=0x05ac;s=0x00000f28d601571d;l=0x1a110000
Current State:      Busy

UUID:               13e7ef3b-e262-48b0-9281-fe8b988d4446
VendorId:           0x14cd (14CD)
ProductId:          0x127a (127A)
Revision:           1.0 (0100)
Port:               1
USB version/speed:  0/2
Manufacturer:       Generic
Product:            Mass Storage Device
SerialNumber:       127A20090522
Address:            p=0x127a;v=0x14cd;s=0x00002a2d9bb767a7;l=0x1d110000
Current State:      Held

So, to solve the problem simply, I add one USB filter to allow VirtualBox to mount any USB mass storage onto the VM:

box.vm.provider :virtualbox do |vb|
    vb.customize ["usbfilter", "add", "0", 
        "--target", :id, 
        "--name", "Any mass storage", 
        "--manufacturer", "Generic",
        "--product", "Mass Storage Device"]

With above script, when the VM is launched with vagrant up command, you can see one USB filter "Any mass storage" is added in VirtualBox GUI:

And, the devices in Ubuntu (precise64) for Digifusion card reader are mounted as sdb ~ sdd:

vagrant@sbc-env:~$ ls -al /dev/sd*
brw-rw---- 1 root disk 8,  0 Oct 13 16:46 /dev/sda
brw-rw---- 1 root disk 8,  1 Oct 13 16:46 /dev/sda1
brw-rw---- 1 root disk 8,  2 Oct 13 16:46 /dev/sda2
brw-rw---- 1 root disk 8,  5 Oct 13 16:46 /dev/sda5
brw------- 1 root root 8, 16 Oct 13 16:47 /dev/sdb
brw------- 1 root root 8, 17 Oct 13 16:47 /dev/sdb1
brw------- 1 root root 8, 18 Oct 13 16:47 /dev/sdb2
brw-rw---- 1 root disk 8, 32 Oct 13 16:47 /dev/sdc
brw-rw---- 1 root disk 8, 48 Oct 13 16:47 /dev/sdd