NVMe Command Guide for Homelab Warriors: Know Your Drive Like a Pro

NVMe Command Guide for Homelab Warriors: Know Your Drive Like a Pro

So, you’ve got some fancy NVMe drives in your homelab, and you’re ready to flex your hardware muscles. But it’s not just about slapping those drives into your system and calling it a day. If you want to maximize performance (or just keep your drives from dying a fiery death), you need to get familiar with NVMe commands. Luckily, the NVMe spec gives us a lot to play with—some universal, some optional—so let’s dive into the commands you’ll actually use.

And because we're practical here, I'll throw in some examples you can use with nvme-cli, the open-source tool that works with most NVMe drives. For the sake of example, let’s target an Intel SSD 660p and an overachiever Samsung 970 Pro.

What is nvme-cli?

nvme-cli is a command-line utility that lets you manage and monitor NVMe SSDs directly from your terminal. It's like the Swiss Army knife for NVMe drives, giving you the power to query, control, and configure these drives without needing to dive into a GUI. This tool is especially useful for homelab enthusiasts (like you) who want to get hands-on with their storage.

The beauty of nvme-cli is that it uses NVMe commands right from the spec, which means you can perform everything from identifying the device, updating firmware, tweaking power management settings, and even securely erasing data. Plus, it’s open-source, so you’re not at the mercy of drive manufacturers to get things done—perfect for those who prefer a DIY approach.

Key Features:

  • Performance Testing: Check out how well your drive is doing with built-in benchmarking commands like reading and writing performance data.

Drive Health Monitoring: Easily pull SMART data to check on the health, temperature, and lifespan of your NVMe.Example:

nvme smart-log /dev/nvme0

Firmware Management: When it’s time to update, you can download and apply new firmware without bricking your drive.Example:

nvme fw-download /dev/nvme0 --fw /path/to/firmware.bin

Device Identification: Want to know what model or firmware your NVMe drive is running? nvme-cli has you covered.Example:

nvme id-ctrl /dev/nvme0

Whether you’re troubleshooting, tuning performance, or just want to make sure your NVMe drives are up-to-date, nvme-cli provides all the tools you need without unnecessary overhead. It's the go-to utility for managing SSDs in a homelab, especially if you value control and flexibility.

Installing nvme-cli

Before you can start flexing your NVMe knowledge, you’ll need to install nvme-cli, as it’s not included by default on most Linux distributions. Luckily, installation is a breeze. make sure you get your apt updates and your yummy upgrades out of the way. Apologies in advanced for some of the command translations from here out, I'm an Ubuntu/Deb whore. Here’s how to get it up and running:

Arch Linux:

sudo pacman -S nvme-cli

CentOS/RHEL:

sudo yum install nvme-cli

Fedora:

sudo dnf install nvme-cli

Ubuntu/Debian-based systems:

sudo apt install nvme-cli

After installation, you’re ready to start managing your NVMe drives like a pro. Just fire up your terminal and run any of the commands covered in this guide. Easy, right?

Admin Commands: Because the NVMe Drive Isn’t Going to Manage Itself


1. Identify (0x06): Know What You’re Working With

Before you do anything dumb (like trying to flash the wrong firmware), you should check what’s actually in your system.

Run this to get a detailed overview of your NVMe device:

nvme id-ctrl /dev/nvme0

You’ll get info like serial numbers, firmware revisions, max data transfer rates—the whole résumé of your NVMe. Perfect for when you need to brag about your hardware or verify the drive specs.


2. Set/Get Features (0x09 / 0x0A): Tweak Your Drive Like a Mad Scientist

Want to optimize power consumption? Or set a thermal threshold so your SSD doesn’t turn into a space heater? Use these commands.

Check what features are available first:

nvme get-feature /dev/nvme0 -f 0x0c

Now, to set something, like limiting power:

nvme set-feature /dev/nvme0 -f 0x02 -v 0x0020

That command sets a lower power limit. Because you’re not paying for a data center’s power bill (yet).


3. Firmware Download/Commit (0x10 / 0x11): Update Without Bricking

Updating firmware is like walking a tightrope. Do it right, and you unlock new features or stability. Do it wrong, and you’ve got yourself a shiny brick. First, download the firmware file from your manufacturer (Intel or Samsung usually have them buried in their website's labyrinth).

Here’s how to upload it:

nvme fw-download /dev/nvme0 --fw /path/to/firmware.bin

Once uploaded, commit it:

nvme fw-commit /dev/nvme0 --action=1

And now you’ve leveled up your SSD without causing a homelab disaster. Hopefully.


4. Format NVM (0x80): When You Need a Clean Slate

Sometimes, starting fresh is the only way forward. Just be aware this nukes the drive’s data, so be sure you’re not wiping out something important—unless you want an excuse to avoid finishing your homelab project.

nvme format /dev/nvme0

Boom, back to factory settings. Now it’s ready to be abused all over again.


5. Security Send/Receive (0x81 / 0x82): Keep Your Secrets Safe

Need to securely erase your data? This command ensures no one can recover your embarrassing old files. (Looking at you, "old-setup-final-final4.docx.") First, set a password and activate security if your drive supports it:

nvme security-send /dev/nvme0 --namespace-id=1 --opcode=0x81 --data=‘YourPassword’

And when it’s time for a full secure wipe:

nvme security-send /dev/nvme0 --opcode=0x82 --data=‘YourPassword’

I/O Commands: Time to Move Some Data


1. Read/Write (0x02 / 0x01): Because What Else Are NVMe Drives For?

At the heart of NVMe is its blazing read and write speeds. You can directly send I/O commands, but let’s be real, you’ll probably rely on benchmarks or your OS for this. However, for those curious, here’s a sample read command:

nvme read /dev/nvme0 --namespace-id=1 --slba=0 --nlb=127

This reads 128 logical blocks starting at LBA 0. Writing is similar, but we’ll skip that here because no one does manual writes like this.


2. Flush (0x00): Data Integrity Over Everything

NVMe drives often cache data for speed, but that can bite you if there’s a power failure. Enter the flush command, which forces the drive to commit its cache to non-volatile storage.

nvme flush /dev/nvme0

Now you can rest easy knowing that your homelab data won’t disappear in a puff of smoke.


3. Deallocate (0x09): Don’t Hoard Data—Free Up Blocks

If you’re managing storage efficiently (unlike that junk drawer in your kitchen), this command helps you free up space by deallocating blocks no longer in use.

nvme deallocate /dev/nvme0 --slba=0 --nlb=127

This tells the drive, “Hey, we’re done with this data. Do what you want with the blocks.”


4. Write Zeroes (0x08): Wipe it Clean (Again)

Need to erase data but don’t want to full-on format the drive? Writing zeroes is a quicker way to clear specific areas of your NVMe without the factory reset drama.

nvme write-zeroes /dev/nvme0 --slba=0 --nlb=127

All gone. Move along.


5. Compare (0x05): Are You Sure You Did That Right?

For the paranoid (or just meticulous) homelabber, this command lets you compare written data to what’s stored. Because why not double-check everything?

nvme compare /dev/nvme0 --slba=0 --nlb=127

Nothing like making sure your drive isn’t lying to you.


Optional Commands: When You Want to Get Fancy


Dataset Management (0x09): Play God with Your Data

This command helps manage datasets, allowing you to efficiently trim and discard unneeded blocks.

nvme dsm /dev/nvme0 --namespace-id=1 --slba=0 --nlb=127 --ad

Great for when you’re juggling data-heavy AI projects and need to keep things organized.


Reservation Register/Report (0x0D / 0x0E): Multiplayer for NVMe

Got a multi-host homelab setup? Use these commands to control access to shared NVMe storage. Definitely an edge case for home users, but hey, it’s cool to know it exists.

nvme resv-register /dev/nvme0 --rtype=1 --crkey=0x1234

And to report current reservations:

nvme resv-report /dev/nvme0

This is more for those times when you’re running clustered VMs, but it’s good to have in your back pocket.


Conclusion: Use These Commands Like You Mean It

There you go—everything you need to know to take control of your NVMe drives in a homelab environment. You now have the power to manage, tweak, and occasionally brick your drives like a real professional. Use it wisely, and make sure your drives are doing what they should be—performing like beasts without burning your data into oblivion.