# help with Persistent hard disk device names with udev

## soya

Hi, i would like to give persistent device names to the system hard drives (just renaming its original device name to the one i want using its serial number). I've created the following rules which are not currently working. I'm trying to use device serial numbers to properly set its device name.

Here are the rules

```

SUBSYSTEM=="block", ATTR{serial}="VNVB05G2RKTRZH", NAME="hda"

SUBSYSTEM=="block", ATTR{serial}="9QK0T4WM", NAME="sda"

SUBSYSTEM=="block", ATTR{serial}="3QD0X58D", NAME="sdb"

SUBSYSTEM=="block", ATTR{serial}="9QK0RS9G", NAME="sdc"

SUBSYSTEM=="block", ATTR{serial}="9VP0SBVN", NAME="sdc"

KERNEL=="hd*", SUBSYSTEM=="block", ATTR{serial}="VNVB05G2RKTRZH", NAME="hda%n"

KERNEL=="sd*", SUBSYSTEM=="block", ATTR{serial}="9QK0T4WM", NAME="sda%n"

KERNEL=="sd*", SUBSYSTEM=="block", ATTR{serial}="3QD0X58D", NAME="sdb%n"

KERNEL=="sd*", SUBSYSTEM=="block", ATTR{serial}="9QK0RS9G", NAME="sdc%n"

KERNEL=="sd*", SUBSYSTEM=="block", ATTR{serial}="9VP0SBVN", NAME="sdc%n"

```

Should this work? Do some one know how can i get it to work? thanks in advanced

----------

## krinn

don't re-invente the wheel  :Very Happy: 

the info is already there: at /dev/disk/by-label/

so just put that in your fstab and you'll get your persistent rules.

cat /etc/fstab

/dev/disk/by-label/myRootLabel     /       ext3....

----------

## soya

Hi, thanks for the tip. It's useful to mount system disk using fstab but its names are difficult to remember. another problem is i have RAID composed by 3 disk (let's say sda sdb sdc) and when i plug another 4 disks sda becomes sde sdb becomes sdf and so on, that's why i would like to make it sure device names remains always the same. Do you think it could be done with udev rules? How would you solve it?

Thanks for the answer  :Smile: 

----------

## BitJam

soya, it sounds like you want something that works just like uuid but has sensible names.  Disk labels do exactly that.  Labels are just like uuid's that you can set to be whatever you want (within a 15 char limit I think).  Here's a little article about using disk labels in Linux.   I usually use gparted for changing/creating disk labels but I've never tried it on a mounted partition.

I agree with krinn that it seems like you are trying to reinvent disk labels.

----------

## soya

Thanks a lot for the answer, but i still can't understand why i can't choose which disk i want to be named sda, sdb or whatever. I'm pretty sure udev can do things like that.

I hope someone can help, pliz!!!!

----------

## idella4

probably not.

The gentoo wiki has an article on udev.  Try that.

----------

## dmpogo

mdadm can also create RAID arrays using UUID's rather than /dev entries (I wonder however, what happens when one replaces a dead drive)

----------

## BitJam

 *soya wrote:*   

> [...] i still can't understand why i can't choose which disk i want to be named sda, sdb or whatever. 

 

And I can't understand why you don't want to use disk labels since they do exactly what you say you want to do.

IMO trying to rename device nodes into the same namespace used by the kernel is the very worst idea I've heard all year.  Even if you can get it to work, it is going to cause tremendous confusion.  For example, you will never know just by looking at the nodes if your udev mapping is in place or not.

If you want to go to the trouble of using udev to fragilely do  what is currently being done by disk labels in a more robust manner, fine.  But for goodness sake choose any node names except sda, sdb, etc. that are already being used by the kernel.  For example, you could use  /dev/soya/sda, /dev/soya/sdb, etc.

What you want to do is like me saying I want my normal username to be "root" so I will change the root account to the name "admin".   Even if I could get that all to work, it is just going to confuse everyone.   The problem is that when I talk about the "root account" it is unclear if I'm talking about "root" or "admin". Or it would be like rewiring your house so that all the hot wires are colored green and all the neutral wires are colored black (the opposite of the standard convention).  

Maybe you have a good reason for not using disk labels but so far you haven't shared with us what it is.

----------

## jathlon

 *soya wrote:*   

> but i still can't understand why i can't choose which disk i want to be named sda, sdb or whatever.

 

Maybe my memory is playing tricks on me, but it seems to me that what disks show up as what is more of a function of what ports they are plugged into on the motherboard.  On the older ide interfaces  (h)sda is always going to be the master device on the first ide controller.  Using a motherboard with sata, sda is always going to be the disk plugged into the lowest numbered sata port.  (I usually plug my dvd drive into sata0 so the drive plugged into sata1 becomes sda)

Pull out your manual for the motherboard and make sure that your drives are plugged into the correct slots.  If your mixing pata and sata drives loading the drivers for the pata as a module and compiling the sata driver into the kernel might do what you want. (or vis a versa)

Good luck,

joe

----------

