Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So i'm trying to automount my usb sticks on my VirtualBox guest via udev.

There was a fine guide to it here:

https://forums.virtualbox.org/viewtopic.php?f=7&t=39374

The problem is that guide is reliant on usb_id which in ubuntu 12.04 is integrated in udev..

They made a udev rule that looked like so:

DRIVERS=="usb-storage", IMPORT{program}="usb_id --num-info --export %p", RUN+="/etc/udev/vbox-automount-usb.sh"

So I found a similar output by doing:

DRIVERS=="usb-storage",IMPORT{program}="/sbin/udevadm info --query=all --path=%p | sed 's/E: -*//g'", RUN+="/etc/udev/vboxusb.sh"

At least I think it's similar because I have nowhere to test a usb_id output.

So that problem seems to be out of the way .. Now the shell script.

#!/bin/bash

attach_storage()
{
  set `/usr/sbin/lsusb -d ${ID_VENDOR}:${ID_MODEL}| sed 's/:.*//g'`
  while [ ! -z "$1" ]; do
    case $1 in
      Bus) shift
      busdevice="$1"
      ;;
      Device) shift
      busdevice=${busdevice}"/$1"
      ;;
    esac
    shift
  done
  if [ ! -z "$busdevice" ]; then
    address=$(VBoxManage list usbhost | grep "Address:" | grep $busdevice | sed -e 's/Address://' -e 's/^[ \t]*//')
    if [ ! -z "$address" ]; then
      su - vbox_user -c "VBoxManage controlvm vm_name usbattach $address"
    fi
  fi
}

case $DEVNAME in
  /dev/sd[a-z])
  attach_storage;
  ;;
esac

First off lsusb is not in /usr/sbin but /usr/bin, and from what I can see the ID_VENDOR and ID_MODE actually needs to be ID_VENDOR_ID and ID_MODEL_ID if we want the output we are looking for.

So:

`set /usr/sbin/lsusb -d ${ID_VENDOR}:${ID_MODEL}| sed 's/:.*//g'`

needs to be:

set `/usr/sbin/lsusb -d ${ID_VENDOR_ID}:${ID_MODEL_ID}| sed 's/:.*//g'`

If I run the vbox commands in the shell script manually with the right data it works, but it's not working when I insert a USB drive..

Can anyone see a problem with the shell script i'm unable to see?

Or does anyone have an alternative working solution to this ?

share|improve this question
i'm thinking the rules file does not actually IMPORT the environment variables from the udevadm command.. the udevadm manual states that it needs to be environment key format .. isn't that just VARIABLE=BLA ? – Axlrod Sep 10 '12 at 14:11

1 Answer

As I understood, there are two versions of Virtualbox. One is open source and doesn't have the possibility to automount USB devices. There is another version with a freeware license (downloadable from the oracle website only), that would give the possibility to do so. I don't know if it really works or if it doesn't, but take a look at this.

Good luck!

share|improve this answer
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Oyibo Jan 15 at 15:01
I am not using VirtualBox OSE. – Axlrod Feb 1 at 9:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.