Really great little script there -- thank you! I have saved for use in my (Currently offline) fileserver :-) Thanks, T On 3 November 2010 21:54, Phil Turmel <philip@xxxxxxxxxx> wrote: > On 11/3/2010 2:13 PM, Nat Makarevitch wrote: >> Hi, >> >> After a spindle (physical hard disk, a "drive") failure in a "md" RAID array, >> how can we know which spindle must be replaced? >> >> We want to avoid extracting a working spindle by mistakenly thinking it is the >> faulty one... > > I wrote a little script that would tell me device name and serial number for each host port on my motherboard, along with anything else that lists a scsi host in sysfs. ÂOutput like so: > > Controller device @ pci0000:00/0000:00:1c.1/0000:06:00.0 [ahci] > ÂRAID bus controller: Marvell Technology Group Ltd. 88SE6145 SATA II PCI-E controller (rev a1) > Â Âhost4: [Empty] > Â Âhost5: /dev/sdd ATA WDC WD5000AAKS-7 {SN: WD-WMAWF1370668} > Â Âhost6: [Empty] > Â Âhost7: [Empty] > Â Âhost8: [Empty] > Controller device @ pci0000:00/0000:00:1f.1 [ata_piix] > ÂIDE interface: Intel Corporation 82801G (ICH7 Family) IDE Controller (rev 01) > Â Âhost9: [Empty] > Â Âhost10: [Empty] > Controller device @ pci0000:00/0000:00:1f.2 [ahci] > ÂSATA controller: Intel Corporation 82801GR/GH (ICH7 Family) SATA AHCI Controller (rev 01) > Â Âhost0: /dev/sda ATA ST31000333AS {SN: 9TE1LTW0} > Â Âhost1: /dev/sdb ATA ST31000333AS {SN: 9TE1MAJT} > Â Âhost2: /dev/sdc ATA ST31000333AS {SN: 9TE1MV1R} > Â Âhost3: /dev/sr0 HL-DT-ST BD-RE GBW-H20L > > Shows me my empty ports, too. ÂAs long as I keep my cables straight to my hot-swap bays, getting the right drive is a snap. > > HTH, > > Phil > > I hereby release the following script into the public domain: > > #! /bin/bash > # > # Examine specific system host devices to identify the drives attached > # > > function describe_controller () { > Â Â Â Âunset SUBSYSTEM PCI_ID DEVICE PCI_SLOT_NAME Manufacturer Product Serial > Â Â Â Âeval `udevadm info --query=all --path="$1" |grep '^E: ' |cut -c 4-` > Â Â Â Âecho "Controller device @ ${1##/sys/devices/} [$DRIVER]" > Â Â Â Âif [[ -n "$PCI_SLOT_NAME" ]] ; then > Â Â Â Â Â Â Â Âecho -e " Â`lspci -s $PCI_SLOT_NAME |cut -d\ Â-f2-`" > Â Â Â Âfi > Â Â Â Âif [[ "${MODALIAS:0:4}" == "usb:" ]] ; then > Â Â Â Â Â Â Â Âeval `lsusb -D ${DEVICE/proc/dev/} |sed -r -n -e 's% *i(Manufacturer|Product|Serial) +[0-9]+ +(.+) *$%\1="\2"%;tFND;b;:FND;p'` > Â Â Â Â Â Â Â Âecho -e " Â[$Manufacturer] $Product {SN: $Serial}" > Â Â Â Âfi > } > > function describe_device () { > Â Â Â Âtarg=${1%/block/*} > Â Â Â Âvnd="`cat $targ/vendor`" > Â Â Â Âmdl=`cat $targ/model` > Â Â Â Ârdev=`readlink -f "$1"` > Â Â Â Âif [[ -d $rdev ]] ; then > Â Â Â Â Â Â Â Âbdev="`basename $rdev`" > Â Â Â Â Â Â Â Âsn="`sginfo -s /dev/$bdev |sed -r -n -e \"/Serial Number/{s%^.+' *(.+) *'.*\\\$%\\\\1%;p;q}\"`" &>/dev/null > Â Â Â Â Â Â Â Âif [[ -n "$sn" ]] ; then > Â Â Â Â Â Â Â Â Â Â Â Âecho -e " Â Â$bhost: `echo /dev/$bdev $vnd $mdl {SN: $sn}`" > Â Â Â Â Â Â Â Âelse > Â Â Â Â Â Â Â Â Â Â Â Âecho -e " Â Â$bhost: `echo /dev/$bdev $vnd $mdl`" > Â Â Â Â Â Â Â Âfi > Â Â Â Âelse > Â Â Â Â Â Â Â Âecho -e " Â Â$bhost: Unknown $rdev" > Â Â Â Âfi > } > > function check_host () { > Â Â Â Âlocal found=0 > Â Â Â Âlocal pController= > Â Â Â Âwhile read shost ; do > Â Â Â Â Â Â Â Âhost=`dirname "$shost"` > Â Â Â Â Â Â Â Âcontroller=`dirname "$host"` > Â Â Â Â Â Â Â Âbhost=`basename "$host"` > Â Â Â Â Â Â Â Âif [[ "$controller" != "$pController" ]] ; then > Â Â Â Â Â Â Â Â Â Â Â ÂpController="$controller" > Â Â Â Â Â Â Â Â Â Â Â Âdescribe_controller "$controller" > Â Â Â Â Â Â Â Âfi > Â Â Â Â Â Â Â Âfor dev in $host/target*/*/block/* ; do > Â Â Â Â Â Â Â Â Â Â Â Âif [[ "${dev: -1}" == '*' ]] ; then > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âecho -e " Â Â$bhost: [Empty]" > Â Â Â Â Â Â Â Â Â Â Â Âelse > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âdescribe_device "$dev" > Â Â Â Â Â Â Â Â Â Â Â Âfi > Â Â Â Â Â Â Â Âdone > Â Â Â Âdone > } > > find /sys/devices/ -name scsi_host |check_host > > -- > To unsubscribe from this list: send the line "unsubscribe linux-raid" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html > -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html