devutils/ATFQ/book ATFQ git

Part II · Your system

13.6 /dev and udev

alsoudev/devdevicesdevice filesudevadmby-idby-uuidudev rules

TL;DR

  • /dev holds device files: /dev/sda (a disk), /dev/ttyUSB0 (a serial adapter), /dev/null. Programs open them like files to talk to drivers.
  • udev names them when hardware appears, sets their owner and rights, and runs actions, following rules.
  • /dev/disk/by-id/ and /dev/disk/by-uuid/ hold names that stay the same from one boot to the next.
ls -l /dev/disk/by-id/
udevadm monitor          # plug something in, watch the events
udevadm info /dev/sda

On your machine

alice@laptopexample
$ atfq 13.6
  Local     70-keyboard.rules
  Packaged  2 rules files

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

Character or block device?

The first letter in ls -l says it. b: a block device, such as a disk, read in blocks through the page cache. c: a character device, such as a terminal, a serial port or /dev/null, a stream of bytes. Each has a major:minor number that names its driver and instance, the same numbers as in /sys/block/*/dev.

Where does /dev come from?

It's a devtmpfs filesystem that the kernel fills itself as devices appear. udev then fixes owners and rights, adds the stable links, and runs actions. Before devtmpfs (kernel 2.6.32, 2009), udev created every file itself; and before udev, /dev was a static folder with thousands of entries.

Commands
udevadm lsblk
Paths
/dev /dev/disk/by-id/ /etc/udev/rules.d/
See also
14. Disk
13.5 fstab and mount options
21.2 Kernel modules
15.3 sudo and groups