Menu
Determine and configure hardware settings
“Find out what hardware is in a Linux box, which driver runs it, and how to switch devices and modules on or off.”
Before you can fix a sound card that stays silent or a USB disk that never shows up, you need to answer two questions: what hardware is in this machine, and which driver is handling it. Linux gives you a few small tools and three special directories for exactly that.
This byte covers how Linux sees hardware: the firmware settings, the tools that list devices, kernel modules (drivers), and the pieces that react when you plug something in: sysfs, udev and D-Bus.
Tip
Try this in a virtual machine or on a real Linux box. A Docker container shares the host’s kernel, so it can’t load modules and only sees part of the hardware. On Debian or Ubuntu, install the tools with sudo apt install pciutils usbutils. On RHEL or Fedora: sudo dnf install pciutils usbutils.
Turning built-in devices on or off#
Most motherboards have integrated peripherals: sound, network, Wi-Fi, Bluetooth, serial ports, sometimes a webcam. The first place to enable or disable them is the firmware setup (BIOS or UEFI). You open it by pressing a key right after power on, often Del, F2 or F10, depending on the maker.
In the setup screens you’ll typically find:
- onboard devices (audio, LAN, SATA mode, USB ports) set to Enabled or Disabled
- CPU features like virtualization (Intel VT-x, AMD-V)
- the boot order and Secure Boot
A device disabled in firmware is invisible to Linux: it won’t show up in lspci at all. On a UEFI machine you can even jump into the setup screen from Linux:
sudo systemctl reboot --firmware-setupYou can also keep a device present but stop Linux from using it, by not loading its driver. More on that in the modules section below.
Three special directories: /proc, /sys and /dev#
None of these hold normal files on disk. The kernel builds them in memory, live.
| Directory | What it is | Examples |
|---|---|---|
/proc/ | procfs: information about processes and kernel internals | /proc/cpuinfo, /proc/meminfo, /proc/interrupts, /proc/modules |
/sys/ | sysfs: the kernel’s device model, one folder per device, bus, driver and module | /sys/class/net/, /sys/block/, /sys/bus/usb/devices/ |
/dev/ | device files that programs open to talk to hardware | /dev/sda, /dev/nvme0n1, /dev/ttyS0, /dev/null |
A few quick looks:
grep "model name" /proc/cpuinfo | head -1
head -3 /proc/meminfo
ls /sys/class/net/model name : Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
MemTotal: 16231140 kB
MemFree: 9876544 kB
MemAvailable: 13209876 kB
enp0s31f6 lo wlp2s0
/proc is the older one and mixes process data with hardware data. /sys came later (Linux 2.6) and is the clean, structured place for devices. Many tools, like lsblk and udev, read /sys under the hood.
Listing hardware#
PCI devices: lspci#
PCI and PCI Express are the internal buses that connect graphics cards, network cards, storage controllers and USB controllers to the CPU. lspci lists everything on them:
lspci00:00.0 Host bridge: Intel Corporation Coffee Lake HOST and DRAM Controller (rev 0c)
00:02.0 VGA compatible controller: Intel Corporation WhiskeyLake-U GT2 [UHD Graphics 620] (rev 02)
00:14.0 USB controller: Intel Corporation Cannon Point-LP USB 3.1 xHCI Controller (rev 30)
00:17.0 SATA controller: Intel Corporation Cannon Point-LP SATA Controller [AHCI Mode] (rev 30)
00:1f.3 Audio device: Intel Corporation Cannon Point-LP High Definition Audio Controller (rev 30)
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (6) I219-V (rev 30)
02:00.0 Network controller: Intel Corporation Wireless-AC 9560 (rev 10)
The first column is the address: bus:device.function. The useful options:
| Option | Shows |
|---|---|
-k | the kernel driver in use and the modules that could drive it |
-v, -vv | more detail: IRQ, memory ranges, I/O ports, capabilities |
-nn | the numeric vendor and device IDs, like [8086:15bc] |
-s 00:1f.6 | only the device at that address |
-t | a tree of buses and bridges |
lspci -k -s 00:1f.600:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (6) I219-V (rev 30)
Subsystem: Lenovo Ethernet Connection (6) I219-V
Kernel driver in use: e1000e
Kernel modules: e1000e
That one line, “Kernel driver in use”, is often the whole answer when a device doesn’t work: no line means no driver has claimed it.
USB devices: lsusb#
lsusbBus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 002: ID 0781:5581 SanDisk Corp. Ultra
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
ID 0781:5581 is the vendor ID and product ID. A root hub is the USB controller itself, as seen from the bus. Useful options:
lsusb -tshows a tree with the driver bound to each device and the speedlsusb -vdumps every descriptor (run it withsudofor the full output)lsusb -s 001:002picks one device by bus and device numberlsusb -d 0781:5581picks one by vendor and product ID
lsusb -t/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 10000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
|__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
|__ Port 3: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 12M
Other handy tools#
lscpu (CPU details), lsblk (block devices), lshw (everything, as a tree, run as root) and dmidecode (firmware tables: board model, RAM slots, serial numbers) are not on the exam list, but you’ll use them all the time.
Hardware resources: IRQs, I/O ports and memory#
Devices need resources to talk to the CPU. The exam expects you to know where to look:
| Resource | What it is | Where to see it |
|---|---|---|
| IRQ | an interrupt line: “hey CPU, I have data” | /proc/interrupts |
| I/O ports | small address ranges for old-style device registers | /proc/ioports |
| Memory ranges | device memory mapped into the address space | /proc/iomem |
| DMA channels | direct memory access without the CPU (legacy ISA) | /proc/dma |
head -5 /proc/interrupts CPU0 CPU1 CPU2 CPU3
0: 20 0 0 0 IR-IO-APIC 2-edge timer
1: 0 0 1834 0 IR-IO-APIC 1-edge i8042
8: 0 1 0 0 IR-IO-APIC 8-edge rtc0
9: 0 4412 0 0 IR-IO-APIC 9-fasteoi acpi
On modern PCI Express hardware these are set up automatically and rarely clash. lspci -v shows the IRQ and ranges for each card, which is enough for most troubleshooting.
Telling storage devices apart#
Linux names disks by the driver that handles them, not by what they look like:
| Device name | Kind of storage |
|---|---|
/dev/sda, /dev/sdb… | SATA and SAS disks, SSDs, USB sticks and USB disks (all through the SCSI disk driver) |
/dev/sda1 | first partition on sda |
/dev/nvme0n1, /dev/nvme0n1p1 | NVMe SSD (controller 0, namespace 1) and its first partition |
/dev/mmcblk0, /dev/mmcblk0p1 | SD cards and eMMC chips |
/dev/vda | virtio disk in a virtual machine |
/dev/sr0 | optical drive (CD, DVD, Blu-ray) |
/dev/hda | old parallel ATA (IDE) disk, legacy naming you may still meet in exam questions |
lsblk can show the transport and whether a disk spins:
lsblk -d -o NAME,TRAN,ROTA,SIZE,MODELNAME TRAN ROTA SIZE MODEL
sda sata 1 931.5G WDC WD10EZEX-08WN4A0
sdb usb 1 14.9G Ultra
sr0 sata 1 1024M DVD-RW DU-8A5LH
nvme0n1 nvme 0 476.9G Samsung SSD 980 PRO 500GB
ROTA 1 means rotational (a spinning hard disk), 0 means solid state. USB sticks often report 1 even though they don’t spin, so treat that column as a hint.
Kernel modules: drivers you can load and unload#
Most drivers are kernel modules: .ko files under /lib/modules/$(uname -r)/. The kernel loads them on demand when it finds matching hardware. Three commands do most of the work.
lsmod: what’s loaded#
lsmod | head -6Module Size Used by
uas 32768 0
usb_storage 86016 1 uas
e1000e 331776 0
snd_hda_intel 61440 3
snd_hda_codec 196608 2 snd_hda_intel,snd_hda_codec_realtek
“Used by” is a count, followed by the modules that depend on this one. lsmod just formats /proc/modules.
modinfo: what a module is#
modinfo e1000e | head -4
modinfo -p snd_hda_intel | head -3filename: /lib/modules/6.1.0-27-amd64/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko
license: GPL v2
description: Intel(R) PRO/1000 Network Driver
author: Intel Corporation, <linux.nics@intel.com>
index:Index value for Intel HD audio interface. (array of int)
id:ID string for Intel HD audio interface. (array of charp)
enable:Enable Intel HD audio interface. (array of bool)
-p lists the parameters a module accepts.
modprobe: load and unload, with dependencies#
sudo modprobe loop # load a module (and anything it needs)
sudo modprobe loop max_loop=16 # load it with a parameter
sudo modprobe -r loop # remove it, and unused dependenciesmodprobe uses the dependency list modules.dep (built by depmod) to load what a module needs first. The older insmod and rmmod work on a single file and ignore dependencies, so prefer modprobe.
If a module is busy you get an error, and nothing changes:
modprobe: FATAL: Module snd_hda_intel is in use.
Making it permanent#
Settings for modprobe live in /etc/modprobe.d/*.conf:
# never auto-load the PC speaker beep driver
blacklist pcspkr
# default options whenever this module loads
options snd_hda_intel power_save=1blacklist stops automatic loading by hardware match, but modprobe pcspkr by hand still works. To block a module completely, add install pcspkr /bin/false. If the module is also inside the initramfs (the small early-boot filesystem), rebuild it afterwards: sudo update-initramfs -u on Debian and Ubuntu, sudo dracut -f on RHEL and Fedora.
To load a module at every boot even without matching hardware, list its name in a file in /etc/modules-load.d/ (systemd). Debian also still reads the older /etc/modules.
The parameters a loaded module is using right now are visible in sysfs:
cat /sys/module/snd_hda_intel/parameters/power_savesysfs, udev and D-Bus: what happens when you plug something in#
The exam wants the concept, so here is the chain of events when you plug in a USB stick:
- The kernel detects the device, loads a driver (here
usb-storage), and adds it to sysfs under/sys/devices/.... It then sends out a “uevent”: a device was added. - udev (the
systemd-udevdservice) receives that event. It creates the device node in/dev(/dev/sdb), sets its owner and permissions, adds stable names like/dev/disk/by-uuid/..., and runs any matching rules. - Desktop services like udisks hear about the new disk and announce it on D-Bus. Your file manager listens there and pops up “USB stick connected”.
Devices that are there at boot are called coldplug devices. udev replays their events at startup so they get the same treatment. Devices you plug in later are hotplug devices.
Watching udev live#
udevadm monitorPlug in a USB stick and you’ll see both the kernel event and udev’s event:
KERNEL[2841.112093] add /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
KERNEL[2841.115830] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
UDEV [2841.130417] add /devices/pci0000:00/0000:00:14.0/usb1/1-2 (usb)
UDEV [2841.142955] add /devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0 (usb)
udevadm info /dev/sdb shows every property udev knows about a device, which is what you match on in rules.
A udev rule#
Rules shipped by packages live in /usr/lib/udev/rules.d/ (on Debian and Ubuntu also reachable as /lib/udev/rules.d/). Your own rules go in /etc/udev/rules.d/ and win when the file names match. This one gives a specific stick a fixed extra name:
SUBSYSTEM=="block", ATTRS{idVendor}=="0781", ATTRS{idProduct}=="5581", SYMLINK+="backupstick"sudo udevadm control --reload
sudo udevadm trigger
ls -l /dev/backupstickD-Bus in one paragraph#
D-Bus is a message bus: a way for programs to talk to each other and to system services. There’s one system bus (for services like systemd, NetworkManager, udisks and logind) and one session bus per logged-in user. You’ll rarely use it by hand, but you can peek:
busctl list | grep freedesktop | head -4org.freedesktop.NetworkManager 812 NetworkManager root :1.6 NetworkManager.service - -
org.freedesktop.UDisks2 934 udisksd root :1.12 udisks2.service - -
org.freedesktop.login1 701 systemd-logind root :1.3 systemd-logind.service - -
org.freedesktop.systemd1 1 systemd root :1.0 init.scope - -
Managing USB devices from the command line#
Besides listing them with lsusb, you can control USB devices:
udisksctl unmount -b /dev/sdb1 # unmount through udisks (no root needed on a desktop)
udisksctl power-off -b /dev/sdb # tell the stick it's safe to pullThe kernel also lets you switch a USB device off through sysfs. Writing 0 to its authorized file disconnects the drivers. Writing 1 brings it back:
echo 0 | sudo tee /sys/bus/usb/devices/1-2/authorized
echo 1 | sudo tee /sys/bus/usb/devices/1-2/authorized1-2 is bus 1, port 2, the same numbers you see in udevadm monitor and lsusb -t. And to keep a USB driver from loading at all, blacklist its module like any other.Tools like USBGuard build on this same authorized switch to allow only USB devices you have approved, which protects against “found a USB stick in the parking lot” attacks.
Exam checklist#
/proc/= processes and kernel info (cpuinfo,meminfo,interrupts,ioports,iomem,dma,modules)./sys/= sysfs, the device model./dev/= device files, managed by udev.lspcilists PCI devices.-kshows the driver,-vthe resources,-nnthe IDs,-ta tree.lsusblists USB devices.-ttree with drivers,-vdetails,-s bus:dev,-d vendor:product.lsmodlists loaded modules (from/proc/modules).modinfodescribes one.modprobe nameloads with dependencies,modprobe -r nameremoves.insmodandrmmodskip dependencies.- Module settings go in
/etc/modprobe.d/*.conf:blacklist,options,install. Boot-time loading:/etc/modules-load.d/(or/etc/moduleson Debian). - Disk names:
sdXfor SATA, SAS and USB,nvme0n1for NVMe,mmcblk0for SD and eMMC,sr0for optical,hdXfor legacy IDE. - udev creates
/deventries and applies rules from/etc/udev/rules.d/.udevadm monitorandudevadm infoto inspect. - D-Bus is the message bus that lets services (udisks, NetworkManager, systemd) tell programs about hardware events.
- Integrated peripherals are enabled or disabled in the BIOS/UEFI setup. Disabled there means Linux never sees them.
Answer these 3 questions to commit this byte to your learning path.
Reset. This byte isn't committed any more. Answer the questions again to commit it.
$ git commit -m "learn(lpic-101): Determine and configure hardware settings"
[main 3afa0e3] learn(lpic-101): Determine and configure hardware settings
1 byte changed, 3 insertions(+)
See it on your path Already committed . Try the questions again any time, it won't undo anything. To uncommit it and start over: