Identify Physical Disks and Rename Devices

Status
Not open for further replies.

T14

Cadet
Joined
Apr 30, 2014
Messages
7
I imagine this is a pretty common task, so I'm sure someone, somewhere has answered this already, but I can't seem to find it. If anyone can point out where this might be, I would appreciate it.

My question: I have a computer with 6x2TB drives in it. Some drives are connected to the motherboard, some to a SATA controller. What I need to know is, when a drive fails, and running 'zpool status' shows me some random device name that failed, how do I know which drive that is in my box?

Right now, the only thing I can think of is to shut down FreeNAS, unplug a drive, start up FreeNAS, and see which drive "failed". Then shutdown FreeNAS again, plug the drive back in, start up FreeNAS, wait several hours for it to rebuild the RAIDZ, and do it again for every other drive. There must be an easier/faster way to do this.

Also, is there a way to rename the devices shown by 'zpool status' when I do figure out which drive is which? Right now, all I see is:

Code:
    NAME                                            STATE    READ WRITE CKSUM
    Volume_Name                                     ONLINE      0    0    0
      raidz1-0                                      ONLINE      0    0    0
        gptid/8a4fffb2-33bc-11e3-957d-000000000000  ONLINE      0    0    0
        gptid/8b7af956-33bc-11e3-957d-000000000000  ONLINE      0    0    0
        gptid/8c46b5b8-33bc-11e3-957d-000000000000  ONLINE      0    0    0
        gptid/8d179e69-33bc-11e3-957d-000000000000  ONLINE      0    0    0
        gptid/8e26eecc-33bc-11e3-957d-000000000000  ONLINE      0    0    0
        gptid/8edfc5cb-33bc-11e3-957d-000000000000  ONLINE      0    0    0


Can I just rename the useless device IDs (or whatever they are) to, say, "Disk 1", "Disk 2", etc.? Then if I know that they are top to bottom in my box, it's easy to tell which drive failed.
 

warri

Guru
Joined
Jun 6, 2011
Messages
1,193
That's what the comment field and serial number field in the volume overview in the GUI is good for. A common approach is to stick labels with the serial number of the disk on a visible surface, some drive models already have a sticker with the s/n visibly placed somewhere.

If the GUI doesn't provide enough information for you or doesn't display the drive's serial numbers, you can utilize command line tools to map the GPTID/GUID to a drive S/N. Have a look at the outputs of camcontrol devlist, glabel list, glabel status and zpool status and smartctl -a /dev/adaX. Basically you can find the mapping of GPTID to physical device (adaX) and then poll the SMART attributes to see the drives serial number.

You cannot change the displayed named in zpool status, since this is the unique partition identifier and it is needed by FreeNAS and ZFS to function properly.
 

T14

Cadet
Joined
Apr 30, 2014
Messages
7
So to summarize for myself and others that may be reading this:

Code:
zpool status


shows me the gptid names of the drives, and tells me which one failed.

Code:
glabel status


can convert those into actual device names (Geom names) - in my case /dev/daX.
The command actually shows the partition too (Ex. /dev/da1p2), but I assume that can be ignored.

A short bash for loop using smartctl such as this one:

Code:
for FILE in /dev/da1 /dev/da2 /dev/da3 /dev/da4 /dev/da5 /dev/da6; do echo -n "${FILE}: "; smartctl -a $FILE | grep 'Serial Number'; done


will reveal the serial numbers of each device.
Then, using those, the physical hard drive can be identified by looking for the Serial Number label on the drive itself.

I can also go to Storage --> Volumes --> View Disks through FreeNAS's web interface, and set a description for each device, describing its position inside the box (top, bottom, etc.) once the drives are identified.
The same page on the web GUI also provides the Geom to Serial number mapping.

Side note: Since 5 out of the 6 drives I have had exactly the same model number, "camcontrol devlist" didn't tell me much.

It's unfortunate that the 'zpool status' command can't simply show comments/descriptions for individual drives, or let the user change the gptid to something more descriptive, but I guess the ZFS team has bigger things to worry about at this point (bugs, functionality, etc.).

I think that pretty much answers all my questions. Thanks!
 

Rand

Guru
Joined
Dec 30, 2013
Messages
906
Ah your script has some issues;)
-Works only for your 6 disks
-only works for SATA drives (different String for serial number in smartctl)
-does not work for onboard channels (/dev/adax)

Since i had some time at hand and needed a similar script i put one together. Hope it helps :)
Save it as file (eg diskinfo.sh, make it excutable (<chmod +x diskinfo.sh> or run as <bash diskinfo.sh>)

You can choose whether it use smartcl or dmesg.today to get the serial number and whether it runs glabel status multiple times or just once (via temp file). Feel free to modify, fix up or improve it. No warranties ;)

Code:
#!/bin/bash
 
#Use smartctl to get Serial Number - else dmesg is used
USESMART=0
#save glabel status to temporary file
CACHEGLABEL=1
 
if  [ $CACHEGLABEL -eq 0 ]
then
GLCMD="glabel status"
else
GLTMP=/var/tmp/$0.glabel
glabel status > $GLTMP
GLCMD="cat $GLTMP"
fi
 
ADALOW=`ls /dev/ada[0-9] 2>/dev/null`
ADAHIGH=`ls /dev/ada[0-9][0-9] 2>/dev/null`
DALOW=`ls /dev/da[0-9] 2>/dev/null`
DAHIGH=`ls /dev/da[0-9][0-9] 2>/dev/null`
#check if all device nodes exist or skip
if  [[ $ADALOW == *ls* ]]
then
$DALOW=
fi
if  [[ $ADAHIGH == *ls* ]]
then
$ADAHIGH=
fi
if  [[ $DALOW == *ls* ]]
then
$DALOW=
fi
if  [[ $DAHIGH == *ls* ]]
then
$DAHIGH=
fi
for FILE in $ADALOW $ADAHIGH $DALOW $DAHIGH
do
DEV=${FILE##'/dev/'}
#echo -n "${DEV}: "
if  [ $USESMART -eq 0 ]
then
SERIAL=`grep $DEV: /var/log/dmesg.today |grep -i Serial | awk '{print $(NF)}'`
else
SERIAL=`smartctl -a $FILE | grep -i 'Serial Number'| awk '{print $(NF)}'`
fi
#this skips all ufs drives
GPTID=`$GLCMD |grep 2$ |grep ${DEV}p|cut -d' ' -f1`
if [ "${GPTID}x" == 'x' ]
then
GPTID="No GPTID"
fi
if [ "${SERIAL}x" == 'x' ]
then
$SERIAL="Not found"
fi
echo  ${DEV}: Serial $SERIAL \; GPTID=$GPTID
done
 
if  [ $CACHEGLABEL -eq 1 ]
then
rm $GLTMP
fi
 

T14

Cadet
Joined
Apr 30, 2014
Messages
7
Mine was more of a one-liner than a script - one that works for me that I posted in case someone wanted to change the devices to work for them.
I didn't know that the smartctl output for the serial number was different for different types of drives though - interesting.
Anyway - thanks for the script - I'm sure it'll come in handy, to me and to others.
 
Status
Not open for further replies.
Top