# LPI Linux Certification/LPIC1 Exam 101/Hardware & Architecture

* LPIC1 Exam 101
* Detailed_Objectives
* Hardware & Architecture
* Linux Installation & Package Management
* GNU & Unix Commands
* Linux Filesystems
* The X Window System
* Exercises results

## Section Overview

* BIOS Setting
* Configure Modem and sound cards
* Setup SCSI Devices
* Setup different PC expansion cards
* Configure USB Devices

## Configure Fundamental BIOS Settings
### Detailed Objective

Weight: 1

#### Description

    Candidates should be able to configure fundamental system hardware by making the correct settings in the system BIOS in x86 based hardware.
* Key knowledge area(s):
** Enable and disable integrated peripherals.
** Configure systems with or without external peripherals such as keyboards.
** Correctly set IRQ,DMA and I/O addresses for all BIOS administrated ports and settings for error handling.
* The following is a partial list of the used files, terms and utilities:
** /proc/ioports
** /proc/interrupts
** /proc/dma
** /proc/pci

## BIOS

* BIOS Tips & Tricks
* Familiarize yourself with BIOS settings in equipment that you support.
* Know your beeps: You may not have access to the internet when things go wrong.
* Change control: Always make sure you can reverse any change you make in a BIOS.
* BIOS updates: Keep informed. Don't roll them out as soon as they hit the mirrors. Wait a couple of months then check manufacturer forums for problems with the update. Once you are happy, update one system, monitor it and then roll out to the rest of your systems. Document the change, BIOS updates are normally a nightmare to reverse.
* Be aware of the F1 key to continue, particularly when rebooting remote servers.
* Lights Out Management if it is available, utilize it.
* Think long and hard about implementing BIOS security. Can the same level of security be implemented elsewhere? Normally it can.
* Understand the limitations of BIOS date and time. Can system date and time be better maintained by other means?

### Introduction

The BIOS (Basic Input / Output System) can be thought of as a suite of small programs that operate between the operating system and the hardware on any given computer. It provides a number of services that enable the computer to boot any given operating system. The BIOS can also provide or present other services to the operating system depending on the operating system and / or the type of hardware installed. It is also wise to note that a modern-day computer may have multiple BIOS chips interfacing the various different hardware components that combine to build the whole computer. These include Disk Array Controllers, Graphic Cards, Sound Cards, and possibly a few others. Firstly let's look at the services the BIOS provides regardless of which operating system is installed: these being the POST (Power On Self Test), Hardware Management, Security and Date & Time.
Intel and other manufacturers have developed another standard called EFI (Extensible Firmware Interface), which performs a similar function to BIOS, but does the job in a different manner. EFI is far more flexible and powerful than BIOS, but it has not enjoyed as much commercial success. Exploration of EFI is beyond the scope of this document for now.

### POST - Power On Self Test

* The POST process involves a small diagnostic program that checks system hardware such as RAM or motherboard components. If a particular piece of hardware is present, a basic test is performed to check for faults. More advanced tests such as a long memory test may be performed, but normally these features need to be manually enabled in the BIOS.
* If the POST process finds errors it will usually sound beeps on the motherboard speaker and / or show some visual message via LEDs on the motherboard and / or messages on the screen. This is known as an "Irregular POST Condition".
* The number (and in some cases the pattern) of the beeps, lights, or messages will aid you in diagnosing the problem; however, different motherboard models (even those from the same manufacturer) have different implementations of these signals, so it is always wise to have a printed reference manual for each model you support or internet access on another machine for a quick look-up.

### Hardware Management

* During the POST process, the BIOS allows you great flexibility to customize certain aspects of the system via settings stored in CMOS (Complementary Metal Oxide Semiconductor) memory. CMOS memory is volatile memory, but your motherboard has a backup battery to preserve any customized system configurations that you have made. This battery will eventually die. If you find that your computer is not retaining BIOS settings from one power cycle to another, the usual reason is that you need to replace this battery.
* Useful BIOS settings often edited by users and system administrators may include:
** Boot device priority
** Enable / disable motherboard features like integrated video, LAN, or sound
** Setting preferred memory addresses or IRQ vectors for PCI (or older) cards
* On older motherboards these configurations were done by positioning certain jumpers or dip switches to the hardware manufacturer's specifications. Modern CMOS menus have replaced nearly all of these devices, with the exception of setting SCSI ID or resetting a BIOS password. There are still some "old school" motherboards in operation, so always keep the possibility of jumpers in mind.

### Security

* Most BIOSs allow the user to set a password. The computer will require this password to be input before completing the boot process. Often this BIOS password adds inconvenience without any real security: information on how to get around these passwords is freely available on the internet. If the user forgets this password, the computer will not proceed to load an operating system. It's not hard to see why BIOS Passwords are rarely invoked at the business level.
* Many modern computers have the ability to detect configuration changes such as memory size changes and even if the case has been removed. The BIOS will often report these changes and prompt the user to press a key (usually the F1 key) to continue if this change is acceptable. Users may be required to hit another key to enter the BIOS configuration screens to change parameters depending on the particular BIOS manufacturer.

### Date and Time

* Setting the time and date are options within any modern BIOS. This is a "real-time" clock that runs constantly, powered by the same battery that preserves the CMOS settings. It's not very accurate, even compared to a wrist-watch, but it's better to have this poor clock than to require users to enter the time manually at every reboot. (That's how it was done in the early days of computers.)
* Linux (like other operating systems) maintains its own clock in software by counting interrupts generated by an oscillator circuit in your computer. This clock only functions while the operating system is running.
* The BIOS provides the date and time to the operating system upon booting. After the operating system has gathered this information, the BIOS clock and the Operating System clock continue to run independently. This means that the BIOS clock will soon differ from the operating system clock, even if it is only in milliseconds.
* Linux has a command called hwclock which can be used to synchronize the operating system clock with the BIOS. Once synchronized, they will drift apart again, however. (This is due to the Hardware nature of the BIOS clock and the Software nature of the OS clock.)
* Further on in the course, you will start to look at ntp and how important it is to maintain a consistent "Network Time". Knowing that the BIOS and operating system maintain separate clocks will aid you in setting out a solution.
* The BIOS does not handle time zone or daylight savings time adjustments. These are handled by the operating system. For this reason, some administrators may choose to set their BIOS clocks to UTC rather than the local time.

### Disk Drives

Most computers use Hard Disk Drives to hold an operating system and users' data. Some newer computers use Solid State Disk Drives instead. Though the physical devices vary greatly, there is little difference from the standpoint of configuring Linux or other operating systems.

#### Attachment Interfaces

Firstly let's address the confusion that often comes around from disk drive terminology such as IDE/ATA (Integrated Drive Electronics / Advanced Technology Attachment) and SATA (Serial Advanced Technology Attachment) and indeed PATA (Parallel Advanced Technology Attachment), which all use the ATA (Advanced Technology Attachment) standard to communicate with the device. The first part of the acronym can be thought of simplistically as a revision. Take for instance the revisions IDE, Fast IDE, EIDE, etc. These revisions changed the physical cables or ribbons that connect the disk drives to the computer, which enabled certain features, e.g. to address more disk space or speed up communications with the device. SATA was like a rewrite, once SATA came into being it was decided that all historical ATA devices that predated SATA (IDE, etc.) were to be grouped under the terminology PATA.
SCSI is another popular attachment interface that has undergone several generations of revision over the years: SCSI, SCSI-2, SCSI-3, U160, U320, and SAS. Click on the link at the head of this paragraph for more details, if desired. The SCSI family of attachment interfaces is not hardware-compatible with the ATA family, nor do they use the same software command set, so you cannot mix SCSI drives with ATA controllers or ATA drives with SCSI controllers. Because they use different commands, Linux will enumerate them with different labels. This will be handled in more detail when it becomes important later.

#### A Brief History

To get an understanding of modern hard drives, it helps to have some background. The BIOS traditionally uses INT13h as an interface to the hard drive. INT13h, from a historical standpoint, had certain limitations. On the other hand, the IDE/ATA interfaces also had restrictions. These restrictions are highlighted in the table below.
| Specification | Max Cylinders | Max heads | Max sectors | Max Size |
| IDE/ATA | 65,536 | 16 | 256 | 138GB |
| INT13h | 1,024 | 256 | 63 | 528MB |
Clearly you can see that because of the limitations of INT13h and IDE/ATA (which we have highlighted) under the above scenario, the largest drive your average computer could handle was 528MB. We call this specification CHS (cylinder-head-sector). You may recall that to calculate the total size of a hard drive use the following formula:
* Cylinders * Heads * Sectors * 512 = Capacity
To get around this a new specification was implemented called ECHS (extended cylinder-head-sector), sometimes also referred to as "Large Mode". This introduced a translation layer between the BIOS and INT13h. The translation layer then allowed a computer to handle disk drives up to 8.4GB in size. We can see this with a modification to the table above, which we have set out below and highlighted the relevant row.
| Specification | Max Cylinders | Max heads | Max sectors | Max Size |
| IDE/ATA | 65,536 | 16 | 256 | 138GB |
| ECHS | 620 | 128 | 63 | 2.5GB |
| INT13h | 1,024 | 256 | 63 | 8.4GB |
To see how the translation works, let's take a 2.5GB hard drive with 4960 cylinders, 16 heads, and 63 sectors. The translation program looks at the number of cylinders and makes a "best fit" with the INT13h limitation of 1,024 cylinders. The translation program does this by division, normally. It divides the number of cylinders by one of the following numbers: 2,4,6,8 and in some cases 16. In our case, 4960 / 8 = 620, which does not break the limitation of INT13h. Now the translation program multiplies the number of heads by 8, so 16 * 8 = 128. In this way, the translation program maintains the INT13h standard and provides a way in which the computer can see the whole disk. We can see this by calculating the disk space at both points previous translation and after.
* Native 4960 * 16 * 63 * 512 = 2.5GB
* Translation 620 * 128 * 63 * 512 = 2.5GB
The Table above needs a little more clarification. You will note that the maximum number of heads for the ECHS (translation layer) is 128, which is incompatible with the IDE/ATA Layer, which specifies a limit of 16. We get away with this because the translation layer is only concerned with INT13h and is not in any way related to the IDE/ATA layer. The next table will show how this model really looks.
| Specification | Max Cylinders | Max heads | Max sectors | Max Size |
| Physical Drive | 4,660 | 16 | 63 | 2.5GB |
| IDE/ATA | 65,536 | 16 | 256 | 138GB |
| INT13h | 1,024 | 256 | 63 | 8.4GB |
| ECHS | 620 | 128 | 63 | 2.5GB |
Needless to say, hard drives got a lot bigger than 8.4GB, so some other way was needed, as the cylinder-head-sector method was no longer a viable option. This is covered in the next section where we bring you right up to date.

#### LBA

LBA (Logical Block Addressing) is the most common scheme in use today to get past the 528MB limit imposed on an IDE/ATA disk drive. With LBA each block has a unique identification number that starts at 0 and then 1,2,3,4,5... In order for this mechanism to work it must be supported by the BIOS, the operating system, and the IDE drive. A common misconception with LBA is that it is the LBA itself that gets around the 528MB limit when in fact LBA uses translation. When you enable LBA mode in a BIOS you are in effect enabling translation. The translation can be the same as ECHS as discussed above, or another algorithm can be used by a 3rd party. It is way beyond the scope of this course to look at these algorithms. But the point of 3rd party algorithms should be made. More and more with modern operating systems the BIOS is taking a back seat when "talking" to the drive, and modern operating systems now perform this function with their own interpretation of the ATA specification preferring to bypass the BIOS altogether.

### IRQ

There are 16 IRQs (Interupt ReQuest) channels on x86 architecture. Of those only a few are freely available. The table below lists the IRQs that cannot be used in red and the IRQs that could be reassigned (providing that certain hardware does not exist in your system) in orange, and those that you are free to assign as you please in white.
| IRQ No. | Hardware Assignment | IRQ No. | Hardware Assignment | IRQ No. | Hardware Assignment | IRQ No. | Hardware Assignment |
| 0 | System timer | 4 | COM1 | 8 | Real Time Clock | 12 | PS2 Mouse |
| 1 | Keyboard | 5 | LPT2 / Sound Card | 9 | Available | 13 | Floating Point Proc |
| 2 | Handles IRQ 8 - 15 | 6 | Floppy Controller | 10 | Available | 14 | Primary IDE |
| 3 | COM2 | 7 | Parallel Port | 11 | Available | 15 | Secondary IDE |
In essence IRQs are used to halt the computer from processing any further information and immediately service the request from the interrupt. That being the device that is assigned to the interrupt. The table above explains what the IRQ architecture looked like under PIC (Programmable Interrupt Controller), however it does hide the issue of priorities. The priorities of the IRQ structure are given by 0-1-2-8-9-10-11-12-13-14-15-3-4-5-6-7. The reason 8-15 have a higher priority is that they hook into IRQ 2, in fact IRQ 2 can be said to be IRQ 9. What we have looked at here is somewhat historical. Under the above scenario adding new hardware quickly became an art and a pain! The advent of PCI and USB enabled a greater range of addresses and also the ability to just plug things in and go.

### DMA

DMA (Direct Memory Access) is a feature of the modern computer to enable devices to bypass the CPU when needing to write or read information to or from another device, the purpose of this is to take the load off the CPU and utilize the DMA controller and RAM to move blocks of data from one area to another. Although the CPU is never completely eliminated in a DMA transfer, its role is purely to initiate the process rather than manage it.

### I/O

I/O (Input / Output) refers to moving data among all devices, both external and internal, within a modern computer system. Some devices can perform both input and output functions. An example of this is a Network Card. Obviously keyboards, mouse, etc. are examples of input devices and monitors and printers are examples of output devices.

### Putting it all together

When you turn the PC on, BIOS instructions are loaded into RAM from a permanently available ROM chip on the motherboard. These instructions, after performing a POST, may further inform the processor where the operating system is located and how to load it into RAM. In order to allow operating systems and applications to run on a PC, the BIOS provides a standard layer of services that the operating system can use to "talk" to the hardware. In turn, the operating system provides standard services to applications to perform their functions. It is important to understand that not all operating systems use all BIOS services: some use their own instructions to access the hardware. The direct method of accessing the hardware may improve performance.
The BIOS utilizes a number of technologies to perform the services we have addressed above. However, as with all things in the computer industry, technology is moving forward fast. The BIOS performs a crucial role within the system and new technology added to the motherboard will normally require BIOS cooperation so that the OS can utilize the new technology.
By now you should have a good understanding of the BIOS and the role it performs with hardware. In the next section we look at Linux and how it interacts with the BIOS / Hardware. This will hopefully give you a system administrator's view of these relationships.

## Viewing BIOS-related information in Linux
### Introduction

From this point onward it becomes necessary to have access to a Linux PC. Although some theory is involved, we shall be interacting with Linux more and more. I advise that you attempt the commands as you come across them, testing your understanding as you go. Do be careful with some of the commands as an incorrect switch, or in some cases running a command from the wrong directory is not healthy. (One famous example is running rm -R * from / as root.) So if you are new to Linux, be careful: don't misuse the root account. Only use it when you have to. I personally advise a separate Linux installation for the course that contains no personal data.
Understand that No author / contributor to this book is in any way responsible for any loss of data or damage to any hardware, however it is caused. Mistakes in typing can happen and this is an open book for anyone to edit regardless of their knowledge.

### /proc

/proc is a pseudo-filesystem which is used as an interface to kernel data structures. Most of it is read-only, but some files allow kernel variables to be changed, particularly in /proc/sys. if you were to list the file system in /proc you would see something like this:
The first thing that you will notice is the numbered directories these represent processes running on your system. Each numbered directory, has a common subset of directories that provide information about that process. The number representing the directory is consistent with the process number seen with the ps command. We cover processes in a later section. The directories and files we are interested in are the following:

### Getting kernel information

/proc is a pseudo-filesystem which is used as an interface to kernel data structures. Most of it is read-only, but some files allow kernel variables to be changed.
Examples of available directories are:

### /proc/acpi

acpi is the interface to monitor events and states.

### Getting hard drive Information

In order to get disk information, use hdparm. More information is available at the hdparm man page
Examples:
And more... Bold text

## Exercises

* What is the RAM size of your system?
* Which devices are sharing an interrupt line?
* Use the lspci utility with the right option to draw the PCI architecture of your system.
** How many PCI buses and bridges are there?
** Are there any PCI/ISA bridges?
* What is the lspci option to list all the Intel PCI devices?
* What is the command to set your IDE hard drive to read-only mode?
* What is the command to turn on/off the hard drive disk cache?
* What does the setpci utility do? (Not mentioned in the above article, but do a web search to understand what it does)
* What is the command to write a word in register N of a PCI device?
* To show the amount of physical RAM available: use free or cat /proc/meminfo | grep MemTotal
* Which are the devices that are sharing an interrupt line? cat /proc/interrupts | more
** How many PCI buses and bridges are there? lspci | wc -l
** Are there any PCI/ISA bridges? lspci | grep 'PCI\|ISA'
* What is the option with lspci to list all the Intel PCI devices? lspci -d 8086:*
* What is the command to set you IDE hard drive in read only mode? hdparm -r1 <device>
* What is the command to turn on/off the disk cache hard drive? hdparm -W1 <device> hdparm -W0 <device>
* What does the setpci utility do? setpci is a utility for querying and configuring PCI devices.
* What would be the command to write a word in register N of a PCI device? setpci -s 12:3.4 N.W=1

## Configure Modem & Sound Cards
### Detailed Objective

Weight: 1

#### Description

    Candidates should be able to configure modem and sound card settings.
* Key knowledge area(s):
** Ensure devices meet compatibility requirements (particularly that the modem is not an unsupported "win-modem").
** Verify that correct resources are used by the cards.
** Configure modem for outbound dial-up.
** Set serial port speeds.
* The following is a partial list of the used files, terms and utilities:
** /proc/dma
** /proc/interrupts
** /proc/ioports
** /proc/pci
** lspci
** lsusb

### Modems

A modem is a device that lets you send digital data through a telephone line. The four types of modem are:
* External: Connected through the serial port.
* USB: Connected through USB.
* Internal: ISA or PCI board.
* Built-in: Part of the motherboard.
Most new modems are Plug and Play and you have various ways to deal with it:
* The serial driver does it all for you.
* Use the isapnp program.
* Let a PnP BIOS do the configuration.
To display the configuration of an ISA device, use pnpdump. This utility can dump information (IO ports, interrupts, and DMA channels) that the card uses. To configure any ISA devices, use isapnp. For more information check the man page of isapnp.conf file.

### Serial ports

An external modem can be configured with setserial.
Example:

### Dial Out and In

In order to dial out with a modem, you can use the application setserial or minicom. A configuration file can be created with the -s option.
In order to be able to handle users dialing in, the system needs to be able to start a getty process to handle the dial-in session. The configuration must be done in the /etc/inittab file.
Once /etc/inittab is modified, init needs to re-read it.

### Exercises

* Exercises results

## Setup Different PC Expansion Cards
### Detailed Objective

Weight: 3

#### Description

    Candidates should be able to configure various cards for the various expansion slots.
* Key knowledge area(s):
** Know the differences between coldplug and hotplug devices.
** Determine hardware recourses for devices.
* The following is a partial list of the used files, terms and utilities:
** The appropriate subdirectories of /proc
** hotplug configuration files, terms and utilities
** lspci
** lsusb

### Hotplug

With proper support from the operating system, some devices can be added and/or removed without shutting the system down, much like a CD-ROM or floppy disk can be mounted or unmounted. USB was designed to be hot-pluggable, but the operating system must still be prepared to deal with the possibility of devices appearing and disappearing.
Some server motherboards support a hot-pluggable PCI slot standard, intended to reduce downtime by allowing administrators to replace failed components without shutting-down the entire server. A few server vendors even go as far as to allow swapping-out bad RAM while the system is running, but this is very rare and expensive. Both the hardware and the operating system must support hot-plugging components in order for the system to work. (There's a limited amount of repair that can be done on an airplane while flying at 10,000 feet.)

### Coldplug

It is much less confusing to your computer if you shutdown the power before making any changes to hardware you are connecting.

### PCI

All PCI cards are normally detected by the BIOS. At boot time the BIOS probes the PCI configuration space and detects all the different devices and bridges. To insure that the BIOS has detected all the PCI devices, use lspci. Check for bridges, special devices, and functions.
All ISA cards are also normally detected with the respected drivers. The utilities that allow you to manually configure any ISA cards are pnpdump, pnpisa and /etc/pnpisa.conf file. The pnpdump program allows you to dump information on all the detected ISA cards. The isapnp works with a configuration file /etc/pnpisa.conf that has the same syntax of the output of pnpdump and it allows you to customize any ISA card settings.

### Exercises

* Exercises results

## Configure Communication Devices
### Detailed Objective

Weight: 1

#### Description

    Candidates should be able to install and configure different internal and external communication devices like modems, ISDN adapters and DSL modems.
* Key knowledge area(s):
** Verification of compatibility requirements (such as the modem is not a "winmodem").
** Correctly set IRQs, DMAs and I/O Ports of the cards to avoid conflicts between devices.
** Load and configure suitable device drivers.
** Set serial port speed.
** Setup modem for outbound PPP connections.
* The following is a partial list of the used files, terms and utilities:
** /proc/dma
** /proc/interrupts
** /proc/ioports
** setserial

### I/O Ports

To list the I/O ports the system uses, print the /proc/ioports file.

### Interrupts

To list all the interrupts used by all the devices, print the /proc/interrupts file.
An optimized system will not have any interrupt lines used by more than one heavily-used device.
Remember that every ISR from every device will be executed for each interrupt.

### DMA

To list all the ISA DMA (Direct Memory Access) channels in-use, print out the /proc/dma file.

### PCI

To list all the devices on the pci buses, print out the /proc/pci file.

### Exercises

* Exercises results

## Configure USB Devices
### Detailed Objective

Weight: 1

#### Description

    Candidates should be able to activate USB support, use and configure different USB devices.
* Key knowledge area(s):
** Identify and load the correct USB driver module.
** Demonstrate knowledge of the USB layer architecture and the modules used in the different layers.
* The following is a partial list of the used files, terms and utilities:
** lspci
** xHCI modules
** lsusb
** /etc/usbmgr/
** usbmodules
** /etc/hotplug
** udev configuration files, utilities and documentation

### Auto detection of new USB Devices

The program that gets executed when a new hardware is connected is hotplug.
The /etc/hotplug directory contains the script that must be executed each time a device gets inserted or removed.
The hotplug program is also started at boot time to initialize all the connected devices. /etc/init.d/hotplug

### List USB Devices

To verify your devices have been detected, use lsusb.
Example:
To display a graphical view of the connected USB devices, use usbview

### USB Drivers

Every detected USB device will be mounted in the /proc/bus/usb filesystem and can be accessed with the appropriate application.
Each USB device will be viewed through a filename like /proc/bus/usb/001/005 .
To check if the appropriate driver has been loaded for a USB devices, use usbmodules.
Examples:
The default modules to be loaded are /lib/modules/<kernel-version>/modules.usbmap.
The mapping is stored in the file /lib/modules/<kernel-version>/modules.usbmap.
All the drivers are stored in the directory /lib/modules/<kernel-version>/kernel/drivers/usb/.

### USB Applications

Many applications exist for many different devices. It is sometimes time consuming to make them work. An application that can be used for a digital camera is gphoto2.
Common options:
    --debug: See what is the problem when talking to the camera.
    --print-usb-usermap: Store the output in /etc/hotplug/usb.usermap in order for the application to support your camera.
    -P: Download pictures.
Example:

### Exercises

USB:
* Check if you can detect a digital camera.
* View the camera device information.
* Take a picture and download it into a system with gphoto2.
* Configure your own device (HD, camera, mouse, keyboard,...)
* Exercises results