NVMe Information for Inventory



  • I have found a method to get at least some of the information about NVMe drives. This will get the model and serial number. I was not able to get the firmware version without using either the nvme-cli or smartctl tools.

    Here is a bash script I used for testing.

    !/bin/bash
    
    hd=`lsblk -dpno KNAME -I 3,8,9,179,202,253,259 | uniq | sort -V | head -1`
    hdinfo=$(hdparm -i $hd 2>/dev/null)
    
    #FOG expects the string in the following format
    ##Model=ST31500341AS, FwRev=CC1H, SerialNo=9VS34TD2
    
    if [[ ! -z $hdinfo ]]; then
      disk_info=`lsblk -dpJo model,serial ${hd}`
      model=`echo ${disk_info} | jq --raw-output '.blockdevices[] | .model' | sed -r 's/^[ \t\n]*//;s/[ \t\n]*$//'`
      sn=`echo ${disk_info} | jq --raw-output '.blockdevices[] | .serial' | sed -r 's/^[ \t\n]*//;s/[ \t\n]*$//'`
      hdinfo="Model=${model},SerialNo=${sn}"
    else
      hdinfo=`echo ${hdinfo} | grep Model=`
    fi
    
    echo $hdinfo
    


  • New script using smartctl. Grabs firmware now as well.

    #!/bin/bash
    
    hd=$(lsblk -dpno KNAME -I 3,8,9,179,202,253,259 | uniq | sort -V | head -1)
    
    #FOG expects the string in the following format
    ##Model=ST31500341AS, FwRev=CC1H, SerialNo=9VS34TD2
    
    disk_info=$(smartctl -i $hd)
    model=$(echo "${disk_info}" | sed -n 's/.*\(Model Number\|Device Model\):[ \t]*\(.*\)/\2/p')
    sn=$(echo "${disk_info}" | sed -n 's/.*Serial Number:[ \t]*\(.*\)/\1/p')
    firmware=$(echo "${disk_info}" | sed -n 's/.*Firmware Version:[ \t]*\(.*\)/\1/p')
    hdinfo="Model=${model}, iFwRev=${firmware}, SerialNo=${sn}"
    
    echo $hdinfo
    

    This works for NVMe and SATA. Note that SATA drives use a ‘Device Model’ where as NVMe drives use ‘Model Number’. This could lead to issues if other drives report it differently.


  • Senior Developer

    @sebastian-roth jq is added for the 1.5.0 inits.



  • I missed that smartctl was in FOS. I will switch it over to smartctl then. That can actually be used for all the drive types. Will require more parsing but it should not be to bad. jq is in FOS, at least it is in 1.5-RC14.


  • Developer

    @jburleson Thanks for your suggestion on using lsblk. Although I really like using it, it does not play nicely on my VM machine - serial is empty. I guess we see this with other machines as well. Why not use smartctl -x /dev/...? Sounds like you tested it and it does work with your NVMe, right? It’s part of the FOS image anyway, so why shouldn’t we use it? As well it works within my test VM.

    By the way, jq is not part of the FOS image yet. Not saying that we can’t add it but I prefer using what we already have to keep things simple.


 

526
Online

41.9k
Users

12.5k
Topics

117.7k
Posts