Wandering Thoughts archives

2021-07-26

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

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.

linux/NVMeDeviceNames written at 23:10:06; Add Comment


Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.