Beruflich Dokumente
Kultur Dokumente
Learn how to set up your computer hardware for Linux and how to find information about your
hardware via Linux commands and tools. You can use the material in this tutorial to study for
the LPI 101 exam for Linux system administrator certification, or to learn for fun.
Overview
In this tutorial, learn to configure and check the hardware for your Linux system. Learn to:
Computer hardware
Today's computers have come a long way from the IBM PCs introduced in 1981. Apart from
massive increases in speed, memory, and storage capabilities, perhaps the most notable changes
have been in configuration and setup. In this tutorial, I cover some common hardware settings that
you might make on current computers, and I explore the commands that Linux has for listing and
managing hardware.
See "Learn Linux, 101: A roadmap for LPIC-1" for a description of and link to each tutorial in
this series. The roadmap is in progress and reflects the version 4.0 objectives of the LPIC-1
exams as updated April 15th, 2015. As tutorials are completed, they will be added to the
roadmap.
This tutorial helps you prepare for Objective 101.1 in Topic 101 of the Linux Server Professional
(LPIC-1) exam 101. The objective has a weight of 2.
Prerequisites
To get the most from the tutorials in this series, you need a basic knowledge of Linux and a
working Linux system on which you can practice the commands that are covered in this tutorial.
Sometimes different versions of a program format output differently, so your results might not
always look exactly like the listings and figures that are shown here. The examples in this tutorial
come from 64-bit systems with traditional Basic Input-Output Services (BIOS) or with the newer
Universal Extensible Firmware Interface (UEFI).
Hardware settings
You usually configure settings by using either BIOS or UEFI firmware. Unless a setting is specific
to UEFI, I use the term BIOS settings to cover both BIOS and UEFI settings.
You can access BIOS settings when you turn on your computer. Usually you do this by pressing
a key such as Del, F1, or F8 after turning on the computer but before the operating system load
starts. As machines have become faster and solid-state drives (SSDs) have reduced boot time
to a few seconds, you might find that your system has a special button or key sequence to use.
Check your system documentation to find out how to access the BIOS settings. The examples that
are shown here illustrate the kinds of settings you might find, but the actual layout of your BIOS
interface will probably be different from mine.
Figure 1 shows an example of a BIOS main screen for a system that I built. On this screen, you
can change the system date and time. You can also change parameters for the legacy floppy drive
if you have one. You also see the summary of installed drives. My system has only SATA drives,
although IDE drives are also supported through the on-board controllers.
If your system supports legacy peripheral interfaces, you might have a place to configure them. In
my case, I can use the Advanced menu to configure the serial and parallel port interrupt requests
(IRQs) and I/O port starting addresses. Figure 2 shows the advanced settings for my system.
In addition to configuring the legacy serial and parallel ports, note that I can enable or disable
the on-board LAN and 1394 (FireWire) controllers. Note that the LAN controller also has a boot
ROM that I have disabled. You enable the boot ROM if you want the system to load over a LAN
from a remote server. You might want this for a kiosk machine or for reimaging a large number of
systems.
Your BIOS can also have settings that you can use to boot without a keyboard or mouse. When
there is a boot error or maybe a change in configuration (such as the addition of memory), many
systems particularly older ones require you to press a key to enter BIOS setup. What
happens if the system has no keyboard? Today, you might plug in a Universal Serial Bus (USB)
keyboard, but older systems with PS2 keyboard connectors could sometimes be damaged when a
keyboard was plugged in. So, on many BIOS systems, you can disable either the keyboard itself or
the warning that you might get if the keyboard is not present. I have a keyboard on my system, so
my Wait for 'F1' If Error setting is enabled, as shown in Figure 3.
Another important setting that you might need to make is the order of boot devices. As shown in
Figure 4, my system is set to check the first floppy drive, then the first SATA drive, and finally a
CD or DVD. I haven't had a working floppy drive for several years, so I could probably safely drop
it from the sequence. If my hard drive isn't working, I have the CD or DVD as a backup. See the
tutorial "Learn Linux, 101: Boot the system" for information on how to choose the CD or DVD if you
want to boot from it only once.
For UEFI systems, many settings are similar to those for traditional BIOS, including date, time, and
whether on-board devices are enabled or not. Figure 5 shows an example from a Lenovo Yoga 2
Pro.
One major difference with UEFI systems is, of course, support for UEFI booting. Your system
might support UEFI-only booting or it might also support legacy BIOS-like booting. My system has
a Boot Mode parameter with two choices, as shown in Figure 6. When I choose Legacy Support,
I can boot a legacy system or a UEFI system. My system will only boot UEFI systems if I choose
UEFI.
If you select UEFI-only booting, then you will probably not see some items that are related to
legacy support, such as the legacy USB support option that you saw in Figure 5. You will also
probably have options for support of secure boot, which allows only signed binaries to be booted.
Figure 7 shows some of the security options that you might see if you select UEFI-only booting.
On my system, there are both status values and options that you can change. For example, the
Platform Mode setting of User confirms that security keys have been installed. If no keys are
installed, the value is likely to be Setup instead. I can use the Reset to Setup Mode to install new
keys, or I can use the Restore Factory Keys to restore the preinstalled factory keys.
Hard drives
The hard drive has been the workhorse of data storage on PCs since the early 1980s. Hard drives
come in a sealed unit and contain several recording surfaces or platters. The ST-506 introduced
in 1980 had a 5MB capacity and used a controller card to translate requests from the computer to
the internal commands needed to access the data on the disk platters. In 1984, IBM introduced
the IBM PC/AT computer with a 16-bit AT bus, later known as an Industry Standard Architecture
(ISA) bus. The AT attachment interface (ATA) standardized the interface between the controller
card and the computer, preserving compatibility with the ST-506 command set. In the early 1980s,
Western Digital moved the controller function inside the drive housing under the name Integrated
Drive Electronics (IDE). You will find several later standards and terms, including ATA-1, ATA-2,
ATA-4, and EIDE, among others. When Serial ATA (SATA) was introduced in 2003, the original
ATA interface became known as Parallel ATA (PATA).
Another popular disk-attachment interface is the Small Computer System Interface (SCSI). SCSI
was developed around 1978 for attaching various devices, including hard drives and printers. SCSI
disks are still popular in larger servers.
The original ATA interface was designed for hard drives. The ATA interface was extended to the
ATA Packet Interface (ATAPI) for use with other devices, such as floppy drives, Zip drives, or CD
drives. ATAPI added capability to detect media presence, or eject media, among other features not
needed for a normal hard drive. The ATAPI interface can carry SCSI commands in packets and
thus support various device types.
Today, internal hard drives usually use either SCSI or SATA attachment. Drives can also be
attached externally using USB, IEE-1394 (FireWire), External Serial Advanced Technology
Attachment (eSATA), or Apple's Thunderbolt.
Hard drives can be partitioned to divide their space for different uses, and they can be combined
into arrays for redundancy. Hard drives can also be grouped together using tools such as Logical
Volume Manager to make several smaller disks appear as one or more larger ones.
Solid-state drives
Solid-state drives (SSDs) are a newer form of drive that is being used in many notebook
computers. Compared to the traditional hard drive, SSDs are lighter and faster, use less power,
and do not suffer from mechanical failure. SSDs are often housed like notebook drives and use
the same interfaces, although this arrangement can limit the theoretical capabilities of an SSD.
A newer attachment called NVM Express (NVMe) has been developed for PCI Express (PCIe)
based solid-state drives. The specification is designed to better use SSDs over PCIe.
With the advent of USB and IEEE-1394 FireWire devices, hot plugging became the norm rather
than the exception. Today, high-end servers can dynamically move resources such as memory or
CPUs between Linux systems that are multiplexed on a single system. The result is that almost
anything can be hot plugged. Consequently, the Linux system now uses only a few cold-plug
devices to start the system, and then activates everything else using hot-plug events that drive
udev rules. Even the cold-plugged devices are rescanned to drive udev events and effectively
become hot plugged.
Sysfs is a simple filesystem with files that represent object attributes. The objects themselves are
represented by directories. Symbolic links represent relationships between objects. The top-level
directories in sysfs represent major subsystems. Listing 1 shows examples of the top-level /sys
directory and the /sys/bus and /sys/devices directories.
If you look at /sys/block, you find your block devices. In my case, I have three hard drives sda,
sdb, and sdc and one CD/DVD drive: sr0. These are actually links to directories under the /
sys/devices directory. If you follow these links, you find the partitions of sda. Looking at the size
file, you see that the disk has 2,040,192 sectors, a value confirmed by fdisk -l, as illustrated in
Listing 2.
../devices/pci0000:00/0000:00:14.1/ata6/host5/target5:0:0/5:0:0:0/block/sr0
[ian@atticf22 ~]$ ls /sys/"devices/pci0000:00/0000:00:11.0/ata1/host0/target0:0:0/0:0:0:0/block/sda"
alignment_offset events power sda10 sda5 slaves
bdi events_async queue sda11 sda6 stat
capability events_poll_msecs range sda12 sda7 subsystem
dev ext_range removable sda2 sda8 trace
device holders ro sda3 sda9 uevent
discard_alignment inflight sda1 sda4 size
[ian@atticf22 ~]$ ls /sys/"devices/pci0000:00/0000:00:11.0/ata1/host0/target0:0:0/0:0:0:0/block/sda"/sda1
alignment_offset discard_alignment inflight power size stat trace
dev holders partition ro start subsystem uevent
[ian@atticf22 ~]$ cat \
> /sys/"devices/pci0000:00/0000:00:11.0/ata1/host0/target0:0:0/0:0:0:0/block/sda"/sda1/size
2040192
[ian@atticf22 ~]$ su -
Password:
[root@atticf22 ~]# fdisk -l /dev/sda1
Disk /dev/sda1: 996.2 MiB, 1044578304 bytes, 2040192 sectors
The tree command is a useful tool for exploring /sys. Note also that you have to escape special
characters such as the colon (:) by enclosing them in quotation marks or using the backslash (\)
character.
You see a large number of numbered directories one for each running process on your system.
The number is the process ID (PID). Listing 4 shows the first few entries for a running bash
command prompt (PID=$$ the current PID). Note that almost all entries in the procfs filesystem
have a length of 0, even though they might not be empty and you can see data if you use the cat
command. Most entries are not terminated with a newline character, so I use the echo command in
Listing 4 for clarity.
The parameters that you can control by setting values in the procfs filesystem can also
be controlled via the sysctl command. Refer to the sysctl and procfs man pages for more
information.
The procfs filesystem also provides information about interrupt, Direct Memory Access (DMA), and
I/O port resources used by your system.
DMA was a technique used in ISA bus systems whereby fast devices such as hard drives could
transfer data to computer memory without involving the processor. DMA frees up the processor to
do other work while the data is being read from or written to the device. The PCI bus architecture
uses bus mastering to achieve a similar goal. Listing 6 shows the contents of /proc/dma on my
system. If you have ISA bus resources, you usually see more than this, and you might need this
information to help diagnose conflicts.
Another resource list you can use to help resolve problems is the listing of I/O ports in /proc/
ioports. Several I/O ports used in ISA bus systems are well known, such as the range 0378 to
037a usually used for the first parallel port. Note that the ports are specified in hexadecimal.
0170-0177 : pata_atiixp
01f0-01f7 : 0000:00:14.1
01f0-01f7 : pata_atiixp
0230-023f : pnp 00:07
0290-029f : pnp 00:07
0300-030f : pnp 00:07
0376-0376 : 0000:00:14.1
0376-0376 : pata_atiixp
0378-037a : parport0
03c0-03df : vga+
03f6-03f6 : 0000:00:14.1
03f6-03f6 : pata_atiixp
03f8-03ff : serial
040b-040b : pnp 00:06
04d0-04d1 : pnp 00:06
04d6-04d6 : pnp 00:06
0800-0803 : ACPI PM1a_EVT_BLK
0804-0805 : ACPI PM1a_CNT_BLK
0808-080b : ACPI PM_TMR
0810-0815 : ACPI CPU throttle
0820-0827 : ACPI GPE0_BLK
08ff-08ff : ACPI PM2_CNT_BLK
0900-090f : pnp 00:06
0910-091f : pnp 00:06
0a30-0a3f : pnp 00:07
0b00-0b3f : pnp 00:06
0b20-0b2f : pnp 00:06
0c00-0c01 : pnp 00:06
0c14-0c14 : pnp 00:06
0c50-0c51 : pnp 00:06
0c52-0c52 : pnp 00:06
0c6c-0c6c : pnp 00:06
The procinfo package also contains the procinfo command, which summarizes other information
from /proc. Try it or see the man page for details.
The udev rules are in /usr/lib/udev/rules.d, with additional local rules in /etc/udev/rules.d. You can
create additional rules in the volatile /run/udev/rules.d directory. You can configure udev using the /
etc/udev/udev.conf file. NOTE: Some systems place rules in /lib/udev/rules.d rather than /usr/lib/
udev/rules.d. Check the udev man page on your system.
The /dev filesystem describes the devices on your system. In a long listing, you find one of four
values in the first column:
b
Represents a block device such as a disk drive
c
Represents a character device such as a terminal or printer, or a special device such as null
d
Represents a directory
l
Represents a symbolic link to another directory of file, either in /dev, /proc, or /run
Listing 9 shows a partial listing of /dev on my system where you see examples of each type of
entry.
Listing 10 shows the linkage between some kernel-assigned names and some more-familiar
names for hard-drive partitions.
If you want to manage or monitor udev events, you can use the udevadm command. See the man
pages for more information.
00:12.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller
00:12.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0 USB OHCI1 Controller
00:12.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller
00:13.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller
00:13.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0 USB OHCI1 Controller
00:13.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller
00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 SMBus Controller (rev 3a)
00:14.1 IDE interface: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 IDE Controller
00:14.2 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 Azalia (Intel HDA)
00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 LPC host controller
00:14.4 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 PCI to PCI Bridge
00:14.5 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI2 Controller
00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor HyperTransport
Configuration
00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Address Map
00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor DRAM Controller
00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Miscellaneous Control
00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Link Control
01:00.0 VGA compatible controller: NVIDIA Corporation GF119 [GeForce GT 610] (rev a1)
01:00.1 Audio device: NVIDIA Corporation GF119 HDMI Audio Controller (rev a1)
02:00.0 FireWire (IEEE 1394): JMicron Technology Corp. IEEE 1394 Host Controller
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit
Ethernet Controller (rev 02)
Listing 12 shows a Ubuntu 15.04 system running on a Lenovo Yoga 2 Pro notebook.
The lspci command looks up much of its data in the /usr/share/hwdata/pci.ids file, which contains
a list of all known IDs (vendors, devices, classes, and subclasses). Vendor and device codes are
assigned numbers. Use the -n option if you want to see numbers instead of names. If you have
a new device that is not yet in your local database, use the -q option to query the central PCI
ID server database using a DNS lookup. If a device is found there, the information is saved in
~/.pciids-cache, and the device is recognized on later runs even if you do not specify -q.
PCI topology is described by four levels: domain, bus, slot, and function. You can restrict output by
using any of these components along with the -s option. The -t option shows the output in a tree
view. Other options of lspci control the verbosity and format of the output. You can have more or
less verbose output, and the output can be suitable for machine or human reading.
Listing 13 shows the topology tree for devices in slot 00 on my system, using the -t and -v
options.
You can also restrict output by vendor ID, device, or class by using the -d option. And the -k
option tells you which kernel driver is handling the device and which kernel modules are capable of
handling it. Listing 14 shows this output for the NVIDIA graphics and sound devices on my system.
The vendor ID for NVIDIA is 10de, which you can find out by using the -nn option of lspci.
See the man pages for the many other options for lspci. Some of them give you access to
detailed information on PCI devices. There is also a setpci command, which enables a root user
to query and configure PCI devices. Again, see the man pages for details.
USB devices connect to a hub. The root hubs are at the top level and can support USB 1, 2, or
3. The OHCI (or UHCI) driver supports USB 1.1 (12Mbps), the EHCI driver supports USB 2.0
(480Mbps), and the XHCI driver supports USB 3.0 (5Gbps). USB Attached SCSI (UAS) is a faster
protocol developed for USB 3.0 that also supports USB 2.0 speeds. UAS was introduced into
Linux at kernel 3.15.
Many attached devices use a class driver, such as usb-storage for a storage device, usbhid for a
human-interface device such as mouse or keyboard, or hub for a cascaded hub. The list in Listing
15 includes two human-interface devices (my mouse and keyboard) and a USB 2.0 hub with an
attached storage device (a thumb drive). Some specialized devices might require a unique driver
for the device.
As with PCI devices, you can limit the output by USB topology or by vendor or device ID. Listing 16
shows an example of each.
There is also a usbview command that you can use to view USB information graphically. The data
is presented in tree view in the left pane. Selecting an entry shows the details in the right pane.
The example in Figure 8 shows details for a USB drive.
There is also a per-user-session daemon that is launched at login time. The user daemon provides
interprocess communication between the user applications. The D-Bus protocol is a general
one-to-one message-passing framework. Two applications could even communicate using the
framework without messages passing through the dbus daemon.
Kernel modules
A long time ago, computer operating systems were configured and built to handle a specific set
of attached hardware. If a device was not built into the operating system kernel, it could not be
added or used. As the variety of devices increased and as the need grew to dynamically add
devices by hot plugging, this model no longer worked. Today the kernel is minimal, and device
support is configured by loadable kernel modules (LKMs). A basic set of device-support modules is
usually included in an initial RAM disk that is loaded as part of the boot process. Once the system
is up, the kernel probes the system further and loads needed device modules as new devices are
discovered.
Several commands are used for interrogating and manipulating kernel modules. I'll cover lsmod,
modinfo, and modprobe here. The modprobe command has now replaced the function of the earlier
insmod and rmmod commands because it is more powerful.
Using lsmod
The lsmod command formats the information from /proc/modules to give you a current status of
the modules in your Linux system. The lsmod command has no options. Listing 17 shows a partial
listing of the module status on my system.
Using modinfo
Use the modinfo command to get information about a module. You can give a full filename or just
the module name. Listing 18 shows information for the vfat module, which handles the various
forms of FAT-formatted drives.
The module information includes the full path to the file and information about any other names
(aliases) the module might be known by. Dependencies, if any, are also listed. So, from Listing 18,
you can see that the vfat module is also known as fs-vfat and depends on another module called
fat. Try running modinfo with these module names.
You can use the -F or --field option to limit the output to a specific field. This option is useful for
scripts.
If you don't specify a full filename, modinfo searches for a module in /lib/modules/version/kernel,
where version is your kernel release as given by uname -r. In the example in Listing 18, the file
vfat.ko.xz (the vfat kernel module) is found in /lib/modules/4.1.6-200.fc22.x86_64/kernel/fs/fat.
Listing 19 illustrates how you might start looking for module files on your system.
You can also find several plain-text files in your /lib/modules/$(uname -r) directory including
modules.dep, which lists dependencies, and modules.alias, which lists aliases. The modules.builtin
file lists modules that are built in to the kernel. These include drivers needed for core functionality
on most systems. If you try to use modinfo to find out about the ehci-pci driver that you might
have noticed in the lsusb output, you probably won't find it because it is a built-in driver. Listing 20
illustrates this scenario.
Using modprobe
As you've seen from the output of lspci, lsusb, lsmod, and modinfo, your system uses several
kernel modules to drive devices. You have also seen that some of these modules have
dependencies. So, loading the right modules in the right order is important. Fortunately, the
modprobe command has taken over the earlier manual work of insmod and rmmod, which can each
insert or remove one module from the system.
I'll use the irnet module for this example on my Ubuntu 16.04.1 LTS system. Use modinfo to see
more about this module, as shown in Listing 21.
As you see, this module has a dependency on irda, which has a further dependency on crc-ccitt.
By using grep to search for irda or crc-ccitt in your modules.dep file, you can see the value of
modularizing driver support. Each of these drivers is used by many other drivers.
If you want to manually load or unload a driver, use modprobe with the -a (or --all) option to load
or insert the module and the -r option to remove or unload the module. The -n, --dry-run, or --
show option shows you what will be done, without doing it. You usually use the -v option with these
to see more information. Listing 22 shows what will happen if I try to load the irda module.
The output shows the insmod commands needed to load each required module with dependencies
resolved.
The modprobe command takes into account modules that are already loaded. In Listing 23, I first
load the crc-ccitt module, then do another dry run, and finally load the irnet module. Note that the
actual loading or unloading requires root authority.
You remove modules by using the -r option of modprobe. You cannot remove a module if it is being
used. Listing 24 shows you some examples.
Module parameters
Some modules have parameters. For example, a device driver might need to know which IRQ or
I/O port to use. Listing 25 shows module information for the nsc-ircc module, which has several
such parameters.
filename: /lib/modules/4.4.0-59-generic/kernel/drivers/net/irda/nsc-ircc.ko
license: GPL
description: NSC IrDA Device Driver
author: Dag Brattli <dagb@cs.uit.no>
srcversion: 9AA374A6DFC1C886D632DC3
alias: acpi*:IBM0071:*
alias: pnp:dIBM0071*
alias: acpi*:HWPC224:*
alias: pnp:dHWPC224*
alias: acpi*:NSC6001:*
alias: pnp:dNSC6001*
depends: irda
intree: Y
vermagic: 4.4.0-59-generic SMP mod_unload modversions
parm: qos_mtt_bits:Minimum Turn Time (int)
parm: io:Base I/O addresses (array of int)
parm: irq:IRQ lines (array of int)
parm: dma:DMA channels (array of int)
parm: dongle_id:Type-id of used dongle (int)
You specify module parameters on the modprobe command line when loading the module. See the
man page for more details and for details on the other available modprobe options.
Related topics
Use the developerWorks roadmap for LPIC-1 to find the developerWorks tutorials to help you
study for LPIC-1 certification based on the LPI Version 4.0 April 2015 objectives.
At the Linux Professional Institute website, find detailed objectives, task lists, and sample
questions for the certifications. In particular, see:
The LPIC-1: Linux Server Professional Certification program details
LPIC-1 exam 101 objectives
LPIC-1 exam 102 objectives
Always refer to the Linux Professional Institute website for the latest objectives.
Learn more about NVMe at NVM Express.
See "Make the most of large drives with GPT and Linux" (developerWorks, July 2009) for
more information on Extensible Firmware Interface (EFI) and the GUID Partition Table (GPT).
Learn more about hot plugging at the Linux Hotplug Project website and "Hotpluggable
devices and the Linux kernel" by Greg Kroah-Hartman.
Learn more about sysfs in "The sysfs Filesystem" by Patrick Mochel.
Learn more about D-Bus in the D-Bus Tutorial at freedesktop.org.