4:29pm, Tuesday 3 January 2006
Task: configure a Linux box so that when my MP3 player is plugged in, it consistently appears as /dev/muvo - rather than /dev/sda1 or /dev/sdc1 or /dev/xyz1 depending on whether the digital camera, USB drive, or whatever also happen to be plugged in at the time. For bonus points, automatically mount it on /muvo.
Solution 1: hotplug. Er, ick. Fiendishly complicated with no obvious "howto" guide. This is what I ended up with:
- create /etc/hotplug/usb/fred.usermap containing
fred 0x0003 0x041e 0x412b 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
(no, I don't know what most of those are either, but the third and fourth fields are the USB vendor and product ID's) - write a grotty shell script - /etc/hotplug/usb/fred - which greps the last bit of /var/log/syslog for a SCSI disk appearing, and based on the USB ID it's been passed, mounts the device somewhere appropriate; and also registers a "remover" for when the device disappears.
- restart hotplug
Solution 2: udev. Er, also fiendishly complicated, but there's a comprehensive guide to writing udev rules with lots of examples which made it easy to find the answer. Create /etc/udev/rules.d/my.rules containing
BUS=="scsi", SYSFS{vendor}=="CREATIVE", SYSFS{model}=="MuVo N200*", KERNEL=="sd?1", NAME="%k", SYMLINK="muvo"and restart udev. Much nicer. It doesn't automatically mount the disk, but the automounter can do that: in /etc/auto.misc, put
muvo -fstype=vfat,sync :/dev/muvoand "cd /misc/muvo" works the magic.