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 ?