# LPI Linux Certification/LPIC1 Exam 101/Linux Installation & Package Management
## Section Overview

* Design hard disk layout
* Install a boot manager
* Make and install programs from source
* Manage shared libraries
* Use Debian package management
* Use Red Hat Package Manager (RPM)

## Detailed Objectives

(LPIC-1 Version 5.0)
Weight: 2
Description:
Candidates should be able to design a disk partitioning scheme for a Linux system.
Key knowledge area(s):
* Allocate filesystems and swap space to separate partitions or disks.
* Tailor the design to the intended use of the system.
* Ensure the /boot partition conforms to the hardware requirements for booting.
The following is a partial list of the used files, terms and utilities:
* / (root) filesystem
* /var filesystem
* /home filesystem
* /boot filesystem
* EFI System Partition (ESP)
* swap space
* mount points
* partitions

## Filesystems

A filesystem is simply a way of organizing data in computer-accessible form on the hard disk or other media. Different filesystems have different organizing structures to determine where the data and indexing information will be stored. Some popular filesystems include:

## Partitions

When doing an installation there is normally a minimum disk configuration of two partitions that needs to be created:
* / (root): directory that contains the Linux distribution.
* Swap space: partition that allows a kernel to run more processes than can normally fit into RAM.
If multiple disks are available it is good practice to also have the /usr and /home directories on different partitions. Each partition will contain a filesystem type and can be mounted on the active system in the filesystem global tree. To print the active mounted filesystems, use mount.
The swap partition doesn't need a file system. It will be accessed in raw mode by the kernel with no filesystem system calls as overhead.

## Disk speed issues

Before deciding on your partitioning scheme, you really need to know exactly what sort of applications you will be running.
* Mail Server
* Web Server
* Graphical X-Windows based applications
* And more
If your system has multiple disks, use the fastest one to store most of your data.
* / Contains most of the system utilities and doesn't get used much. These can be shipped off to the slowest disk.
* /var/log contains a lot of logging information. Best on a fast disk.
* /usr is typically on a separate partition anyway and if you have a lot of clients starting lots of X applications, use a fast disk.
Examples of system applications:
For e-mail serving, Sendmail writes to two main locations: mail queue, usually /var/spool/mqueue and /var/spool/mail as well as other locations. Apache uses several different files, two log files per site hosted for logging and access to the actual pages. Apache spends quite a bit of time writing to log files in /var/log (or where configured to do so).

## Virtual memory (Swap)

When you set up a new system, swap should be twice your actual RAM. This is not always sensible in real-world scenarios, however it is a traditional guideline and a conservative answer to give in an exam. swapon is used to enable specified devices/partitions designated for swapping. On the contrary, swapoff is used to disable a specified device/partition of swapping. Both commands can take the -a option, which iterates all swap devices found in /proc/swaps or /etc/fstab.
Information on the swap partition can be displayed with swapon.
To get information on the usage of virtual memory, use vmstat.

## Exercises

* Exercises results
* Open two terminals: In one terminal display periodically the virtual memory usage. In the second terminal disable the virtual memory and re-enable it. Notify the changes in the first terminal.
* What is the disk layout of your system and how many disks do you have?
* How many swap space can you use?

## Detailed Objective

(LPIC-1 Version 5.0)
Weight: 2
Description:
Candidates should be able to select, install and configure a boot manager.
Key knowledge area(s):
* Providing alternative boot locations and backup boot options.
* Install and configure a boot loader such as GRUB Legacy.
* Perform basic configuration changes for GRUB 2.
* Interact with the boot loader.
The following is a partial list of the used files, terms and utilities:
* menu.lst, grub.cfg and grub.conf
* grub-install
* grub-mkconfig
* MBR

## Boot managers

A boot loader is installed in the MBR (Master Boot Record). When a system starts, it loads what is in the MBR to RAM. Under Linux there are two main boot loaders:
* Lilo: LInux LOader.
* Grub: GRand Unified Boot Loader.
A boot loader allows you to select the image that you would like to boot from. A system can contain multiple images (operating systems).
A boot loader allows you to interactively run commands and pass parameters to the image that you will boot. The initrd is the driver that will be used to build a filesystem on RAM to mount other filesystems and execute programs.
GRUB is today's default boot loader for many distributions. When installing Windows with Linux, install Windows first and Linux second, because Windows overwrites the MBR without asking.

## LILO vs. GRUB

Both are used to load an image from a disk to RAM. GRUB has the following advantages to LILO:
* More pre-OS commands.
* Supports images stored beyond the 1024 BIOS cylinder limitation.
* Can access its configuration file through the filesystem.
When using LILO, each time you add a new image or change an image a new LILO needs to be installed in the MBR.
* LILO keeps its boot information in the MBR
* GRUB keeps its boot information in the filesystem (menu.lst).
* LILO also has a configuration file /etc/lilo.conf.
To install GRUB on the MBR, use grub-install. The command setup will override the MBR.
To install LILO on the MBR, use lilo. The lilo will use the /etc/lilo.conf file to know what to write into the MBR.
Example of /etc/lilo.conf:
Example of menu.lst (GRUB configuration file):

## Exercises

* Exercises results
1) Install Grub on a floppy disk and try to boot your image manually:
Now reboot with the floppy and from the prompt select the kernel on the hard disk.
2) Create /boot/grub/menu.lst file and install Grub on your hard drive with the grub utility.
3) Install back lilo. Change the linux label of the default kernel image to SuSE in /etc/lilo.conf and re-install the lilo program in the MBR.

## Detailed Objective (206.1)

(LPIC-2 Version 4.5)
Weight: 2
Description: Candidates should be able to build and install an executable program from source. This objective includes being able to unpack a file of sources.
Key Knowledge Areas:
* Unpack source code using common compression and archive utilities.
* Understand basics of invoking make to compile programs.
* Apply parameters to a configure script.
* Know where sources are stored by default.
Terms and Utilities:
* /usr/src/
* gunzip
* gzip
* bzip2
* xz
* tar
* configure
* make
* uname
* install
* patch

## Source files

An archive is a collection of related files stored in one file. The command that allows you to store files and subtree directories in one file is tar.
Common functions: -c: Create a new tar file. -t: Tell the contents of a tar file. -x: Extract the contents of a tar file.
Common options: -f file: Specify the name of the tar file.
Examples:
It is good practice to use the .tar extension for all files archived with tar.

## File compression

Compression saves space for storage and file transfer. There are multiple utilities to do compression:
* compress, uncompress # Old Unix compression algorithm
* gzip, gunzip # Most common use
* bzip2, bunzip2 # Best compression algorithm
Once an archive has been created , it can be compressed. Examples:

## Files archiving and compression

When archiving files and subdirectories it is possible to package and compress them in one command. Examples:
By default tar uses a relative path but with the -P option it is possible to save files with an absolute path. Files in this mode will always be extracted at the same location.
For compressing and archiving in one line
For unzipping a compressed archive:

## GNU tool chain

Under Linux all the sources can be built with the standard GNU tool chain. make Utility to maintain group of programs. Use the rules defined in Makefile.
* gcc ANSI C Compiler
* g++ C++ Compiler
Many compressed or archived packages once installed will have information files (README, INSTALL) that should explain how it should be built and installed. The files Makefile.in and configure.in are the basic files that will be used to generate a final Makefile. The configured file in general scans the system and will build a final Makefile.

## Exercises

* Exercises results
* Do an archive of the /bin and the /sbin directories. With which compression utilities do you get the smallest file size? Use -v to get in percentage the size file reduction.
* Install the file /usr/src/packages/SOURCES/grub-09.tar.bz2 in /tmp and by reading INSTALL and README build the sources.
* Find the way to uncompress a .deb an a .rpm archive, what is in ?
* In on command line, compress a new file and uncompress this new file somewhere else.

## Detailed Objective

(LPIC-1 Version 5.0)
Weight: 1
Description:
Candidates should be able to determine the shared libraries that executable programs depend on and install them when necessary.
Key knowledge areas:
* Identify shared libraries.
* Identify the typical locations of system libraries.
* Load shared libraries.
The following is a partial list of the used files, terms and utilities:
* ldd
* ldconfig
* /etc/ld.so.conf
* LD_LIBRARY_PATH

## Shared libraries

A library is a set of functions that programs can use to implement their functionalities. When building (linking) a program, those libraries can be statically or dynamically linked to an executable. Static link means that the final program will contain the library function within its file. (lib.a) Dynamic link means that the needed libraries would need to be loaded into RAM when the program needs to be executed. (lib.so)
The default directories for all the standard libraries are:
* /lib: Used mainly by /bin programs.
* /usr/lib: Used mainly by /usr/bin programs.
The file /etc/ld.so.conf is used by the system to specify other library locations. To build a cache file used by the runtime loader of all the available libraries, use ldconfig. The file /etc/ld.so.cache will be generated.

## Library dependencies

To print shared programs or library dependencies, use ldd.
Example:

## Runtime loader

The runtime loader ld.so finds the needed library of a program and will load them into RAM. The search order of ld.so is:
* LD_LIBRARY_PATH
* The cache file /etc/ld.so.cache
* The default directories /lib and /usr/lib.

## Exercises

* Exercises results

## Detailed Objective

(LPIC-1 Version 5.0
Weight: 3
Description:
Candidates should be able to perform package management using the Debian package tools.
Key knowledge areas:
* Install, upgrade and uninstall Debian binary packages.
* Find packages containing specific files or libraries which may or may not be installed.
* Obtain package information like version, content, dependencies, package integrity and installation status (whether or not the package is installed).
* Awareness of apt.
The following is a partial list of the used files, terms and utilities:
* /etc/apt/sources.list
* dpkg
* dpkg-reconfigure
* apt-get
* apt-cache

## Package Structure

In order to understand how to use Debian's package management system, it would be useful to first have an understanding of how a Debian package is named. For example, the package ncftp_3.1.3-1_i386.deb has 5 major parts:
* ncftp - the name of the program/application/library
* 3.1.3 - the version of the program/application/library assigned by the original (upstream) author(s)
* 1 - the revision number of the package assigned by the person(s) who packaged the program for a Debian system
* i386 - the architecture the packaged program is designed to run on
* .deb - signifies this is a Debian package
Note that there is special significance to the use of underscores(_) and hyphens(-); an underscore shall separate the name of the program and its version, a hyphen shall separate a version number and the revision number, and an underscore shall separate the revision number and the architecture.

## dpkg

dpkg is the "grandaddy" or "back-end" of the Debian Package Management System. Features present in the more advanced tools are not available to dpkg but it is nevertheless a useful tool.
Some notes:
* dpkg keeps its record of available packages in /var/lib/dpkg/available.
Some of the more common functions used by administrators by dpkg are:
Adding, Removing, and Configuring Packages
* dpkg {-i|--install} <package-name> will install the specified package
* dpkg {-r|--remove} <package-name> will remove the specified package (but leave the configuration files intact)
* dpkg {-P|--purge} <package-name> will remove the specified package and the corresponding configuration files
* dpkg --root /target -i <package> will install a package into a unbootable system by specifying the system root.
* dpkg --unpack <package-name> will unpack (but do not configure) a Debian archive into the file system of the hard disk
* dpkg --configure <package-name> will configure a package that already has been unpacked
Querying Package Information
* dpkg --info <package-name> will print out the control file (and other information) for a specified package
* dpkg {-l|--list} this will give you a list of installed packages.
* dpkg {-a|--pending} is given instead of a package name, then all packages unpacked, but marked to be removed or purged in file /var/lib/dpkg/status, are removed or purged, respectively.
* dpkg -s (--status) <package-name> will give you a description of installed package
Updating Package Information
* dpkg --update-avail <package-name> will replace old information with with new information from package.
* dpkg --merge-avail <package-name> will combine old information with new information from package.

## dpkg-reconfigure

dpkg-reconfigure reconfigures packages after they have already been installed.
* dpkg-reconfigure <package-name> to reconfigure the initial installation settings
* dpkg-reconfigure --priority=medium package [...] will set the minimum priority of question that will be displayed
* dpkg-reconfigure --all will reconfigure all packages
* dpkg-reconfigure locales will generate any extra locales
* dpkg-reconfigure --p=low xserver-xfree86 will reconfigure X server

## Dselect

The utility that allows you on Debian to easily add/remove packages is dselect.
* Choose the access method to use.
* Update the list of available packages, if possible.
* Request which packages you want on your system.
* Install and upgrade wanted packages.
* Configure any packages that are unconfigured.
* Remove unwanted software.
There is on dselect an interactive menu that will allow you to install/remove packages. Care must be taken with this utility. You can damage your system.
Dselect menu example:

## apt-get

If you know the name of a package you want to install, use apt-get. You must configure the sources.list file. This same file is used when you choose the apt access method of dselect. The location is /etc/apt.
* apt-get install <package-name> will search its database for the most recent version of this package and will retrieve and install it from the corresponding archive as specified in sources.list. In the event that this package depends on another APT will check the dependencies and install the needed packages.
** apt-get install <package-name>=<version> will install a package at the version specified
** apt-get install <package-name> -o DPkg::options::="--force-overwrite" installs a package ignoring "error processing ..., which is also in package ..." errors.
* apt-get remove <package-name> will remove the specified package but keep its configuration files.
* apt-get --purge remove <package-name> will remove the specified package and its configuration files.
* apt-get -u install <package-name> will upgrade and install a specific package.
* apt-get -u upgrade will upgrade packages within the same distribution packages except those which have been kept back because of broken dependencies or new dependencies.
* apt-get -u dist-upgrade will upgrade an entire Debian system at once.

## apt-file

* apt-file search <file-name> will search for a package which includes the specified file.
* apt-file list <package-name> will list the contents of a package matching the pattern. This action is very close to the dpkg -S command except the package does not need to be installed or fetched.

## Apt-cache

To find the name of a package that you want to install use apt-cache. apt-cache main options are :
* add - Add a package file to the source cache
* showpkg - Show some general information for a single package
* stats - Show some basic statistics
* search - Search the package list for a regex pattern
* show - Show a readable record for the package
* depends – Show raw dependency information for a package

## Resources

APT HOWTO http://www.debian.org/doc/manuals/apt-howto/index.en.html dselect Documentation for Beginners http://www.debian.org/doc/manuals/dselect-beginner/

## Exercises

* Exercises results
* Install a system with Debian.
* Get familiar with dselect and remove the tcpdump utility.
* Install back with apt-get the package that contains the tcpdump utility.
* Try kpackage to install ethereal
Red Hat Package Manager is a powerful package manager, which can be used to build, install, query, verify, update, and erase individual software packages. A package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package. Packages come in two varieties: binary packages, used to encapsulate software to be installed, and source packages, containing the source code and recipe necessary to produce binary packages.

## Detailed Objective

(LPIC-1 Version 5.0)
Weight: 3
Description:
Candidates should be able to perform package management using RPM, YUM and Zypper.
Key Knowledge Areas:
* Install, re-install, upgrade and remove packages using RPM, YUM and Zypper.
* Obtain information on RPM packages such as version, status, dependencies, integrity and signatures.
* Determine what files a package provides, as well as find which package a specific file comes from.
* Awareness of dnf.
The following is a partial list of the used files, terms and utilities:
* rpm
* rpm2cpio
* /etc/yum.conf
* /etc/yum.repos.d/
* yum
* zypper

## Red Hat Package Manager

Some Linux distribution uses rpm the “Red Hat Package Manager” for all its distribution software. RPM maintains a detailed database of all software installed in the system.
To install a RPM package, do:
The package will be installed only if the dependency are met and there is no conflict with another package. To upgrade a package, do:
The files of the old package version will be removed and replaced by the new files. To remove a RPM package, do:
The package will be removed only if no other package depends on it.

## RPM Queries

With the -q option you can query the RPM database or display information about package file.
There are several switches that you can use:
* -i: to get package information
* -l: To get a file list of a package.
* -f file: Query which package a file belongs to.
* -s: File list with status information.
* -d: list only documentation files.
* -a: List all the installed packages.
If you want to display information about package file you can specify filename using -p switch:

## RPM Commands

To get general information on a package or program, use rpmlocate.
Searching for ipcs in rpm db:
To list all the installed packages, use rpmqpack:
Alternatively use:

## Source Installation

The RPM source files have generally the format package.src.rpm and can be installed the same way as binaries. The directories where they will be installed from /usr/src/packages are:
* SOURCES: For the original sources.
* SPECS: For the .spec file that controls the build process.
* BUILD: All the sources are built in this directory.
* RPMS: Where the complete binary packages are stored.
* SRPMS: The sources.
To install the source of a package, do:
The source files will be stored in the /usr/src/packages in directories SPEC and SOURCES. To compile the sources, do:
The result of the compilation will be stored in the BUILD directory

## Exercises

* Exercises results
* Is the apache package installed?
* In which package are the files /bin/ls, /usr/sbin/tcpdump, and /sbin/ifconfig?
* From the floppy disk install the pci utilities and grub packages. Build the binaries and try to execute them. The sources should be in the /usr/src/packages/BINARY directory.