Sunday, December 10, 2006

Udev

Usually when I plug in a usb drive, it will be allocated a slot at /dev/sda* (* denotes number 1, 2, 3 and so on). However if there were 2 usb drives or more, the drives will be allocated slots (nodes or slots? I don't know the correct terminology.) at /dev/sd* where * denotes the alphabet a, b, c and so on. This is troublesome as I mount my devices manually using the rules at /etc/fstab and it is a bother changing the rules everything to suite the alphabet sd*. Therefore now I use udev to customise the naming of device nodes. This was done by following instructions at the Gentoo Wiki.

1. My udev rules are kept in the file /etc/udev/rules.d/10-local.rules

2. Examples of rules in the file are: 

BUS=="usb", SYSFS{serial}=="00000000000000000182", KERNEL=="sd?1", NAME="%k", SYMLINK="pdrive"
BUS=="usb", SYSFS{serial}=="000000899406", KERNEL=="sd?2", NAME="%k", SYMLINK="ipod" 

3. The serial number in SYSFS{serial} is obtain as follows:

a. udevadm -a -p /sys/path/to/hardware/info - which for my pendrive and ipod is actually /dev/sda. Therefore:

i. $ udevadm -q path -n /dev/sda
That will result in /block/sda
ii. $ udevadm -a -p /sys/block/sda


b. (i) and (ii) can be combined : udevadm -a -p 'udevinfo -q path -n /dev/sda' 

4. My rules used to read 

BUS="usb", SYSFS{serial}="00000000000000000182", KERNEL="sd?1", NAME="%k", SYMLINK="pdrive" 

Note the single equal sign. That used to work until udev was upgraded to udev-103. After that the double equal signs have to be used or else the udev rules will not load with errors of 'invalid rules' and 'subsystem' not found (something like that).

No comments: