35

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)

  • No RAID controller? – ewwhite Jun 8 '12 at 21:44
  • @ewwhite Not for the purposes of this question, no. =) – Wesley Jun 8 '12 at 21:51
  • btw. if you don't have the /dev/disk/ directory you probably don't have udev. – Ulrich Dangel Jun 9 '12 at 3:32
  • @UlrichDangel Very observant because... I don't have udev. =( – Wesley Jun 9 '12 at 3:43
21

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
  • Awesome, I have /sys/ (as well as /proc/) Lots of great info there. Still consuming it. – Wesley Jun 8 '12 at 21:24
  • Also, take a look at /dev/disk/by-path (assuming your udev supports it). Of course, OPs doesn't, so... – derobert Jun 8 '12 at 21:39
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 8 '12 at 21:19
  • 1
    smartctl -i is worth trying, too. Works on SCSI drives, whereas hdparm often won't. – derobert Jun 8 '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.)

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).

  • 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 8 '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 8 '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 Jun 9 '12 at 22:55
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.

4

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
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.