Determining and configuring hardware settings

How a Linux system finds out what hardware it has, and where that information lives: the kernel exposes devices through the /proc, /sys and /dev trees, udev creates the device nodes, and a handful of ls* commands read it back for you.

Lesson 1 of 3 in objective 101. System architecture, part of LPIC-1 Exam 101-500.

The three trees the kernel exposes, and what each one answers. /proc — What it is: The kernel talking about itself; What is in it: A directory per PID, cpuinfo, meminfo; You read it for: Process and memory state. /sys — What it is: The device model, structured; What is in it: A directory per device, by bus; You read it for: Which driver is bound. /dev — What it is: The nodes you open; What is in it: Special files created by udev; You read it for: Talking to a device /proc /sys /dev What it is The kernel talking about itself The device model, structured The nodes you open What is in it A directory per PID, cpuinfo, meminfo A directory per device, by bus Special files created by udev You read it for Process and memory state Which driver is bound Talking to a device
The three trees the kernel exposes, and what each one answers.

Three trees, three different jobs

/proc is the kernel talking about itself. It is a virtual filesystem — nothing in it is on a disk — holding one numbered directory per running process plus files describing the machine: /proc/cpuinfo, /proc/meminfo, /proc/interrupts, /proc/ioports, /proc/dma. Reading it is how tools like ps and free get their numbers.

/sys is newer, and it is the structured version of the same idea: one directory per device, arranged by the bus it hangs off, with the driver bound to it and the attributes it exposes. Where /proc grew organically and mixes everything together, sysfs is the tree udev and systemd actually walk.

/dev holds the device nodes — the special files a program opens to talk to a device. They are created at boot and on hotplug by udev, which watches kernel events, applies the rules in /etc/udev/rules.d and /lib/udev/rules.d, and can name a device predictably so that a USB disk gets the same path every time it is plugged in.

Modules are how the kernel gets a driver

Most drivers are not compiled into the kernel; they are loadable modules under /lib/modules/$(uname -r)/. lsmod lists what is loaded — it is a formatter for /proc/modules and takes no module argument — modprobe loads a module by name and pulls in whatever it depends on, and modprobe -r or rmmod unloads it. insmod loads a single file and resolves no dependencies at all, which is why it is almost never the right command.

Two more commands complete the set, and they are the two candidates most often meet for the first time in the exam room. modinfo reads the metadata compiled into the .ko file itself — description, author, licence, the modules it depends on, and one parm: line per parameter the driver accepts — so it works on a module that is not loaded and is how you find out which options a driver takes before setting them. depmod scans everything under /lib/modules/$(uname -r) and rebuilds modules.dep, the dependency map modprobe consults; you run it after installing a module by hand. The four divide cleanly: modinfo describes, lsmod lists, modprobe loads, depmod indexes.

Configuration for modules lives in /etc/modprobe.d/ — options passed to a driver, aliases, and blacklist lines that stop a module being loaded automatically. That last one is the usual fix when two drivers both claim a device, and usb_storage is the module most often blacklisted that way.

The three ways a module gets loaded, how they differ, and the way back out. A column of 2 states: Not loaded (modinfo still describes it, straight from the .ko file); Loaded (lsmod lists it, with its size and what is using it). You get from Not loaded to Loaded by modprobe, by name, pulling in what it depends on; from Not loaded to Loaded by insmod, a single file, resolving no dependencies; from Not loaded to Loaded by an automatic load, which a blacklist line in /etc/modprobe.d stops; from Loaded to Not loaded by modprobe -r, or rmmod. Not loaded modinfo still describes it, straight from the .ko file modprobe, by name, pulling in what it depends on insmod, a single file, resolving no dependencies an automatic load, which a blacklist line in /etc/modprobe.d stops Loaded lsmod lists it, with its size and what is using it modprobe -r, or rmmod
The three ways a module gets loaded, how they differ, and the way back out.
modinfo usb_storagefilename:     /lib/modules/6.1.0-18/kernel/.../usb-storage.kolicense:      GPLdescription:  USB Mass Storage driver for Linuxdepends:      usb-common,usbcoreparm:         delay_use:seconds to delay (uint)Nothing was loaded — that came out of the filemodprobe usb_storagelsmod | grep usb_storageusb_storage     81920  0usbcore        348160  2 usb_storage,xhci_hcd
Inspecting a driver without loading it, then loading it.

Reading and setting kernel tunables

A running kernel has several hundred settings that can be changed without rebooting, and they are exposed as files under /proc/sys. Reading one is cat; changing one is writing to it. sysctl is the front end for the same tree with dots in place of slashes, so /proc/sys/net/ipv4/ip_forward is net.ipv4.ip_forward to sysctl, and sysctl -a lists everything.

A write to /proc/sys lasts until the next reboot, because nothing in /proc is on a disk. To make a setting survive, put it in /etc/sysctl.conf or a file under /etc/sysctl.d/, which are read at boot; sysctl -p applies them again immediately. Turning a machine into a router — net.ipv4.ip_forward = 1 — is the example the exam reaches for every time.

A tunable set two ways, and only one of them survives a reboot. sysctl -w — Where you write it: /proc/sys, in memory; Takes effect: Immediately; After a reboot: Gone. /etc/sysctl.d/ — Where you write it: A file on disk; Takes effect: At boot, or on sysctl -p; After a reboot: Kept sysctl -w /etc/sysctl.d/ Where you write it /proc/sys, in memory A file on disk Takes effect Immediately At boot, or on sysctl -p After a reboot Gone Kept
A tunable set two ways, and only one of them survives a reboot.
cat /proc/sys/net/ipv4/ip_forward0sysctl net.ipv4.ip_forwardnet.ipv4.ip_forward = 0sysctl -w net.ipv4.ip_forward=1net.ipv4.ip_forward = 1Gone at the next reboot. To keep it:echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/99-router.confsysctl -p /etc/sysctl.d/99-router.conf
The same tunable, three ways: read, set for now, set for good.

Firmware, and what is below the operating system

Before Linux runs at all, the machine's own firmware has already decided which devices exist. Classic BIOS and modern UEFI both offer a setup screen where integrated peripherals — the onboard serial port, the audio chip, virtualization extensions — can be enabled or disabled, and a device switched off there is invisible to Linux no matter what you do afterwards. UEFI adds an EFI system partition, a FAT-formatted partition holding boot loaders, which is why /boot/efi appears in the mount table on modern installs.

One small thing worth knowing about where these tools live: the ls* inspection commands are ordinary user programs in /usr/bin/usr/bin/lspci, /usr/bin/lsusb, /usr/bin/lsblk — while the ones that change kernel state live in /sbin or /usr/sbin, which is why /sbin/lsmod and /sbin/modprobe are the paths that turn up in a question about a command a normal user cannot run. lsblk, the block-device version of the same idea, lists disks and partitions as a tree.

Worth carrying in

lspci
Devices on the PCI bus. -v for detail, -k to show the kernel driver in use.
lsusb
Devices on the USB bus, with vendor and product ids.
lsblk
Block devices — disks, partitions and their mount points — as a tree.
/sbin/lsmod
Loaded kernel modules, their size, and what is using them. A formatter for /proc/modules; it takes no module name.
modinfo
Describes a module from the .ko file, loaded or not: licence, depends, and the parameters it accepts.
modprobe
Load a module by name, with dependencies. -r removes it.
depmod
Rebuilds modules.dep, the dependency map modprobe reads. Run after installing a module by hand.
dmesg
The kernel ring buffer: what the kernel said about the hardware as it found it.
/proc/cpuinfo
Per-core processor detail, including the flags that reveal virtualization support.
/sys
sysfs: one directory per device, by bus, with its driver and attributes.
sysctl
Read and write /proc/sys by dotted name. -w sets for now, -p re-reads /etc/sysctl.conf and /etc/sysctl.d/.
udevadm
Query and control udev. udevadm monitor shows events as devices appear.

What the exam does with this

Objective
101. System architecture
Share of the exam
13.33% (the whole objective)
Questions in this lesson
10
Signed for by a person
0

Partly checked. None of the 10 questions here has been read against the cited source by a person. 10 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Determining and configuring hardware settings

Questions in this lesson

Practise Determining and configuring hardware settings

The rest of objective 101