Skip to content

Commit

Permalink
Retrieve generic information about NVMe disks
Browse files Browse the repository at this point in the history
Add nvme-cli to Recommends and try to gather generic NVMe information
from disks

NOTE: we identify the NVMe disks using lsblk, because this doesn't
require any special tools or alike then. We could use something like:

  nvme list --output-format=json | jq -r '.Devices[].DevicePath'

But then we'd need to have jq available. Also, if there is no
NVMe subsystem available (like often in VMs), then we'd get:

  {
    "error":"Failed to scan topology: No such file or directory"
  }

... in its *stdout* and would need to deal with that then.

Closes: #5
  • Loading branch information
mika committed Aug 2, 2024
1 parent 52436a1 commit 6bfd6dd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Recommends:
mokutil,
net-tools,
numactl,
nvme-cli,
open-iscsi,
parted,
powermgmt-base,
Expand Down
48 changes: 48 additions & 0 deletions grml-hwinfo
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,51 @@ get_network_devices() {
done
}

nvme_info() {
if ! exectest nvme ; then
return 0
fi

# `nvme list` returns with `Failed to scan topology` and exit code 1,
# if there's no NVMe device present. There's no point in running any
# further commands then, so let's avoid collecting empty files and
# error messages
if ! nvme list &>/dev/null ; then
return 0
fi

# list
nvme list > ./nvme_list 2>./nvme_list.error
nvme list --output-format=json > ./json/nvme_list

# list-subsys
nvme list-subsys > ./nvme_list-subsys 2>./nvme_list-subsys.error
nvme list-subsys --output-format=json > ./json/nvme_list-subsys

# get list of available disks
mapfile -t nvme_disks < <(lsblk -nd -o NAME -e 7,11 | sed -n 's/^nvme/\/dev\/&/p')

for disk in "${nvme_disks[@]}" ; do
disk_name="${disk##*/}" # /dev/nvme0n1 -> nvme0n1

# smart-log
nvme smart-log "$disk" > ./nvme_smart-log_"${disk_name}"
nvme smart-log --output-format=json "$disk" > ./json/nvme_smart-log_"${disk_name}"

# fw-log
nvme fw-log "$disk" > ./nvme_fw-log_"${disk_name}"
nvme fw-log --output-format=json "$disk" > ./json/./nvme_fw-log_"${disk_name}"

# error-log
nvme error-log "$disk" > ./nvme_error-log_"${disk_name}"
nvme error-log --output-format=json "$disk" > ./json/./nvme_error-log_"${disk_name}"

# effects-log
nvme effects-log "$disk" > ./nvme_effects-log_"${disk_name}"
nvme effects-log --output-format=json "$disk" > ./json/./nvme_effects-log_"${disk_name}"
done
}

# Check if X server is running
#
# If xset is missing, we rely on the existence of the $DISPLAY variable.
Expand Down Expand Up @@ -459,6 +504,9 @@ cd "${OUTDIR}" || exit 1
lsscsi -t > ./lsscsi_transport 2>./lsscsi_transport.error
fi

# NVMe
nvme_info

for disk in $disklist; do
if exectest sfdisk && [[ -b "/dev/${disk}" ]] ; then
sfdisk -d "/dev/${disk}" > "./sfdisk_${disk}" 2>"./sfdisk_${disk}.error"
Expand Down

0 comments on commit 6bfd6dd

Please sign in to comment.