I am writing an installation automation BASH script. I'd like to install the nvme-cli
package only if an NVMe SSD is actually present.
I couldn't find a simple way to query the hardware (say, using lshw
) to get a kind-of-yes-or-no answer.
Any of you can give a way to extract the specific answer from within a BASH script?
I'd like to use the case
conditioning to either install it or not.
A directory test is sufficient:
(the path
/sys/class/nvme
is created by the modulenvme
. However, this does not say anything about the operational state of the drive(s) or even if a drive exists, though).Or, if you prefer using globbing to check for the existence of a file(s), a
for
-loop will have the advantage of avoiding a subshell:Also, if you can, you should avoid globbing as an argument, where there are alternatives, e.g., in this case, the use of
echo
orprintf
is preferable (which is, in reality, a loop construct).Check to see if any nvme device files exist:
All of these solutions should work about the same; they're all testing to see if the kernel has found a NVME device in any way.
If the installer runs at boot, this is probably adequate. If the installer might run long after boot, then the first line would be better as:
Try using lsscsi:
Check if the nvme driver is loaded
In some cases, free space is an issue, besides, i am a firm believer in not installing redundant packaged as a rule, so, eventually I went with:
Thanks!