Chapter 4. Linux Installation & Package Management

Table of Contents

1. A Brief Look At The Objectives
2. Disk Partitioning
3. Boot Loaders
3.1. GRUB
3.2. LILO
3.3. MBR vs. Superblock
4. Package Management
5. Shared Libraries
6. Installing From Source Code
7. Practice Questions
8. Answers To Practice Questions

1. A Brief Look At The Objectives

To be successful with the Linux Installation & Package Management topic of the exam, candidates should have a good understanding of disk partitioning, installing a boot loader as well as the various methods of installing programs and shared libraries. Your understanding of partitioning should go beyond just how to use fdisk and focus on designing a partition scheme with separate /, /boot, /home, /usr, /var and swap file systems. Since LPI exams strive to be distribution neutral you should understand all of the various boot loader and package management options. This includes configuration of both LILO and GRUB boot loaders as well as installation of packages distributed in RPM, DPKG, .tar.gz or source code.

2. Disk Partitioning

Many times administrators of Linux systems will divide the hard disks into several partitions. It is common to see separate partitions for /, /home, /usr, /var and swap. Dividing a disk this way can help keep the root file system from filling up and crashing the system. For example, if /var/log/messages grows to an extremely large size only the partition holding /var will fill up.

If you have access to a system with multiple partitions, take a look at the sizes of various file systems by using the df command.

gnu-linux:~$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/md0                 50627     11995     36018  25% /
/dev/md1                199053    125479     63296  67% /usr
/dev/md2                249839     97970    138970  42% /var
/dev/md3                475953    299517    151848  67% /opt
/dev/md4               2111188    356140   1647804  18% /home

The actual sizes of the disk partitions can vary quite a bit from one system to another, but the sizes in relation to each other is fairly consistent. For example the partition holding / is small compared to the partitions for /usr, /var and /home. If you are inexperienced with this type of partitioning scheme or just want more information, refer to the Partition-HOWTO.

Although not shown in the example above, it is sometimes necessary to create a separate /boot partition below the hard disk's 1024th cylinder. This is used as a work-around for older PC BIOSs that are unable to boot from a partition above the 1024th cylinder. Modern, LBA-capable BIOSs do not suffer from this limitation. For additional information, see the Large-Disk-HOWTO.

3. Boot Loaders

The two popular boot loaders for Linux systems are LILO and GRUB. All boot loaders for PC architecture work in essentially the same way.

  1. The system powers up and the PC BIOS loads a 512-byte chunk of code called the Master Boot Record (MBR) from the first hard disk. This is the first stage.

  2. Execution of the code from the MBR loads a larger, second-stage boot loader. This stage is not constrained to a 512-byte limit.

  3. The second-stage boot loader then loads the operating system. For Linux systems this includes the Linux kernel and optionally an initial ramdisk (initrd) image.

3.1. GRUB

The GRUB boot loader stores copies of boot loader files in /boot/grub. Look at the example below and note the stage1, stage2 and menu.lst files.

gnu-linux:/boot/grub$ ls -l
total 111
-rw-r--r--  1 root root   7840 Nov 17  2004 e2fs_stage1_5
-rw-r--r--  1 root root    480 Nov 17  2004 menu.lst
-rw-r--r--  1 root root    512 Nov 17  2004 stage1
-rw-r--r--  1 root root 101586 Nov 17  2004 stage2

When the system administrator runs grub-install the stage1 file is written to the first sector of the boot device. At boot-time the code from stage1 will load and execute stage2. The configuration of kernel and ramdisk options is done by editing menu.lst.

Note

Some systems use a file called grub.conf in place of menu.lst. Do not be surprised to see these filenames used interchangeably in exam questions.

3.2. LILO

LILO loads the kernel and ramdisk in two stages similar to GRUB, but there are some important differences. LILO keeps some files in /boot, but its configuration file, lilo.conf, is stored in the /etc directory. LILO also requires administrators to run /sbin/lilo after any changes are made to /etc/lilo.conf or the kernel and ramdisk files.

3.3. MBR vs. Superblock

The first stage of the GRUB and LILO boot loaders does not always have to be installed in the Master Boot Record of the hard disk. Sometimes it is convenient to install the boot loader in the first sector, or superblock, of the root partition, particularly for systems that have multiple operating systems. Check the boot loader's man page for details on how to specify the installation location.

4. Package Management

In an effort to be distribution-neutral, the LPI exams cover several types of package management systems. This includes DPKG, RPM and .tar.gz. You should study the man pages for each and familiarize yourself with the command-line syntax required to perform the following tasks:

  • Install a package

  • Remove a package

  • Upgrade a currently installed package with a new version

  • Find out what files a particular package contains

  • Given a filename, find out which package it came from

  • Determine dependencies for a package

  • Find the version number of a package

  • Check a package's signature to verify its integrity.

The best way to learn package management for the exam is to do it on a day-to-day basis. Forget about the GUI tools that come with your system and start working exclusively on the command-line.

Unfortunately, you will probably only be able to get hands-on experience for two out of the three types of packages since DPKG and RPM are generally not seen together on the same system.

5. Shared Libraries

Shared libraries contain the code to perform common system tasks. Almost every program on a Linux system is linked to at least one shared libraries and cannot function independently of it. Most of the time everything works fine and the end user never even knows that shared libraries exist. However, a good system administrator, and a successful LPI candidate, must understand the inner workings of shared libraries.

The ldd command will let you find out which libraries a program uses. Take a look at the sample output below.

gnu-linux:~$ ldd /usr/bin/bash
        libncurses.so.5 => /usr/lib/libncurses.so.5 (0x40015000)
        libdl.so.2 => /lib/libdl.so.2 (0x40050000)
        libc.so.6 => /lib/libc.so.6 (0x40053000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

From the ldd output you can see that bash is linked to libncurses, libdl, libc and ld-linux. At the bottom of the list ld-linux, the dynamic loader, is in charge of locating and loading all of the other libraries. If ld-linux is unable to find any one of the other libraries in the list, bash will not run.

There are several methods ld-linux uses to find shared libraries. The easiest way to ensure a library can be found is to place it in either the /lib or /usr/lib directory since ld-linux will look here by default. Other directories to be searched can be added to the environmental variable LD_LIBRARY_PATH or the file /etc/ld.so.conf.

A portion of a typical ld.so.conf is shown below.

gnu-linux:~$ head -3 /etc/ld.so.conf
/usr/X11R6/lib/Xaw95
/usr/X11R6/lib/Xaw3d
/usr/X11R6/lib

New directories added to ld.so.conf do not take effect until the ldconfig command is executed and the changes are written to ld.so.cache. Most systems are configured to execute ldconfig at boot-up, but savvy Linux admins will execute it after making adjustments to ld.so.conf, because rebooting is for Windoze users.

6. Installing From Source Code

Occasionally, you may want to install a program that does not have a pre-compiled version available. When this happens you will need to know how to compile from source code. The basic steps involved are detailed below.

  1. Expand the compressed archive using bunzip2 or gunzip

  2. Extract the archive with tar

  3. Set options by executing the configure script or manually editing the Makefile

  4. Run make

  5. Run make install

The best way to understand installing from source code is to do it. Download the hello program from ftp.gnu.org/gnu/hello and practice the steps for installation.

7. Practice Questions

Note

Thanks go out to Paul van der Vlis for providing dpkg questions.

  1. You are planning a new Linux installation with separate partitions for /, /boot, /tmp and /usr. Which of the following file systems will be the largest?

    1. /

    2. /boot

    3. /tmp

    4. /usr

  2. What is the configuration file for LILO? (give the full path)

  3. What is the directory that contains configuration files for GRUB? (give the full path)

  4. You have accidentally deleted the file /usr/lib/libm.so. It needs to be re-installed, but you cannot remember what package it comes from. Which of the following commands would help you find the package that contains libm.so?

    1. rpm -qf libm.so

    2. rpm -e libm.so

    3. rpm -ivh libm.so

    4. rpm -qi libm.so

  5. You have accidentally deleted the file /usr/lib/zlib.so on a Debian system. Which of the following commands would help you find the package that contains zlib.so?

    1. dpkg -S zlib.so

    2. dpkg -r zlib.so

    3. dpkg -i zlib.so

    4. dpkg -l zlib.so

  6. Version 1.7 of your favorite web browser has just been released as an RPM package. You would like to install it while automatically un-installing any other versions. Which RPM command will allow you to install a new version of an RPM while automatically un-installing other versions?

    1. rpm --install

    2. rpm --upgrade

    3. rpm --verify

    4. rpm --erase

  7. Version 1.5 of your favorite instant messenging client has just been released as a Debian package. You would like to install it while automatically un-installing any other versions. Which dpkg command will allow you to install a new version of a dpkg while automatically un-installing other versions?

    1. dpkg --extract

    2. dpkg --install

    3. dpkg --new

    4. dpkg --purge

  8. What function will be performed by the command rpm -ivh foo.rpm?

    1. Verification of the files in foo.rpm

    2. Recalculation of the MD5 hash value for foo.rpm

    3. Installation of the package foo.rpm

    4. Verification of the signature for foo.rpm

  9. What will happen if you issue the command dpkg -iR /var/tmp/downloads?

  10. You have just downloaded the latest binary version of your favorite streaming audio server in a tarball called llama-i386.tar.gz. Which command could you use to extract the contents of llama-i386.tar.gz? (choose 2)

    1. tar -zxf llama-i386.tar.gz

    2. tar -xf llama-i386.tar.gz | gunzip -c

    3. gunzip -c llama-i386.tar.gz | tar xf -

    4. gunzip -c | tar xf - llama-i386.tar.gz

  11. You have just installed the new wizbang-2.0 library and added its library path to /etc/ld.so.conf. What command should be run after adding the new library path to ld.so.conf?

8. Answers To Practice Questions

  1. Of the partitions listed /usr will need to be the largest, so D is the correct answer. Answers A, B and C are incorrect, because the space requirements for / /boot and /tmp are small when compared to /usr.

  2. LILO's configuration file is /etc/lilo.conf.

  3. GRUB keeps configuration files in the /boot/grub directory.

  4. The correct answer is A, rpm -qf will query a file to find out which package it came from. Answer B is incorrect because rpm -e is used to erase packages and cannot be used to find individual files. Answer C is incorrect since rpm -ivh is used to install packages, it has nothing to do with finding individual files. Answer D is incorrect because rpm -qi is used to query packages for information, not individual files.

  5. The correct answer is A, dpkg -S will query a file to find out which package it came from. Answer B is incorrect because dpkg -r is used to remove packages and cannot be used to find individual files. Answer C is incorrect since dpkg -i is used to install packages, it has nothing to do with finding individual files. Answer D is incorrect because dpkg -l is used to list packages, not individual files.

  6. The correct answer is B, rpm --upgrade will install the new version of an RPM and then un-install any other version. Answer A is incorrect, because while rpm --install will install a package it will not un-install other versions. Answer C is incorrect, because rpm --verify does not install or remove packages. Answer D is incorrect, rpm --erase removes packages.

  7. The correct answer is B, dpkg --install will install the new version of a dpkg while removing any previous versions. Answer A is incorrect, because while dpkg --extract will extract a package it will not un-install other versions. Answer C is incorrect, because dpkg --new selects the binary format, but does not install anything. Answer D is incorrect, dpkg --purge removes packages.

  8. The correct answer is C, rpm -ivh foo.rpm will install the package foo.rpm. More specifically it will install verbosely with hash marks to indicate the installation progress. Answer B is incorrect, do not confuse hash marks with hash values. Answer D is incorrect as signatures verification is performed with rpm --checksig.

  9. The command dpkg -iR ~/downloads will recursively install all dpkg files found in the ~/downloads directory.

  10. The correct answers are A and C. Both tar -zxf llama-i386.tar.gz and gunzip -c llama-i386.tar.gz | tar xf - will extract the contents of the llama-i386.tar.gz tarball. Answer B is incorrect, because it reverses the order of things by attempting to un-tar before decompressing. Answer D is incorrect, because the filename argument is in the wrong place and therefore gunzip will not pipe anything meaningful to tar.

  11. The ldconfig command should be run after adding new library paths to /etc/ld.so.conf.