Skip to content

Chapter 3: Devices

This should be mostly used as a reference. It explains how the kernel creates IO interface to devices via files, for example /dev/sda.

Types of devices

  • Block devices: e.g. Hard Drives, flash disks
  • Character Devices: e.g. /dev/null
  • Pipe device: e.g. named pipes
  • Socket device: Used for process communication.

The sysfs interface versus the /dev interface

The /dev interface purpose is to interact with user processes; while the sysfs purpose is to give a full picture of the device. It is also represented as a directory hierarchy and it is located at /sys/devices. The sysf path of a device can be quite long: For example:

/sys/devices/pci0000:00/0000:00:17.0/ata3...

Standard device names

  • /dev/sd* for hard drives
  • /dev/sr* for cd and dvd drives
  • /dev/tty, /dev/pts/ for terminal and pseudo-terminal devices.

Virtual consoles and pseudo-consoles

Virtual consoles are hardware emulated; while pseudo-consoles are software emulated.

When you open a terminal window, this is a pseudo-console and it is likely to have a some device /dev/pts/* associated to it. Actually, you can check with the command tty.

$$ tty
/dev/pts/4
$$ echo "Test" > /dev/pts/4
Test

Regarding virtual consoles, linux distribution usually comes with 6 of them. The first runs the login screen; the second runs the system via a graphical interface; and the others runs via a command line. You can switch between them with Ctrl+Alt+F{1,2,3,4,5,6}.

This can be useful if you get a problem in some of the system views, for example, you can use virtual console 3 to investigate a crash in thegraphical interface.

Virtual consoles on linux

Useful commands

# List device interface files
ls /dev

# Get the sysfs device path
udevadm info --query=all --name=/dev/sda