Script to Identify Disk Drives - device name / Serial / GPTID

Status
Not open for further replies.

NASbox

Guru
Joined
May 8, 2012
Messages
650
As part of the process of upgrading my FreeNAS box, I'm going through and sorting all my scripts.

I put together this script to aid in drive identification so that when a drive fails it's easier to locate the correct drive for replacement.

The similar scripts I have come across used smartctl which has a lot of overhead, so I found a way to avoid using it. I also avoid multiple redundant calls to glabel and diskinfo. I use glabel as the source of drive device names, but since I only have one FreeNAS box, I have no way of knowing if this method will work on a wide range of hardware.

I welcome any constructive feedback on style, technique or I've employed any bad practices or if there are any bugs. What happens if this script is run on a pool with a bad drive (since that's the main reason for this scripts existence). Does it give useful output, or does it fail?

I've included a sample output (with a few numbers changed for privacy), and the complete source code. Feel free to use it as you see fit, I offer it to the community without warranty or accepting any liability - enjoy!

Code:
driveid - Mounted Drives on hostname
FreeNAS-11.1-RELEASE (dc7d195f4)
Tue Jan  9 01:14:12 EST 2018

+========+==========================+==================+============================================+
| Device |	 DISK DESCRIPTION	 |  SERIAL  NUMBER  |				   GPTID					|
+========+==========================+==================+============================================+
| ada0   | Hitachi HDS724040ALE640  | PK1331PAG91XSS   | gptid/eb2ee48c-a398-11e2-bccb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| ada1   | Hitachi HDS724040ALE640  | PK1331PAG21SXC   | gptid/ec0615be-a398-11e2-bccb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| ada2   | HP SSD S700 120GB		| HBSA17660907645  | gptid/62a1164b-9da1-11e7-af23-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da0	| ATA WDC WD60EFRX-68L	 | WD-WX21D7243NEX  | gptid/77285d08-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da1	| ATA WDC WD60EFRX-68L	 | WD-WX11D66CQ29N  | gptid/79586ddf-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da2	| ATA WDC WD60EFRX-68M	 | WD-WX11FU2FKUL8  | gptid/7a88a3fa-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da3	| ATA WDC WD60EFRX-68M	 | WD-WX31DA43KKK4  | gptid/7b573fdd-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da4	| ATA WDC WD60EFRX-68M	 | WD-WX11DY4U93HD  | gptid/7c1ae2a3-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da5	| ATA WDC WD60EFRX-68M	 | WD-WX21D26E7LXN  | gptid/7cdc01d2-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da6	| ATA WDC WD60EFRX-68L	 | WD-WX11T4243VS2  | gptid/7ed11b20-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+
| da7	| ATA WDC WD60EFRX-68L	 | WD-WX11B48EPJD6  | gptid/811b73c6-f115-11e7-addb-001517d2673c |
+--------+--------------------------+------------------+--------------------------------------------+




Code:
#!/bin/sh
echo
echo $(basename $0) - Mounted Drives on $(hostname)
cat /etc/version
date
echo
diskinfo="$(glabel status | tail -n +2 | awk '{split($3,a,"p"); print a[1],$1}')"
echo "+========+==========================+==================+============================================+"
echo "| Device |	 DISK DESCRIPTION	 |  SERIAL  NUMBER  |				   GPTID					|"
echo "+========+==========================+==================+============================================+"

for d in $(echo "$diskinfo" | cut -d" " -f 1)
do
   diskinf=$(diskinfo -v $d | grep '# Disk ')
   diskdescription=$(echo "$diskinf" | grep '# Disk desc' | cut -d# -f 1 | xargs)
   diskserialno=$(echo "$diskinf" | grep '# Disk ident' | cut -d# -f 1 | xargs)
   diskgptid=$(echo "$diskinfo" | grep ^$d | cut -d" " -f 2)
   printf "| %-6s | %-24s | %-16s | %-42s |\n" "$d" "$diskdescription" "$diskserialno" "$diskgptid"
   echo "+--------+--------------------------+------------------+--------------------------------------------+"
done


EDIT: It works under /bin/sh... so I changed the bang path accordingly.

Edit: Thanks to @toadman for identifying a small bug where the script gets tripped up on disks with swap (p1, p2) by listing them twice (two rows per disk) and printing their gptid twice (and line wrapping). I've applied a quick patch here:

https://forums.freenas.org/index.php?posts/430669

Code:
# diskinfo="$(glabel status | tail -n +2 | awk '{split($3,a,"p"); print a[1],$1}')"
diskinfo="$(glabel status | tail -n +2 | awk '{print $3,$1}')" # Temp Bug fix to accomodate botH p1/p2
that displays the slice information and fixes the line wrap by only showing the gptid that belongs to that slice.

Given that this is a script that would likely be used for troubleshooting, I decided it's better not to sanitize and delete information. If something unexpected is going on, I wouldn't want to hide it. As always, I'm open to suggestions.
 
Last edited:

MrToddsFriends

Documentation Browser
Joined
Jan 12, 2015
Messages
1,338
Seems to work flawlessly on my system with six disks on Supermicro A1SAi-2750F onboard SATA controller and two disks (freenas-boot) on a Syba SI-PEX40063 (Marvell 88SE9235), running FreeNAS-11.1-RELEASE (dc7d195f4). Thanks.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710

NASbox

Guru
Joined
May 8, 2012
Messages
650
@Bidule0hm... full credit for the inspiration you've posted some great resources and I'm not taking anything away from your good work. I didn't plagiarize in anyway as a quick look at the code will verify... 100% my original code.

Please avoid making bash-specific scripts.
The script works under /bin/sh, so I changed the bang path accordingly. What's the beef with bash? In this case it's no big deal, but somethings are a real pain to do without some of the "bash enhancements".
 
Last edited:

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
Bash was popularized by Linux and now there are legions of well-meaning people who think it is the only thing that exists. In reality, there are loads of different shells, and an effort needs to be made to make shell scripts as cross-platform as possible. So use plain sh when possible, and reserve using bash for scripts that require the extra, incompatible features.
 

toadman

Guru
Joined
Jun 4, 2013
Messages
619
I put together this script to aid in drive identification so that when a drive fails it's easier to locate the correct drive for replacement.

Thx for the work! I tried it quickly. It gets tripped up on disks with swap. The have a p1 and a p2. It lists them twice (two rows per disk) and also prints their gptid twice (line wraps).

I didn't have time to sit and parse through it to make suggestion on changes, but wanted to let you know.
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
Bash was popularized by Linux and now there are legions of well-meaning people who think it is the only thing that exists. In reality, there are loads of different shells, and an effort needs to be made to make shell scripts as cross-platform as possible. So use plain sh when possible, and reserve using bash for scripts that require the extra, incompatible features.
I get that in many contexts... such as a general purpose admin script that is designed to run in many different contexts.

In this case, this script is designed for use on a FreeNAS box - is it likely that bash would not be available?

I can't think of all the specifics right now, but substitution and tests are much richer and of course there are arrays in bash.
Can it be done is sh? Likely but it's often much more clunky and/or more work. Is it REALLY worth it?

Thx for the work! I tried it quickly. It gets tripped up on disks with swap. The have a p1 and a p2. It lists them twice (two rows per disk) and also prints their gptid twice (line wraps).

I didn't have time to sit and parse through it to make suggestion on changes, but wanted to let you know.
Thanks for the feedback... I think that must be the swap partition. Any idea how I can differentiate between the two?
Any chance you could post the output of glabel status > textfile?
(Feel free to "consistently falsify any information you deem sensitive-I don't think it's a significant risk, but I used an editor to change the gptids I posted just in case there was some reason not to make them public that I wasn't aware of.)
 
Last edited:

toadman

Guru
Joined
Jun 4, 2013
Messages
619
Definitely the swap file. I have four disks that have swap and 9 that do not. (I don't use those partitions for swap, it's legacy that I haven't gone back to correct as there is really no need. I use a file for swap at present.) On the disks with swap that is the p1 slice and p2 is the zfs slice. ada2p1 (swap) and ada2p2 (zfs). da0, da5, and da6 are the other disks with swap. On all remaining disks without swap p1 is zfs.

Code:
gptid/b49d5795-7f8e-11e3-82c9-0015172951de	 N/A  ada0p1
gptid/bd63331d-7ee4-11e3-b083-0015172951de	 N/A  ada1p1
gptid/97be6ea4-360e-11e4-8aad-0015172951de	 N/A  ada2p2
gptid/dbf40258-a206-11e5-a8b2-0050568babb8	 N/A  ada3p1
gptid/28b22a4b-99f5-11e5-b85b-0050568babb8	 N/A  da0p1
gptid/28c55815-99f5-11e5-b85b-0050568babb8	 N/A  da0p2
gptid/8db30582-7ee4-11e3-b083-0015172951de	 N/A  da1p1
gptid/be6510a8-7ee4-11e3-b083-0015172951de	 N/A  da2p1
gptid/8e3575d1-7ee4-11e3-b083-0015172951de	 N/A  da3p1
gptid/db466bd2-7ee4-11e3-b083-0015172951de	 N/A  da4p1
gptid/03f25d1a-50cf-11e5-8c95-0015172951de	 N/A  da5p2
gptid/04a8c358-50cf-11e5-8c95-0015172951de	 N/A  da6p2
gptid/4ba87812-ee5f-11e7-bde2-00505686d746	 N/A  da7p1
gptid/4a406251-ee5f-11e7-bde2-00505686d746	 N/A  da8p1
gptid/978c5092-360e-11e4-8aad-0015172951de	 N/A  ada2p1
gptid/03decee6-50cf-11e5-8c95-0015172951de	 N/A  da5p1
gptid/0494d836-50cf-11e5-8c95-0015172951de	 N/A  da6p1


EDIT: To guarantee some order I suppose you could pipe the glabel status | tail -n +2 into a sort -k53. That at least ensures the disk partitions are listed back to back in the top down order. That way if the current slice is a "p1" one could always check the next value in the list. If that contains a "p2" then the current "p1" is swap and can be tossed from the list.

Code:
[root@fileserver /mnt/pool0/scripts]$ glabel status | tail -n +2 | sort -k53
gptid/03decee6-50cf-11e5-8c95-0015172951de	 N/A  da5p1
gptid/03f25d1a-50cf-11e5-8c95-0015172951de	 N/A  da5p2
gptid/0494d836-50cf-11e5-8c95-0015172951de	 N/A  da6p1
gptid/04a8c358-50cf-11e5-8c95-0015172951de	 N/A  da6p2
gptid/28b22a4b-99f5-11e5-b85b-0050568babb8	 N/A  da0p1
gptid/28c55815-99f5-11e5-b85b-0050568babb8	 N/A  da0p2
gptid/4a406251-ee5f-11e7-bde2-00505686d746	 N/A  da8p1
gptid/4ba87812-ee5f-11e7-bde2-00505686d746	 N/A  da7p1
gptid/8db30582-7ee4-11e3-b083-0015172951de	 N/A  da1p1
gptid/8e3575d1-7ee4-11e3-b083-0015172951de	 N/A  da3p1
gptid/978c5092-360e-11e4-8aad-0015172951de	 N/A  ada2p1
gptid/97be6ea4-360e-11e4-8aad-0015172951de	 N/A  ada2p2
gptid/b49d5795-7f8e-11e3-82c9-0015172951de	 N/A  ada0p1
gptid/bd63331d-7ee4-11e3-b083-0015172951de	 N/A  ada1p1
gptid/be6510a8-7ee4-11e3-b083-0015172951de	 N/A  da2p1
gptid/db466bd2-7ee4-11e3-b083-0015172951de	 N/A  da4p1
gptid/dbf40258-a206-11e5-a8b2-0050568babb8	 N/A  ada3p1


Though there are probably more elegant ways to do it.
 
Last edited:

NASbox

Guru
Joined
May 8, 2012
Messages
650
Definitely the swap file. I have four disks that have swap and 8 that do not. (I don't use those partitions for swap, it's legacy that I haven't gone back to correct as there is really no need. I use a file for swap at present.) On the disks with swap that is the p1 slice and p2 is the zfs slice. ada2p1 (swap) and ada2p2 (zfs). da0, da5, and da6 are the other disks with swap. On all remaining disks without swap p1 is zfs.

Code:
gptid/bd63331d-7ee4-11e3-b083-0015172951de	 N/A  ada1p1
gptid/97be6ea4-360e-11e4-8aad-0015172951de	 N/A  ada2p2


EDIT: .... If that contains a "p2" then the current "p1" is swap and can be tossed from the list.
Thanks @toadman for taking the time do reply.

It appears that this is a problem that will eventually go away when legacy formats go away. Shortly after posting my reply, I mounted a drive with the old pool format and I got both a p1 and p2 listed and the error you describe.

My main pool is RAID-Z2 with 8 disks that I created with the default settings using the FreeNAS GUI, and IIRC the default is a 2GB swap on each drive, but the glabel status doesn't show p1 using the latest ZFS format.

I'm wondering if I should just do one line/slice and be done with it. Is there any reasonable use case that would result in a p3? Is there any reason someone would want to see p1 (or p(x) if there were more than 2-don't know if/why this would be done in practice)?

@toadman a couple of follow up questions:

Am I correct in assuming that ada1 was created with NO SWAP area?

What's up with ada2?
It appears that there is a swap (p1), but the command doesn't list it?
 

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
Disk partition types can be identified with the output of gpart show.
 

toadman

Guru
Joined
Jun 4, 2013
Messages
619
I'm wondering if I should just do one line/slice and be done with it. Is there any reasonable use case that would result in a p3? Is there any reason someone would want to see p1 (or p(x) if there were more than 2-don't know if/why this would be done in practice)?

@toadman a couple of follow up questions:

Am I correct in assuming that ada1 was created with NO SWAP area?

What's up with ada2?
It appears that there is a swap (p1), but the command doesn't list it?

Answering in order...

Yes, one line per slice would be fine I think. I see no harm in having a disk listed twice. After all the purpose is seeing the mapping.

I cannot think of a realistic use case in FreeNAS that would use a p3. That would be a very custom case where someone partitioned the drive(s) themselves and did some custom pools or something. (I remember some people doing this back in the say where they had widely differing drive sizes. They cut them up and laid down multiple pools across the drives to better utilize the space.)

Correct, ada1 has no swap space. It was added from the GUI with the swap number in Settings set to "0". (The pool has grown through the addition of mirrors. Started with 4 disks in 2x2TB mirrors. Those are the disks with swap. The subsequent disks were all added over time in mirrored pairs, with no swap, as additional capacity was required.)

ada2 does appear twice in the original command. It's listed 3rd (the p2) and then 15th near the bottom (the p1). (And the two are next to each other after piping into "sort".)
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
Answering in order...

Yes, one line per slice would be fine I think. I see no harm in having a disk listed twice. After all the purpose is seeing the mapping.

I cannot think of a realistic use case in FreeNAS that would use a p3. That would be a very custom case where someone partitioned the drive(s) themselves and did some custom pools or something. (I remember some people doing this back in the say where they had widely differing drive sizes. They cut them up and laid down multiple pools across the drives to better utilize the space.)

Correct, ada1 has no swap space. It was added from the GUI with the swap number in Settings set to "0". (The pool has grown through the addition of mirrors. Started with 4 disks in 2x2TB mirrors. Those are the disks with swap. The subsequent disks were all added over time in mirrored pairs, with no swap, as additional capacity was required.)

ada2 does appear twice in the original command. It's listed 3rd (the p2) and then 15th near the bottom (the p1). (And the two are next to each other after piping into "sort".)

Sorry I missed the ada2p2 in the original command. FYI, a safer way to do the sort is sort -t" " -k 3, it protects against someone adding or subtracting a space from the command output.

For now I've applied a quick patch to display one line/slice:
Code:
#!/bin/sh
echo
echo $(basename $0) - Mounted Drives on $(hostname)
cat /etc/version
date
echo
# diskinfo="$(glabel status | tail -n +2 | awk '{split($3,a,"p"); print a[1],$1}')"
diskinfo="$(glabel status | tail -n +2 | awk '{print $3,$1}')" # Temp Bug fix to accomodate botH p1/p2
echo "+========+==========================+==================+============================================+"
echo "| Device |	 DISK DESCRIPTION	 |  SERIAL  NUMBER  |				   GPTID					|"
echo "+========+==========================+==================+============================================+"

for d in $(echo "$diskinfo" | cut -d" " -f 1)
do
   diskinf=$(diskinfo -v $d | grep '# Disk ')
   diskdescription=$(echo "$diskinf" | grep '# Disk desc' | cut -d# -f 1 | xargs)
   diskserialno=$(echo "$diskinf" | grep '# Disk ident' | cut -d# -f 1 | xargs)
   diskgptid=$(echo "$diskinfo" | grep ^$d | cut -d" " -f 2)
   printf "| %-6s | %-24s | %-16s | %-42s |\n" "$d" "$diskdescription" "$diskserialno" "$diskgptid"
   echo "+--------+--------------------------+------------------+--------------------------------------------+"
done

Given that a script like this is for "engineering" use, it's likely better not to hide any information. That way if something "non-standard" is going on, it's clear.
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
Sorry I missed the ada2p2 in the original command. FYI, a safer way to do the sort is sort -t" " -k 3, it protects against someone adding or subtracting a space from the command output.
.
Not detracting from the work you have done, but there are many scripts for this type of thing. Here is another:
https://forums.freenas.org/index.ph...ktype-serial-num-multipath.59319/#post-421424

They have a nice explanation of the commands they use to obtain the data on the github site:
https://github.com/nephri/FreeNas-DiskList

https://github.com/nephri/FreeNas-DiskList/blob/master/README.md
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
Not detracting from the work you have done, but there are many scripts for this type of thing. Here is another:
https://forums.freenas.org/index.ph...ktype-serial-num-multipath.59319/#post-421424

They have a nice explanation of the commands they use to obtain the data on the github site:
https://github.com/nephri/FreeNas-DiskList

https://github.com/nephri/FreeNas-DiskList/blob/master/README.md
Thanks Chris. WOW! Now that is a serious script that is clearly designed for enterprise equipment that is a lot more complicated than anything I'm likely to see.

The good news is, all I had to do was copy it to my machine and it works!

As an aside, I currently have an unmounted drive in the hot swap on my box, my little script shows gptids, but the huge script doesn't - also needs command line options to get the gptid - to know which disk to swap if a disk fails. That aside, thanks, that a nice tool and a great addition to my library.
 
Last edited:

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
Thanks Chris. WOW! Now that is a serious script that is clearly designed for enterprise equipment that is a lot more complicated than anything I'm likely to see.
No problem. I like to help. Speaking of which, did you look at the links in my signature? Under the "Useful Links" button?
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
No problem. I like to help. Speaking of which, did you look at the links in my signature? Under the "Useful Links" button?
I did awhile back, and I missed disklist.pl.

I remember in particular reading the guide on cross flashing... In the end I got lucky and found a unit that had been cross flashed right up to the at the time current v20.

I saw a script in the scripts directory that did something similar, but didn't quite meet my needs, so I used the general idea as inspiration for what I actually wrote. On one hand I wasted a fair bit of time, on the other hand I learned a bit.
 

Rob Townley

Dabbler
Joined
May 1, 2017
Messages
19
I am just trying to get the hang of identifying drives reliably. Please tell me where i have gone wrong or if the following two statements are correct.
The da# seems to be set based on the first bay the drive is installed into, but does not change even when the drive is moved to another bay.
The Dk# from dmesg or diskinfo -v da# is much more useful as it indicates the physical bay location.
Anticipating what rebooting the server will do to these identifiers.

For example, look at ./diskLocation.bash output below:
  • da7 is actually in bay Dk9,
  • da10 is actually in bay Dk7,
  • bay Dk3 is empty, so da3 is actually in bay Dk4
  • bay Dk11 is also empty.
  • i tried most all of the scripts and not one of them reliably identify where the drive actually resides except for the following:
freenas8# cat ./diskLocation.bash
Code:
#!/bin/bash

for D in `seq 0 1 11`; do echo $D;
  diskinfo -v da${D} | egrep -i '(Disk ident|Dk)' ;
done;



freenas8# ./diskLocation.bash
0
9WK0KP9E # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@1/elmdesc@Dk0_ # Physical path
1
9WK26YJZ # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@2/elmdesc@Dk1_ # Physical path
2
ZA126D06 # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@3/elmdesc@Dk2_ # Physical path
3
9WK31WFZ # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@5/elmdesc@Dk4_ # Physical path
4
ZA11SQNB # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@6/elmdesc@Dk5_ # Physical path
5
9WK0TR9C # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@7/elmdesc@Dk6_ # Physical path
6
9WK0MXJY # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@9/elmdesc@Dk8_ # Physical path
7
9WK26F20 # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@a/elmdesc@Dk9_ # Physical path
8
9WK277XC # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@b/elmdesc@Dk10 # Physical path
9
07BA1302D6C000CB # Disk ident.
10
Z1P4BSCZ0000C3158ZF2 # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@8/elmdesc@Dk7_ # Physical path
11
diskinfo: da11: No such file or directory
freenas8#
freenas8#

 

Rob Townley

Dabbler
Joined
May 1, 2017
Messages
19
Here is the output from the script referred to in this thread ./diskInfoMountedOnly.sh and disklist.pl -all. Not even disklist.pl tells the location. Yes, some drives are unmounted.
Code:

freenas8#  ./diskInfoMountedOnly.sh
FreeNAS forum member NASbox contributed this script.
https://forums.freenas.org/index.php?threads/script-to-identify-disk-drives-device-name-serial-gptid.60497/
diskInfoMountedOnly.sh - Mounted Drives on freenas8.corp.eceo.us
FreeNAS-9.10.2-U6 (561f0d7a1)
Mon Jan 29 01:48:20 CST 2018

+========+==========================+==================+============================================+
| Device |	 DISK DESCRIPTION	 |  SERIAL  NUMBER  |				   GPTID					|
+========+==========================+==================+============================================+
| da0p2  |						  | 9WK0KP9E		 | gptid/7e7cb5d0-a301-11e6-b143-001517e36381 |
+--------+--------------------------+------------------+--------------------------------------------+
| da1p2  |						  | 9WK26YJZ		 | gptid/809a8aad-a301-11e6-b143-001517e36381 |
+--------+--------------------------+------------------+--------------------------------------------+
| da3p2  |						  | 9WK31WFZ		 | gptid/82a31d92-a301-11e6-b143-001517e36381 |
+--------+--------------------------+------------------+--------------------------------------------+
| da4p2  |						  | ZA11SQNB		 | gptid/395ce6d6-ab01-11e7-a40b-001517e36380 |
+--------+--------------------------+------------------+--------------------------------------------+
| da6p2  |						  | 9WK0MXJY		 | gptid/88ed75b6-a301-11e6-b143-001517e36381 |
+--------+--------------------------+------------------+--------------------------------------------+
| da7p2  |						  | 9WK26F20		 | gptid/8b05fdde-a301-11e6-b143-001517e36381 |
+--------+--------------------------+------------------+--------------------------------------------+
| da8p2  |						  | 9WK277XC		 | gptid/8d164024-a301-11e6-b143-001517e36381 |
+--------+--------------------------+------------------+--------------------------------------------+
| da9p1  |						  | 07BA1302D6C000CB | gptid/b7101e33-a2d3-11e6-9dab-001517e28e00 |
+--------+--------------------------+------------------+--------------------------------------------+
| da9p2  |						  | 07BA1302D6C000CB | gptid/b743692e-a2d3-11e6-9dab-001517e28e00 |
+--------+--------------------------+------------------+--------------------------------------------+
freenas8#
freenas8#
freenas8#  ./disklist.pl -all
partition  label									   zpool		   device  sector  disk					  size  type  serial				 rpm  location  multipath  mode
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
da0p2	  gptid/7e7cb5d0-a301-11e6-b143-001517e36381  FreeNas8-POOL0  da0		512  ATA ST31000524NS		  1000  HDD   9WK0KP9E			  7200
da1p2	  gptid/809a8aad-a301-11e6-b143-001517e36381  FreeNas8-POOL0  da1		512  ATA ST31000524NS		  1000  HDD   9WK26YJZ			  7200
da3p2	  gptid/82a31d92-a301-11e6-b143-001517e36381  FreeNas8-POOL0  da3		512  ATA ST31000524NS		  1000  HDD   9WK31WFZ			  7200
da4p2	  gptid/395ce6d6-ab01-11e7-a40b-001517e36380  FreeNas8-POOL0  da4		512  ATA ST8000NM0055-1RM	  2199  HDD   ZA11SQNB			  7200
da6p2	  gptid/88ed75b6-a301-11e6-b143-001517e36381  FreeNas8-POOL0  da6		512  ATA ST31000524NS		  1000  HDD   9WK0MXJY			  7200
da7p2	  gptid/8b05fdde-a301-11e6-b143-001517e36381  FreeNas8-POOL0  da7		512  ATA ST31000524NS		  1000  HDD   9WK26F20			  7200
da8p2	  gptid/8d164024-a301-11e6-b143-001517e36381  FreeNas8-POOL0  da8		512  ATA ST31000524NS		  1000  HDD   9WK277XC			  7200
da9p2	  gptid/b743692e-a2d3-11e6-9dab-001517e28e00  freenas-boot	da9		512  MUSHKIN MKNUFDMH8GB		  8  ???   07BA1302D6C000CB	   ???
																	   da2		512  ATA ST8000NM0055-1RM	  2199  HDD   ZA126D06			  7200
																	   da5		512  ATA ST31000524NS		  1000  HDD   9WK0TR9C			  7200
																	   da10	   512  IBM-XIV ST2000NM0001  A2  2000  HDD   Z1P4BSCZ0000C3158ZF2  7200
freenas8#
freenas8#
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
I am just trying to get the hang of identifying drives reliably. Please tell me where i have gone wrong or if the following two statements are correct.
The da# seems to be set based on the first bay the drive is installed into, but does not change even when the drive is moved to another bay.
The Dk# from dmesg or diskinfo -v da# is much more useful as it indicates the physical bay location.
Anticipating what rebooting the server will do to these identifiers.

For example, look at ./diskLocation.bash output below:
  • da7 is actually in bay Dk9,
  • da10 is actually in bay Dk7,
  • bay Dk3 is empty, so da3 is actually in bay Dk4
  • bay Dk11 is also empty.
  • i tried most all of the scripts and not one of them reliably identify where the drive actually resides except for the following:
freenas8# cat ./diskLocation.bash
Code:
#!/bin/bash

for D in `seq 0 1 11`; do echo $D;
  diskinfo -v da${D} | egrep -i '(Disk ident|Dk)' ;
done;



freenas8# ./diskLocation.bash
0
9WK0KP9E # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@1/elmdesc@Dk0_ # Physical path
1
9WK26YJZ # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@2/elmdesc@Dk1_ # Physical path
2
ZA126D06 # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@3/elmdesc@Dk2_ # Physical path
3
9WK31WFZ # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@5/elmdesc@Dk4_ # Physical path
4
ZA11SQNB # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@6/elmdesc@Dk5_ # Physical path
5
9WK0TR9C # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@7/elmdesc@Dk6_ # Physical path
6
9WK0MXJY # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@9/elmdesc@Dk8_ # Physical path
7
9WK26F20 # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@a/elmdesc@Dk9_ # Physical path
8
9WK277XC # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@b/elmdesc@Dk10 # Physical path
9
07BA1302D6C000CB # Disk ident.
10
Z1P4BSCZ0000C3158ZF2 # Disk ident.
id1,enc@n50050cc10b8b701d/type@0/slot@8/elmdesc@Dk7_ # Physical path
11
diskinfo: da11: No such file or directory
freenas8#
freenas8#

Need a bit of context here so maybe I can help... What version of FreeNAS/What hardware?
Did this pool get physically moved from one machine to another? What is the history of the disks in this pool since the last time they were reformatted? Did you swap them in the machine?

Show us the output of this (without the grep):
Code:
#!/bin/bash

for D in `seq 0 1 11`; do echo $D;
  diskinfo -v da${D}
done;
so we can see what diskinfo is producing. The script is only reformatting what the utility is producing.
I'm not 100% sure about the answer to your question, but here is what I can tell you:

As long as you export a pool correctly, and the pool isn't damaged you can pull the disks out of a FreeNAS, shuffle them (with the possible exception of the boot drive-the MB needs to know which drive to boot from, but it MAY even figure that out by default depending on the hardware) put them back in, reboot the machine and it will work fine. You can even change physical machines as long as it is running a compatable verion of FreeNAS.

Why not answer your question by swapping a couple of disks and see if the da# changes - it won't do any harm as long as you are careful. (Export the pool, Power down, swap the drives, power up, import the pool) I'd be interested in knowing - report back.

What are you trying to accomplish? Are you just trying to identify a disk when it eventually goes bad or are your needs more complex?

The da# is the order in which the disks are detected by FreeBSD. The order in which the SATA(or SAS or whatever) is on the hardware bus and the physical drive bay may or may not correlate. I don't know if FreeNAS changes the order of device names.

I moved a pool from one machine to another and new machine had an LSI HBA, and my pool changed from ada0,1,2,3 to da0,1,2,3 (but ada0 wasn't da0-the order changed) but everything worked just fine. As a result I gave up on device names/physical location for identification. Use the gptid (will never change until the disk is reformatted) and the serial number of the disk. Zpool status only shows the gptid and if the disk is healthy or failed. If you have to replace a disk, for example da1, the new da1 will have a new gptid when it takes over da1 in the pool.

IIUC, depending on how a drive fails, the device (daX), may disappear completely anyway and it may not even be possible to identify the disk. When this happens the only way to proceed is to eliminate the disks that are working.

If you've had the foresight to keep good notes you will know which gptid corresponds to which serial number, and when you installed the disks hopefully you noted the serial number as you put the drive in the bay. (If not, and the bar codes on the drives are visible, you may be able to read the serials without physically pulling the disk using the bar code reader on a smart phone. The drives I have have the serial number bar coded on the front of the drive i.e. the side opposite the side with the connectors.)

Hope some of the above helps.
 
Status
Not open for further replies.
Top