Subject: 'Wiring down' hard disks

From: <[email-masked]>
Date: Tue, 20 Sep 2016 20:03:46 +0000 (UTC)

Hi
Could someone please advise me the best way to ensure a particular hard disk (SATA) always appears at a specific device node, i.e how can I be sure /dev/sdb for example is always going to refer to a specific drive even if others are added or removed?
UUIDs only apply to partitions, is there no way to do a similar thing for a physical disk?
I have some existing partitioned and formatted disks in a server which I want to plug into another machine and move the services over to a VM
Many thanks 

Sent from Yahoo Mail. Get the app

---

From: Reco <[email-masked]>
Date: Wed, 21 Sep 2016 18:16:05 +0300

Hi.

> I have some existing partitioned and formatted disks in a server which I want to plug into another machine and move the services over to a VM

It's possible, although unless you're trying to change device's
permissions permanently you'd better use those /dev/disk/by-id symlinks
instead.

What you'd need is a custom udev rule like this (in a single line):

KERNEL=="sd*", BUS=="scsi", PROGRAM=="/lib/udev/scsi_id -g -d $devnode",
RESULT==<UUID>, NAME=<devicename>

Where device UUID can be obtained by:

/lib/udev/scsi_id -g <your_block_device_here>

Another dirty hack (as it's not intended to be used this way) whould be
configuring multipathing with a single path representing your disk
device.

Reco

---

From: "Neal P. Murphy" <[email-masked]>
Date: Tue, 20 Sep 2016 17:10:50 -0400

> I have some existing partitioned and formatted disks in a server which I want to plug into another machine and move the services over to a VM

Not possible; udev's detection order is not defined (meaning the order can change from boot to boot).

However, there are options that can accomplish almost the same thing. Look at the things in /dev/disk/.

If you know the drives' serial numbers (from the barcode on its front), you can symlink /dev/vdska to one drive's link in /dev/disk/by-id, and /dev/vdskb to the other drive's link there. Thus vdska and vdskb will always refer to those two drives, respectively. Or just use the link in /dev/disk/by-id and forget about the 'real' node.

Aside, I just happened to notice that .../by-uuid and .../by-partuuid both seem to link to partition nodes and none of the by-uuid UUIDs matches a disk or partition.

It would seem Dan is right. Use the wwn- nodes in by-id.

Something like this might help you correlate serial# and WWN:
(
  SERIAL=Y3Q3DK9N
  for i in /sys/block/sb*; do
    unset ID_SERIAL_SHORT ID_WWN
    eval `/sbin/udevadm info -q all -p /sys/block/sdb|egrep -i "id_serial_short|id_wwn=" | cut -c 4-`
    if [ ! -z "$ID_SERIAL_SHORT" ]; then
      rm -f /dev/vdska
      ln -s /dev/disk/by-id/wwn-$ID_WWN /dev/vdska
    fi
  done
  SERIAL=Y3GA2FXN
  for i in /sys/block/sb*; do
    unset ID_SERIAL_SHORT ID_WWN
    eval `/sbin/udevadm info -q all -p /sys/block/sdb|egrep "$SERIAL|WWN" | egrep "ID_SERIAL_SHORT|ID_WWN=" | cut -c 4-`
    if [ ! -z "$ID_SERIAL_SHORT" ]; then
      rm -f /dev/vdskb
      ln -s /dev/disk/by-id/wwn-$ID_WWN /dev/vdskb
    fi
  done
)

Plug in the right serial numbers and this bit of script creates the dsk[ab] nodes.

---

From: Dan Ritter <[email-masked]>
Date: Tue, 20 Sep 2016 16:18:35 -0400

> I have some existing partitioned and formatted disks in a server which I want to plug into another machine and move the services over to a VM

That's a WWN -- look in /dev/disk/by-id/*

It identifies the disk itself, plus a -part* for partitions on
it.

-dsr-