Updfstab (english)

This script has been obsoleted by all the improvements of Hal. I don't use it any more, but it can still be useful.


Automatic handling of USB storage devices

(cliquez ici pour la version en français.)

1) Context and goal

This applies to devices managed by the usb_storage driver, i.e. usb keys, usb hard drives, and many digital cams. Your kernel must be in the 2.6.x series and your devices must be handled by Udev (not DevFS, nor a static /dev).

When plugging such a device, the purpose is to:

  • create a mount point with an explicit name corresponding to the real device (""/media/IntelligentStick""). Information is retrieved from the partition label, otherwise from /sys (model or vendor)
  • add the corresponding line in /etc/fstab

When unplugging, we remove the line in fstab, and the mount point.

So, under Gnome, with FAM or GAMIN installed and enabled, the device automatically appears in the mountable devices list (right-clic on the desktop -> Volumes, or in Computer for gnome >= 2.6), and it makes it possible to mount and unmount it very easily with a mouse click.

2) The script

The latest version is updfstab-17 The other versions are here : http://ccomb.gorfou.fr/static/usbstorage/

Thanks to all those who helped me improving this script (Stefan Illner, Thomas Jahns, Elia Yehuda, Iain Mac Donald, Jan Schulz, Peter Kolloch, Christian Perrier, Eric Freyens, Yth., Florian Iragne, Gurvan huiban, Benoit-Pierre Demaine, Emmanuel Bouthenot, Christophe Jenaux, gpe92)

Here is a port to perl 5.6 of the script, made by Thomas Jahns, and that create an autofs map instead of modifying the fstab: hotplug-mount.pl, and its README

Here is a modified 17+ version by Christophe Thiesset with KDE icon management, warning message at unplugging without unmounting, and other changes : updfstab-17.chthiesset.dev (and associated daemon : updfstab-sync.chthiesset.c)

Here is a Debian package of the modified version (dec 2005), which contains both the script and the daemon, and which was deployed at the INSA Toulouse (a french engineering college) for courses rooms and user workstations. The improvements are warning messages for users, automatic opening of konqueror and hot unplugging without much loss. The bad point is a small drop in the transfer rate (the daemon synchronizes every 10 seconds).

Here is another 17+ version by Yannick Torres with KDE icon management: updfstab-17.yannick

Christian Gatzemeier suggests to modify the mount options in the script. Please see at the bottom of the page.

3) Prerequisites

You must have installed:

  • optional for gnome : gnome-volume-manager and hal allow to automount and to automatically open nautilus when plugging the device. (it must be enabled in gnome-volume-properties).

4) Installation

the script must be copied as /etc/dev.d/default/updfstab.dev, and set executable:

  • Open a terminal and become root by typing su <Enter>, then your root password.
  • Paste the following line in your terminal:

of=/etc/dev.d/default/updfstab.dev; wget ccomb.gorfou.fr/static/usbstorage/updfstab-latest -O $of; chmod 755 $of

5) Uninstallation

  • Open a terminal and become root by typing su <Enter>, then your root password.
  • Just delete the script by typing: rm -f /etc/dev.d/default/updfstab*

6) Changelog

  • updfstab-17 (23-Jan-2005) - support devices without a partition (formatted as is) - changed the choice for mount point name. (label->model->vendor->"usb-disk") - use "ext2", "ext3" and "xfs" instead of "auto" to mount these filesystems
  • updfstab-2.6-16 (14-Jan-2005) - minor improvements and fixes - support for kernel 2.6.10 - removed dependency with procmail (/usr/bin/lockfile) - better behaviour with several devices - use "vfat" instead of "auto" for FAT devices - automounting (disabled by default. See the end of the script)
  • updfstab-2.6-15 (13-Dec-2004) - fixed a bug in case a mounted device is unplugged. - other minor modification
  • updfstab-2.6-14 (24-Nov-2004) - support for udev 0.46 that does not seem to provide DEVNAME anymore at removal
  • updfstab-2.6-13 (02-Nov-2004) - removed the "sync" option which divided par 10 the transfer rates. Something has to be found to enable the "sync" option __and__ to specify the blocksize at mount (the -o blocksize option has no effect).
  • updfstab-2.6-12 (11-Oct-2004) - now manages EXT2/3 partition label (with e2label) - add "noatime" mount option to avoid unnecessary write while reading
  • updfstab-2.6-11 (27-Aug-2004) - now manages XFS partition label (with xfs_admin) - the full script is protected by the lockfile (to avoid simultaneous access to the device) - extended partitions are skipped (they are not mountable) - partition number is no more appended to the mountpoint name
  • updfstab-2.6-10 (08-Jul-2004) - exit immediately if /usr/bin/ is not yet available (during boot if /usr is a separate partition) - use a lockfile instead of a sleep to protect /etc/fstab access - use syslog
  • updfstab-2.6-9 (03-Jul-2004) - using iocharset=utf-8 only for FAT and NTFS - if a mounted device is unplugged, kill the process accessing it and unmount the device. (optionnally, restart famd if it was running, because it often blocks unmounting because of nautilus)
  • updfstab-2.6-8 (03-Jul-2004) - add a debug option (comment in DEBUG=1) - fix a bug preventing fstab line and mountpoint removal - remove non fatal errors from stdout (-q option to modprobe add add >/dev/null to ls) - delete the fstab line and mountpoint if they exist at plugging (to clean) - other bug fixes
  • updfstab-2.6-7 (06-Jun-2004) - Complete rewriting of the script - The script now use variables provided by udevd (ACTION, DEVNAME, DEVPATH) - The mountpoint is now also removed at unplugging - Should now work with any udev rules (with /dev/scsi or /dev/sda) - /dev is no more hardcoded, so it should also work now with /udev instead of /dev - replace modprobe with /sbin/modprobe in case /sbin is not in the PATH. - protect against execution for non usb devices (errors at boot)
  • updfstab-2.6-6 (05-Jun-2004) - The mount point is now /media instead of /mnt (recommandation of FHS standard)
  • updfstab-2.6-5 (05-Jun-2004) - if the chosen mount point is already used, a number is appended (ex: usb-disk => usb-disk-2) - serial number is no more used
  • updfstab-2.6-4 (05-Jun-2004) - changed the choice for mount point name. (label->product->manufacturer->"usb-disk")
  • updfstab-2.6-3 (05-Jun-2004) - changed the choice order for mount point name. (product->manufacturer->"usb-disk")
  • updfstab-2.6-2 (19-Apr-2004) - changed the choice order for mount point name. (manufacturer->product->"usb-disk")
  • updfstab-2.6 (18-Mar-2004) - rewriting for 2.6 kernels

7)Version for kernel 2.4 and DevFS

I had begun this script with a 2.4 kernel and devfs. The script I wrote is here : http://ccomb.gorfou.fr/static/usbstorage/updfstab-2.4 It must be copied as /usr/sbin/updfstab, and set executable. hotplug is in charge of running it automatically. (it replaces the updfstab script usually installed by kudzu.) It is experimental, and may not work in many cases. Since I definitely migrated to 2.6 and udev, I don't maintain anymore this script.

This script has been modified by some other people: http://ccomb.gorfou.fr/static/usbstorage/updfstab.florian http://ccomb.gorfou.fr/static/usbstorage/updfstab.gurvan_huiban

Comments :

__Christian Gatzemeier proposal:__ For better vfat integration for systems that use umask 002, in line 225 you can add ",quiet,shortname=mixed,dmask=0002,fmask=0113" to the mount options. Use ",quiet,shortname=mixed,dmask=0022,fmask=0133" for systems with umask 022. Non-english systems could benefit refering to multilingual ",codepage=850".

I think ",iocharset=utf8" should only be added in your script on UTF8 enabled systems. So what I did was replacing ",iocharset=utf8" in line 225 with the options above. I don't know how one could probe for the default umask. It might be set diferently for root, and thus for the running script.


Problems when migrating to udev:

  • I lost the text mode terminals (The VTs, reachable with Alt-Ctrl-F1, ...-F2, etc.)

-> Replace compat.rules with compat-full.rules in /etc/udev/rules.d/ :

cd /etc/udev/rules.d; rm -f compat.rules; ln -s ../compat-full.rules

-> or better : onlt keep compat.rules in /etc/udev/rules.d

cd /etc/udev/rules.d; rm -f *; ln -s ../compat.rules

Works great! Thanks!

~ {emeitner} AT [ f2o DOT org ]

...

Todo list

  • configuration GUI to :
  • choose to enable automatic mounting
  • modify mountpoints (either a mapping on mountpoint name, or a direct modification of the label)
  • why not also manage HD partitions ? (other than those already known by the FSTAB)

Bugs :

(feel free to modify this wiki page by adding new bugs below)

  • doesn't work well with flash card usb readers : the reader has to be unplugged/replugged for the device to appear.

Other similar projects

[[http://usbmount.alioth.debian.org/ usbmount]]