Privacy Policy
© 2026 linux101.dev

A Practical Guide to the /dev Directory on Linux

Understand device nodes, naming schemes, and how user space interacts with hardware through /dev — with practical commands and safety tips.

TL;DR
  • /dev is a virtual filesystem containing device nodes, not regular files.
  • Device nodes are special files that let programs talk to drivers via the kernel.
  • Storage devices appear as block devices (e.g., /dev/sda, /dev/nvme0n1), terminals as character devices (e.g., /dev/tty).
  • The kernel (devtmpfs) and udev populate and manage entries dynamically.

1) What is /dev?

/dev is a directory backed by a kernel-managed virtual filesystem (devtmpfs) where hardware devices are exposed to user space as special files. Tools open these files to perform I/O through system calls; the kernel routes requests to the appropriate driver.

Key idea: A device node is an interface, not a place where data is stored. Its content is generated by the driver.

2) Block vs Character devices

Block devices

Provide buffered, random access in fixed-size blocks. Typical examples are disks and partitions.

$ ls -l /dev/sda
brw-rw---- 1 root disk 8, 0 ... /dev/sda   ← b = block

Character devices

Provide unbuffered, byte-stream I/O. Examples include serial ports, terminals, sound, and input devices.

$ ls -l /dev/tty
crw-rw-rw- 1 root tty 5, 0 ... /dev/tty    ← c = char

The major,minor numbers (like 8,0) identify the driver (major) and the specific device instance (minor).

3) Common naming patterns

FamilyExamplesNotes
SATA/SCSI/SAS disks/dev/sda, /dev/sdb
/dev/sda1, /dev/sda2
Historical SCSI naming; partitions are numbered.
NVMe SSD/dev/nvme0n1, /dev/nvme0n1p1nvme<ctrl>n<ns>p<part> (controllers, namespaces, partitions).
MMC/SD/dev/mmcblk0, /dev/mmcblk0p1Embedded/SD storage; note the p before partition number.
Loop devices/dev/loop0, /dev/loop1Files mapped as block devices (disk images, snaps, AppImages).
Optical/dev/sr0CD/DVD drives.
Terminals & serial/dev/tty, /dev/ttyS0, /dev/pts/0, /dev/ttyUSB0Hardware UARTs, USB serial adapters, PTYs under /dev/pts.
Input/dev/input/event0, /dev/uinputKeyboards, mice, and the user input injection interface.

4) Stable device paths in /dev/disk/by-*

Device names like /dev/sda can change between boots. Use udev-generated symlinks for stable addressing:

  • /dev/disk/by-id/ → vendor/model/serial based
  • /dev/disk/by-uuid/ → filesystem UUID (after formatting)
  • /dev/disk/by-label/ → filesystem label
  • /dev/disk/by-path/ → physical bus topology
$ ls -l /dev/disk/by-uuid/
... 9c7e-1a2b -> ../../sda1
... 1b2c3d4e-... -> ../../nvme0n1p2

Tip: In /etc/fstab, prefer UUID=... or LABEL=... for reliability.

5) Who creates entries? devtmpfs & udev

The kernel mounts devtmpfs at /dev and exposes a minimal set of device nodes. The udev daemon (usually systemd-udevd) listens to kernel events, applies rules, sets permissions, names, and creates helpful symlinks.

$ udevadm info --query=all --name=/dev/nvme0n1
$ udevadm monitor --environment --udev   # watch hotplug events

6) Inspecting device nodes

List with types and majors/minors

$ ls -l /dev/sd*
$ stat -c "%n %t,%T %F" /dev/sda     # major,minor in hex
$ cat /proc/partitions                 # kernel view

Find the backing hardware

$ lsblk -o NAME,MAJ:MIN,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL,SERIAL
$ blkid
$ lsscsi    # for SCSI/SATA/SAS
$ nvme list # for NVMe

7) Using device files (safely)

Block devices can be read or written directly. This is powerful—and dangerous.

# Read the first 512 bytes (MBR/GPT header area)
$ sudo dd if=/dev/sda of=mbr.bin bs=512 count=1

# Write an ISO to a USB stick (DOUBLE‑CHECK target!)
$ sudo dd if=debian.iso of=/dev/sdX bs=4M status=progress oflag=sync

# Create a filesystem and mount it
$ sudo mkfs.ext4 /dev/nvme0n1p3
$ sudo mount /dev/nvme0n1p3 /mnt/data
$ df -Th /mnt/data
        
Danger zone: Writing to the wrong device node will destroy data. Always confirm with lsblk first.

8) Special pseudo-devices

NodeWhat it doesExample
/dev/nullBit bucket—writes are discarded, reads return EOFcmd > /dev/null 2>&1
/dev/zeroInfinite stream of zero bytesdd if=/dev/zero of=blank.img bs=1M count=100
/dev/random, /dev/urandomCryptographic/random bytes (blocking vs non‑blocking)head -c 16 /dev/urandom | xxd
/dev/tty, /dev/pts/*Controlling terminal and pseudo-terminalsecho "hi" > /dev/pts/3
/dev/loop*Files mapped as block devices (loopback)losetup -fP disk.img
/dev/shmPOSIX shared memory (actually a tmpfs mount)mount | grep /dev/shm

9) Troubleshooting & gotchas

  • Permissions: Device nodes often belong to groups like disk, video, audio. Use getent group and udevadm info to understand access.
  • Missing entries: Check that devtmpfs is mounted and systemd-udevd is running. Hotplug rules may control creation.
  • Stable naming: Prefer /dev/disk/by-uuid in /etc/fstab instead of /dev/sdX.
  • mknod: Avoid manual mknod unless you know the exact major/minor and have a good reason—udev should manage nodes.
  • Containers: In Docker/containers, /dev is namespaced; only selected devices are passed through.

10) FAQ

Is /dev a real directory on disk?

No. It is a virtual filesystem (devtmpfs) populated by the kernel and managed by udev. Entries appear/disappear as hardware changes.

Why do some disk names change between reboots?

Enumeration order can vary. Use stable symlinks under /dev/disk/by-* to avoid surprises.

What are the numbers like 8,0 in ls -l?

They are the major and minor device numbers. Major selects the driver, minor identifies the device instance.

How do I see which filesystem is on a partition?

$ lsblk -f   # shows FSTYPE, LABEL, UUID
$ blkid      # probe block devices

How do I map a process to a TTY?

$ ps -o pid,tty,cmd -p <PID>
$ ls -l /proc/<PID>/fd | grep /dev/pts