LPI Linux Certification in a Nutshell - novelonlinefull.com
You’re read light novel LPI Linux Certification in a Nutshell Part 3 online at NovelOnlineFull.com. Please use the follow button to get notification about the latest chapter next time when you visit NovelOnlineFull.com. Use F11 button to read novel in full-screen(PC only). Drop by anytime you want to read free – fast – latest novel. It’s great if you could leave a comment, share your opinion about the new chapters, new novel with others on the internet. We’ll do our best to bring you the finest, latest novel everyday. Enjoy
Installing GRUB The simplest way to install GRUB is to use the grub-install grub-install script. script.
For example, to install GRUB on the master boot record of the first hard drive in a system, invoke grub-install grub-install as follows: as follows: #grub-install'(hd0)'
grub-install looks for a device map file ( looks for a device map file (/boot/grub/device.map by default) to determine the mapping from BIOS drives to Linux devices. If this file does not exist, it will attempt to guess what devices exist on the system and how they should be mapped to BIOS drives. If by default) to determine the mapping from BIOS drives to Linux devices. If this file does not exist, it will attempt to guess what devices exist on the system and how they should be mapped to BIOS drives. If grub-install grub-install guesses incorrectly, just edit guesses incorrectly, just edit /boot/grub/device.map /boot/grub/device.map and rerun and rerun grub-install grub-install.
The device map file contains any number of lines in this format: (disk)/dev/device So, for example, on a system with a floppy and a single SCSI disk, the file would look like this: (fd0)/dev/fd0 (hd0)/dev/sda GRUB can also be installed using the grub grub command. The command. The grub-install grub-install example shown earlier could also have been done as follows, a.s.suming example shown earlier could also have been done as follows, a.s.suming /boot /boot is on the first part.i.tion of the first hard disk: is on the first part.i.tion of the first hard disk: #grub grub>root(hd0,0) grub>setup(hd0) Booting GRUB If there is no configuration file (or the configuration file does not specify a kernel to load), when GRUB loads it will display a prompt that looks like this: grub> GRUB expects a certain sequence of commands to boot a Linux kernel. They are as follows: 1. root device device 2. kernel filename filename [ [options]
3. initrd filename filename optional, only present if an initial ramdisk is required optional, only present if an initial ramdisk is required 4. boot For example, the following sequence would boot a stock Red Hat 8.0 system with /boot /boot on on /dev/hda1 /dev/hda1 and and / / on on /dev/hda2 /dev/hda2: grub>root(hd0,0) grub>kernel/vmlinuz-2.4.18-14roroot=/dev/hda2 grub>initrd/initrd-2.4.18-14.img grub>boot The GRUB configuration file GRUB can be configured to boot into a graphical menu, allowing the user to bypa.s.s the GRUB sh.e.l.l entirely. To display this menu, GRUB needs a specific configuration file, /boot/grub/menu.lst /boot/grub/menu.lst.
NoteThe location of this file may be different on your system. For example, on Red Hat systems the default configuration file is /boot/grub/grub.conf /boot/grub/grub.conf.
The configuration file defines various menu options along with the commands required to boot each option. The earlier example of booting a stock Red Hat Fedora 8.0 system could have been accomplished with the following configuration file: default=0 timeout=3 t.i.tleRedHatLinux(2.4.18-14) root(hd0,0) kernel/vmlinuz-2.4.18-14roroot=/dev/hda2 initrd/initrd-2.4.18-14.imgNoteGRUB has many more features, including serial console support, support for booting other operating systems, and so on. For more information about GRUB, see the info doc.u.mentation (info grub or or pinfo grub pinfo grub) or the online doc.u.mentation.
Name lilo Syntax lilo[options]
The lilo lilo map installer reads a configuration file and writes a map file, which contains information needed by the boot loader to locate and launch Linux kernels or other operating systems. map installer reads a configuration file and writes a map file, which contains information needed by the boot loader to locate and launch Linux kernels or other operating systems.
Frequently used options -C config _ file Read the config _ file config _ file file instead of the default file instead of the default /etc/lilo.conf /etc/lilo.conf.
-m map _ file Write map _ file map _ file in place of the default as specified in the configuration file. in place of the default as specified in the configuration file.
-q Query the current configuration.
-v Increase verbosity.
LILO's configuration file contains options and kernel image information. An array of options is available. Some are global, affecting LILO overall, whereas others are specific to a particular listed kernel image. Most basic Linux installations use only a few of the configuration options. Example5-1 Example5-1 shows a simple LILO configuration file. shows a simple LILO configuration file.
Example5-1.Sample /etc/lilo.conf file boot=/dev/hda timeout=50 prompt read-only map=/boot/map install=/boot/boot.b
image=/boot/bzImage-2.6.0 label=test-2.6.0 root=/dev/hda1 Each line in the example is described in the following list: boot Sets the name of the hard disk part.i.tion device that contains the boot sector. For PCs with IDE disk drives, the devices will be /dev/hda /dev/hda, /dev/hdb /dev/hdb, and so on.
timeout Sets the timeout in tenths of a second (deciseconds) for any user input from the keyboard. To enable an unattended reboot, this parameter is required if the prompt prompt directive is used. directive is used.
prompt Sets the boot loader to prompt the user. This behavior can be stimulated without the prompt directive if the user holds down the Shift, Ctrl, or Alt key when LILO starts.
read-only Sets the root filesystem to initially be mounted read-only. Typically, the system startup procedure will remount it later as read/write.
map Sets the location of the map file, which defaults to /boot/map /boot/map.
install Sets the file to install as the new boot sector, which defaults to /boot/boot.b /boot/boot.b.
image Sets the kernel image to offer for boot. It points to a specific kernel file. Multiple image lines may be used to configure LILO to boot multiple kernels and operating systems.
label Sets the optional label parameter to be used after an image line and offers a label for that image. This label can be anything you choose and generally describes the kernel image. Examples include linux linux and and smp smp for a multiprocessing kernel. for a multiprocessing kernel.
root Sets the devices to be mounted as root for the specified image (used after each image line).
There is more to configuring and setting up LILO, but a detailed knowledge of LILO is not required for this LPI Objective. It is important to review one or two sample LILO configurations to make sense of the boot process.
Objective 3: Manage Shared Libraries When a program is compiled under Linux, many of the functions required by the program are linked from system libraries libraries that handle disks, memory, and other functions. For example, when the standard C-language that handle disks, memory, and other functions. For example, when the standard C-language printf() printf() function is used in a program, the programmer doesn't provide the function is used in a program, the programmer doesn't provide the printf() printf() source code, but instead expects that the system already has a library containing such functions. When the compiler needs to link the code for source code, but instead expects that the system already has a library containing such functions. When the compiler needs to link the code for printf() printf(), it can be found in a system library and copied into the executable. A program that contains executable code from these libraries is said to be statically linked statically linked because it stands alone, requiring no additional code at runtime. because it stands alone, requiring no additional code at runtime.
Statically linked programs can have a few liabilities. First, they tend to get large because they include executable files for all of the library functions linked into them. Also, memory is wasted when many different programs running concurrently contain the same library functions. To avoid these problems, many programs are dynamically linked dynamically linked. Such programs utilize the same routines but don't contain the library code. Instead, they are linked into the executable at runtime. This dynamic linking process allows multiple programs to use the same library code in memory and makes executable files smaller. Dynamically linked libraries are shared among many applications and are thus called shared libraries shared libraries. A full discussion of libraries is beyond the scope of the LPIC Level 1 exams. However, a general understanding of some configuration techniques is required.
Shared Library Dependencies Any program that is dynamically linked will require at least a few shared libraries. If the required libraries don't exist or can't be found, the program will fail to run. This could happen, for example, if you attempt to run an application written for the GNOME graphical environment but haven't installed the required GTK+ libraries. Simply installing the correct libraries should eliminate such problems. The ldd ldd utility can be used to determine which libraries are necessary for a particular executable. utility can be used to determine which libraries are necessary for a particular executable.
Linking Shared Libraries Dynamically linked executables are examined at runtime by the shared object dynamic linker, ld.so ld.so. This program looks for dependencies in the executable being loaded and attempts to satisfy any unresolved links to system-shared libraries. If ld.so ld.so can't find a specified library, it fails, and the executable won't run. can't find a specified library, it fails, and the executable won't run.
To find a new library, ld.so ld.so must be instructed to look in must be instructed to look in /usr/local/lib /usr/local/lib. There are a few ways to do this. One simple way is to add a colon-separated list of directories to the sh.e.l.l environment variable LD_LIBRARY_PATH LD_LIBRARY_PATH, which will prompt ld.so ld.so to look in any directories it finds there. However, this method may not be appropriate for system libraries, because users might not set their to look in any directories it finds there. However, this method may not be appropriate for system libraries, because users might not set their LD_LIBRARY_PATH LD_LIBRARY_PATH correctly. correctly.
To make the search of /usr/local/lib /usr/local/lib part of the default behavior for part of the default behavior for ld.so ld.so, files in the new directory must be included in an index of library names and locations. This index is /etc/ld.so.cache /etc/ld.so.cache. It's a binary file, which means it can be read quickly by ld.so ld.so. To add the new library entry to the cache, first add its directory to the ld.so.conf ld.so.conf file, which contains directories to be indexed by the file, which contains directories to be indexed by the ldconfig ldconfig utility. utility.
Name ldd Syntax lddprograms Description Display shared libraries required by each of the programs programs listed on the command line. The results indicate the name of the library and where the library is expected to be in the filesystem. listed on the command line. The results indicate the name of the library and where the library is expected to be in the filesystem.
Example The bash bash sh.e.l.l requires three shared libraries: sh.e.l.l requires three shared libraries: #ldd/bin/bash /bin/bash: libtermcap.so.2=>/lib/libtermcap.so.2(0x40018000) libc.so.6=>/lib/libc.so.6(0x4001c000) /lib/ld-linux.so.2=>/lib/ld-linux.so.2(0x40000000)
Name ldconfig Syntax ldconfig[options]lib_dirs Description Update the ld.so ld.so cache file with shared libraries specified on the command line in cache file with shared libraries specified on the command line in lib_dirs lib_dirs, in trusted directories /usr/lib /usr/lib and and /lib /lib, and in the directories found in /etc/ld.so.conf /etc/ld.so.conf.
Frequently used options -p Display the contents of the current cache instead of recreating it.
-v Verbose mode. Display progress during execution.
Example 1 Examine the contents of the ld.so ld.so library cache: library cache: #ldconfig-p 144libsfoundincache'/etc/ld.so.cache'
libz.so.1(libc6)=>/usr/lib/libz.so.1 libuuid.so.1(libc6)=>/lib/libuuid.so.1 libutil.so.1(libc6,OSABI:Linux2.2.5)=>/lib/libutil.so.1 libutil.so(libc6,OSABI:Linux2.2.5)=>/usr/lib/libutil.so libthread_db.so.1(libc6,OSABI:Linux2.2.5)=>/lib/libthread_db.so.1 libthread_db.so(libc6,OSABI:Linux2.2.5)=>/usr/lib/libthread_db.so Example 2 Look for a specific library entry in the cache: #ldconfig-p|grepncurses libncurses.so.5(libc6)=>/usr/lib/libncurses.so.5 Example 3 Rebuild the cache: #ldconfig After /usr/local/lib /usr/local/lib is added, is added, ld.so.conf ld.so.conf might look like this: might look like this: /usr/lib /usr/i486-linux-libc5/lib /usr/X11R6/lib /usr/local/lib Next, ldconfig ldconfig is run to include libraries found in is run to include libraries found in /usr/local/lib /usr/local/lib in in /etc/ld.so.cache /etc/ld.so.cache. It is important to run ldconfig ldconfig after any changes in system libraries to be sure that the cache is up-to-date. after any changes in system libraries to be sure that the cache is up-to-date.
Objective 4: Use Debian Package Management The Debian package management system is a versatile and automated suite of tools used to acquire and manage software packages for Debian Linux. The system automatically handles many of the management details a.s.sociated with interdependent software running on your system.
Debian Package Management Overview Each Debian package contains program and configuration files, doc.u.mentation, and noted dependencies on other packages. The names of Debian packages have three common elements, including: Package name A Debian package name is short and descriptive. When multiple words are used in the name, they are separated by hyphens. Typical names include binutils binutils, kernel-source kernel-source, and telnet telnet.
Version number Each package has a version. Most package versions are the same as that of the software they contain. The format of package versions varies from package to package, but most are numeric (major.minor.patchlevel).
A file extension By default, all Debian packages end with the .deb .deb file extension. file extension.
Figure5-1 ill.u.s.trates a Debian package name. ill.u.s.trates a Debian package name.
Figure5-1.The structure of a Debian GNU/Linux package name Managing Debian Packages The original Debian package management tool is dpkg dpkg, which operates directly on .deb .deb package files and can be used to automate the installation and maintenance of software packages. The alternative package files and can be used to automate the installation and maintenance of software packages. The alternative apt-get apt-get tool operates using package names, obtaining them from a predefined source (such as CD-ROMs, FTP sites, etc.). Both tools work from the command line. tool operates using package names, obtaining them from a predefined source (such as CD-ROMs, FTP sites, etc.). Both tools work from the command line.
The dselect dselect command offers an interactive menu that allows the administrator to select from a list of available packages and mark them for subsequent installation. The command offers an interactive menu that allows the administrator to select from a list of available packages and mark them for subsequent installation. The alien alien command allows the use of non-Debian packages, such as the Red Hat RPM format. command allows the use of non-Debian packages, such as the Red Hat RPM format.
For complete information on Debian package management commands, see details in their respective manpages.
Name dpkg Syntax dpkg[options]action Description The Debian package manager command, dpkg dpkg, consists of an action action that specifies a major mode of operation as well as zero or more that specifies a major mode of operation as well as zero or more options options, which modify the action's behavior.
The dpkg dpkg command maintains package information in command maintains package information in /var/lib/dpkg /var/lib/dpkg. There are two files that are of particular interest: available The list of all available packages.
status Contains package attributes, such as whether it is installed or marked for removal.
These files are modified by dpkg, dselect dpkg, dselect, and apt-get apt-get, and it is unlikely that they will ever need to be edited.
Frequently used options -E Do not overwrite a previously installed package of the same version.
-G Do not overwrite a previously installed package with an older version of that same package.
-R (also (also -- --recursive) Recursively process package files in specified subdirectories. Works with -i -i, --install --install, --unpack --unpack, and so on.
Frequently used options --configure package package Configure an unpacked package. This involves setup of configuration files.
-i package_file package_file (also (also --install --install package_file package_file) Install the package contained in package_file package_file. This involves backing up old files, unpacking and installation of new files, and configuration.
-l [ [pattern] (also (also --list --list [ [pattern]) Display information for installed package names that match pattern pattern.
-L package package (also (also --listfiles --listfiles package package) List files installed from package package.
--print-avail package package Display details found in /var/lib/dpkg/available /var/lib/dpkg/available about about package package.
--purge package package Remove everything for package package.
-r package package (also (also --remove --remove package package) Remove everything except configuration files for package package.
-s package package (also (also --status --status package package) Report the status of package package.
-S search_pattern search_pattern (also (also --search --search search_pattern search_pattern) Search for a filename matching search_pattern search_pattern from installed packages. from installed packages.
--unpack package_file package_file Unpack package_file package_file, but don't install the package it contains.
Example 1 Install a package using dpkg -i dpkg -i with the name of an available package file: with the name of an available package file: #dpkg-i./hdparm_3.3-3.deb (Readingdatabase...54816filesanddirectories currentlyinstalled.) Preparingtoreplacehdparm3.3-3(usinghdparm_3.3-3.deb) Unpackingreplacementhdparm...
Settinguphdparm(3.3-3)...
Alternatively, use apt-get install apt-get install with the name of the package. In this case, the package comes from the location or locations configured in with the name of the package. In this case, the package comes from the location or locations configured in /etc/apt/sources.list /etc/apt/sources.list. For this example, the location is http://http.us.debian.org: #apt-getinstallelvis ReadingPackageLists...Done BuildingDependencyTree...Done Thefollowingextrapackageswillbeinstalled: libncurses4xlib6g ThefollowingNEWpackageswillbeinstalled: elvis 2packagesupgraded,1newlyinstalled,0toremove and376notupgraded.
Needtoget1678kBofarchives.Afterunpacking2544kB willbeused.
Doyouwanttocontinue?[Y/n]y Get:1http://http.us.debian.orgstable/main libncurses44.2-9[180kB]
Get:2http://http.us.debian.orgstable/main xlib6g3.3.6-11[993kB]
Get:3http://http.us.debian.orgstable/main elvis2.1.4-1[505kB]
Fetched1678kBin4m11s(6663B/s) (Readingdatabase...54730filesanddirectories currentlyinstalled.) Preparingtoreplacelibncurses44.2-3(using .../libncurses4_4.2-9_i386.deb)...
Unpackingreplacementlibncurses4...
(installationcontinues...) Example 2 Upgrading a package is no different from installing one. However, you should use the -G -G option when upgrading with option when upgrading with dpkg dpkg to ensure that the installation won't proceed if a newer version of the same package is already installed. to ensure that the installation won't proceed if a newer version of the same package is already installed.
Example 3 Use dpkg -r dpkg -r or or dpkg --purge dpkg --purge to remove a package: to remove a package: #dpkg--purgeelvis (Readingdatabase...54816filesanddirectories currentlyinstalled.) Removingelvis...
(purgecontinues...) Example 4 Use the dpkg -S dpkg -S command to find a package containing specific files. In this example, command to find a package containing specific files. In this example, apt-get apt-get is contained in the is contained in the apt apt package: package: #dpkg-Sapt-get apt:/usr/share/man/man8/apt-get.8.gz apt:/usr/bin/apt-get Example 5 Obtain package status information, such as version, content, dependencies, integrity, and installation status, using dpkg -s dpkg -s: #dpkg-sapt Package:apt Status:installokinstalled Priority:optional Section:admin Installed-Size:1388 (listingcontinues...) Example 6 List the files in a package using dpkg -L dpkg -L and process the output using and process the output using grep grep or or less less: #dpkg-Lapt|grep'^/usr/bin'
/usr/bin /usr/bin/apt-cache /usr/bin/apt-cdrom /usr/bin/apt-config /usr/bin/apt-get Example 7 List the installed packages using dpkg -l dpkg -l; if you don't specify a pattern, all packages will be listed: #dpkg-lxdm iixdm3.3.2.3a-11Xdisplaymanager Example 8 Use dpkg -S dpkg -S to determine the package from which a particular file was installed with the filename: to determine the package from which a particular file was installed with the filename: #dpkg-S/usr/bin/nl textutils:/usr/bin/nl
Name apt-get Syntax apt-get[options][command][package_name...]
Description The apt-get apt-get command is part of the Advanced Package Tool (APT) management system. It does not work directly with command is part of the Advanced Package Tool (APT) management system. It does not work directly with .deb .deb files like files like dpkg dpkg, but uses package names instead. apt-get apt-get maintains a database of package information that enables the tool to automatically upgrade packages and their dependencies as new package releases become available. maintains a database of package information that enables the tool to automatically upgrade packages and their dependencies as new package releases become available.
Frequently used options -d Download files, but do not install. This is useful when you wish to get a large number of package files but delay their installation to prevent installation errors from stopping the download process.
-s Simulate the steps in a package change, but do not actually change the system.
-y Automatically respond "yes" to all prompts, instead of prompting you for a response during package installation/removal.
Frequently used commands dist-upgrade Upgrade automatically to new versions of Debian Linux.
install Install or upgrade one or more packages by name.
remove Remove specified packages.
update Fetch a list of currently available packages. This is typically done before any changes are made to existing packages.
upgrade Upgrade a system's complete set of packages to current versions safely. This command is conservative and will not process upgrades that could cause a conflict or break an existing configuration; it also will not remove packages.
Additional commands and options are available. See the apt-get apt-get manpage for more information. manpage for more information.
apt-get uses uses /etc/apt/sources.list /etc/apt/sources.list to determine where packages should be obtained. The file should contain one or more lines that look something like this: to determine where packages should be obtained. The file should contain one or more lines that look something like this: debhttp://http.us.debian.org/debianstablemaincontribnon-free Example Remove the elvis elvis package using package using apt-get apt-get: #apt-getremoveelvis ReadingPackageLists...Done BuildingDependencyTree...Done ThefollowingpackageswillbeREMOVED: elvis 0packagesupgraded,0newlyinstalled,1toremove and376notupgraded.
Needtoget0Bofarchives.Afterunpacking1363kB willbefreed.
Doyouwanttocontinue?[Y/n]y (Readingdatabase...54816filesanddirectories currentlyinstalled.) Removingelvis...
(removalcontinues...) In this example, the user is required to respond with y y when prompted to continue. Using the when prompted to continue. Using the -y -y option to option to apt-get apt-get would eliminate this interaction. would eliminate this interaction.