Linux › Section C · Devices › Topic C.3

Device name summary

Before you can partition a disk, open a serial console or write an image to a USB stick, you need the device's name. Linux names follow patterns, such as sda1 or nvme0n1p2, and once you can decode them, and find them reliably, you can work with hardware confidently.

Ways to find a device's name

Several methods can reveal which name the kernel gave a device. lsblk lists block devices as a tree of disks and partitions with their sizes and mount points. udevadm info, which queries udev, is the most reliable source and also gives stable alternative names. The /sys tree shows every device the kernel knows about. journalctl -k, or dmesg, shows kernel messages, which usually announce each device as it is found. mount, or findmnt, shows which devices hold mounted filesystems. cat /proc/devices lists the major numbers of loaded drivers, which you can match against ls -l /dev. Without udev, the guesswork methods are all you have, and a device may have no file at all.

SCSI-style disks: /dev/sd*

Most disks are named /dev/sda, /dev/sdb, continuing through the alphabet, each a whole disk, with partitions numbered after the letter: /dev/sda1, /dev/sda2. After sdz come sdaa, sdab and onwards. The sd stands for SCSI disk. Real SCSI hardware is rare, but the SCSI command set is used for SATA disks, through a translation layer, and for USB storage, so all of these get sd names. lsscsi, if installed, lists such devices with their SCSI addresses. Letters are handed out in the order drivers find the disks, so they can change: if /dev/sdb fails and is removed, the old /dev/sdc becomes /dev/sdb at the next boot.

Stable names

Because detection order can shift, configuration files should not rely on names such as /dev/sdb. udev creates permanent symbolic links that follow the device instead: /dev/disk/by-id/ uses the model and serial number, /dev/disk/by-uuid/ uses the unique identifier stored in each filesystem, /dev/disk/by-label/ uses filesystem labels, and /dev/disk/by-path/ uses the physical connection. Filesystems are therefore usually listed by UUID in /etc/fstab, as Mounting filesystems and /etc/fstab shows. The Logical Volume Manager, covered in its own topic, gives volumes stable names too, under /dev/mapper.

NVMe, virtual and memory-card storage

Solid-state drives on the NVMe interface are named differently: /dev/nvme0n1 is controller 0, namespace 1, and its partitions add p and a number, as in /dev/nvme0n1p1. Most drives have one namespace, so n1 is usual. The nvme list command, from the nvme-cli package, lists them. Virtual machines often use paravirtual disks: /dev/vda for virtio disks and /dev/xvda for Xen, used by some cloud providers. SD cards and built-in eMMC storage appear as /dev/mmcblk0, with partitions /dev/mmcblk0p1. Partition names add p whenever the disk name ends in a digit, so the number stays readable.

Other storage names

Loop devices, /dev/loop0 and onwards, present an ordinary file as a disk; Ubuntu's snap packages are mounted from them, which is why such systems list many loop entries. The device mapper, used by LVM and disk encryption, creates /dev/dm-0 and similar, with friendlier links in /dev/mapper. Optical drives are /dev/sr0 and onwards, block devices that are read-only as such; burning programs send raw drive commands instead, through /dev/sr0 itself or the generic SCSI nodes, /dev/sg0 and onwards. Very old systems named parallel ATA disks /dev/hda to /dev/hdd. The old driver that made those names was removed in Linux 5.14 (2021), and such disks appear as sd devices instead.

Terminals and consoles

Terminal devices carry characters between a process and a screen and keyboard. /dev/tty1, /dev/tty2 and so on are virtual consoles, separate text screens on the physical display; from a graphical session, Ctrl+Alt+F3, for example, switches to the third, and as root chvt 3 does the same from a command line. Which console holds the desktop varies by distribution. Terminal windows and SSH sessions use pseudo-terminals, /dev/pts/0, /dev/pts/1 and so on, emulated by software rather than tied to hardware. The tty command prints the name of your current terminal. /dev/tty always means the controlling terminal of the process using it.

Serial ports and other devices

Built-in serial ports, of the RS-232 kind, are /dev/ttyS0, /dev/ttyS1 and so on; the port Windows calls COM1 is /dev/ttyS0. USB serial adapters appear as /dev/ttyUSB0, and many microcontroller boards as /dev/ttyACM0. They usually belong to the dialout group, so adding a user to that group grants access. A terminal program such as screen /dev/ttyACM0 115200 connects at a chosen speed. Old parallel printer ports are /dev/lp0 and /dev/lp1. Sound cards appear under /dev/snd, used by ALSA, but programs normally reach them through a sound server such as PipeWire. Input devices such as keyboards and mice appear as /dev/input/event0 and so on.

Worked example: naming a new USB stick

You plug in a USB stick and want its name before writing to it. 1. Run lsblk before and after inserting it; the new entry is the stick. 2. Confirm with journalctl -k, where illustrative lines read sd 6:0:0:0: [sdb] 60555264 512-byte logical blocks: (31.0 GB/28.9 GiB) and then sdb: sdb1. 3. Check the arithmetic: 60,555,264 × 512 = 31,004,295,168 bytes, about 31.0 GB, matching the label on a 32 GB stick. 4. So the whole stick is /dev/sdb and its one partition /dev/sdb1. 5. Check the model as well with lsblk -o NAME,SIZE,MODEL before any destructive command such as dd.

Worked example: decoding names

Read each name from left to right. 1. /dev/sdc3: SCSI-style disk c, the third found, partition 3. 2. /dev/nvme1n1p2: NVMe controller 1, namespace 1, partition 2; the p separates the partition because the name ends in a digit. 3. /dev/mmcblk0p1: the first SD card or eMMC device, partition 1. 4. /dev/vdb: the second virtio disk in a virtual machine, as a whole disk. 5. /dev/ttyUSB0: the first USB serial adapter, a character device rather than storage. 6. /dev/pts/4: a pseudo-terminal, perhaps an SSH session. 7. /dev/sr0: the first optical drive. Knowing which names are whole disks prevents writing to a partition by mistake.

Common mistakes to avoid

First, assuming /dev/sda is always the system disk; the order depends on detection and can change. Second, writing a disk image to a partition such as /dev/sdb1 when the whole device /dev/sdb was meant, or the reverse. Third, forgetting the p in NVMe and memory-card partition names, as in nvme0n1p1. Fourth, using names such as /dev/sdb in /etc/fstab instead of UUIDs. Fifth, expecting /dev/hda names on a modern system. Sixth, trusting a single source: confirm a target's size and model with lsblk before any destructive command.

Key takeaways

Find names with lsblk, udevadm info, /sys, journalctl -k, mount and /proc/devices; udev is the most reliable. /dev/sda, sdb and so on are SCSI-style disks, including SATA and USB, with partitions sda1 and so on, assigned in detection order. Stable links live under /dev/disk/by-id, by-uuid, by-label and by-path. NVMe drives are nvme0n1 with partitions nvme0n1p1; virtio disks are vda; SD and eMMC are mmcblk0p1. Other names: loop0, dm-0 and /dev/mapper, sr0, tty1 consoles, pts/N pseudo-terminals, ttyS0, ttyUSB0 and ttyACM0 serial ports, and /dev/snd for sound.

Flashcards

Flashcard

/dev/sda

The first SCSI-style disk, which includes SATA and USB disks

Partitions: sda1, sda2.

Test your understanding

Question 1 of 5

What is /dev/nvme0n1p3?

Question 2 of 5

A server had disks sda, sdb and sdc. After sdb failed and was removed, the boot fails because /etc/fstab mounts /dev/sdc1. Why?

Question 3 of 5

Which name refers to the first partition of an SD card?

Question 4 of 5

In a terminal window, tty prints /dev/pts/2. What does that tell you?

Question 5 of 5

Which is the most reliable way to identify a device before writing an image to it with dd?

← Previous topicNext topic →