Friday, 6 January 2012

Consistent device links with udev

I have a Linux server that contains several disks used for holding photos, movies, videos and any other general junk myself and my partner dump on there. I've had some hassles with several of the drives and I also have one that is mounted in a caddy so it can be removed and hidden away (important data!).

What I found when things failed or needed to be moved was that having the drives mounted through fstab at boot time could lead to the machine just not starting. So I used automount to get round this problem. So far so good, but if one or more drives are removed the device names they use (/dev/sda /dev/sdb etc) change so my automount maps get screwed up.

After much searching I found some articles and bits and pieces that explained how to get around this issue using udev rules. I just had to re-fix this after an update to CentOS stopped these rules matching properly. Here is the file I use now:

KERNEL=="sd*[1-9]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u /dev/%P", RESULT=="1ATA_ST31000524AS_9VPCT2B9", SYMLINK+="array0%n"
KERNEL=="sd*[1-9]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u /dev/%P", RESULT=="1ATA_ST31000524AS_9VPCS7ZT", SYMLINK+="array1%n"
KERNEL=="sd*[1-9]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u /dev/%P", RESULT=="1ATA_SAMSUNG_HD103SJ_S246J90B653757", SYMLINK+="array2%n"
KERNEL=="sd*[1-9]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u /dev/%P", RESULT=="1ATA_SAMSUNG_HD103SJ_S246J90B653776", SYMLINK+="array3%n"
KERNEL=="sd*[1-9]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u /dev/%P", RESULT=="1ATA_WDC_WD20EARS-00MVWB0_WD-WCAZA0998064", SYMLINK+="drives0%n"
KERNEL=="sd*[1-9]", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u /dev/%P", RESULT=="1ATA_ST2000DL003-9VT166_6YD0EPBS", SYMLINK+="drives1%n"

The file is save as /etc/udev/rules.d/25-names.rules and looks for specific devices and creates links like /dev/array01 and /dev/drives11 depending on the ID it finds.

The bit I had to change was using %P for the parent device (/dev/sda1 has /dev/sda as a parent) and "sd*[1-9]" for the pattern to match only the partitions rather than the whole drive. Previously I used %k and a pattern that matched both the drive and partitions which did work before but not after the recent update.

1 comment:

Osias said...
This comment has been removed by a blog administrator.