Unlike SATA SSDs (which use hdparm or ATA SECURE_ERASE ), NVMe drives use a different command set. The correct way is typically via the nvme-cli tool. Important Warning
Data is NOT recoverable. This permanently destroys all data on the drive, including the file system, partition table, and any user data. Performance: This typically restores the drive to factory write performance. Locked Drives: If the drive is password-locked (e.g., BIOS security freeze), you may need to suspend the OS or hot-plug the drive.
Prerequisites
Install nvme-cli: # Ubuntu/Debian sudo apt install nvme-cli RHEL/CentOS/Fedora sudo yum install nvme-cli nvme secure erase
Identify the NVMe device: sudo nvme list
Look for the device node (e.g., /dev/nvme0n1 ). Note the Namespace ID (usually 1 ).
Method 1: The Standard NVMe Format (Recommended) This sends a nvme format command to the namespace. It is the fastest and most reliable method. sudo nvme format /dev/nvme0n1 --ses=1 --lbaf=0 Unlike SATA SSDs (which use hdparm or ATA
--ses=1 : Secure Erase Setting = 1 (User data erase). (Option 2 = Cryptographic erase if drive supports it). --lbaf=0 : Use the default LBA Format (sector size). Use nvme id-ns /dev/nvme0n1 -n 1 to see available LBAFs.
After this command completes (usually 2-10 seconds), the drive is completely blank. You must repartition it. Method 2: The Sanitize Command (Thorough, Slower) The sanitize command is a newer, more thorough erase (similar to ATA "Enhanced Secure Erase"). It overwrites or blocks all media. sudo nvme sanitize /dev/nvme0n1 --sanact=1 --no-secure-erase
--sanact=1 : Exit failure mode (completes the sanitize operation). --no-secure-erase : Use Block Erase (overwrites). Add --ovrpat=0x00 if you want a pattern write. This permanently destroys all data on the drive,
Note: Some enterprise drives require sanitize over format for certain compliance standards. Method 3: Cryptographic Erase (Fastest, but specific) If your NVMe drive supports hardware encryption (most modern ones do), you can simply delete the encryption key. sudo nvme format /dev/nvme0n1 --ses=2
--ses=2 : Cryptographic Erase (changes the media encryption key). This takes 0.5 seconds.