13

Since SSD has write amplification, I want to reset the SSD to the initial out-of-box performance. Most tutorials are for SATA SSD (hdparm --secure-erase), I want to know how to erase a partition of NVMe SSD (maybe use nvme command?).

One more question: does dd if=/dev/zero of=/dev/nvme0n1 help? Or does fio --filename=/dev/nvme1n1 --direct=1 --buffered=0 --rw=trim --bs=4k --size=100G --numjobs=16 --iodepth=32 --group_reporting --name=trim help?

Thanks!

3
  • One partition or entire device? See nvme help & then nvme help format I have in my notes this but never used it. It will erase entire drive. sudo nvme format -s1 <device> To see devices: sudo nvme list
    – oldfred
    Jan 23, 2021 at 15:11
  • sudo nvme format -s1 <device> works! Thanks for the help.
    – Tim He
    Jan 25, 2021 at 8:05

3 Answers 3

19

To totally erase a NVMe drive.

This will erase entire drive.

You may need to first install nvme - the NVMe storage command line interface utility (nvme-cli). Then review commands and list all nvme devices. List wil also show firmware revision & you should check that you have latest firmware.

sudo apt install nvme-cli
nvme help
nvme --help
nvme --help format
sudo nvme list
sudo nvme format -s1 <device>

    fred@z170-focal-k:/mnt/data$ sudo nvme list
[sudo] password for fred: 
Node             SN                   Model                                    Namespace Usage                      Format           FW Rev  
---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1     S4P2NF0M514514L      Samsung SSD 970 EVO Plus 500GB           1         164.30  GB / 500.11  GB    512   B +  0 B   2B2QEXM7

See comment below y rootkea, if using more than one namespace.

Use -n 0xffffffff to format all the namespaces.

see also

man nvme
4
  • 1
    How long should this secure erase take? I tried doing this and got Success formatting namespace:1 after only about 2-3 seconds. It seems way too fast for a 480 GB drive.
    – Brad
    Nov 13, 2021 at 17:28
  • 5
    In general, securely erasing an SSD does not involve writing every bit, which would take a long time. And the NVME standard has secure erase built in, so the drive maker (presumably) made this very fast. Jan 27, 2022 at 4:15
  • 4
    @Brad I suspect that secure erase mostly entails destroying (forgetting) the key used to encrypt and decrypt the data and generating a new key.
    – Syncopated
    Nov 16, 2022 at 5:44
  • 1
    @Brad Use -n 0xffffffff to format all the namespaces. @oldfred please update the answer adding this bit. Thanks!
    – rootkea
    Jul 7, 2023 at 1:30
3

For resetting to Out Of Box performance you DO NOT want to use the "write zeroes" technique of dd/fio. There is a BIG semantic difference saying "this area must contain and maintain zeroes" (fio/dd technique) and saying "this area is must be empty" (secure erase). For example the Solid State Storage (SSS) Performance Test Specification (PTS) specifies techniques it considers reasonable for preconditioning.

2

As OldFred's post states, you need to use an actual secure erase utility, such as the nvme-cli package.

The reason this will run so quickly is because the drive's contents are already transparently encrypted. That is, if you were to read the flash chips directly, you would not find any of the content you see on your drive when accessing it normally. The onboard controller handles this process completely transparently, storing the encryption key in a secure enclave within the controller.

This is useful both from a security and longevity standpoint. Encrypting data helps soften repetitive pattern writes from being so repetitive, which in turn helps to decrease the wear and tear on flash cells.

When you run a secure erase on an SSD, no data is actually being erased -- instead, the controller is generating a new encryption key and writing it into the secure enclave, overwriting the old key in the process and permanently rendering all binary data on the flash cells unrecoverable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .