How to Format an NVMe Drive? How to Permanently Erase Data from an NVMe Drive?

| F.A.Q.Support

How to Format an NVMe Drive? How to Permanently Erase Data from an NVMe Drive?

The nvme-cli format command is used to format an NVMe drive based on specific parameters. It can be used to change the sector format (block size) or to perform a complete data wipe. Below is a detailed explanation of how the command works and its key options.

Basic Usage

The command to format an NVMe drive is as follows:

sudo nvme format /dev/nvmeXnY

Where /dev/nvmeXnY is the path to the NVMe device you want to format, such as /dev/nvme0n1.

Running this command without additional options will format the NVMe drive using its default sector size and other parameters.

Main Formatting Options

When formatting an NVMe drive using nvme-cli, you can use several options to better tailor the formatting process to your needs.

  • Changing Sector Size

The logical block size (sector size) can be changed using the -l option (logical block size). Most NVMe drives support multiple sector sizes, such as 512 bytes or 4096 bytes. To format the drive with a 4K (4096 bytes) sector size, use:

sudo nvme format /dev/nvmeXnY -l 2

    -l 0: 512 B sectors
    -l 1: 512 B sectors + extended size
    -l 2: 4096 B (4K) sectors

Secure Erase

nvme-cli offers the option to perform a secure erase, meaning a full and secure deletion of data from the drive. This is especially useful if you want to ensure that all data is permanently removed. To perform a secure erase:

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

    --ses=0: No data removal.
    --ses=1: Normal data removal, which overwrites all sectors with zeros.
    --ses=2: Secure data removal, often requiring drive support.

Force Format

If the drive is locked by a password (e.g., after using TCG OPAL functions), you may need to force format using the --force option. This option ignores warnings and forces formatting, which may result in permanent data loss.

sudo nvme format /dev/nvmeXnY --force

Preserve Sector Size

If you want to ensure that the drive is formatted with its current sector size without changing it, use the -l option with the value current:

sudo nvme format /dev/nvmeXnY -l current

Example of Full Formatting with Secure Erase:

If you want to perform a full format of the NVMe drive, overwriting all data with zeros (secure erase), you can do it as follows:

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

This process will completely erase the data and restore the drive to factory settings unless you change the sector size.

Checking Supported Drive Format Information

Before formatting, it's a good idea to check what formats are supported by the NVMe drive. You can do this with the following command:

nvme id-ns /dev/nvmeXnY

This command will display detailed information about the drive's namespace, including supported block sizes.

Sanitize

The --sanitize option in the nvme-cli tool is used for the secure deletion of all data from the NVMe drive, in compliance with higher security standards. Sanitize operates at the physical memory level, meaning that after its execution, data is irreversibly destroyed, even if recovery technologies (e.g., cell-level backups) have been used.
Types of Sanitize:

The sanitize command can perform one of three types of data removal processes:

  1. Block Erase: Physically erases memory blocks (most effective and fastest if supported by the drive).
  2. Crypto Erase: Destroys the cryptographic key used to encrypt the drive's data.
  3. Overwrite: Overwrites all data on the drive with a specified pattern (e.g., zeros), generally a slower method.

Using Sanitize in nvme-cli:

To begin the sanitization process, use the following command:

sudo nvme sanitize /dev/nvmeXnY --ses=type

Where:

    --ses=type defines the type of sanitization process:
        --ses=1: Overwrite.
        --ses=2: Block Erase (if supported).
        --ses=3: Crypto Erase.

Example of Crypto Erase:

sudo nvme sanitize /dev/nvme0n1 --ses=3

Monitoring Sanitize Progress

The sanitization process may take some time, depending on the size of the drive and the chosen method. To monitor its progress, you can use the command:

nvme sanitize-log /dev/nvmeXnY

Example of Full Sanitize with Crypto Erase:

sudo nvme sanitize /dev/nvme0n1 --ses=3

This command will perform data removal using cryptographic erasure, which is the fastest method if the drive supports encryption.

Important Notes:

    Irreversibility: The sanitize process is irreversible, and data cannot be recovered after its completion.
    Drive Support: Not all NVMe drives support all sanitization methods. You can check available options using the command nvme id-ctrl /dev/nvmeXnY (look for the SANICAP field, which shows Sanitize Capabilities).
    Security: The sanitize function meets the standards required for data destruction according to corporate and institutional security policies.

Summary:

  1. Formatting: Used to change logical block sizes or completely wipe data from the drive.
  2. Secure Erase: You can perform secure data deletion using the --ses option.
  3. Sanitize: A tool for thoroughly and securely wiping an NVMe drive, with options to select the data removal method (overwrite, physical block erase, cryptographic key destruction).
  4. Block Size Change: The -l option allows you to choose the appropriate block size, such as 512 bytes or 4096 bytes.

Note: Formatting a drive results in data loss, so ensure you have a backup before proceeding.

The nvme-cli format command is a powerful tool that gives full control over formatting the NVMe drive and managing its sector sizes.

Related pages:

  1. Linux Tools - dd
  2. Linux tools - Hdparm - (Disk management and bandwidth testing).
  3. Bad sector removal (hdparm) - How to remove bad sectors?
  4. Installing Windows on an M.2 NVMe drive [AMI Native Support].
  5. The NVMe drive is marked as faulty by the BIOS on Supermicro motherboards (NVM Express Controller Failed)
  6. Updating NVMe Drive Firmware Using nvme-cli: Example with Samsung PM9A3