• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    NVMe Information for Inventory

    Scheduled Pinned Locked Moved
    Feature Request
    3
    5
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jburleson
      last edited by

      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
      
      1 Reply Last reply Reply Quote 0
      • S
        Sebastian Roth Moderator
        last edited by Sebastian Roth

        @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.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        Tom ElliottT 1 Reply Last reply Reply Quote 0
        • J
          jburleson
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • Tom ElliottT
            Tom Elliott @Sebastian Roth
            last edited by

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

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            1 Reply Last reply Reply Quote 0
            • J
              jburleson
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post

              213

              Online

              12.0k

              Users

              17.3k

              Topics

              155.2k

              Posts
              Copyright © 2012-2024 FOG Project