38

A drive is beginning to fail and I only know the device by its /dev/sdb device file designation. What are the ways that I can use to correlate that device file to an actual hardware device to know which drive to physically replace?

Bonus: What if I don't have /dev/disk/ and its sub directories on this installation? (Which, sadly, I don't)

Wesley
  • 14,263

7 Answers7

23

You can look in /sys/block:

-bash-3.2$ ls -ld /sys/block/sd*/device
lrwxrwxrwx 1 root root 0 Jun  8 21:09 /sys/block/sda/device -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0
lrwxrwxrwx 1 root root 0 Jun  8 21:10 /sys/block/sdb/device -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0
lrwxrwxrwx 1 root root 0 Jun  8 21:10 /sys/block/sdc/device -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:0/2:0:0:0
lrwxrwxrwx 1 root root 0 Jun  8 21:10 /sys/block/sdd/device -> ../../devices/pci0000:00/0000:00:1f.2/host3/target3:0:0/3:0:0:0

Or if you don't have /sys, you can look at /proc/scsi/scsi:

-bash-3.2$ cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST31000340AS     Rev: SD1A
  Type:   Direct-Access                    ANSI SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST31000340AS     Rev: SD1A
  Type:   Direct-Access                    ANSI SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST31000340AS     Rev: SD1A
  Type:   Direct-Access                    ANSI SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST31000340AS     Rev: SD1A
  Type:   Direct-Access                    ANSI SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
  Vendor: PepperC  Model: Virtual Disc 1   Rev: 0.01
  Type:   CD-ROM                           ANSI SCSI revision: 03
Handyman5
  • 491
14
hdparm -i /dev/sdb

That should give you the model and serial number of the drive.

  • This would work for most situations, I believe. However, for some reason the controller in this server is sketchy. Performing that command earns me this: HDIO_GET_IDENTITY failed: Invalid argument – Wesley Jun 08 '12 at 21:19
  • 2
    smartctl -i is worth trying, too. Works on SCSI drives, whereas hdparm often won't. – derobert Jun 08 '12 at 21:41
  • Does not work with USB drices – Mads Skjern Jul 30 '15 at 15:17
12

As the inimitable Gilles mentioned in this answer of his, if your kernel uses udev you can use the udevadm command to interrogate a device:

udevadm info -n /dev/sda -a

(Sadly, in some cases [doubly sad is that it's true in this case for me] udev is not used and/or udevadm is not available.)

Wesley
  • 14,263
8

If you can see the LED on the drive, or listen to the disk noise, you can run

sudo cat /dev/sdb >/dev/null

and see which drive suddenly becomes continuously active. Or, if you're going by noise,

sudo find /mount/point >/dev/null

which will make the heads move more (it may be better not to do it on the failing disk, and instead use a process of elimination with the other disks).

jippie
  • 14,086
  • 2
    I had considered how to get the lights to go blinky-blinky, so this is an answer to that curiosity of mine. =) – Wesley Jun 08 '12 at 21:20
  • 1
    Some drives have an extra LED for this, but they're usually only found in enterprise grade drives (read bizarrely expensive at relatively low capacity). Don't know how to work those LED's, but the dd trick usually works well enough. – jippie Jun 08 '12 at 21:24
  • @WesleyDavid Even if there are no LEDs, listening to the noise can be a last recourse. There's no need to use dd here (nor in most circumstances), cat or any other program that reads from a file will do. – Gilles 'SO- stop being evil' Jun 09 '12 at 22:55
5

I have 4 methods. The first one is the easiest:

dmesg | egrep "sd[a-z]"

For the others, I'm not sure if they need /dev/disk except for this one:

ls -lF /dev/disk/by-uuid

The others:

blkid -o list -c /dev/null

And the obvious:

fdisk -l
4

Here are some ways I know to find the SCSI device name

  • dmesg | egrep "sd[a-z]"
  • lsblk --scsi (from package util-linux >= v2.22)
  • lshw -C disk
  • ls -ld /sys/block/sd*/device
SamK
  • 1,610
4

Assuming this is Linux, most obvious thing is to check dmesg for where the kernel first initializes the device. It logs the drive model.

  • Check http://unix.stackexchange.com/questions/39886/from-df-device-name-to-physical-drive-name-vendor-type/39888 for more details. – jippie Jun 08 '12 at 21:16
  • Yes, it's Linux. Specifically Debian 4. I checked dmesg, but didn't see any mention of a drive model, oddly. Perhaps I'm misreading it. – Wesley Jun 08 '12 at 21:24