2

I want to use dd under linux to make a backup image of my disk. With sata devices there is a /dev/sda for the disk, and /dev/sdaX for each partition.

But with this nvme I see /dev/nvme0, /dev/nvme0n1, and /dev/nbme0n1pX. That last is clearly the partitions, but which of the former should I use to backup my disk? (nvme0 vs nvme0n1).

What is the purpose of having 2 devices representing the disk?

And when I restore the disk, to which device do I write?

1
  • 1
    I'm struggling to think of a good use case for dd as a backup solution in 2024. Unless you have very specific reasons for doing this, you might benefit from considering a different approach.
    – symcbean
    Commented 12 hours ago

2 Answers 2

3

You should use /dev/nvme0n1 to image your entire disk. This is the block device associated with the nvme device; you can verify this by looking at the device major/minor numbers:

crw-------. 1 root root 238, 0 Sep 10 18:10 /dev/nvme0
brw-rw----. 1 root disk 259, 0 Sep 10 10:17 /dev/nvme0n1
brw-rw----. 1 root disk 259, 2 Sep 10 10:17 /dev/nvme0n1p1
brw-rw----. 1 root disk 259, 5 Sep 10 10:17 /dev/nvme0n1p2
brw-rw----. 1 root disk 259, 7 Sep 10 10:17 /dev/nvme0n1p3

Major number 259 corresponds to block devices:

$ grep 259 /proc/devices
259 blkext

Major device 238 corresponds to "nvme" devices:

$ grep 238 /proc/devices
238 nvme

A block device is "a disk"; you can create a backup from that devices and then write it back to another block device -- whether the target is nvme or something else.

/dev/nvme0 is an nvme device, and you would use that if you need to interact with the underlying nvme controller, e.g., using the nvme cli.

0

but which of the former should I use to backup my disk?

/dev/nvme0n1, and you will need the same target for restoration as well.

What is the purpose of having 2 devices representing the disk?

The specification for NVMe includes the concept of ‘namespaces’. Quoting directly from the official resources at https://nvmexpress.org/resource/nvme-namespaces/:

... a namespace is a collection of logical block addresses (LBA) accessible to host software. A namespace ID (NSID) is an identifier used by a controller to provide access to a namespace. A namespace is not the physical isolation of blocks, rather the isolation of logical blocks addressable by the host software.

If that sounds kind of technical, it is. From a practical perspective, you can think of NVMe namespaces as partitions that are understood and managed by the device itself instead of by the host, with the option to control some of the device’s functionality and configuration independently for each namespace.

This lets you do interesting things like use OPAL SED functionality only on part of the NVMe device, or present different slices of the device to different parts of the system without partitioning it. NVMe namespaces are also an integral part of how multipathing works with NVMe.

But the virtual block device that is a namespace is not the same thing as the NVMe controller. Because of this, for each NVMe controller in the system, Linux presents one character device for the controller (/dev/nvmeX), which is used to issue management commands (such as those used to reconfigure namespaces), and one block device for each namespace on that controller (/dev/nvmeXnY).

For almost all commercially shipped NVMe devices, there will be a single namespace covering the whole device (because this lets you plug in the device and use it immediately without any need for configuration unless you want to do something different with namespaces), so you’ll only see the one block device for each NVMe device.


As an aside, I strongly second the comment that you should be looking at something other than dd for backups. It can’t do incremental backups, it can’t actually reliably do stable backups on the system being backed up, it is entirely dependent on external tooling for deduplication, compression and encryption, and it’s astronomically unlikely you need all the extra state it’s saving (nothing sane cares about block layouts on disk, almost nothing sane except backup software cares about inode numbers, the handful of extended attributes that can’t be dumped by real backup software should be regenerated manually on restore anyway, etc).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .