[Solved]: USB Automount

Discussions related to using VirtualBox on Linux hosts.
Post Reply
bundabrg
Posts: 47
Joined: 22. Feb 2008, 04:01

[Solved]: USB Automount

Post by bundabrg »

VirtualBox: 1.6.2
Host: Ubuntu Hardy 8.04 i386
Guests: Windows XP, Windows 2003 Server

I've hit a wall and hope someone can help. I'm sure (if memory serves me) that I used to be able to setup a guest with a 'default' usb filter (ie match everything) and when it boots I could just plug in any usb device and it is automatically seen by the guest. I'm reasonably certain I used to be able to do that in 1.5.6.

Running now with 1.6.2, this does not work. If I plug in a USB device to the host and issue a "VBoxManage list usbhost", it simply returns the devices with a "Current Status: Busy".

If I run under 'VirtualBox' GUI, and then select the device from the menu, it will capture it, and will show "Current Status: Captured"

Is there anyway to have the guest automatically capture the device?

Failing that, I've not yet worked out how one is able to 'trigger' a capture through VBoxSDL. There doesn't seem to be a host-key shortcut unless I'm missing something? Does that mean using VBoxSDL its impossible to use USB?

Brendan
Last edited by bundabrg on 27. Jul 2008, 04:41, edited 1 time in total.
bundabrg
Posts: 47
Joined: 22. Feb 2008, 04:01

Post by bundabrg »

Just to answer myself, I think the closest thing that _may_ work is:
- Using HAL, have it execute 'VBoxManage controlvm usbattach' each time a usb device is attached to the system.

Brendan
brandonheat
Posts: 10
Joined: 26. Jul 2008, 14:13

Post by brandonheat »

I write udev rules to do that, see below. Hope it is helpful to you.
you may need to modify the script a bit for your case. --brandon

Here's
  • DRIVERS=="usb-storage",IMPORT{program}="usb_id --num-info --export %p", RUN+="/etc/udev/vboxusb.sh"
where vboxusb.sh does,

Code: Select all

#!/bin/sh                                                                    
                                                                             
attach_storage()                                                             
{                                                                            
  set `/sbin/lsusb -d ${ID_VENDOR}:${ID_MODEL}| sed 's/:.*//g'`        
  while [ ! -z "$1" ]; do                                              
    case $1 in                                                   
      Bus) shift                                           
      address="/proc/bus/usb/$1"                           
      ;;                                                   
      Device) shift                                        
      address=${address}"/$1"                              
      ;;                                                   
    esac                                                         
    shift                                                        
  done                                                                 
  if [ ! -z "$address" ]; then                                         
    su - root -c "VBoxManage controlvm  winxp usbattach"         
  fi                                                                   
}                                                                            
                                                                             
case $DEVNAME in                                                             
  /dev/sd[a-z])                                                        
  attach_storage;                                                      
  ;;                                                                   
esac 
bundabrg
Posts: 47
Joined: 22. Feb 2008, 04:01

Post by bundabrg »

Thanks, that's exactly what I was going to do. You saved me some work.

I vote for this to be added to a FAQ or manual entry.

- Brendan
dutch1918
Posts: 7
Joined: 24. Jul 2008, 14:52

Post by dutch1918 »

Being a linux newbie (I'm using "ubuntu" with WinXP guest. Were does one place the following:

DRIVERS=="usb-storage",IMPORT{program}="usb_id --num-info --export %p", RUN+="/etc/udev/vboxusb.sh"
bundabrg
Posts: 47
Joined: 22. Feb 2008, 04:01

Post by bundabrg »

Check /etc/udev/rules.d.

Most likely you'd need to create a new file there.

- Brendan
tave
Posts: 8
Joined: 20. Jun 2008, 03:18

USB Automount

Post by tave »

Im a bit confused on what to do with this. I have created the .sh file with the code provided and put it in the udev folder, but I am not sure what to do with the line

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

Do I use this to call the vboxusb.sh file, put it in the file or is there somewhere to put it in the system?

This is pretty new to me but if I can get this working I will have very happy clients so hopefully someone will beable to help me :D.

Thanks in advance!!
Tave
tave
Posts: 8
Joined: 20. Jun 2008, 03:18

Post by tave »

Ok, so I know how to call an sh file now.
In the command line I type "sh vboxusb.sh" to call the sh file but it still doesn't work?

Im still unsure what to do with this line.
DRIVERS=="usb-storage",IMPORT{program}="usb_id --num-info --export %p", RUN+="/etc/udev/vboxusb.sh"
I have this in the file vboxusb.sh

Code: Select all

#!/bin/sh                                                                   
                                                                             
attach_storage()                                                             
{                                                                           
  set `/sbin/lsusb -d ${ID_VENDOR}:${ID_MODEL}| sed 's/:.*//g'`       
  while [ ! -z "$1" ]; do                                             
    case $1 in                                                   
      Bus) shift                                           
      address="/proc/bus/usb/$1"                           
      ;;                                                   
      Device) shift                                       
      address=${address}"/$1"                             
      ;;                                                   
    esac                                                         
    shift                                                       
  done                                                                 
  if [ ! -z "$address" ]; then                                         
    su - root -c "VBoxManage controlvm  winxp usbattach"         
  fi                                                                   
}                                                                           
                                                                             
case $DEVNAME in                                                             
  /dev/sd[a-z])                                                       
  attach_storage;                                                     
  ;;                                                                   
esac
If anyone can help I would be really appreciate it!
rtirrell
Posts: 4
Joined: 19. Jul 2009, 23:59
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Vista, XP

Re: [Solved]: USB Automount

Post by rtirrell »

Late, but this helped me, so someone else might read it...
You'll want to put that line in a file in /etc/udev/rules.d/. Call the file whatever you please, as long as it's beginning with a number (if you're unsure which, 30 should work, check the README that should be in that directory for more info) and has extension .rules. I don't think the permissions matter.
dyd
Posts: 1
Joined: 23. Nov 2012, 17:35

Re: [Solved]: USB Automount

Post by dyd »

To make it work I had to change a few lines:

Code: Select all

#!/bin/bash

attach_storage()
{
  set `lsusb -d ${ID_VENDOR_ID}:${ID_MODEL_ID}| 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 user_name -c "VBoxManage controlvm vm_name usbattach $address"
    fi
  fi
}

case $DEVNAME in
  /dev/sd[a-z])
  attach_storage;
  ;;
esac
Obviously you have to replace user_name with yours as well as vm_name.
Post Reply