Map Custom Device Entries with udev

This information is basically mirrored from the gentoo wiki with some additional hints. Recently it was updated to reflect changes in udev >= 98 syntax.

This process allows you to always map a specific device to the same /dev node. This can then be used in fstab to ensure you can always mount the device same device in exactly the same place - which is great for desktop shortcuts!

Create a udev rule

You then use the ATTRS{serial} in a udev rule as follows:

Note: The convention for Arch Linux is to place custom rules into /etc/udev/rules.d/00.rules
You may, however create a file with a different name. Just remember that udev processes these files in alphabetical order.

Create an fstab entry and mount point

Additionally, depending on your locale preferences, add something like codepage=866,iocharset=utf-8 to be able to see non-Latin filenames correctly.

Now root or any user who belongs to the storage group can mount the USB stick by simply doing

mount /mnt/usbdrive

BTW, all the last 3 additional mount options are meant to increase your system's security, e.g. they will prevent you running an executable file directly from the USB drive.

To allow non-root users to access to USB stick do

gpasswd -a user1 storage
gpasswd -a user2 storage

Restart udev

to test your updated rules you can run:

udevcontrol reload_rules

Only if really needed, you may restart udev like this. As root, run those 3 commands:

/etc/./start_udev
mount /dev/pts
mount /dev/shm

Examples

Here are some examples from my system. My devices sometimes mount on sda or sda1 so I have two rules for each - this is a work around for device not found problems. The sda node is also needed for disk-level activities e.g. fdisk /dev/sda.

This always maps my disgo USB pen to /dev/usbpen which I then map in fstab to mount on /mnt/usbpen

Note the order of the lines. Since all the usb keys should create the /dev/sd<a||b> node, udev will first check if it is your own usb key, defined with the serial number. But if you plug another key witch you don't know the serial number, it will create a node too, with a generic name "otherkey". That rule should be the last one your rules file.