3

I have 8 hard disks on a home server. Sometimes I plug and unplug one or two, and if I restart the system all the drive letters are messed up. I would like to assign a block to each hard drive based on its serial number or other attributes that may identify each hard drive. The problem is that using udevadm info --attribute-walk --path /sys/block/sda I can't find any unique attribute that a udev rule can match! This is the output for udevadm info --attribute-walk --path /sys/block/sda:

looking at device '/devices/pci0000:00/0000:00:1c.6/0000:08:00.0/0000:09:00.0/host4/target4:0:0/4:0:0:0/block/sda':
  KERNEL=="sda"
  SUBSYSTEM=="block"
  DRIVER==""
  ATTR{range}=="16"
  ATTR{ext_range}=="256"
  ATTR{removable}=="0"
  ATTR{ro}=="0"
  ATTR{size}=="976773168"
  ATTR{alignment_offset}=="0"
  ATTR{discard_alignment}=="0"
  ATTR{capability}=="50"
  ATTR{stat}=="  303039  9092221 74569992  3246580    12765      996    11288  1415644        0  3250052  4661800"
  ATTR{inflight}=="       0        0"
  ATTR{events}==""
  ATTR{events_async}==""
  ATTR{events_poll_msecs}=="-1"

looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:08:00.0/0000:09:00.0/host4/target4:0:0/4:0:0:0':
  KERNELS=="4:0:0:0"
  SUBSYSTEMS=="scsi"
  DRIVERS=="sd"
  ATTRS{device_blocked}=="0"
  ATTRS{type}=="0"
  ATTRS{scsi_level}=="6"
  ATTRS{vendor}=="ATA     "
  ATTRS{model}=="ST3500630A      "
  ATTRS{rev}=="3.AA"
  ATTRS{state}=="running"
  ATTRS{timeout}=="30"
  ATTRS{iocounterbits}=="32"
  ATTRS{iorequest_cnt}=="0xa39aa"
  ATTRS{iodone_cnt}=="0xa39aa"
  ATTRS{ioerr_cnt}=="0xfa0d"
  ATTRS{evt_media_change}=="0"
  ATTRS{queue_depth}=="1"
  ATTRS{queue_type}=="none"

All the other hard drives have similar output, there isn't a way to identify them. ATTRS{model} is not suitable because I have 3 hard disks that are the same model.

2 Answers 2

1

Use Persistent naming, instead of using /dev/sdX you can use

/dev/disk/by-id/scsi-SATA_MODELNUMBER_XXXXXXXX
1
  • This wouldn't work, because I want to choose the block letter assigned to each hard drive. I want to choose that /sys/block/sda is assigned to the hard drive with serial number xyz (or any other attribute to identify the hard drive, I mentioned serial number but it could be anything)
    – giovi321
    Jul 14, 2014 at 14:57
1

Do you really care about the drive letter, or is your problem with mounting the filesystems on them correctly and consistently?

If the latter is the case maybe use the UUID in /etc/fstab instead of a device entry. UUID can be found with blkid /dev/sd[a-z]* and regardless you may want to check the /dev/disk/by-id/ directory.

I noticed that in my RHEL 6 test box udev uses a helper program /lib/udev/ata_id to retrieve more information about (S)ATA devices, including a HW serial number, resulting in the following rule:

# by-id (hardware serial number)
KERNEL=="hd*[!0-9]", IMPORT{program}="ata_id --export $tempnode"
KERNEL=="hd*[!0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_SERIAL}"
KERNEL=="hd*[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_SERIAL}-part%n"
6
  • Does the UUID change if the drive letter changes? I mean if sda1 has UUID="ACA84C0EA84BD60C", if it becomes sdk1 will the UUID change?
    – giovi321
    Jul 14, 2014 at 14:30
  • 1
    Yes, I really need to choose the letters of the drives. Does this rule make me choose the letter of the block?
    – giovi321
    Jul 14, 2014 at 14:55
  • The whole idea is that the UUID is persistent, if /dev/sde is removed and then returned later and gets detected as /dev/sdk the partition UUID will be the same.
    – HBruijn
    Jul 14, 2014 at 16:33
  • 1
    I would like to make the block letters persistent though. Does the udev script you mentioned do this?
    – giovi321
    Jul 14, 2014 at 16:42
  • 1
    The reason why I want to do this is that munin and other hard drives analysis softwares show me the drives using the block that is assigned to them, and I want to recognize the hard drives. For example munin tells me that /dev/sda is overheating, how can I remember which is /dev/sda if this block is assigned sometimes to hard disk #1 and other times to hard disk #2?
    – giovi321
    Jul 17, 2014 at 13:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .