Understanding plain Linux NVMe device names (in /dev and kernel messages)

July 26, 2021

On Linux, plain disk names for most modern disk devices are in the form /dev/sda for the whole disk and /dev/sda3 for the partition (regardless of whether the disk is partitioned through modern GPT or old MBR). When I got NVMe SSDs for my office workstation, one of my many discoveries about them is that Linux gives them different and more oddly formed names. Since I had many other NVMe related issues on my mind at the time, I didn't look into the odd names; I just accepted them and moved on. But now I want to actually understand how Linux's NVMe device names are formed and what they mean, and it turns out to be relatively simple.

Let's start with the actual names. On Linux, NVMe devices have three levels of names. On my office workstation, for the first NVMe device there is /dev/nvme0, /dev/nvme0n1, and then a series of /dev/nvme0n1p<X> devices for each partition. Unusually, /dev/nvme0 is a character device, not a block device. Kernel messages will talk about both 'nvme0' and 'nvme0n1':

nvme nvme0: pci function 0000:01:00.0
nvme nvme0: 15/0/0 default/read/poll queues
 nvme0n1: p1 p2 p3 p4 p5

(I don't know yet what names will appear in kernel messages about IO errors.)

If I want to partition the disk, install GRUB bootblocks, or the like, I want to use the 'nvme0n1' name. Querying certain sorts of NVMe information is done using 'nvme0'. I can apparently use either name for querying SMART information with smartctl.

Numbering NVMe SSDs instead of giving them letters and naming partitions with 'p<X>' instead of plain numbers are both sensible changes from the somewhat arcane sd... naming scheme. The unusual thing is the 'n1' in the middle. This is present because of a NVMe feature called "namespaces", which allows you (or someone) to divide up a NVMe SSD into multiple separate ranges of logical block addresses that are isolated from each other. Namespaces are numbered starting from one, and I think that most NVMe drives have only one, hence 'nvme0n1' as the base name for my first NVMe SSD's disk devices.

(This is also likely part of why 'nvme0' is a character device instead of a block device. Although I haven't checked the NVMe specification, I suspect that you can't read or write blocks from a NVMe SSD without specifying the namespace.)

The Arch wiki page on NVMe drives has a nice overview of all sorts of things you can find out about your NVMe drives through the nvme command. Based on the Arch nvme manpage, it has a lot of sub-commands and options.

For my expected uses, I suspect that I will never change or manipulate NVMe namespaces on my NVMe drives. I'll just leave them in their default state, as shipped by the company making them. Probably all consumer NVMe SSDs will come with only a single namespace by default, so that people can use the entire drive's official capacity as a single filesystem or partition without having to do strange things.

Comments on this page:

By Andy Smith at 2021-07-27 10:08:44:

I've been wondering if I should at least reformat the namespace to 4k LBAs. In theory the "nvme id-ns -H" command tells you which formats are supported and which are optimal, but for all my drives it says both 4096 byte and 512 byte sectors are "best". (512 is what it comes formatted as)

Written on 26 July 2021.
« I should probably learn command-line NetworkManager usage
Modern email is hard to search, which encourages locked up silos »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Mon Jul 26 23:10:06 2021
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.