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?
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:Major number 259 corresponds to block devices:
Major device 238 corresponds to "nvme" devices:
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 thenvme
cli./dev/nvme0n1
, and you will need the same target for restoration as well.The specification for NVMe includes the concept of ‘namespaces’. Quoting directly from the official resources at https://nvmexpress.org/resource/nvme-namespaces/:
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).