FreeNas script for a convenient way to report installed disks

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

nephri

Active Member
Sep 23, 2015
541
106
43
46
Paris, France
Hi,

I just wrote a script disklist.pl for getting informations about all installed disks inside my FreeNas box.
This script is written in Perl and use under the hood theses commands:
  • geom disk list
  • gmultipath status
  • zpool status
  • glabel status
  • sas2ircu list
  • sas2ircu # display
  • sas3ircu list
  • sas3ircu # display
  • nvmecontrol devlist
It's only a convenient tool for me for report disks, locate them, etc...
I share it here, because maybe someone else may find it useful.
If it's the case and if i have good feedback, i will maybe post it on the FreeNas forum (i will see).

First Exemple:
  • ./disklist.pl -short -fs:zfs
Code:
partition           zpool         device     disk                      size
---------------------------------------------------------------------------
da112p2             freenas-boot  da112      SanDisk Ultra Fit           62
da104p2             volBACKUP     da104      ATA Hitachi HUA72302      2000
da105p2             volBACKUP     da105      ATA Hitachi HUA72302      2000
da106p2             volBACKUP     da106      ATA Hitachi HUA72302      2000
da107p2             volBACKUP     da107      ATA Hitachi HUA72302      2000
da108p2             volBACKUP     da108      ATA Hitachi HUA72302      2000
da109p2             volBACKUP     da109      ATA Hitachi HUA72302      2000
da110p2             volBACKUP     da110      ATA Hitachi HUA72302      2000
da111p2             volBACKUP     da111      ATA Hitachi HUA72302      2000
ada0p2              volFAST       ada0       INTEL SSDSC2BA400G4        400
ada1p2              volFAST       ada1       INTEL SSDSC2BA400G4        400
ada2p2              volFAST       ada2       INTEL SSDSC2BA400G4        400
ada3p2              volFAST       ada3       INTEL SSDSC2BA400G4        400
ada4p2              volMAIN       ada4       INTEL SSDSC2BA100G3        100
ada5p2              volMAIN       ada5       INTEL SSDSC2BA100G3        100
da0p2               volMAIN       da0        SEAGATE ST33000650SS      3000
da1p2               volMAIN       da1        SEAGATE ST33000650SS      3000
da2p2               volMAIN       da2        SEAGATE ST33000650SS      3000
da3p2               volMAIN       da3        SEAGATE ST33000650SS      3000
da4p2               volMAIN       da4        SEAGATE ST33000650SS      3000
da5p2               volMAIN       da5        SEAGATE ST33000650SS      3000
da6p2               volMAIN       da6        SEAGATE ST33000650SS      3000
da7p2               volMAIN       da7        SEAGATE ST33000650SS      3000
multipath/disk30p2  volTEST       da49,da97  HITACHI HUS72302CLAR2000  2000
multipath/disk31p2  volTEST       da50,da98  HITACHI HUS72302CLAR2000  2000
This command output only disks used inside a zpool and show only few columns.

Second Exemple:
  • ./disklist.pl -i:zpool volTEST -all
Code:
partition           label                                       zpool    device     sector  disk                      size  type  serial     rpm  location         multipath         mode
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
multipath/disk30p2  gptid/fe38f700-829a-11e7-810a-00074304a2f0  volTEST  da49,da97     512  HITACHI HUS72302CLAR2000  2000  HDD   YGH1E3DD  7200  SAS3008(1):3#53  multipath/disk30
multipath/disk31p2  gptid/01a5298c-829b-11e7-810a-00074304a2f0  volTEST  da50,da98     512  HITACHI HUS72302CLAR2000  2000  HDD   YGH1Y9KD  7200  SAS3008(1):3#54  multipath/disk31
The uploaded file "disklist.txt" have to be renamed to "disklist.pl"

Best regards,
Sébastien.
 

Attachments

nephri

Active Member
Sep 23, 2015
541
106
43
46
Paris, France
Here the help usage of the script:

Code:
disklist.pl [-i:<class> <entity>] [-fs:<fstype>] [-disk:<disktype>] [-multi[:<multitype>]] [-o:<otype>] [-c:<columns>] [-all] [-long] [-short] [-h]

   List informations of detected disks from a single command by grabbing and merging theses informations from multiples standard FreeBSD tools:
            > geom disk list
            > gmultipath status
            > zpool status
            > glabel status
            > sas2ircu list
                 > sas2ircu # display
            > sas3ircu list
                 > sas3ircu # display
            > nvmecontrol devlist

   This program comes with ABSOLUTELY NO WARRANTY.
   This is free software, and you are welcome to redistribute it under certain conditions (cf. GNU Lesser General Public Licence v3)

   Arguments are followings:

   -i:<class> <entity>
          Filter devices/partitions that matches the specified <entity> on the corresponding <class>
          Classes are:
             dev       : Filter on a device name             (exemple: -i:dev ada0)
             zpool     : Filter on a ZFS pool name           (exemple: -i:zpool tank)
             part      : Filter on a partition name          (exemple: -i:part ada0p1)
             gptid     : Filter on a glabel name             (exemple: -i:gptid gptid/fe38f700-829a-11e7-810a-00074304a2f0)
             serial    : Filter on a Disk Serial number      (exemple: -i:serial YFJ4G2BD)
             multipath : Filter on a SAS multipath disk name (exemple: -i:multipath multipath/disk1)

   -fs:<fstype>
          Filter devices/partitions that have a partition that match the specified file system type
          FileSystem types are:
             none      : The disk must not be used inside a ZFS pool.   (exemple: -fs:none)
             zfs       : The disk must     be used inside a ZFS pool.   (exemple: -fs:zfs)

   -disk:<disktype>
          Filter devices/partitions that match the specified disk type
          Disk types are:
             sdd       : Solid State Drive       (exemple: -disk:ssd)
             hdd       : Spindle Drive           (exemple: -disk:hdd)
             nvme      : NVME Solid State Drive  (exemple: -disk:nvme)
             unknown   : Untyped Drive           (exemple: -disk:unknown)

   -multi[:<mode>]
          Filter devices/partitions that use SAS multipath and optionaly match the multipath mode (ACTIVE or PASSIVE)
          Multipath modes are:
             none      : The disk device must not use SAS multipath                           (exemple: -multi:none)
             active    : The disk device must     use SAS multipath and be the ACTIVE  device (exemple: -multi:active)
             passive   : The disk device must     use SAS multipath and be the PASSIVE device (exemple: -multi:passive)

          If no Multipath mode is specified, the disk device must use SAS multipath, whatever the mode of the device.

   -o:<otype>
          Output format to use for reporting devices.
          Output formats are:
             col       : Each devices are reported in a dedicated row.  Informations are padded with whitespace into columns and columns are separated by 2 whitespaces.
             csv       : Each devices are reported in a dedicated row.  Columns are separated by a semi-colon accordingly to CSV format without any padding.
             list      : Each devices are reported in   multiples rows. Each informations are dedicated on a row using the format "property: value".

         If ommited, this command consider -o:col

   -c:<columns>
          Specify a serie of columns to report represented by <columns>. Each columns have a symbol identifier.
          The appearence order of a symbol identifier determine the appearance order of the column in the report output.
          Columns identifiers are:
             p         : Partition name                 (exemple: ada0p1)
             l         : Partition label (gptid).       (exemple: gptid/fe38f700-829a-11e7-810a-00074304a2f0)
             z         : ZFS pool name                  (exemple: tank)

             d         : device code                    (exemple: ada0)
             t         : device sectorsize in Bytes     (exemple: 512)

             D         : Disk Description               (exemple: HITACHI HUS72302CLAR2000)
             U         : Disk size in Gb                (exemple: 2000)
             T         : Disk type                      (exemple: SSD)
             S         : Disk Serial Number             (exemple: YFJ4G2BD)
             R         : Disk Rotational Rate           (exemple: 7200)

             e         : Controller/Enclosure location  (exemple: SAS3008(0):1#6)

             m         : SAS Multipath device           (exemple: multipath/disk1)
             o         : SAS Multipath device mode      (exemple: ACTIVE or PASSIVE)

    -all
          Reports all columns. It's equivalent to -c:plzdtDUTSRemo

    -long
          Reports with most of columns (but omit fews). It's equivalent to -c:pzdDUSR
          It's the default layout of columns if the user didn't specify it.

    -short
          Reports with a base of columns. It's equivalent to -c:pzdDU

    -h
          Print this help.
 

Chris Moore

New Member
Nov 24, 2017
2
1
3
54

james23

Active Member
Nov 18, 2014
441
122
43
52
wow is this useful!! thanks so much! very helpful, will cron this and have it email me results daily (or save to a offsite location). thanks for sharing
 

Rand__

Well-Known Member
Mar 6, 2014
6,634
1,767
113
Any particular reason you only identify pools which have drives with gptids?
Eg it does not identify my boot

Code:
zpool status
  pool: freenas-boot
 state: ONLINE
  scan: scrub repaired 0 in 0 days 00:00:28 with 0 errors on Mon May 27 03:45:28 2019
config:

        NAME        STATE     READ WRITE CKSUM
        freenas-boot  ONLINE       0     0     0
          da0p2     ONLINE       0     0     0

errors: No known data errors

perl disklist.pl
partition  zpool  device  disk                  size  serial     rpm
--------------------------------------------------------------------
                  da0     VMware Virtual disk     68  (null)       0
                  da1     VMware Virtual disk     42  (null)       0
                  da2     VMware Virtual disk     42  (null)       0
Easily fixed o/c but wonder whether its intentional :)
 

nephri

Active Member
Sep 23, 2015
541
106
43
46
Paris, France
I have yet a pending new version available.

Before to release it, i would find someone that can review the help page with a fluent english (i'm french and i produce frenglish ^^)
I want to polish this part but i can't do it alone...

So if someone want or accept to help me and have good skills in english, don't hesitate to PM me !

Best regards,
Sébastien.
 

nephri

Active Member
Sep 23, 2015
541
106
43
46
Paris, France
A new version is available (the major update is to handle encrypted pools).
It's downloadable here : nephri/FreeNas-DiskList

Code:
version 1.1a (12/06/2019)
------------
fix:
- fix display of unused disks (when not partitioned). In 1.1 some partitioned disks were also reported as unused disks
core:
- gptid association are now done with "glabel list" + "geli list" for handling encrypted partitions (GELI)
- zpool list are now used for determine the pool mount point (from the altroot)
layout:
- columns without any values are automatically removed from the layout.
For example, if you don't have multipath drives, subsequents columns are automatically removed from the final layout
This behaviour may be disabled using switch -static
- new column "M" giving the mount point of the zfs pool associated to the specified partition
- new column "X" giving the encryption algorithm used for encrypt the specified partition
- "-all" profil is now pPlzZMdtDUTSRHXemos
- "-long" profile is now plzdDUTSRHXemos
enhance:
- new switch -locate allow to blink disk enclosure led for 10 seconds
This switch works only for drive connected to a sas hba (sas2ircu & sas3ircu compatible controllers)
- switch -multi:<multitype> can be set multiple times.
For example for listing physical drive only once you can use these arguments: -multi:none -multi:active -nolabel
- new switch "-sort:<columns>" that allow to define the sort order of partitions and devices
- new switch "-static" for prevent columns to be removed even if they are empties.
- new switch "-nolabel" that allow to report only disk information without information about partitions
- print at the end of the report the number of disks reported
 

Dave Corder

Active Member
Dec 21, 2015
296
192
43
41
I have a conceptually similar script I use on my own FreeNAS system that I based off something I think I found on the FreeNAS forums. I like this a lot better!

Could you also add support for reporting link speed (e.g., 1.5 Gbps, 3 Gbps, 6 Gbps, etc)? That bit was useful to me to verify things were working properly in my system, at least when I was using the HP SAS expanders that don't always link SATA devices at the right speeds. My Perl's a bit rusty and I don't have much free time these days, but I could potentially take a stab at that myself.
 

nephri

Active Member
Sep 23, 2015
541
106
43
46
Paris, France
Thanks,

For the speed link negociation, for sata devices, i can use camcontrol identify ada0 (but i dislike commands that i muse execute per disk)
But for sas drives, i don't know how to obtain such informations...
 

Dave Corder

Active Member
Dec 21, 2015
296
192
43
41
Thanks,

For the speed link negociation, for sata devices, i can use camcontrol identify ada0 (but i dislike commands that i muse execute per disk)
But for sas drives, i don't know how to obtain such informations...
I understand your hesitation there (the script I have takes a while to run because it has a bunch of commands for each disk...).

Link speed is also in the smartctl -i "Info" output for SATA drives; maybe SAS drives as well? (I don't have any SAS to check personally).

Example:
Code:
SATA Version is:  SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)
One option would be to change your 'smartctl -A' to 'smartctl -Ai' and re-jig the parser code for the output. Just a thought.
 

Rand__

Well-Known Member
Mar 6, 2014
6,634
1,767
113
or use dmesg info:)
Code:
 dmesg |grep da9
da9 at mpr0 bus 0 scbus3 target 11 lun 0
da9: <SEAGATE ST320004CLAR2000 BS17> Fixed Direct Access SPC-3 SCSI device
da9: Serial Number 9WM6NT6J    0000C15109JX
da9: 600.000MB/s transfers
da9: Command Queueing enabled
da9: 1907729MB (3907029168 512 byte sectors)
GEOM: da9: the primary GPT table is corrupt or invalid.
GEOM: da9: using the secondary instead -- recovery strongly advised.


 dmesg |grep transfer
da0: 300.000MB/s transfers
da1: 600.000MB/s transfers
da2: 600.000MB/s transfers
da4: 600.000MB/s transfers
da9: 600.000MB/s transfers
da5: 600.000MB/s transfers
da3: 600.000MB/s transfers
da6: 600.000MB/s transfers
da7: 600.000MB/s transfers
da8: 600.000MB/s transfers
smart does not list speed
Code:
 smartctl -a /dev/da9
smartctl 6.6 2017-11-05 r4594 [FreeBSD 11.2-STABLE amd64] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               SEAGATE
Product:              ST320004CLAR2000
Revision:             BS17
User Capacity:        2,000,398,934,016 bytes [2.00 TB]
Logical block size:   512 bytes
Rotation Rate:        7200 rpm
Form Factor:          3.5 inches
Logical Unit id:      0x5000c500348adbfb
Serial number:        9WM6NT6J    0000C15109JX
Device type:          disk
Transport protocol:   SAS (SPL-3)
Local Time is:        Wed Jun 12 22:24:09 2019 CEST
SMART support is:     Available - device has SMART capability.
SMART support is:     Enabled
Temperature Warning:  Enabled