udev for USB sticks

I am not too fond of Gnome’s volume manager (GVM). I still use it, but for one of my sticks it doesn’t quite suffice, at least not for my current use of that stick. GVM doesn’t seem to handle USB sticks with multiple partitions that well (it mounts all partitions as well as the basic device), it doesn’t mount them with nice names (for FAT partitions it seems to take the volume name, nice, but ext2 doesn’t have a volume name). I’ve put two partitions on my USB stick, one FAT and one ext2. The first one I use for moving files between work and home, since I’m forced to use Windows at work :( The second one is where I put my important things, GNUPG keys, lists of passwords for different places, etc. I simply don’t trust FAT that much so the option of having one big FAT partition with a file mount on a loop device didn’t give me the same warm and fuzzy feeling as two separate partitions.

Just popping the stick in will most likely cause GVM to mount it for you. Unmount it using the right mouse button then throw up a terminal. This is what I did to find the required information on my USB stick:

$ udevinfo -q path -n /dev/sda
/block/sda
$ udevinfo -a -p /sys/block/sda | less

Look for a an entry the looks like this SYSFS{serial}="070B000514B09F0". Now you know enough to set up your udev rule. I don’t like modifying system files so I created a new one /etc/udev/rules.d/local.rules and put the following line in it:

BUS="usb", SYSFS{serial}="070B000514B09F0", KERNEL="sd*", \
  NAME="%k", SYMLINK="usbstick_priv%n"

This means that when my USB stick is inserted a few symlinks will be created, one for the device (usbstick_priv to sdX) and one for each partition (usbstick_priv1 to sdX1, etc). Pretty nice, I think, since it doesn’t matter what X is. Then I use pmount to mount the partitions using the link names:

pmount /dev/usbstick_priv1 mystick_1
pmount /dev/usbstick_priv2 mystick_2

More information can be found in the document titled Writing udev rules.

Share

One Comment

  1. Pingback: therning.org/ magnus » udev update

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>