It is annoyingly difficult (and at the same time pretty easy once somebody tells you what to do) to access your USB devices in Linux. In this document I will discuss how to access "mass storage" USB devices from Linux. This includes most digital (photo) cameras, mp3 players, memory sticks, zip drives, whatever. The only defining property of the device is that it is based on either a memory card or a disk of some sort.
Note that there are *many* cameras that are not so simple, and in fact they require special drivers. Please see the DigiKam section for more information concerning these (you may want to look there anyway even for USB mass storage-type cameras - it's a pretty good program to manage photo albums).
First, you will need to have "usbfs/usbdevfs/whatever" support compiled into your kernel. If you are using Debian, then this is probably already true. There are a couple of resources on the internet documenting this process, and I have no intention of worrying about it anymore since it wasn't an issue for me.
Next you will need to have a certain mount option set up in your /etc/fstab. The kernel needs to "mount" the device onto "/proc/bus/usb", and that shouldn't be changed. The following line in /etc/fstab does the job:
none /proc/bus/usb usbfs defaults,noatime 0 0
Notice that a lot of the documentation says to make the filesystem of type "usbdevfs", but that didn't work for me (using kernel 2.6.10). Instead I kept receiving the error "mount: fs type usbdevfs not supported by kernel" - this was true even though I knew that usb support was compiled in. Using instead the filesystem type "usbfs" as in the above example worked immediately!
Now this does NOT MEAN that your usb devices are now magically mounted at /proc/bus/usb. This is a strange sort of pseudo-mount, and the data is just in some crazy binary format.
How to REALLY mount the USB devices
There are now several ways to *actually* mount the USB device so that
you can play with it. First, you need to realize that the USB device
at /proc/bus/usb is MAPPED to a SCSI device (say /dev/sda1). This may
or may not mean anything to you (depending on how you want the USB
device accessed). Below I will outline several methods to mount your USB
devices. I consider the first method ("Barebones") in
the following only
useful for testing your USB subsystem. The second method is
deprecated. The third method (using the "usbmount" utility) is
good for non-Desktop systems like XFCE or ICEWM. The fourth method
is *the* way if you are using KDE or GNOME.
Barebones method
Since the kernel maps the USB device to a SCSI device, all that you need
to figure out is WHICH SCSI device it is. Just use the command (as root)
"fdisk -l". This will list all of the known drives, including any
/dev/sd* SCSI drives.
You can then mount the drive manually (this way seems good only for testing). I don't recommend trying to put an entry in /etc/fstab since tomorrow the USB device will be on /dev/sdb2 or something.
Less manual method (DEPRECATED)
Fortunately,
this page
has a pretty good method for removing the need to guess at which /dev/sd* the
USB is mapped to by making a special dedicated device using the "udev" utility.
Since you are probably not in the mood to read a bunch of junk, I'll summarize. Make sure that you install the Debian package "udev". This package is a way for userland to create new devices (which was previously handled in kernel-land using the "devfs" paradigm). udev allows nifty things like hotpluggable devices (e.g. USB devices, etc) which may not be on the computer at boot time but instead are added later. In this way you will be able to make up a new device (e.g. /dev/mp3player) that you can ALWAYS rely on to be there when the mp3 player is plugged in. THEN you may put an entry in /etc/fstab like the following
/dev/mp3player /media/mp3player vfat rw,noatime,user,noauto 0 0
This is really no different than what we did above for the SCSI device, except that now we are creating a new special device just for the mp3 player which we can ALWAYS rely on (as long as the USB device is plugged in, that is).
Since I already configured my mp3 player, let's consider another example to illustrate the concept - my digital camera. I can plug it in and have it mounted in /proc/bus/usb automatically (see above). Of course, this mount isn't worth much to me right now! Now I need to find some kind of identifying characteristic about the camera - say the serial number. So let's first determine which SCSI device it is mapped to by running "fdisk -l". In my case I can see that it is sitting (after a small pause to wait for the camera to negotiate) on /dev/sda1. So now I want to know all about my camera, so I enter the command
udevinfo -a -p /sys/block/sda/sda1
which spews out a whole bunch of junk. In there I am looking for some identifying characteristics. In my case I found the line
SYSFS{serial}="Y-712^^^^^040716XFPX0003001138"
and that's pretty characteristic. So now I want to create a device which is associated with the camera (it will know the camera by this serial number). This can be done by creating a new file in /etc/udev/rules.d/ called (in my case) "/etc/udev/rules.d/AAcamera.rules". The reason for the "AA" is that I need this rule to be added before the /etc/udev/udev.rules file is added (see the udev documentation). In the AAcamera.rules file I add the line
BUS="usb", SYSFS{serial}="Y-712^^^^^040716XFPX0003001138", NAME="%k", SYMLINK="camera"
This adds a "/dev/camera" device whenever my camera is plugged in. I need to restart the "udev" daemon by calling (in Debian this works like any other daemon) "/etc/init.d/udev restart" in order for the new configuration to be installed. Now replugging in my camera gives a /dev/camera device! Now it is easy to add an entry in /etc/fstab like
/dev/camera /media/camera vfat rw,noatime,user,noauto 0 0
Now I can mount my camera whenever I want by mounting /media/camera.
Automatic mounting (NOT for KDE or GNOME)
A better way to do this is to install the program "usbmount" (Debian package
usbmount). This program will take care of the mounting FOR you. In fact, usbmount
will discover any plugged in USB and try to mount it at /media/usb[0-7].
You will still probably need to configure the script a little. First, you will need to turn on the ability to mount vfat partitions (most USB mass storage devices use vfat). These settings can be found in "/etc/usbmount/usbmount.conf". I added "vfat" to the FILESYSTEMS list. Then I added the mount option "umask=0" to the MOUNTOPTIONS variable. This just allows all users to do anything with the USB device.
Please note that there is a warning that USB, vfat, and automounting don't go well together. When writing to a USB device, you will need to make sure that you open up a terminal window and type "sync" before you disconnect it from the computer. Otherwise, kaboom.
Automatic mounting from GNOME or KDE
Here's what you've been waiting for. There is now a set of utilities out
there called "pmount" and "hal" which provide a more dependable interface
so that GNOME and KDE can automatically mount these things. So first, install
the packages
"pmount" and "hal" (in Debian "hal" depends automatically on "udev", -
hence you will need to be running kernel 2.6 for any
of this to work). Then, you will need to add all authorized users to the
group "plugdev". Any user in this group will be able to automatically mount
a USB device.
Now in GNOME (Debian package version 64) the gnome-volume-manager will automatically bring up a window for any USB device that is plugged in. In KDE (you need KDE 3.4) you can access the USB device from within Konqueror using the media:/ URL (or using Go->Storage Media in the menu).
Note if you are upgrading KDE from 3.3 that the "devices:/" URL in Konqueror is now deprecated. You can change the "Devices" button in the sidebar to "Media" (and change the URL to "media:/") by right-clicking on the button.
Using your digital camera with Digikam and gPhoto2
On top of this you will probably want to install the package "digikam" - this is a KDE front-end for gphoto2, and it has a lot of extra stuff for managing photo albums. Also you will likely want to install "imagemagik" since this makes manipulating batches of photos very easy.
Digikam is pretty self-explanatory EXCEPT if you have a USB mass storage camera. In that case it may seem strange because your camera won't show up in the list of supported cameras. This is because you need NO SPECIAL DRIVERS to use the USB-type camera - in fact you WILL NOT NEED to "add camera" your USB-mass-storage-type camera at all. It's already in the KDE system (using hal and pmount, as above). In order to get your photos from your camera into digikam you can just go to Album->Import->Import Folders->Storage Media (just like in Konqueror). Your camera should show up in there.
This page has been visited times since April 8, 2005