Re: Possible HDD error, how do I find which HDD it is?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/19/2011 10:37 AM, John Robinson wrote:
> On 19/02/2011 11:52, Mathias BurÃn wrote:
> [...]
>> What I wonder is, how do I know what device is ata3? I do have 4
>> devices of that model (WD20EARS). I've tried searching in /sys but
>> there's nothing of value there (or I've missed it). If dmesg only
>> showed the S/N...
>> I posted the smartctl --all output of all devices here in case someone
>> has time to take a look:
>> http://stuff.dyndns.org/logs/smart-sd[a,b,c,d,e,f,g].log
> 
> Try using Phil Turmel's excellent lsdrv script; I've attached the version I use on EL5, but I hacked it about to work on such an old distro so I wouldn't swear it will work on more recent distros; Phil's original that does work on more recent distros can be found in the list archives around 6 November last year in the thread "Determining which spindle is out of order".

I've attached the latest version.  It falls back to smartctl if it can't find the sginfo utility.  It should work on both old and new sysfs layouts.

Phil

#! /bin/bash
#
# Examine specific system host devices to identify the drives attached
#

function describe_controller () {
	local device driver modprefix serial slotname
	driver="`readlink -f \"$1/driver\"`"
	driver="`basename $driver`"
	modprefix="`cut -d: -f1 <\"$1/modalias\"`"
	echo "Controller device @ ${1##/sys/devices/} [$driver]"
	if [[ "$modprefix" == "pci" ]] ; then
		slotname="`basename \"$1\"`"
		echo "  `lspci -s $slotname |cut -d\  -f2-`"
		return
	fi
	if [[ "$modprefix" == "usb" ]] ; then
		if [[ -f "$1/busnum" ]] ; then
			device="`cat \"$1/busnum\"`:`cat \"$1/devnum\"`"
			serial="`cat \"$1/serial\"`"
		else
			device="`cat \"$1/../busnum\"`:`cat \"$1/../devnum\"`"
			serial="`cat \"$1/../serial\"`"
		fi
		echo "  `lsusb -s $device` {SN: $serial}"
		return
	fi
	echo -e "  `cat \"$1/modalias\"`"
}

function describe_device () {
	local empty=1
	while read device ; do
		empty=0
		if [[ "$device" =~ ^(.+)/block[/:](.+)$ ]] ; then
			targ="${BASH_REMATCH[1]}"
			bdev="${BASH_REMATCH[2]}"
			vnd="$(< $targ/vendor)"
			mdl="$(< $targ/model)"
			sn="`sginfo -s /dev/$bdev 2>/dev/null | \
				sed -rn -e \"/Serial Number/{s%^.+' *(.+) *'.*\\\$%\\\\1%;p;q}\"`" &>/dev/null
			if [[ -n "$sn" ]] ; then
				echo -e "    $1: `echo /dev/$bdev $vnd $mdl {SN: $sn}`"
			else
				sn="`smartctl -i /dev/$bdev 2>/dev/null | \
					sed -rn -e \"/Serial Number:/{s%^.+: *(.+) *.*\$%\\\\1%;p;q}\"`" &>/dev/null
				if [[ -n "$sn" ]] ; then
					echo -e "    $1: `echo /dev/$bdev $vnd $mdl {SN: $sn}`"
				else
					echo -e "    $1: `echo /dev/$bdev $vnd $mdl`"
				fi
			fi
		else
			echo -e "    $1: Unknown $device"
		fi
	done
	[[ $empty -eq 1 ]] && echo -e "    $1: [Empty]"
}

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
		find $host -regex '.+/target[0-9:]+/[0-9:]+/block[:/][^/]+' |describe_device "$bhost"
	done
}

find /sys/devices/ -regex '.+/scsi_host\(:block\)?' |check_host

[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux