# Using UDEV to rename SD devices

## HishnGA

Hello there everyone.  I am hoping that I am not on an impossible mission here.

What I want to do is use UDEV to change the SD device that assigned to given hardware.

Here is the stanza from the "udevinfo --export":

P: /block/sda

N: sda

S: disk/by-id/scsi-SATA_SAMSUNG_SP2504CS09QJ1ML304070

S: disk/by-path/pci-0000:00:09.0-scsi-0:0:0:0

E: ID_VENDOR=ATA

E: ID_MODEL=SAMSUNG_SP2504C

E: ID_REVISION=VT10

E: ID_SERIAL=SATA_SAMSUNG_SP2504CS09QJ1ML304070

E: ID_SERIAL_SHORT=S09QJ1ML304070

E: ID_TYPE=disk

E: ID_BUS=scsi

E: ID_PATH=pci-0000:00:09.0-scsi-0:0:0:0

E: ID_FS_USAGE=raid

E: ID_FS_TYPE=linux_raid_member

E: ID_FS_VERSION=0.90.0

E: ID_FS_UUID=a01fb743-f02c-c76f-1337-909dad3c69c8

E: ID_FS_LABEL=

E: ID_FS_LABEL_SAFE=

Here is the rule I wrote in "95-local-2.rules" to assign it to a different SD device:

KERNEL=="sd*", ENV{ID_SERIAL_SHORT}=="S09QJ1ML304070", NAME="sdc".

It is not working to effect this change.  Has anyone got any suggestions on what I might be doing wrong with this?

Thanks!

----------

## PaulBredbury

Put it in 10-local.rules, because the NAME keeps its first-assigned value, apparently. From man udev:

```
       NAME

          The name of the node to be created, or the name the network

          interface should be renamed to. Only one rule can set the node name,

          all later rules with a NAME key will be ignored.
```

----------

## HishnGA

I had tried it there and it did not work.

I had moved it to the end based on a comment in the Gentoo Wiki that ENV type rules did not seem to work unless they were at the end.

Since I want to use the serial number from the environment rather then something from SYSFS, it seemed like at the end made sense.

Is there anyway I can get the serial numbers for the device brought in without assigning them to names?

----------

## toofastforyahuh

Wondering if anyone ever got this to work?

I want to do the same thing to make my software RAID device nodes "stick".

I don't want them sliding around when I install a second device (SATA300TX4) that uses the same driver as my motherboard chip (Promise 20378).  :-/

All the udev rule websites seem to only give examples about USB devices.   :Sad: 

----------

## PaulBredbury

Ubuntu has this in /etc/fstab:

```
# /dev/hdc1

UUID=4f890405-2c20-4a92-8af3-e67b750c10b4 /               ext3    defaults,noatime,errors=remount-ro    0    1

# /dev/hdc5

UUID=1fb44767-6728-4bdd-ab53-d72f15a7cbee none            swap    sw              0       0
```

It doesn't rename the devices, but it does set their mount points without needing their names.

----------

## toofastforyahuh

Fair enough but in this case 2 drives are part of /dev/md0.

I have no way to predict where the component drives will slide, so I don't know how to edit /etc/raidtab.

And even when I do, I'll have to reconstruct the array.

(e.g. when /dev/sdb1 and /dev/sdc1 slid to /dev/sdc1 and /dev/sdd1 because I added a second drive to the southbridge controller, one drive was kicked out of the array and had to be raidhotadd-ed.  I no longer trust said southbridge SATA so want to move this second drive to a PCI card to see if it's more stable.)

So I'm hoping to find a way to keep specific drive serial numbers linked to /dev/sdc1 and /dev/sdd1.

----------

## toofastforyahuh

No luck so far.  Tried https://forums.gentoo.org/viewtopic-t-518394-highlight-sda+udev.html and the description there was both incorrect and ineffective.

```

If you want to use that in a udev rule, do something like (borrowed from /etc/udev/rules.d/60-persistent-storage.rules):

KERNEL=="sd*[!0-9]", ENV{ID_SERIAL_SHORT}=="", IMPORT{program}="scsi_id -g -x -s %p -d $tempnode"

KERNEL=="sd*[!0-9]", ENV{ID_SERIAL_SHORT}=="12345678", NAME="sda"

KERNEL=="sd*[0-9]", ENV{ID_SERIAL_SHORT}=="12345678", NAME="sda%n"

```

For one thing, there is no 60-persistent-storage.rules, so I made one following this example.  For another, there is no ID_SERIAL_SHORT in scsi_id's output, but even if you use the ID_SERIAL it does not have any effect.

At any rate I've completed my main experiment (moving a hard drive from one SATA controller to another for stability testing) and already suffered the agony of shifting device nodes, losing one drive from my SW RAID, and raidhotadd-ing it back.  But I really wish there was an answer for this in the future.

----------

