Difference between revisions of "NVMe/nvme-cli"

From Omnia
Jump to navigation Jump to search
 
Line 16: Line 16:
 
  make clean
 
  make clean
 
  make
 
  make
 +
rm -f `which nvme`  # remove previous version, as 1.8.1 installed in a different location
 
  sudo make install
 
  sudo make install
  

Latest revision as of 12:02, 24 March 2020

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

# Ubuntu:
apt-get install gcc make libudev-dev git pkg-config libsystemd-dev
git clone https://github.com/linux-nvme/nvme-cli
cd nvme-cli
#git checkout v1.8.1   # <--- recommended version!
git checkout v1.10.1   # <--- recommended version!
make clean
make
rm -f `which nvme`  # remove previous version, as 1.8.1 installed in a different location
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 WDC E6 Log

nvme wdc cap-diag /dev/nvme0 -o e6.bin
nvme wdc vs-internal-log /dev/nvme0 -o e6.bin

Read Example

nvme read:

--start-block=<NUM>, -s <NUM>
--block-count=<NUM>, -c <NUM>
--data-size=<NUM>, -z <NUM>
--data=<FILE>, -d <FILE>

Pass or fail result:

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

Read to file:

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

Write Example

nvme write:

--start-block=<NUM>, -s <NUM>
--block-count=<NUM>, -c <NUM>
--data-size=<NUM>, -z <NUM>
--data=<FILE>, -d <FILE>

Write data:

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

Read Write Example

# write 4k random data file
dd if=/dev/urandom of=write_data.img bs=4k count=1

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

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

# checksum both (should match)
md5sum write_data.img read_data.img

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:

# default LBA format
$ sudo nvme format /dev/nvme0n1
$ sudo nvme format /dev/nvme0n1 --lbaf=0
# LBA format option 1
$ sudo nvme format /dev/nvme0n1 --lbaf=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