我收到有关“ata3”的内核消息。如何找出它对应的设备 (/dev/sd_)?
答案1
从http://www.phuket-data-wizards.com/blog/2011/07/16/matching-linux-ata-numbers-to-the-device-names/:
该命令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:0
/sys/class/scsi_host/host3/unique_id:0
/sys/class/scsi_host/host4/unique_id:3
/sys/class/scsi_host/host5/unique_id:4
/sys/class/scsi_host/host6/unique_id:5
/sys/class/scsi_host/host7/unique_id:6
因此我们可以将内核错误消息中使用的唯一 ID 与主机号进行匹配。然后该命令ls -l /sys/block/sd*
将显示哪个设备名称属于哪个主机号:
/sys/block/sda -> ../devices/pci0000:00/0000:00:13.2/usb1/1-6/1-6:1.0/host2/target2:0:0/2:0:0:0/block/sda
/sys/block/sdb -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:0/block/sdb
/sys/block/sdc -> ../devices/pci0000:00/0000:00:12.0/host6/target6:0:0/6:0:0:0/block/sdc
/sys/block/sdd -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:1/block/sdd
/sys/block/sde -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:2/block/sde
/sys/block/sdf -> ../devices/pci0000:00/0000:00:13.2/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:3/block/sdf
/sys/block/sdg -> ../devices/pci0000:00/0000:00:12.0/host7/target7:0:0/7:0:0:0/block/sdg
从这两个输出中我们可以看到唯一 ID 6 映射到 host7,而 host7 映射到 /dev/sdg。最后,使用命令hdparm -i /dev/sdg
:
/dev/sdg: Model=ST3500418AS, FwRev=CC34, SerialNo=6VM2KSFD
我们可以找到驱动器的序列号。
答案2
我不是 Linux 专家,但在我的 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
答案3
无法评论以前的答案,但是对于那一行,您想要将 grep 更改为更加严格,因为 1 和 10 都是有效的 ata#:
$ grep 1 /sys/class/scsi_host/host*/unique_id
/sys/class/scsi_host/host0/unique_id:1
/sys/class/scsi_host/host9/unique_id:10
$ grep ^1$ /sys/class/scsi_host/host*/unique_id
/sys/class/scsi_host/host0/unique_id:1
所以...
ata=3; ls -l /sys/block/sd* | grep $(grep ^$ata$ /sys/class/scsi_host/host*/unique_id | awk -F'/' '{print $5}')
为了满足我的需要,我想将驱动器号映射到 ata,因此我写了这个,并且在我的系统上,ata 字符串并不总是路径的第 5 个组成部分:
#!/bin/sh
dev=$1
name=`basename $dev`
readlink /sys/block/$name | perl -ne'm{/(ata\d+)/} && print "$1\n"'
使用方式如下:
$ ./map2ata /dev/sda
ata2
答案4
我更喜欢这个:
sg_inq /dev/sdq --verbose --id
VPD INQUIRY: Device Identification page
inquiry cdb: 12 01 83 00 fc 00
inquiry: requested 252 bytes but got 54 bytes
Designation descriptor number 1, descriptor length: 24
id_type: T10 vendor identification, code_set: ASCII
associated with the addressed logical unit
vendor id: HITACHI
vendor specific: R500D1075BCC
Designation descriptor number 2, descriptor length: 6
id_type: vendor specific [0x0], code_set: Binary
associated with the target port
00 00 00 ..
Designation descriptor number 3, descriptor length: 20
id_type: NAA, code_set: Binary
associated with the addressed logical unit
NAA 6, IEEE Company_id: 0x60e8
Vendor Specific Identifier: 0x6d10700
Vendor Specific Identifier Extension: 0xd10700005bcc
[0x60060e8006d107000000d10700005bcc]
Logical device number in HEX:
vendor specific: R500D107**5BCC**
Array Serial in HEX:
vendor specific: R500**D107**5BCC
我不确定这对其他存储阵列制造商是否有利,但对日立来说却很有效,