randy/NVME-block-size.md
2023-08-19 20:42:49 -07:00

1.9 KiB

Optimizing Block Size of an NVME Drive

from Robert Edmonds @edmonds@infosec.exchange

TIL how to switch an NVMe SSD from 512B to 4K sector size, if supported. Not all drives support this, but the Solidigm P41 Plus 512GB ($25) that I tested does.

  • Boot off a Debian Live image.

  • Install the nvme-cli package.

  • Confirm that the drive supports the 4K sector size but is currently using 512B sectors:

root@debian:~# fdisk -l /dev/nvme0n1
Disk /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SOLIDIGM SSDPFKNU512GZ
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
root@debian:~# nvme id-ns /dev/nvme0n1 -H
[…]
LBA Format 0 : Metadata Size: 0 bytes - Data Size: 512 bytes - Relative Performance: 0 Best (in use)
LBA Format 1 : Metadata Size: 0 bytes - Data Size: 4096 bytes - Relative Performance: 0 Best

This particular drive supports 4K sectors as "LBA Format 1". This format index can vary by drive. Reformat the drive using "LBA Format 1" (--lbaf=1):

root@debian:~# nvme format /dev/nvme0n1 --lbaf=1 --reset --force
Success formatting namespace:1

Confirm that the drive is now using the 4K sector size:

root@debian:~# fdisk -l /dev/nvme0n1
Disk /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 125026902 sectors
Disk model: SOLIDIGM SSDPFKNU512GZ
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
root@debian:~# nvme id-ns /dev/nvme0n1 -H
[…]
LBA Format 0 : Metadata Size: 0 bytes - Data Size: 512 bytes - Relative Performance: 0 Best
LBA Format 1 : Metadata Size: 0 bytes - Data Size: 4096 bytes - Relative Performance: 0 Best (in use)

Now install the OS. Note that the EFI Service Partition needs to be at least 260 MB on a drive with 4K sectors.


2023.08.19