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.
/devis 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.
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 = blockCharacter 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 = charThe major,minor numbers (like 8,0) identify the driver (major) and the specific device instance (minor).
3) Common naming patterns
| Family | Examples | Notes |
|---|---|---|
| SATA/SCSI/SAS disks | /dev/sda, /dev/sdb … /dev/sda1, /dev/sda2 | Historical SCSI naming; partitions are numbered. |
| NVMe SSD | /dev/nvme0n1, /dev/nvme0n1p1 | nvme<ctrl>n<ns>p<part> (controllers, namespaces, partitions). |
| MMC/SD | /dev/mmcblk0, /dev/mmcblk0p1 | Embedded/SD storage; note the p before partition number. |
| Loop devices | /dev/loop0, /dev/loop1 | Files mapped as block devices (disk images, snaps, AppImages). |
| Optical | /dev/sr0 | CD/DVD drives. |
| Terminals & serial | /dev/tty, /dev/ttyS0, /dev/pts/0, /dev/ttyUSB0 | Hardware UARTs, USB serial adapters, PTYs under /dev/pts. |
| Input | /dev/input/event0, /dev/uinput | Keyboards, 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-... -> ../../nvme0n1p2Tip: 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 events6) 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 viewFind the backing hardware
$ lsblk -o NAME,MAJ:MIN,TYPE,SIZE,MOUNTPOINT,FSTYPE,MODEL,SERIAL
$ blkid
$ lsscsi # for SCSI/SATA/SAS
$ nvme list # for NVMe7) 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
lsblk first.8) Special pseudo-devices
| Node | What it does | Example |
|---|---|---|
/dev/null | Bit bucket—writes are discarded, reads return EOF | cmd > /dev/null 2>&1 |
/dev/zero | Infinite stream of zero bytes | dd if=/dev/zero of=blank.img bs=1M count=100 |
/dev/random, /dev/urandom | Cryptographic/random bytes (blocking vs non‑blocking) | head -c 16 /dev/urandom | xxd |
/dev/tty, /dev/pts/* | Controlling terminal and pseudo-terminals | echo "hi" > /dev/pts/3 |
/dev/loop* | Files mapped as block devices (loopback) | losetup -fP disk.img |
/dev/shm | POSIX shared memory (actually a tmpfs mount) | mount | grep /dev/shm |
9) Troubleshooting & gotchas
- Permissions: Device nodes often belong to groups like
disk,video,audio. Usegetent groupandudevadm infoto understand access. - Missing entries: Check that
devtmpfsis mounted andsystemd-udevdis running. Hotplug rules may control creation. - Stable naming: Prefer
/dev/disk/by-uuidin/etc/fstabinstead of/dev/sdX. - mknod: Avoid manual
mknodunless you know the exact major/minor and have a good reason—udev should manage nodes. - Containers: In Docker/containers,
/devis 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 devicesHow do I map a process to a TTY?
$ ps -o pid,tty,cmd -p <PID>
$ ls -l /proc/<PID>/fd | grep /dev/pts