NVMe/nvme-cli

nvme-cli
nvme-cli - NVMe management command line interface.

GitHub - linux-nvme/nvme-cli: NVMe management command line interface. - https://github.com/linux-nvme/nvme-cli

Build and install
apt-get install gcc make libudev-dev git pkg-config libsystemd-dev
 * 1) Ubuntu:

git clone https://github.com/linux-nvme/nvme-cli cd nvme-cli git checkout v1.8.1  # <--- recommended version! make clean make sudo make install

nvme --version

nvme --help nvme list

Build and install with additional WDC vendor specific functionality
git clone https://github.com/wdc-tools/nvme-cli.git wdc-nvme-cli cd wdc-nvme-cli make clean make sudo make install

Useful Commands
List NVME devices:

sudo nvme list

Capture E6 Log
nvme wdc cap-diag /dev/nvme0 -o e6.bin

Read Example
nvme read: --start-block=, -s  --block-count=, -c  --data-size=, -z  --data=, -d 

Pass or fail result:

sudo nvme read /dev/nvme0n1 -s 1 -c 0 -z 4096 read: Success
 * 1) read lba 1 -> lba 2

Read to file:

sudo nvme read /dev/nvme0n1 -s 1 -c 0 -z 4096 -d read.img read: Success
 * 1) read lba 1 -> lba 2

Write Example
nvme write: --start-block=, -s  --block-count=, -c  --data-size=, -z  --data=, -d 

Write data:

sudo nvme write /dev/nvme0n1 -s 1 -c 0 -z 4096 -d write.img read: Success
 * 1) write lba 1 -> lba 2

Read Write Example
dd if=/dev/urandom of=write_data.img bs=4k count=1
 * 1) write 4k random data file

sudo nvme write /dev/nvme0n1 -s 1 -c 0 -z 4096 -d write_data.img
 * 1) write 4k random data file to nvme device at first block

sudo nvme read /dev/nvme0n1 -s 1 -c 0 -z 4096 -d read_data.img
 * 1) read 4k random data file from nvme device at first block

md5sum write_data.img read_data.img
 * 1) checksum both (should match)

Format
4k or 512 format may or may not be the default, so check the LBA Format options first:

List LBA Format Options: $ sudo nvme id-ns -H /dev/nvme0n1 ... LBA Format 0 : Metadata Size: 0   bytes - Data Size: 4096 bytes - Relative Performance
 * 0 Best (in use)

LBA Format 1 : Metadata Size: 0   bytes - Data Size: 512 bytes - Relative Performance: 0 Best

Format with chosen LBA Format option: $ sudo nvme format /dev/nvme0n1 $ sudo nvme format /dev/nvme0n1 --lbaf=0
 * 1) default LBA format

$ sudo nvme format /dev/nvme0n1 --lbaf=1
 * 1) LBA format option 1

--

$ sudo nvme id-ns /dev/nvme0n1 lbaf 0 : ms:0   lbads:12 rp:0 (in use) lbaf 1 : ms:0   lbads:9  rp:0

ms:0 = metadata size is 2^0 = 0 lbads 12 = LBA size = 2^12 = 4096 lbads 12 = LBA size = 2^9 = 512

Activate Firmware
$ sudo nvme fw-download /dev/nvme0 -f firmware_image.vpkg $ sudo nvme fw-activate /dev/nvme0 --action 1 --slot 1 $ sudo nvme reset /dev/nvme0

SMART Log
nvme smart-log /dev/nvme0

additional smart log:

nvme smart-log-add /dev/nvme0

Temperature
nvme smart-log /dev/nvme0 | grep "^temperature"

Unmap
There is a Dataset Management Deallocate command (UNMAP) in nvme-cli: sudo nvme dsm /dev/nvme0n1 -d -s 0x1bf0ea00 -b 0xff

nvme dsm /dev/nvme0n1 -d -s 0x100000 -b 0x80000 0x80000 blocks, starting at 0x100000. -s and -b can be, separated lists to do multiple ranges

keywords
nvme nvme-cli NVME CLI