Use this Linux command-line tool to learn more about your NVMe drives

The nvme-cli command has lots of useful options, and it's a great way to take control of how you manage your data.
48 readers like this.
Command line prompt

Opensource.com

NVMe stands for Non-Volatile Memory Express, and it refers to how software and storage communicate across PCIe and other protocols, including TCP. It's an open specification led by a non-profit organization and defines several forms of solid-state storage.

My laptop has an NVMe drive, as does my desktop. And they're fast. I love how quickly my computers boot and how quickly they're able to read and write data. There's no perceptible delay.

It also didn't take long for me to get curious about the technology driving this ultra-fast storage, so I did a little investigation. I learned that NVMe drives consume less power while delivering much faster access to data compared to even SSD drives over SATA. That was interesting, but I wanted to know more about my particular NVMe drives, and I wanted to know how they compared with other drives. Could I securely erase the drive? How could I check its integrity?

Those questions led me to an Internet search that yielded an open source project with a collection of tools to manage NVMe drives. It's called nvme-cli.

Install nvme-cli

You can install nvme-cli from your distribution's package manager. For instance, on Fedora, CentOS, or similar:

$ sudo dnf install nvme-cli

On Debian, Mint, Elementary, and similar:

$ sudo apt install nvme-cli

Exploring an NVMe drive

After installing nvme-cli for my distribution, I wanted to explore my drive. There's no man page for nvme-cli, but you can get lots of help by entering nvme help:

$ nvme help
nvme-1.14
usage: nvme <command> [<device>] [<args>]

The '<device>' may be either an NVMe character device (ex: /dev/nvme0) or an
nvme block device (ex: /dev/nvme0n1).

The following are all implemented sub-commands:
 list List all NVMe devices and namespaces on machine
 list-subsys List nvme subsystems
 id-ctrl Send NVMe Identify Controller
 id-ns Send NVMe Identify Namespace, display structure
 id-ns-granularity Send NVMe Identify Namespace Granularity List, display structure
 list-ns Send NVMe Identify List, display structure
 list-ctrl Send NVMe Identify Controller List, display structure
 nvm-id-ctrl Send NVMe Identify Controller NVM Command Set, display structure
 primary-ctrl-caps Send NVMe Identify Primary Controller Capabilities
[...]

List all NVMe drives

The sudo nvme list command lists all NVMe devices and namespaces on your machine. I used it and found an NVMe drive at /dev/nvme0n1. Here is the output:

$ sudo nvme list

Node SN Model Namespace Usage Format FW Rev

--------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------

/dev/nvme0n1    S42GMY9M141281 SAMSUNG MZVLB256HAHQ-000L7 1 

214.68 GB / 256.06 GB 512  B + 0 B 0L2QEXD7

I have a drive called nvme0n1. It lists the serial number, brand, size, firmware revision, and so on.

You can get even more information about the drive and the features it supports by using the id-ctrl subcommand:

$ sudo nvme id-ctrl /dev/nvme0n1
NVME Identify Controller:
vid : 0x144d
ssvid : 0x144d
sn : S42GMY9M141281
mn : SAMSUNG MZVLB256HAHQ-000L7
fr : 0L2QEXD7
rab : 2
ieee : 002538
cmic : 0
mdts : 9
cntlid : 0x4
ver : 0x10200
rtd3r : 0x186a0
rtd3e : 0x7a1200
[...]

Drive health

You can read about the overall health of a drive with the smart-log subcommand:

$ sudo nvme smart-log /dev/nvme0n1
Smart Log for NVME device:nvme0n1 namespace-id:ffffffff
critical_warning : 0
temperature : 21 C
available_spare : 100%
available_spare_threshold : 10%
percentage_used : 2%
endurance group critical warning summary: 0
data_units_read : 5,749,452
data_units_written : 10,602,948
host_read_commands : 77,809,121
host_write_commands : 153,405,213
controller_busy_time : 756
power_cycles : 1,719
power_on_hours : 1,311
unsafe_shutdowns : 129
media_errors : 0
num_err_log_entries : 1,243
Warning Temperature Time : 0
Critical Composite Temperature Time : 0
Temperature Sensor 1 : 21 C
Temperature Sensor 2 : 22 C
Thermal Management T1 Trans Count : 0
Thermal Management T2 Trans Count : 0
Thermal Management T1 Total Time : 0
Thermal Management T2 Total Time : 0

This provides you with the drive's current temperature, the hours of use it's had so far, how many times it was unsafely shut down, and so on.

Formatting an NVMe drive

You can format an NVMe drive with nvme-cli, but beware: This erases all of the data on the drive! If there's important data on your drive, you must back it up before doing this, or else you will lose data. The subcommand is format:

$ sudo nvme format /dev/nvme0nX

(For safety, I've replaced the actual location of the drive with X to prevent copy-paste mishaps. Change the X to 1 or the appropriate location as listed in the results of nvme list.)

Securely erasing an NVMe drive

When you get ready to sell or dispose of your NVMe computer, you probably want to erase the drive securely. The same warnings apply here as with the format process: Back up important data first because this command erases it!

$ sudo nvme sanitize /dev/nvme0nX

Try nvme-cli

The nvme-cli command is released under a GPLv2 license. It's a robust command with lots of useful options, and it's a great way to take control of how you manage your data.

What to read next
User profile image.
Educator, entrepreneur, open source advocate, life long learner, Python teacher. M.A. in Educational Psychology, M.S. Ed. in Educational Leadership, Linux system administrator.

9 Comments

Great find, just tried it.

Glad you found it useful. I"ve got two Linux computers with NVMe drives. My laptop from System76 has a Samsung SSD 970 EVO 250GB the other computer is an Intel NUC which has a Crucial 1 TB NVMe drive. I've learned a bit about the nuances of each drive with the 'nvme-cli' utility.

In reply to by alanfd_oss

Great article! I didn't know about this set of commands to examine NVMe drives. My desktop has an NVMe in it. Looks like I'm doing okay so far:

$ sudo nvme smart-log /dev/nvme0
Smart Log for NVME device:nvme0 namespace-id:ffffffff
critical_warning : 0
temperature : 35 C
available_spare : 100%
available_spare_threshold : 10%
percentage_used : 2%
endurance group critical warning summary: 0
data_units_read : 7,336,493
data_units_written : 17,442,001
host_read_commands : 59,730,342
host_write_commands : 173,036,281
controller_busy_time : 244
power_cycles : 1,271
power_on_hours : 1,249
unsafe_shutdowns : 37
media_errors : 0
num_err_log_entries : 1
Warning Temperature Time : 0
Critical Composite Temperature Time : 0
Thermal Management T1 Trans Count : 0
Thermal Management T2 Trans Count : 0
Thermal Management T1 Total Time : 0
Thermal Management T2 Total Time : 0

Here's mine:
Smart Log for NVME device:nvme0n1 namespace-id:ffffffff
critical_warning : 0
temperature : 36 C
available_spare : 100%
available_spare_threshold : 10%
percentage_used : 0%
endurance group critical warning summary: 0
data_units_read : 6,413,373
data_units_written : 18,311,308
host_read_commands : 19,884,112
host_write_commands : 26,224,405
controller_busy_time : 4,489
power_cycles : 2,052
power_on_hours : 296
unsafe_shutdowns : 53
media_errors : 0
num_err_log_entries : 0
Warning Temperature Time : 0
Critical Composite Temperature Time : 0
Temperature Sensor 1 : 36 C
Temperature Sensor 2 : 38 C
Thermal Management T1 Trans Count : 0
Thermal Management T2 Trans Count : 0
Thermal Management T1 Total Time : 0
Thermal Management T2 Total Time : 0

In reply to by Jim Hall

Your section on formatting an nvme drive: When you format it, what's the format you're formatting TO? Fat32? Ext4? Can you elaborate on WHAT format you're fomatting the drive to be in? And how you would do that? Formatting from what (UN-formatted, I guess) TO what? How would you choose which format you want?

Also, it would be great if you could add a section on upgrading an nvme drive's firmware. Because as many Linux users know all too well, most of the companies that make these drives offer nice convenient drivers for updating firmware in the MICROSOFT WINDOWS platform ONLY. Linux doesn't seem to exist for them.

I need to upgrade the firmware of a new Sabrent Rocket 4 Plus nvme drive and I'm on shaky ground, not sure if I can really do it with nvme-cli. I don't want to fry or ruin the drive.

I've unzipped what the company offers as its Windows driver, but I don't see a dot-image (.img) file there. It's all rather confusing trying to do this for the first time.

I formatted my drives in ext4. Refer to this link for more help, https://nvmexpress.org/open-source-nvme-management-utility-nvme-command-line-interface-nvme-cli/. I also found an article on Phoronix https://www.phoronix.com/scan.php?page=article&item=sabrent-rocket4-linux&num=1 that specifically mentions your drive. I have the benefit that my laptop came from System76 who used parts that are designed for Linux. The second drive that I specifically reformatted with nvme-cli was in an Intel NUC that I outfitted with a Samsung 970 EVO Plus. I later installed Windows 10 without issue on that drive and its firmware updated with Intel's firmware update utliity in the NUC. The third NVME drive I have used was a Crucial P5 1TB 3D NAND NVMe Internal SSD, I've used the 'nvme-cli' utilities on all three drives.

Thanks for the response, I hadn't seen the Phoronix benchmark review.

My concern is with updating the firmware on the Sabrent drive. I don't think I'll be able to do it, because the only update util is for windows.

I called their tech support to see if they'd give me an image file of the update, and you can guess their response.

If anyone knows of a way to update a Sabrent drive using nvme-cli, (short of pulling the drive out of my Linux box and putting into a Windows laptop that probably doesn't have an M.2 PCIe slot for it) I'd love to hear it.

In reply to by Don Watkins

Get a drive enclosure. Sabrent makes them for M.2 PCIe NVMe drives and perform the update with someone else's Windows machine. They cost less than $30.

In reply to by watchpocket

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.