• No results found

Linux Kernel (201)

1.3 Kernel runtime management and troubleshooting (20)

1.3.11 Hardware and Kernel Information

uname

uname prints system information such as machine type, network hostname, OS release, OS name, OS version and processor type of the host. The parameters are:

-a, --all print all information, in the order below, except omit -p and -i if these are unknown.

-s, --kernel-name prints the kernel name -n, --nodename prints the network node hostname -r, --kernel-release prints the kernel release

-v, --kernel-version prints the kernel build version, date and time -m, --machine prints the machine hardware architecture name -p, --processor prints the name of the processor type

-i, --hardware-platform prints the name of hardware platform -o, --operating-system prints the name of the operating system Example:

debian-601a:~$ uname -a

Linux debian-601a 2.6.32-5-amd64 #1 SMP Mon Mar 7 21:35:22 UTC 2011 x86_64 GNU/Linux

/proc/sys/kernel/is a directory in the /proc pseudo filesystem. It contains files that allow you to tune and monitor the Linux kernel. Be careful, as modification of some of the files may lead to a hanging or dysfunctional system. As these parameters are highly dependant on the kernel verions, it is advisable to read both documentation and source before actually making adjustments. See alsothe section on the /proc filesystem.

Some files are quit harmless and can safely be used to obtain information, for instance to show the version of the running kernel:

debian-601a:~$ cat /proc/sys/kernel/osrelease

Some files can be used to set information in the kernel. For instance, the following will tell the kernel not to loop on a panic, but to auto-reboot after 20 seconds:

debian-601a:~$ echo 20 > /proc/sys/kernel/panic

lspci

With lspci you can display information about all the PCI buses in the system and all the devices that are connected to them. Keep in mind that you need to have Linux kernel 2.1.82 or newer. With older kernels direct hardware access is only available to root.

To make the output of lspci more verbose, one or more -v paramaters (up to 3) can be added. Access to some parts of the PCI configuraion space is restricted to root on many operating systems. So lspci features available to normal users are limited.

Example of lspci output on a system running Debian in Virtualbox:

debian-601a:~$ lspci

00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]

00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)

00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter 00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02) 00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service

00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC’97 Audio Controller (rev ←-01)

00:06.0 USB Controller: Apple Computer Inc. KeyLargo/Intrepid USB 00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)

00:0d.0 SATA controller: Intel Corporation 82801HBM/HEM (ICH8M/ICH8M-E) SATA AHCI ←-Controller (rev 02)

lsusb

lsusb is similiar to lspci, but checks the USB buses and devices. To make use of lsusb a Linux kernel which supports the /proc/bus/usbinferface is needed (Linux 2.3.15 or newer). lsusb -v will provide verbose information.

Example of lsusb output as generated on a laptop running Ubuntu:

ubuntu:/var/log$ lsusb

Bus 007 Device 003: ID 03f0:0324 Hewlett-Packard SK-2885 keyboard Bus 007 Device 002: ID 045e:0040 Microsoft Corp. Wheel Mouse Optical Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 004 Device 002: ID 147e:2016 Upek Biometric Touchchip/Touchstrip Fingerprint Sensor Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 002: ID 04f2:b018 Chicony Electronics Co., Ltd 2M UVC Webcam Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

lsdev

lsdev displays information about installed hardware. It gathers information from interupts, DMA files, and interrupts from the /procdirectory. lsdev gives a quick overview about which device is using what I/O address and IRQ/DMA channels. Files being used:

/proc/interrupts

/proc/ioports

/proc/dma

Example of lsdev output on a Debian based system:

debian-601a:/var/log$ lsdev

0000:00:05.0 d100-d1ff d200-d23f

0000:00:0d.0 d240-d247 d250-d257 d260-d26f

82801AA-ICH 5

ACPI 4000-4003 4004-4005 4008-400b 4020-4021

ahci d240-d247 d250-d257 d260-d26f

ata_piix 14 15 0170-0177 01f0-01f7 0376-0376 03f6-03f6 d000-d00f

cascade 4 2

On some systemslsdev is missing, use procinfo instead.

sysctl

sysctl is used to modify kernel paramaters at runtime. The parameters available are those listed under /proc/sys/. The configu-ration file can usually be found in /etc/sysctl.conf. It is important to know that modules loaded after sysctl is used may override its settings. You can prevent this by running sysctl only after all modules are loaded.

dmesg

With the dmesg command you can write kernel messages to standard output. Or write them to a file using dmesg > /var/log/-boot.messages. This can be helpful when it comes to troubleshooting issues with your system or when you just want to get some information about the hardware in your system. The output of dmesg can usually be found in /var/log/dmesg. Use dmesg in combination with grep to find specific information.

1.3.12 udev

Candidates should understand device detection and management using udev. This objective includes troubleshooting udev rules Key Knowledge Areas:

• udev rules

• Kernel interfaces

udev was designed to make Linux device handling more flexible and safe by taking device handling out of system space into userspace.

udev consists of a userspace daemon (udevd) which receives "uevents" from the kernel. Communication between the userspace daemon and the kernel is done through the sysfs pseudo filesystem. The kernel sends the aforementioned "uevents" when

it detects addition or removal of hardware, for example when you plug in your camera or USB disk. Based on a set of rules to match these uevents the kernel provides a dynamic device directory containing only device files for devices that are actually present, and can fire up scripts etc. to perform various actions. Hence, it is possible, for example, to plug in a camera, which will be automatically detected and properly mounted in the right place. After that a script might be started that copies all files to the local disk into a properly named subdirectory that will be created using the proper rights.

/etc/udev/

The /etc/udev/ directory contains the configuration and the rule files for the udev utility. The udev.conf is the main configuration file for udev. Here, for instance, the logging priority can be changed.

udev rules

udev rules are read from files located in the default rules directory. /lib/udev/rules.d/. Custom rules to override these default rules are specified in the /etc/udev/rules.d/ directory.

When devices are initialized or removed, the kernel sends an ’uevent’. These uevents contain information such as the subsystem (e.g. net, sub), action and attributes (e.g. mac, vendor). udev listens to these events, matches the uevent information to the specified rules, and responds accordingly.

A udev rule consists of multiple key value pairs separated by a comma. Each key value pair represents either a match key, that matches to information provided with the uevent or an assign key, which assign values, names and actions to the device nodes maintained by udev:

SUBSYSTEM=="net", ACTION=="ADD", DRIVERS="?*", ATTR{address}=="00:21:86:9e:c2:c4", ATTR{type}=="1", KERNEL="eth*", NAME=="eth0"

The rule specified above would add a device /dev/eth0 for a network card with MAC address 00:21:86:9e:c2:c4

As shown, a key value pair also specifies an operator. Depending on the used operator, different actions are taken. Valid operators are:

== Compare for equality

!= Compare for inequality

= Assign a value to a key. Keys that represent a list, are reset and only this single value is assigned

+= Add the value to a key finally; disallow any later changes, which may be used to prevent changes by any later rules When specifying rules, be careful not to create conflicting rules (e.g. do not point two different netword cards to the same device name). Also, changing device names into something else could cause userpsace software incompatibilities. You have power, use it wisely.

udevmonitor

udevmonitor will print udev and kernel uevents to standard output. You can use it to analyze event timing by comparing the timestamps of the kernel uevent and the udev event. Usually udevmonitor is a symbolic link to udevadm. In some distributions, this symbolic link no longer exists. To access the monitor on these systems, use the command udevadm monitor.

1.4 Questions and answers

Linux Kernel

1. Which technique is used in modern kernels to reduce their disk footprint?

Kernel images are compressed to reduce diskspace.Types of kernel images[13]

2. What is the purpose of using kernel modules?

In order to only use resources when needed, kernel modules can be loaded into the kernel on demand. Also, modules can be changed and reloaded without the need to reboot the kernel.What are kernel modules[14]

3. Why is running the command make mrproper generally a good idea?

As it prevents problems with the subsequent configuration and/or build of the kernel.Using mrproper[16]

4. What is the most important advantage of running make config in stead of make menuconfig, make xconfig or make gconfig?

The command does not depend on any full-screen display capabilities and is therefore useable on slow links and systems with limited display capabilities.Why use make config?[17]

5. What needs to be done after running make modules?

make modules_install is used after succesfully building the modules (device drivers and other items that were configured as modules). This installs them under /lib/modules/ kernel-version.How to install modules?[22]

6. For which distributions should you use mkinitramfs for creating an initrd image?

The debian(-based) distributions use mkinitramfs.Create an ignited image using mkinitramfs[43]

7. By which means can a patch be removed from a production kernel?

Either apply the patch again or run the command patch with the -R parameter.Removing a kernel patch from a production kernel[26]

8. Why is using modprobe recommended instead of using insmod to insert modules?

Modprobe is more specific about errors. It also works with just the module name and it can handle prerequisite relation-ships between modules.Using modprobe[28]

9. By which means may the version of the running kernel be determined?

You could check by usingcat /proc/sys/kernel/osrelease or by using uname -r.Obtain version of the running kernel[37]

10. Which command generates the file /lib/modules/kernel-version/modules.depfile (a list of module de-pendencies)?

This file is generated by the depmod command.Obtain version of the running kernel[37]

11. Which technique is used in modern kernels to reduce their memory footprint?

On demand loadable modules are used to reduce a kernel’s memory footprint.Types of kernel images[13]

12. For which reason was udev designed?

It was designed to make Linux device handling more flexible by taking device handling out of the kernel into user space.

udev device handling[39]

Chapter 2