Boston Terrier inside a vehicle

Manage your NVMe drive in the Linux terminal

Learn how to manage NVMe drives directly from the Linux terminal using the Open Source nvme-cli…
Home » Blog » Manage your NVMe drive in the Linux terminal

Both of my laptops use non-volatile memory express (NVMe) drives, and their speed is undeniable. Faster boot times and smoother data operations are clear advantages. To gain more control over these drives, I’m interested in exploring how to manage them directly through the Linux terminal. Learning these commands can allow for performance optimization, health monitoring, and potentially, uncover additional features. It seems like a practical way to get more out of the NVMe drives.

I decided to explore the technology behind this blazing-fast storage. After a bit of research, I discovered that NVMe drives not only offer exceptional speed but also consume less power compared to traditional SSD drives using SATA connections. The efficiency intrigued me, but I wanted to delve deeper into the specifics of my NVMe drives and compare them with other options. I had questions about securely erasing the drive and ensuring its integrity.

A quick internet search led me to the perfect solution—an Open Source project called nvme-cli. This collection of tools provides comprehensive management capabilities for NVMe drives, offering the functionality I was seeking and more.

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

Getting help

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.16
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 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’s the output:

$ sudo nvme list
[sudo] password for don: 
Node                  SN                   Model                                    Namespace Usage                      Format           FW Rev  
--------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1          ASB3N553810103J14    SK hynix PC711 HFS001TDE9X073N           1           1.02  TB /   1.02  TB    512   B +  0 B   HPS0    

Drive information

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       : 0x1c5c
ssvid     : 0x1c5c
sn        : ASB3N553810103J14   
mn        : SK hynix PC711 HFS001TDE9X073N          
fr        : HPS0    
rab       : 3
ieee      : ace42e
cmic      : 0
mdts      : 6

Drive health

You can check out 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                : 29 C (302 Kelvin)
available_spare                : 100%
available_spare_threshold        : 5%
percentage_used                : 0%
endurance group critical warning summary: 0
data_units_read                : 8,524,708
data_units_written            : 5,777,269

Format your drive

Be careful when you use the nvme-cli format command. This action erases all data on the target drive. It’s crucial to back up any essential data before proceeding with the formatting process to avoid permanent data loss.

$ sudo nvme format /dev/nvme0nx

Securely erase your drive

When the time comes to sell or dispose of a NVMe drive, you can erase and “sanitize” the drive to remove all traces of the data it once held. As with the formatting process, it’s essential to back up any crucial data before initiating this command, because it’s intended to make data unrecoverable!

$ sudo nvme sanitize /dev/nvme0nx

And those are your basics. 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.

The nvme-cli is Open Source and it’s been a great tool for me as an NVMe drive owner. Try it for yourself!

Author

  • Don Watkins

    Educator, entrepreneur, open source advocate, life long learner, Python teacher. M.A. in Educational Psychology, M.S. in Educational Leadership, Linux system administrator, Follow me on Mastodon, https://fosstodon.org/@donwatkins

    View all posts

If you enjoyed this post, you might also enjoy these