Linux tools: usbmount

The Problem

When you plug in a mass storage USB device (hard disk, mp3-player, camera, etc) you have to mount it to have access to its data.
The regular way is: And only root can do this. Nasty.

The automounters of Gnome or KDE are even worse: they mount all new disk partitions without request as /media/disk-NUMBER.
How should one know which device this means?
And you cannot change the mount options!

Next problem:
When you unmount ("eject") an USB device the filesystem write cache has to be written to it.
But you see no progress. You just have to wait. And wait...

The Solution

The shell tool usbmount is the solution for all these problems:

framstag@moep:~: usbmount
    /dev/sdc: 8 GB Multiple Card_Reader
[a] /dev/sdc1 (vfat 8 GB)

    /dev/sdd: 29 GB Lexar USB_Flash_Drive
[b] /dev/sdd1 (vfat 13 GB)
[c] /dev/sdd2 (btrfs 16 GB)
mount partition: [a]
# mount  -t vfat -o noatime,nodiratime,flush,shortname=lower,user,uid=1001 /dev/sdc1 /usb/CR
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       8.1G  4.1k  8.1G   1% /usb/CR
starting new bash for mounting (exit this shell for unmounting!):
(usbmount CR)framstag@moep:/usb/CR: ll
drwxrwxrwx framstag     users        - 2016-01-12 15:53:42 $RECYCLE.BIN
drwxrwxrwx framstag     users        - 2016-01-12 14:32:26 debilian
drwxrwxrwx framstag     users        - 2016-01-11 21:13:39 taliesin
(usbmount CR)framstag@moep:/usb/CR: exit
/dev/sdc1 has been unmounted

As you can see at the example, usbmount works only on user request!
And it mounts the partition under the name the drive identifies itself (here: "Multiple:Card_Reader") or optional under an alternative alias name given by the user (here: "CR").

After mounting the USB device usbmount starts a bash where you can do your business.
When exiting this bash the device automatically gets unmounted and you will see consecutivly information how much filesystem cache still has to be written.

In opposition to other usbmount programs this one does mounting in async mode which results in a writing speed plus of factor 2-5!
To enhance data integrity every 30 seconds the file system buffer will be flushed.
Nevertheless you should exit the mounting bash before removing the USB device.

usbmount also can mount all partitions in one go with default mount options:

framstag@moep:~: usbmount -a
# mount -t vfat -o noatime,user,shortname=lower,uid=1001 /dev/sdc1 /usb/XD_1
# mount -t ext3 -o noatime,nodiratime,user /dev/sdc2 /usb/XD_2
Filesystem             Size   Used  Avail Use% Mounted on
/dev/sdc1               33G   5.5G    28G  17% /usb/XD_1
/dev/sdc2              266G    99G   154G  40% /usb/XD_2
starting new bash for mounting (exit this shell for unmounting!):
(usbmount)framstag@moep:/usb: exit
/dev/sdc1 umounted
/dev/sdc2 umounted

Instead of option -a you can use an alias argument in which case only this (previously bookmarked) device will get mounted.

framstag@moep:~: usbmount WDC
# mount  -t vfat -o noatime,nodiratime,flush,shortname=lower /dev/sdd1 /usb/WDC
Filesystem             Size   Used  Avail Use% Mounted on
/dev/sdd1               33G   5.5G    28G  17% /usb/WDC
starting new bash for mounting (exit this shell for unmounting!):
(usbmount)framstag@moep:/usb: exit

usbmount remembers the mount options of known devices.

usbmount can also handle internal (SD) card-readers.

Here is the full usage:

usage: usbmount [-v] [-a] [-F seconds] [-m mount-root-directory]
usage: usbmount [-v] [-n] [-m mount-root-directory] alias
usage: usbmount [-v] [-l] [-e]
usage: usbmount [-v] -u alias
usage: usbmount -H
options: -v  verbose mode
         -a  mount all
         -m  root-directory for mountpoints (default: /usb)
         -n  non-interactive mode: do not fork a bash
         -l  list stored aliases and mount options
         -e  edit alias table
         -u  unmount alias
         -F  flush disk buffer after seconds (default: 30)
         -H  more help


To use usbmount as an ordinary user, you have to install it as root with perl -T usbmount INSTALL /usr/local/bin/

On exit usbmount can sort a FAT filesystem, if you have fatsort installed.
(Debian and Ubuntu: apt-get install fatsort)

Author: Ulli Horlacher