Persistent device name

From VVCWiki
Jump to navigationJump to search

Persistent device name in Linux

Sometimes it's necessary to have a persistent device name, in case block device name changes, for DRBD for instance.

Lets say we need always be able to refer to a particular partition of a particular ATA disk.
Since it can be /dev/hda, /dev/sda or /dev/sdb we can't rely on this name to stay permanent.
To solve this create a following udev rule in /etc/udev/rules.d/local.rules

KERNEL=="sd*[0-9]", PROGRAM=="/lib/udev/ata_id /dev/%b", RESULT=="ST3750640AS_3QD13TE9", SYMLINK+="diskB%n"

RESULT is a unique string returned by /lib/udev/ata_id /dev/sdb, for example

# start_udev
# ls -l /dev/diskB*
lrwxrwxrwx 1 root root 4 May 16 22:31 /dev/diskB1 -> sdb1
lrwxrwxrwx 1 root root 4 May 16 22:31 /dev/diskB2 -> sdb2

Now you can use /dev/diskB1 in drbd.conf reliably.