NVMe Secure Erase in Linux Using nvme-cli

This article provides an overview of how the Linux operating system handles NVMe secure erase operations using the native nvme-cli utility. It details the interaction between user-space commands, the Linux kernel, and the NVMe hardware controller. Readers will learn the core mechanisms behind NVMe formatting and sanitization, the distinction between cryptographic and user data erasures, and the practical steps required to safely execute these operations on Linux.

The Architecture: How Linux Interacts with NVMe Hardware

When you manage an NVMe SSD in Linux, the operating system exposes the drive through character and block device nodes in /dev/:

The nvme-cli package is a user-space management tool. When a command like format or sanitize is run, nvme-cli does not manually overwrite sectors one by one as legacy tools (like dd) do. Instead, it constructs standard NVMe specification commands and delivers them to the Linux NVMe kernel driver using the ioctl() system call (specifically via NVME_IOCTL_ADMIN_CMD).

The kernel driver forwards these commands across the PCIe bus directly to the NVMe SSD's onboard controller. The SSD controller processes the operation at the firmware level, managing the underlying NAND flash cells independently of system CPU and RAM.


Secure Erase Methods in NVMe

The NVMe specification provides two primary mechanisms for securely erasing data: Format NVM and Sanitize.

1. Format NVM (nvme format)

The Format command is typically executed per namespace or across all namespaces. It supports the Secure Erase Settings (--ses) parameter:

2. Sanitize (nvme sanitize)

Sanitize is a controller-level operation designed for more stringent declassification standards. Unlike Format, Sanitize cannot be aborted, affects the entire drive (all namespaces), and persists even across system reboots or power cycles until the process finishes.

Sanitize supports:


Executing Secure Erase Using nvme-cli

Step 1: Identify the Drive

Before wiping data, verify the target drive and namespace:

sudo nvme list

Inspect controller capabilities to see which erase actions are supported:

sudo nvme id-ctrl /dev/nvme0

Look for the fna (Format NVM Attributes) or sanicap (Sanitize Capabilities) fields in the output to determine support for cryptographic erase, block erase, and per-namespace operations.

Step 2: Unmount Filesystems

The Linux kernel will encounter I/O errors or filesystem corruption if an active partition is wiped. Unmount all partitions and deactivate any LVM or software RAID configurations mapped to the drive:

sudo umount /dev/nvme0n1p*

Step 3: Run the Format or Sanitize Command

Option A: Cryptographic Erase via Format To initiate a cryptographic erase across namespace 1:

sudo nvme format /dev/nvme0n1 --ses=2

Option B: User Data Erase via Format To physically wipe user data blocks on namespace 1:

sudo nvme format /dev/nvme0n1 --ses=1

Option C: Controller-Wide Block Sanitize To perform an irreversible block-level sanitize across the entire controller:

sudo nvme sanitize /dev/nvme0 -a start-block-erase

Step 4: Monitor Progress (Sanitize Only)

Because Sanitize runs asynchronously in drive firmware, you must check its status:

sudo nvme sanitize-log /dev/nvme0

The output indicates the progress percentage and whether the operation has successfully finished.


Post-Erase Kernel Handling

Once the SSD controller signals completion, the Linux kernel must refresh its view of the storage device. If the drive geometry or namespace layout was altered, inform the kernel by re-reading the partition table:

sudo partprobe /dev/nvme0n1

Or trigger a hardware namespace rescan:

sudo nvme ns-rescan /dev/nvme0

At this stage, the NVMe SSD is returned to a clean, factory-like state with all target data permanently unrecoverable.