Wednesday, January 7, 2009

VirtualBox, USB & Kubuntu Intrepid

First of all, USB will not work with VirtualBox OSE found in the Ubuntu repositories. You have to download the compiled binary files from Sun. There are many, many Internet references to getting the USB system to work in VirtualBox, but very few make this very important point. You can get your VirtualBox system up and running using the OSE version, in order to make sure that everything works according to the book. After that, you can install the binaries from Sun, which will pick up your virtual machine and its settings with no problem, including the VirtualBox Guest Additions, if they are installed (which should be as far as I'm concerned, but getting those additions installed has issues of its own).

First off, you must add yourself to the group vboxusers (System>KUser Manager). Select the Groups tab and look for vboxusers (#121 on my system). Click on it and you will get the "Group Properties" dialog. Find your username in the right hand box, select yourself and add it to the group. Close the User Manager.

Now comes the magic bits. You now have to do some editing.

Edit mountdevsubfs.sh:

sudo kate /etc/init.d/mountdevsubfs.sh

Near the beginning of the file, you will see the following:

do_start () {
#
# Mount a tmpfs on /dev/shm
#
SHM_OPT=
[ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE"
domount tmpfs shmfs /dev/shm tmpfs -onosuid,nodev$SHM_OPT

#
# Mount /dev/pts. Master ptmx node is already created by udev.
#
domount devpts "" /dev/pts devpts -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
}


Add the following lines before the final brace (}) (copy and paste them to avoid errors such as unwanted line breaks):

#
# Magic to make /proc/bus/usb work
#
mkdir -p /dev/bus/usb/.usbfs
domount usbfs "" /dev/bus/usb/.usbfs usbfs -obusmode=0700,devmode=0600,listmode=0644
ln -s .usbfs/devices /dev/bus/usb/devices
mount --rbind /dev/bus/usb /proc/bus/usb


Save mountdevsubfs.sh

Now run mountdevsubfs.sh:

sudo /etc/init.d/mountdevsubfs.sh start

You now need to edit two rules files:

sudo kate /etc/udev/rules.d/40-permissions.rules

Add the following lines at the end:

# USB devices (usbfs replacement)
SUBSYSTEM=="usb_device", MODE="0664", GROUP="vboxusers"


Now edit the basic-permissions rules file:

sudo kate /etc/udev/rules.d/40-basic-permissions.rules

Modify the first two active lines so that they look like this:

# USB devices (usbfs replacement)
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664", GROUP="vboxusers"
SUBSYSTEM=="usb_device", MODE="0664", GROUP="vboxusers"


(What you should essentially have had to do was add [, GROUP="vboxusers"] to the end of both lines.)

Now restart the udev service:

sudo /etc/init.d/udev restart

If everything went according to plan, your USB devices should now be selectable from the VirtualBox. You can now install the drivers for the devices under the guest operating system.

Note1: you may have to reinstall the Guest Additions after installing Sun's non-OSE VirtualBox.

Note2: active devices used by the VirtualBox will not be accessible to the host system while VirtualBox is running. For devices such as flash disks, I prefer to mount them through the host OS, then access them from the guest OS via the /media directory (which I have as a shared folder under VirtualBox). This means both OSes can access those devices.

Note3: if you want to run a tablet under your guest OS, make sure it is working in the host OS and make sure it is active in the VirtualBox's USB filtes before you install the guest OS drivers. You may have to disable mouse integration in the Guest Additions to get it to work in the guest OS (guest OS main window menu>Machine>"Disable Mouse Integration"). My Genius WizardPen 5x4 (UC Logic Tablet WP5540U) works, but the response is a little slow when drawing. Judging from the way it draws, I think it's a combination of both the VirtualBox video driver and the way that the tablet's event manager is shared between the two operating systems. It is usable though.

Very useful links:
VirtualBox FAQ
Ubuntu VirtualBox Community Document

There were many others that I looked at, but these contained most of what was necessary to get my scanner running under XP in a VirtualBox

No comments:

Post a Comment