Skip to content

101.1 Determine and configure hardware settings

Find out about the hardware

An operating system manages computer hardware and software resources. It sits on top of the hardware and manages resources when other software asks for it.

Firmware is the software on your hardware that runs it - think of it as a built-in OS or driver for your hardware. Motherboards need firmware to work too. Firmware is a type of software that lives in hardware.

Until the mid-2000s, the configuration utility was implemented in the BIOS. From the end of the first decade of the 2000s, x86 machines started replacing BIOS with UEFI. Despite the change, it's still common to call the configuration utility "BIOS", as both fulfill the same basic purpose.

BIOS

Basic Input/Output System. Old and redundant. Text menu-based, boots the computer by accessing the first sector of the first partition of the hard disk (MBR). Not enough for modern systems, so most systems use a two-step boot procedure.

UEFI

Unified Extensible Firmware Interface. Started as EFI in 1998 at Intel, now the standard. Uses a specific disk partition for boot (EFI System Partition, ESP) formatted as FAT. On Linux it's located at /boot/efi, and the files use the .efi extension. Each bootloader needs to be registered.

Device activation

The system configuration utility appears after pressing a key at power-on (often Del, F2, or F12, varies by manufacturer).

In the BIOS setup utility you can: enable/disable integrated peripherals, activate basic error protection, and change hardware settings like IRQ (interrupt request) and DMA (direct memory access). You can also define which storage device has the correct bootloader and should be first in the boot order - the OS may not load if the wrong device comes first.


Peripheral Devices

These are device interfaces.

PCI

Peripheral Component Interconnect. Enables adding extra components to the motherboard. Most servers now use PCI Express (PCIe).

  • Internal HDD: PATA (old), SATA (serial, up to 4 devices), SCSI (parallel, up to 8 devices)
  • External HDD: Fiber (high-speed connection), SSD over USB
  • Network cards: RJ45
  • Wireless cards: IEEE 802.11
  • Bluetooth: IEEE 802.15 (short-range, up to 10m)
  • Video accelerators: hardware circuits on a graphics card that speed up full-motion video
  • Audio cards
SSD vs HDD
  • SSDs are faster (reads up to 10x, writes up to 20x faster), quieter, smaller, more durable, and consume less energy. HDDs are cheaper and offer more storage capacity and easier data recovery if damaged.
  • SSDs have no moving parts (flash memory), so they withstand drops, shocks, vibration, extreme temperatures, and magnetic fields better than HDDs.
  • HDDs last around 3-5 years; SSDs can last 10+ years. SSDs have reserve capacity to replace defective cells - "Bad-Block-Management".
Network cards vs Wireless cards
  • NIC (Network Interface Card) provides Ethernet connectivity through an RJ45 port. A wireless adapter card provides connectivity via Access Points.
  • Wireless cards on industrial computers enable wireless internet connectivity.

USB

Universal Serial Bus. Serial, needs fewer connections.

  • USB 1 (12Mbps), USB 2 (480Mbps), USB 3 (PCIe 2.0 bus: 5Gbps, PCIe 3.0: 10Gbps, PCIe 3.2: 20Gbps, PCIe 4.0: 40Gbps)
  • Connector types: A, B, C

GPIO

General Purpose Input Output. Used to control other devices. Examples: Arduino, Raspberry Pi.


Sysfs

Sysfs is a pseudo filesystem provided by the Linux kernel that exports information about kernel subsystems, hardware devices, and device drivers from the kernel's device model to user space, through virtual files. These virtual files are also used for configuration.

Sysfs is mounted at /sys.

ls /sys
# block  bus  class  dev  devices  firmware  fs  hypervisor  kernel  module  power

All block devices are at the block directory, and bus has all the connected PCI, USB, serial devices. In /sys, devices are organized by technology, while /dev/ is abstracted.


udev

udev (userspace /dev) is a device manager for the Linux kernel. As successor of devfsd and hotplug, udev primarily manages device nodes in /dev. It also handles user space events raised when hardware devices are added or removed, including firmware loading as required by certain devices.

If you plug in a device, it's assigned a file in /dev (e.g. /dev/sdb2). udev lets you control what will be what in /dev - for example, force a specific 128GB flash drive to always be /dev/mybackup, and even start a process as soon as it connects.

udev abstracts the representation of devices - a hard disk is identified as /dev/sda or /dev/hd0 regardless of manufacturer, model, or underlying technology.

ls /dev/sda*
# /dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda5  /dev/sda6

If a program wants to read/write from/to a device, it uses the corresponding file in /dev. This can be a character device or a block device. When listing, a b or c at the start of the line indicates this:

ls -ltrh /dev/
crw-rw---- 1 root tty       4,   1 Dec 15  2019 tty1
crw-rw-rw- 1 root root      1,   5 Dec 15  2019 zero
brw-rw---- 1 root disk      1,   0 Dec 15  2019 ram0
brw-rw---- 1 root disk 253,   0 Dec 15  2019 /dev/vda

udev is responsible for the identification and configuration of devices already present at machine power-up (coldplug detection) and devices identified while the system is running (hotplug detection). Udev relies on SysFS (/sys) for hardware-related information.

Hotplug is the detection and configuration of a device while the system is running, such as when a USB device is inserted. The Linux kernel has supported hotplug since version 2.6, allowing most system buses (PCI, USB, etc.) to trigger hotplug events on connect/disconnect.

As new devices are detected, udev searches for a matching rule in /etc/udev/rules.d/. Most important rules are provided by the distribution, but new ones can be added.

Storage device naming

Storage devices are generically referred to as block devices, because data is read/written in blocks of buffered data. Every block device is identified by a file in /dev, named according to device type and partitions.

Device Naming
Legacy IDE (first channel, master/slave) /dev/hda, /dev/hdb (partitions: /dev/hda1, /dev/hda2...)
CD/DVD (second IDE channel) /dev/hdc
Floppy /dev/fd0, /dev/fd1...
IDE, SSD, USB (SCSI-like, since kernel 2.4+) /dev/sda, /dev/sdb... (partitions: /dev/sda1, /dev/sda2...)
SD cards /dev/mmcblk0, /dev/mmcblk1... (partitions: /dev/mmcblk0p1, /dev/mmcblk0p2...)
NVMe (SSD on PCIe bus) /dev/nvme0n1... (partitions: /dev/nvme0n1p1, /dev/nvme0n1p2...)

For IDE disks, master is sda, slave is sdb on the first channel. Partitions are numbered: /dev/sda1, /dev/sda2 for the first device; /dev/sdb1, /dev/sdb2 for the second.


dbus

D-Bus is a message bus system - a simple way for applications to talk to one another. In addition to inter-process communication, D-Bus helps coordinate process lifecycle - it makes it simple to code a "single instance" application or daemon and to launch applications and daemons on demand when their services are needed.


proc directory

This is where the kernel keeps its settings and properties. Created in RAM, and files might have write access (for some hardware configurations). Contains things like:

  • IRQs (interrupt requests)
  • I/O ports (memory locations where the CPU talks with devices)
  • DMA (direct memory access, faster than I/O ports)
  • Processes
  • Network settings

Key files for inspecting hardware:

File Content
/proc/cpuinfo Detailed CPU information
/proc/interrupts Number of interrupts per I/O device for each CPU
/proc/ioports Currently registered I/O port regions in use
/proc/dma Registered DMA channels in use
cat /proc/cpuinfo
# processor, vendor_id, model name, cpu MHz, cache size, flags, ...

The /sys directory has a similar role, but is specifically for device information and kernel data related to hardware, while /proc also contains other kernel data structures (running processes, configuration).

You can also write to /proc files. Example - turning an IBM Lenovo laptop's LED on/off:

echo on > /proc/acpi/ibm/light
echo off > /proc/acpi/ibm/light

Another example - changing the max number of open files per user:

cat /proc/sys/fs/file-max
# 797946
echo 1000000 > /proc/sys/fs/file-max
cat /proc/sys/fs/file-max
# 1000000

/proc/sys/net/ipv4 controls real-time networking configurations.

All changes made through /proc are reverted after a reboot. Write to config files in /etc/ to make them permanent.


lsusb, lspci, lsblk, lshw

Just like ls, but for PCI, USB, and other devices. These are front-ends to read hardware information stored by the OS in /proc and /sys.

Commands directly related to hardware often require root privileges, or show limited information otherwise.

lspci

Shows PCI devices connected to the computer.

lspci
# 01:00.0 VGA compatible controller: NVIDIA Corporation GM107 [GeForce GTX 750 Ti]
# 04:02.0 Network controller: Ralink corp. RT2561/RT61 802.11g PCI

The hexadecimal numbers at the start of each line are the unique PCI address. Show more details for a specific device with -s (address) and -v:

lspci -s 04:02.0 -v
# Subsystem: Linksys WMP54G v4.1
# kernel driver in use: rt61pci

The kernel driver in use line confirms: the device was identified, a matching kernel module was loaded, and the device should be ready for use.

Another way to check the kernel module in use, available in recent versions:

lspci -s 01:00.0 -k
# kernel driver in use: nvidia
# kernel modules: nouveau, nvidia_drm, nvidia

lsusb

Shows all USB devices connected to the system.

lsusb
# Bus 001 Device 029: ID 1781:0c9f Multiple Vendors USBtiny

Option -v shows more detail; select a specific device by ID with -d:

lsusb -v -d 1781:0c9f

Option -t shows the USB device tree, including which driver/module is used:

lsusb -t
# |__ Port 3: Dev 20, If 0, Class=Wireless, Driver=btusb, 12M

Select a device by Bus and Dev number with -s:

lsusb -s 01:20

lshw

Shows hardware. Might need root to get the full list.

lsblk

Lists devices that can read/write by blocks of data.


Loadable Kernel Modules

Linux needs drivers to work with hardware. Unlike Windows, most drivers are built into the system. To avoid loading all of them at once and to keep the kernel size down, Linux uses kernel modules.

Loadable kernel modules (.ko files) are object files that extend the kernel. They provide drivers for hardware not already included in the distribution. Modules related to hardware are also called drivers.

Inspect modules with lsmod, manage them with modprobe.

lsmod

Shows currently loaded kernel modules. Located at /lib/modules.

lsmod
# Module                  Size  Used by
# kvm_intel               138528  0
# kvm                     421021  1 kvm_intel

Three columns: Module (name), Size (RAM used, in bytes), Used by (depending modules).

lsmod | fgrep -i snd_hda_intel

Get more info about a module:

modinfo nouveau              # description, file, author, license, dependencies, parameters
modinfo -p nouveau            # only the available parameters

Add or remove a module:

modprobe iwlwifi              # load (handles dependencies)
modprobe -r snd-hda-intel     # unload (and dependent modules, if unused)
rmmod iwlwifi                 # remove
rmmod -f iwlwifi              # force remove, even if in use

insmod also loads modules, but nobody uses it - it doesn't understand dependencies and needs the full path to the file.

Persist module parameters: add them to /etc/modprobe.conf or a .conf file in /etc/modprobe.d/. Example - disable a feature:

# /etc/modprobe.d/nouveau.conf
options nouveau modeset=0

Block a module from loading: add blacklist module_name to /etc/modprobe.d/blacklist.conf (or a dedicated <module_name>.conf file).

Load modules automatically at boot:

  1. Add their name to /etc/modules
  2. Add config files to /etc/modprobe.d/

Summary

I have a computer with hardware inside it, and each device has firmware, code stored on a chip inside the device itself. The motherboard's firmware is BIOS or UEFI, and I can enable/disable peripherals or change IRQ and DMA settings from its setup utility.

When the system runs, the kernel exposes hardware as files in a virtual filesystem called sysfs, mounted at /sys. A daemon called udev watches for devices and creates the matching files in /dev, whether they're present at boot (coldplug) or plugged in later (hotplug).

/proc is where the kernel keeps its own settings and process info - I can read /proc/cpuinfo or write to /proc/sys/fs/file-max to change a limit, though it resets at reboot.

The kernel stays small by loading only the drivers it needs, called modules. I list them with lsmod, get details with modinfo, and load or remove them with modprobe. To see what hardware is connected, I use lspci, lsusb, lsblk, and lshw.