通过ata硬盘报错查找对应硬盘

通过ata硬盘报错查找对应硬盘

查看报错

dmesg|grep error
[2349121.449762] ata8.00: error: { ABRT }
         res 51/04:00:00:80:98/00:00:00:00:00/af Emask 0x1 (device error)
[2349793.559822] ata8.00: error: { ABRT }
         res 51/04:00:00:80:98/00:00:00:00:00/af Emask 0x1 (device error)
[2355121.907598] ata8.00: error: { ABRT }

因此我们可以将内核错误消息中使用的唯一 ID 与主机号相匹配。然后该命令ls -l /sys/block/sd*将显示哪个设备名称属于哪个主机号

grep '[0-9]' /sys/class/scsi_host/host{0..9}/unique_id
/sys/class/scsi_host/host0/unique_id:1
/sys/class/scsi_host/host1/unique_id:2
/sys/class/scsi_host/host2/unique_id:3
/sys/class/scsi_host/host3/unique_id:4
/sys/class/scsi_host/host4/unique_id:5
/sys/class/scsi_host/host5/unique_id:6
/sys/class/scsi_host/host6/unique_id:7
/sys/class/scsi_host/host7/unique_id:8
/sys/class/scsi_host/host8/unique_id:9
/sys/class/scsi_host/host9/unique_id:10
ls -l /sys/block/sd*
lrwxrwxrwx 1 root root 0 Jan 31 13:20 /sys/block/sda -> ../devices/pci0000:00/0000:00:11.5/ata1/host0/target0:0:0/0:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 Jan 31 13:20 /sys/block/sdb -> ../devices/pci0000:00/0000:00:11.5/ata2/host1/target1:0:0/1:0:0:0/block/sdb
lrwxrwxrwx 1 root root 0 Jan 31 13:20 /sys/block/sdc -> ../devices/pci0000:00/0000:00:17.0/ata7/host6/target6:0:0/6:0:0:0/block/sdc
lrwxrwxrwx 1 root root 0 Jan 31 13:20 /sys/block/sdd -> ../devices/pci0000:00/0000:00:17.0/ata8/host7/target7:0:0/7:0:0:0/block/sdd

从这两个输出中我们可以看到唯一的 id 8 映射到 host7,而 host7 映射到 /dev/sdd。最后,使用命令
hdparm -i /dev/sdd 或者lsblk -o name,serial /dev/sdd
/dev/sdg: Model=ST3500418AS, FwRev=CC34, SerialNo=6VM2KSFD
我们可以找到驱动器的序列号。

Ubuntu 系统上一切都变得容易得多:

# sudo ls /dev/disk/by-path -al
lrwxrwxrwx 1 root root   9 Jun 16 14:28 pci-0000:00:0b.0-ata-1 -> ../../sda
lrwxrwxrwx 1 root root  10 Jun 16 14:28 pci-0000:00:0b.0-ata-1-part1 -> ../../sda1
lrwxrwxrwx 1 root root  10 Jun 16 14:28 pci-0000:00:0b.0-ata-1-part2 -> ../../sda2
lrwxrwxrwx 1 root root  10 Jun 16 14:28 pci-0000:00:0b.0-ata-1-part3 -> ../../sda3
lrwxrwxrwx 1 root root   9 Jun 16 14:28 pci-0000:00:0b.0-ata-2 -> ../../sdb
lrwxrwxrwx 1 root root  10 Jun 16 14:28 pci-0000:00:0b.0-ata-2-part2 -> ../../sdb2
lrwxrwxrwx 1 root root  10 Jun 16 14:28 pci-0000:00:0b.0-ata-2-part5 -> ../../sdb5
lrwxrwxrwx 1 root root   9 Jun 16 14:28 pci-0000:00:0b.0-ata-3 -> ../../sdc
lrwxrwxrwx 1 root root  10 Jun 16 14:28 pci-0000:00:0b.0-ata-3-part1 -> ../../sdc1
lrwxrwxrwx 1 root root   9 Jun 16 14:28 pci-0000:00:0b.0-ata-4 -> ../../sdd
lrwxrwxrwx 1 root root  10 Jun 16 14:28 pci-0000:00:0b.0-ata-4-part1 -> ../../sdd1
posted @ 2024-02-21 10:47  Suixin随心  阅读(117)  评论(0编辑  收藏  举报