NB This information is likely outdated, usbmount does much of this automagically for most use cases.

Automounting removable devices

Here's a short introduction on how to automount various external devices, for example USB sticks, memory card readers, external hard disks etc.

Install required packages

 # apt-get install autofs udev

You need to be running a 2.6 kernel for udev to work.

Configure udev

You need to find out some details of the device in question for udev to recognize it properly. Plug in the device you're configuring and check its info using udevinfo command. For example, I'm configuring my external USB HDD, which normally appears as /dev/sd? (?=a,b,c...) and I want to be able to identify it uniquely.

 $ udevinfo -a -p /sys/block/sdb/sdb5/ | grep model
 ATTRS{model}="Storage Device  "

udevinfo is missing in Squeeze and Sid. So, use "udevadm info" instead:

sudo udevadm info --query all --path /sys/block/sdb/sdb5/ --attribute-walk

We add this info to a rule in /etc/udev/rules.d/custom.rules:

 SUBSYSTEM=="scsi", ATTRS{model}=="Storage Device  ", SYMLINK+="ehd%n"
 SUBSYSTEM=="scsi", KERNEL=="sd?2", ATTRS{model}=="iPod            ", SYMLINK+="ipod"

After restarting udev, this configurationmakes udev to create custom links in /dev to pinpoint our devices. When I plug in my ipod or external HDD:

 $ ls -l /dev/ehd*
 lrwxrwxrwx    1 root     root            3 Apr 13 18:29 /dev/ehd -> sdb
 lrwxrwxrwx    1 root     root            3 Apr 13 19:16 /dev/ehd1 -> sg1
 lrwxrwxrwx    1 root     root            4 Apr 13 18:29 /dev/ehd2 -> sdb2
 lrwxrwxrwx    1 root     root            4 Apr 13 18:29 /dev/ehd3 -> sdb3
 lrwxrwxrwx    1 root     root            4 Apr 13 18:29 /dev/ehd5 -> sdb5
 lrwxrwxrwx    1 root     root            4 Apr 13 18:29 /dev/ehd6 -> sdb6
 lrwxrwxrwx    1 root     root            4 Apr 13 18:29 /dev/ehd7 -> sdb7


Configuring autofs

By default autofs mounts devices in /var/autofs/. We need to configure it to mount the devices.


 /var/autofs/removable   /etc/auto.removable --timeout=2,sync,nodev,nosuid

The first field is the path under which autofs mounts the devices. Second field denotes the configuration file for this entry. Last field lists options for this directory: timeout=2 is the minimum timeout until items are unmounted.


 ipod            -fstype=vfat            :/dev/ipod
 ehd5            -fstype=reiserfs        :/dev/ehd5
 ehd7            -fstype=vfat,uid=1000,gid=1001          :/dev/ehd7

First field denotes mount point, second field has options (man 5 autofs) and the third field is the device to mount.

Restart autofs and you are ready to go.

Alternatively, use autofs with UUID

This option does not require you to create named /dev entries for your devices with udev.

Edit the file auto.master as described above.


 /var/autofs/removable   /etc/auto.removable --timeout=2,sync,nodev,nosuid

Create your file that contains the individual disks like this:


usb             -fstype=auto       UUID=2a2a2a2a-2a2a-2a2a-2a2a-2a2a2a2a2a2a

Whenever the disk with UUID 2a2a2a2a-2a2a-2a2a-2a2a-2a2a2a2a2a2a is plugged into your computer, it will be mounted under /var/autofs/removable/usb. To find the UUID of a disk use either blkid or if not available udevadm.

$ sudo blkid /dev/sda5
/dev/sda5: UUID="2a2a2a2a-2a2a-2a2a-2a2a-2a2a2a2a2a2a" TYPE="ext3"

$ sudo udevadm info --query all --path /sys/block/sda/sda5/ | grep UUID
E: ID_FS_UUID=2a2a2a2a-2a2a-2a2a-2a2a-2a2a2a2a2a2a
E: ID_FS_UUID_ENC=2a2a2a2a-2a2a-2a2a-2a2a-2a2a2a2a2a2a

Note that this requires that the drive is already connected to your computer and you need to replace /sda/sda5 in the examples accordingly.

$ /etc/init.d/autofs restart


More information