LPI Linux Certification in a Nutshell (38 page)

Read LPI Linux Certification in a Nutshell Online

Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger

Tags: #Reference:Computers

BOOK: LPI Linux Certification in a Nutshell
9.72Mb size Format: txt, pdf, ePub
Chapter 10. Exam 101 Highlighter’s Index
System Architecture
Objective 101.1: Determine and Configure Hardware
Settings
PC BIOS
  • 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.

Resource assignments
  • 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
BIOS)

lp1 (LPT2)

278-27f

5

NA

fd0, fd1 (floppies 1 and
2)

3f0-3f7

6

2

Objective 101.2: Boot the System
Boot order
  • Power on

    BIOS

    Boot Loader

    Kernel

    init

    startup services

    shell

Information
  • 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.

Objective 101.3: Change Runlevels and Shut Down or
Reboot System
Runlevels
  • Defaults are defined in
    Table 10-2
    .

    Table 10-2. Default Runlevels

    Runlevel

    Description

    0

    Halt

    1

    Single-user mode

    2

    Multiuser, without
    NFS

    3

    Full multiuser mode, without
    X

    4

    Unused

    5

    Full multiuser mode, with
    X

    6

    Reboot

  • Runlevels can be changed on-the-fly with
    init

    or
    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.

Linux Installation and Package Management
Objective 102.1: Design Hard Disk Layout
  • 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.

/proc
  • The
    /proc
    filesystem includes
    information on interrupts, I/O ports, and DMA in
    /proc/interrupts
    ,
    /proc/ioports
    , and
    /proc/dma
    .

Objective 102.2: Install a Boot Manager
LILO
  • 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
  • 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).

Objective 102.3: Manage Shared Libraries
Concepts
  • 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.

Commands
  • 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 the
    LD_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
    .

Objective 102.4: Use Debian Package Management
Commands
  • 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.

Objective 102.5: Use Red Hat Package Manager (RPM)
Concepts
  • 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.

GNU and Unix Commands
Objective 103.1: Work on the Command Line
The interactive shell and shell variables
  • 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 the
    PATH
    , or explicitly
    defined in order to succeed.

  • When shell variables are
    exported
    , they
    become part of the
    environment
    .

Entering commands
  • 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.

Command history, editing, and substitution
  • 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
line

 

Ctrl-Y, paste (yank)
text

Substitution

VAR=$(command)
or
VAR='command'

Recursive execution
  • 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.

Objective 103.2: Process Text Streams Using Filters
The commands

The following programs modify or manipulate text from
files and standard input:

cat
[file]

Print
file
to standard
output.

cut
[files]

Cut out selected columns or fields from one or more
files
.

expand
[files]

Convert Tabs to spaces in
files
.

fmt
[files]

Format text in
files
to a
specified width by filling lines and removing newline
characters.

head
[files]

Print the first few lines of
files
.

join
file1
file2

Print a line for each pair of input lines, one each from
file1
and
file2
, that have identical join
fields.

nl
[files]

Number the lines of
files
,
which are concatenated in the output.

od
[files]

Dump
files
in octal,
hexadecimal, ASCII, and other formats.

paste
files

Paste together corresponding lines of one or more files
into vertical columns.

pr
[file]

Convert a text file into a paginated, columnar version,
with headers and page fills.

sort
[file]

Sort lines in
file
alphabetically, numerically, or other ways.

split
[infile]
[outfile]

Split
infile
into a specified
number of line groups; the output will go into a succession of
files:
outfilea
a
,
outfilea
b
, and so on.

tac
[file]

Print
file
to standard output
in reverse line order.

tail
[files]

Print the last few lines of one or more files.

tr
[string1
[string2]]

Translate characters by mapping from
string1
to the corresponding
character in
string2
.

unexpand
[files]

Convert spaces to Tabs in
files
.

uniq
[files]

Display only unique lines in
files
that are already sorted.

wc
[files]

Print counts of characters, words, and lines for
files
.

The stream editor, sed

sed
is a popular
text-filtering program found on every Unix system. It
has the following syntax:

sed
command
[
files
]
sed -e
command1
[-e
command2
] [
files
]
sed -f
script
[
files
]

Execute
sed
commands
, or those found in
script
, on standard input or
files
.

Objective 103.3: Perform Basic File Management
Concepts
  • 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.

File and directory management commands

The following commands are essential for the management of files
and directories:

bzip2
[options]
[pattern]

Create or uncompress an archive with the bzip2
algorithm.

cp
file1
file2
cp
files
directory

Copy
file1
to
file2
, or copy
files
to
directory
.

cpio
[options]
[files]

Create or extract a binary archive, containing
either files or a recursive set of files and directories.

dd
[options]
[files]

Copy and convert files. The
dd
command can also copy data from raw devices, bypassing the
filesystem layer.

file
[file]

Determine the type of
file
by performing a number of
tests.

find
[directory] [options]
[pattern]

Search through
directory
looking for objects that
match
pattern
.

gunzip
[options]
[file]

Uncompress an archive created with
gzip
.

gzip
[options]
[pattern]

Create a compressed archive containing files and
directories that match
pattern
.

ls
[options]
[pattern]

List the contents of a directory, or list only
files that match
[pattern]
.

mkdir
directories

Create one or more
directories
.

mv
source
target

Move or rename files and directories.

rm
files

Delete one or more
files
from the filesystem. When used
recursively (with the
-r
option),
rm
also removes directories.

rmdir
directories

Delete
directories
,
which must be empty.

tar
[options]
[files]

Create or extract a Tape Archive, containing
either files or a recursive set of files and directories.

touch
files

Change the access and/or modification times of
files
by default to the present
time.

File-naming wildcards

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
characters.

?

Match exactly one
character.

[
characters
]

Match any single character from
among
characters
listed between
brackets.

[!
characters
]

Match any single character other
than
characters
listed between
brackets.

[
a-z
]

Match any single character from
among the range of characters listed between
brackets.

[!
a-z
]

Match any single character from
among the characters not in the range listed between
brackets.

{
frag1
,
frag2
,
frag3
,...}

Brace expansion: create strings
frag1
,
frag2
, and
frag3
, etc., such that
file_{one,two,three}
yields
file_one
,
file_two
, and
file_three
.

Objective 103.4: Use Streams, Pipes, and Redirects
Concepts
  • 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.

Standard I/O
  • 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.

Pipes and redirection
  • 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
    function

    Syntax for
    bash

    Send
    STDOUT
    to
    file
    .

    $ cmd
    > file

     

    $ cmd
    1> file

    Send
    STDERR
    to
    file
    .

    $ cmd
    2> file

    Send both
    STDOUT
    and
    STDERR
    to
    file
    .

    $ cmd
    > file 2>&1

     

    $ cmd
    > file 2> file

    Receive
    STDIN
    from
    file
    .

    $ cmd
    < file

    Append
    STDOUT
    to
    file
    .

    $ cmd
    >> file

     

    $ cmd
    1>> file

    Append
    STDERR
    to
    file
    .

    $ cmd
    2>> file

    Append both
    STDOUT
    and
    STDERR
    to
    file
    .

    $ cmd
    >> file 2>&1

    Pipe
    STDOUT
    from
    cmd1
    to
    cmd2
    .

    $ cmd1
    | cmd2

    Pipe
    STDOUT
    and
    STDERR
    from
    cmd1
    to
    cmd2
    .

    $ cmd1
    2>&1 | cmd2

    Pipe
    STDOUT
    from
    cmd1
    to
    cmd2
    while simultaneously
    writing it to
    file1
    using
    tee
    .

    $ cmd1
    | tee file1 | cmd2

Other books

Sympathy for the Devil by Billy London
The Stolen Voice by Pat Mcintosh
Real Vampires Get Lucky by Gerry Bartlett
Sharp Shooter by Marianne Delacourt
Christian Mingle by Louisa Bacio
Savant by Rex Miller
Benworden by Neal Davies