Read LPI Linux Certification in a Nutshell Online
Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger
Tags: #Reference:Computers
The BIOS is the PC’s firmware.
The BIOS sets date and time for on-board clock, storage
device configuration, and so on, via menus.
Interrupts (IRQs) allow peripherals to interrupt the
CPU.
I/O addresses are locations in the processor’s
memory map for hardware de
vices
.
Useful files to query for hardware information:
/proc/interrupts
,
/proc/ioports
,
/proc/cpuinfo
,
/proc/devices
.
Useful commands to run for hardware information:
/sbin/lspci
,
/sbin/lsusb
.
DMA allows certain devices to work directly with memory,
freeing the processor (see
Table 10-1
).
Table 10-1. Common device settings
Device | I/O address | IRQ | DMA |
---|---|---|---|
ttyS0 (COM1) | 3f8 | 4 | NA |
ttyS1 (COM2) | 2f8 | 3 | NA |
ttyS2 (COM3) | 3e8 | 4 | NA |
ttyS3 (COM4) | 2e8 | 3 | NA |
lp0 (LPT1) | 378-37f | 7 | 3 (if configured in the |
lp1 (LPT2) | 278-27f | 5 | NA |
fd0, fd1 (floppies 1 and | 3f0-3f7 | 6 | 2 |
Power on
→
BIOS
→
Boot Loader
→
Kernel
→
init
→
startup services
→
shell
The command
dmesg
can be used to view
the output of the boot process.
The
init
process is always PID 1 and is
the parent of all other processes.
Defaults are defined in
Table 10-2
.
Table 10-2. Default Runlevels
Runlevel | Description |
---|---|
0 | Halt |
1 | Single-user mode |
2 | Multiuser, without |
3 | Full multiuser mode, without |
4 | Unused |
5 | Full multiuser mode, with |
6 | Reboot |
Runlevels can be changed on-the-fly with
init
telinit
The default runlevel is stored in the file
/etc/inittab
.
The
init
process will run the scripts
in
/etc/rc.d/rcX.d
(where X is your default
runlevel) in order, sending a “stop” parameter to scripts that
start with K and a “start” parameter to scripts that start with
S.
Keep
/
small by distributing
larger parts of the directory tree to other filesystems.
Separate a small
/boot
partition below
cylinder 1024 for kernels.
Separate
/var
into its own partition to
prevent runaway logs from filling
/
.
Separate
/tmp
.
Separate
/usr
if it is to be shared
read-only among other systems via NFS.
Set swap size to be somewhere between one and two times the
size of main memory.
The
/proc
filesystem includes
information on interrupts, I/O ports, and DMA in
/proc/interrupts
,
/proc/ioports
, and
/proc/dma
.
LILO has historically been the default Linux boot
loader.
LILO consists of the
lilo
command,
which installs the boot loader, and the boot loader itself.
LILO is configured using
/etc/lilo.conf
.
Any modification to the
/etc/lilo.conf
file requires the
lilo
command to be
rerun.
GRUB can boot Linux as well as most other PC-based operating
systems.
GRUB relies on various files in the
/boot/grub
directory to support reading from
various types of filesystems.
GRUB is configured using
/boot/grub/menu.lst
(or
/boot/grub/grub.conf
on some
distributions).
GRUB can be configured to present a text or graphical menu
interface and also has a command-line interface.
Modifications to the GRUB configuration files do not require
the
grub
command to be re-run (unlike
LILO).
System libraries provide many of the functions
required by a program.
A program that contains executable code from libraries is
statically linked
because
it stands alone and contains
all necessary code to execute.
Since static linking leads to larger executable files and
more resource consumption, system libraries can be shared among
many executing programs at the same time.
A program that contains references to external, shared
libraries is
dynamically linked
at runtime by
the dynamic linker,
ld.so
.
New locations for shared libraries can be added to theLD_LIBRARY_PATH
variable. As an
alternative, the locations can be added to
/etc/ld.so.conf
, which lists library file
directories. After this, you must run
/sbin/ldconfig
to translate this file into
the binary index
/etc/ld.so.cache
.
dpkg
automates the installation
and maintenance of software packages and offers a number of
options.
dselect
uses a text-based interactive
menu to select (or deselect) packages for installation.
alien
can convert packages to and from
the RPM and Debian package format.
apt-get
is a powerful tool that
interfaces with online repositories of Debian packages to install
and upgrade packages by name and resolves each package’s
dependencies automatically.
RPM automates the installation and maintenance of
software packages.
Package dependencies are defined but not resolved
automatically.
-i
,
-e
,
-U
,
-v
,
-h
,
--nodeps
, and
--force
are common options.
The
yum
command is a frontend to RPM,
interacting with online software repositories to download and
install software automatically.
The command
yum update
will search for
updates to installed packages, download them, resolve
dependencies, and install them automatically.
A
shell
provides the command
prompt and interprets commands.
A
shell variable
holds a value that is
accessible to shell programs.
PATH
is a shell variable
that contains a listing of directories that hold executable
programs.
Commands must be
bash
built-ins, found
in thePATH
, or explicitly
defined in order to succeed.
When shell variables are
exported
, they
become part of the
environment
.
Commands are comprised of a valid command, with or without
one or more options and arguments, followed by a carriage
return.
Interactive commands can include looping structures more
often used in shell scripts.
Shell sessions can be viewed as a conversation.
History, expansion, and editing make that dialog more
productive.
Commands can be reissued, modified, and edited. Examples are
shown in
Table 10-3
.
Command substitution allows the
result
of a command to be placed into a shell variable.
Table 10-3. Shell expansion, editing, and substitution examples
History type | Examples |
---|---|
Expansion | !! |
| !n |
| ^string1^string2 |
Editing | Ctrl-P, previous line |
| Ctrl-K, kill to end of |
| Ctrl-Y, paste (yank) |
Substitution |
|
Many commands contain either a
-r
or
-R
option for
recursive execution through a directory hierarchy.
The
find
command is inherently
recursive, and is intended to descend through directories looking
for files with certain attributes or executing commands.
The following programs modify or manipulate text from
files and standard input:
[file]
Printfile
to standard
output.
[files]
Cut out selected columns or fields from one or morefiles
.
[files]
Convert Tabs to spaces infiles
.
[files]
Format text infiles
to a
specified width by filling lines and removing newline
characters.
[files]
Print the first few lines offiles
.
file1
file2
Print a line for each pair of input lines, one each fromfile1
andfile2
, that have identical join
fields.
[files]
Number the lines offiles
,
which are concatenated in the output.
[files]
Dumpfiles
in octal,
hexadecimal, ASCII, and other formats.
files
Paste together corresponding lines of one or more files
into vertical columns.
[file]
Convert a text file into a paginated, columnar version,
with headers and page fills.
[file]
Sort lines infile
alphabetically, numerically, or other ways.
[infile]
[outfile]
Splitinfile
into a specified
number of line groups; the output will go into a succession of
files:outfilea
a
,outfilea
b
, and so on.
[file]
Printfile
to standard output
in reverse line order.
[files]
Print the last few lines of one or more files.
[string1
[string2]]
Translate characters by mapping fromstring1
to the corresponding
character instring2
.
[files]
Convert spaces to Tabs infiles
.
[files]
Display only unique lines infiles
that are already sorted.
[files]
Print counts of characters, words, and lines forfiles
.
sed
is a popular
text-filtering program found on every Unix system. It
has the following syntax:
sedcommand
[files
]
sed -ecommand1
[-ecommand2
] [files
]
sed -fscript
[files
]
Execute
sedcommands
, or those found inscript
, on standard input orfiles
.
Filesystem creation prepares a disk device (or
partition) for use. Linux usually uses the native
ext3
(third extended) journaling filesystem,
but it supports many other filesystem types. You can see a list of
all the filesystems Linux supports by using the “l” option under
the
fdisk
command.
The Linux filesystem is arranged into a hierarchical
structure anchored at the
root directory
, or
/
. Beneath this is a tree of directories and
files.
Identification information for a filesystem object is stored
in its
inode
(index node), which holds
location, modification, and security information. Filesystems are
created with a finite number of inodes.
The following commands are essential for the management of files
and directories:
[options]
[pattern]
Create or uncompress an archive with the bzip2
algorithm.
file1
file2
files
directory
Copyfile1
tofile2
, or copyfiles
todirectory
.
[options]
[files]
Create or extract a binary archive, containing
either files or a recursive set of files and directories.
[options]
[files]
Copy and convert files. The
dd
command can also copy data from raw devices, bypassing the
filesystem layer.
[file]
Determine the type offile
by performing a number of
tests.
[directory] [options]
[pattern]
Search throughdirectory
looking for objects that
matchpattern
.
[options]
[file]
Uncompress an archive created withgzip
.
[options]
[pattern]
Create a compressed archive containing files and
directories that matchpattern
.
[options]
[pattern]
List the contents of a directory, or list only
files that match[pattern]
.
directories
Create one or moredirectories
.
source
target
Move or rename files and directories.
files
Delete one or morefiles
from the filesystem. When used
recursively (with the
-r
option),
rm
also removes directories.
directories
Deletedirectories
,
which must be empty.
[options]
[files]
Create or extract a Tape Archive, containing
either files or a recursive set of files and directories.
files
Change the access and/or modification times offiles
by default to the present
time.
Wildcards (also called
file globs
) allow the specification
of many files at once. A list of commonly used wildcards can be found
in
Table 10-4
.
Table 10-4. File-naming wildcards
Wildcard | Function |
---|---|
* | Match zero or more |
? | Match exactly one |
[ | Match any single character from |
[! | Match any single character other |
[ | Match any single character from |
[! | Match any single character from |
{ | Brace expansion: create strings |
A central concept for Linux and Unix systems is that
everything is a file
.
Many system devices are represented in the filesystem using
a
device file
, such as
/dev/ttyS0
for a serial port.
The shell provides the
standard I/O
capability, offering three default file descriptors to running
programs:
Standard input
(
STDIN
) is a text input stream, by
default attached to the keyboard.
Standard output
(
STDOUT
) is an output stream for normal
program output. By default, this is the screen.
Standard error
(
STDERR
) is an output stream meant for
error messages. By default, this is the screen.
It is possible to tie the output of one program to the input
of another. This is known as a
pipe
and is
created by joining commands using the pipe symbol (|
).
Pipes are a special form of
redirection
, which allows you
to manage the origin of input streams and the destination of
output streams. Redirection syntax for various shells differs
slightly. See
Table 10-5
for
examples of common redirection operators.
Table 10-5. Common redirection operators
Redirection | Syntax for |
---|---|
Send |
|
|
|
Send |
|
Send both |
|
|
|
Receive |
|
Append |
|
|
|
Append |
|
Append both |
|
Pipe |
|
Pipe |
|
Pipe |
|