BUY THIS BOOK

Safari Books Online

What is this?

Looking to Reprint this content?


Linux in a Nutshell
Linux in a Nutshell, Fourth Edition A Desktop Quick Reference

By Ellen Siever, Stephen Figgins, Aaron Weber

Cover | Table of Contents | Colophon


Table of Contents

Chapter 1: Introduction
It is hard to chart the rise of Linux over its twelve years of existence without risking the appearance of exaggeration and hyperbole. During the past five years alone, Linux has grown from a student/hacker playground to an upstart challenger in the server market to a well-respected system taking its rightful place in educational and corporate networks. Many serious analysts claim that its trajectory has just begun, and that it will eventually become the world's most widespread operating system.
Linux was first developed by Linus Torvalds at the University of Helsinki in Finland. From his current location in Silicon Valley, Linus continues to centrally coordinate improvements. The Linux kernel continues to develop under the dedicated cultivation of a host of other programmers and hackers all over the world, joined by members of programming teams at major computer companies, all connected through the Internet.
By "kernel," we mean the core of the operating system itself, not the applications (such as the compiler, shells, and so forth) that run on it. Today, the term "Linux" is often used to mean a software environment with a Linux kernel along with a large set of applications and other software components. In this larger meaning, many people prefer the term GNU/Linux, which acknowledges the central role played by tools from the Free Software Foundation's GNU project in the development of the kernel.
Linux systems cannot be technically referred to as a "version of Unix," as they have not undergone the required tests and licensing. However, Linux offers all the common programming interfaces of standard Unix systems, and as you can see from this book, all the common Unix utilities have been reimplemented on Linux. It is a powerful, robust, fully usable system for those who like Unix.
The historical impact of Linux goes beyond its role as a challenge to all versions of Unix as well as Microsoft Windows, particularly on servers. Linux's success has also inspired countless other free software or open source (defined at http://opensource.org) projects, including Samba, GNOME, and a mind-boggling collection of innovative projects that you can browse at numerous sites like SourceForge (
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
The Excitement of Linux
Linux is, first of all, free software: anyone can download the source from the Internet or buy it on a low-cost CD-ROM. But Linux is becoming well known because it's more than free software—it's unusually good software. You can get more from your hardware with Linux and be assured of fewer crashes; even its security is better than many commercial alternatives.
Linux first appeared in organizations as ad hoc installations by hackers running modest web servers or development systems at universities and research institutions, but now extends deeply into corporations around the world. People deploying Linux for mission-critical systems tend to talk about its ample practical advantages, such as the ability to deliver a lot of bang for the buck and the ease of deploying other powerful tools on Linux such as Apache, Samba, and Java environments. They also cite Linux's ability to grow and sprout new features of interest to large numbers of users. But these advantages can be traced back to the concept of software freedom, which is the root of the broad wave of innovation driving Linux.
As free software, Linux revives the grand creativity and the community of sharing that Unix was long known for. The unprecedented flexibility and openness of Unix—which newcomers usually found confusing and frustrating, but eventually found they couldn't live without—continually inspired extensions, new tools like Perl, and experiments in computer science that sometimes ended up in mainstream commercial computer systems.
Many programmers fondly remember the days when AT&T provided universities with Unix source code at no charge, and the University of Berkeley started distributing its version in any manner that allowed people to get it. For these older hackers, Linux brings back the spirit of working together—all the more so because the Internet is now so widespread. And for the many who are too young to remember the first round of open systems or whose prior experience has been constricted by trying to explore and adapt proprietary operating systems, now is the time to discover the wonders of freely distributable source code and infinitely adaptable interfaces.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Distribution and Support
While it is convenient to download one or two new programs over the Internet and fairly feasible to download something as large as the Linux kernel, getting an entire working system over the Internet is difficult without a high-speed Internet connection. Over the years, therefore, commercial and noncommercial packages called distributions have emerged. The first distribution consisted of approximately 50 diskettes, at least one of which would usually turn out to be bad and have to be replaced. When CD-ROM drives became widespread, Linux really took off.
After getting Linux, the average user is concerned next with support. While Usenet newsgroups offer very quick responses and meet the needs of many intrepid users, you can also buy support from the vendors of the major distributions and a number of independent experts. Linux is supported at least as well as commercial software. When you buy a distribution from a vendor, you typically are entitled to a period of free support as well.
Intel's x86 family and other compatible chips are still by far the most common hardware running Linux, but Linux is also now commercially available on a number of other hardware systems, notably the PowerPC, the 64-bit Intel Itanium processor, Sun Microsystems' SPARC, and the Alpha (created by Digital Equipment Corporation).
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Commands on Linux
Linux commands are not the same as standard Unix ones. They're better! This is because most of them are provided by the GNU project run by the Free Software Foundation (FSF). GNU means "GNU's Not Unix"—the first word of the phrase is expanded with infinite recursion.
Benefiting from years of experience with standard Unix utilities and advances in computer science, programmers on the GNU project have managed to create versions of standard tools that have more features, run faster and more efficiently, and lack the bugs and inconsistencies that persist in the original standard versions.
While GNU provided the programming utilities and standard commands like grep, many of the system and network administration tools on Linux came from the Berkeley Software Distribution (BSD). In addition, some people wrote tools that specifically allow Linux to deal with special issues such as filesystems. This book documents all the standard Unix commands that are commonly available on most Linux distributions.
The third type of software most commonly run on Linux is the X Window System, ported by the XFree86 project to standard Intel chips. While this book cannot cover the wide range of utilities that run on X, we briefly cover some of the useful customizations you can make to your KDE, GNOME, or fvwm2 desktop.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
What This Book Offers
Originally based on the classic O'Reilly & Associates quick reference, Unix in a Nutshell, this book has been expanded to include much information that is specific to Linux. These enhancements include chapters on:
  • Package managers (which make it easy to install, update, and remove related software files)
  • The KDE and GNOME desktops and the fvwm2 window manager
  • Boot parameters
  • The CVS version control system
The book also contains dozens of Linux-specific commands, along with tried-and-true Unix commands that have been supporting users for decades (though they continue to sprout new options).
This book does not cover the graphical tools contained in most distributions of Linux. Many of these, to be sure, are quite useful and can form the basis of everyday work. Examples of these tools include OpenOffice (the open source version of the StarOffice suite distributed by Sun Microsystems), Evolution (a mail, calendar, and office productivity tool from Ximian), Mozilla (the open source cousin of the Netscape web browser), and the GIMP (a graphic image manipulation program and the inspiration for the GNOME project). But they are not Linux-specific, and their graphical models do not fit well into the format of this book.
While you can do a lot of valuable work with the graphical applications, the core of Linux use is the text manipulation and administration done from the command line, within scripts, or using text editors such as vi and Emacs. Linux is still mostly a command-driven system, and this book continues to focus on this level of usage. In your day-to-day work, you'll likely find yourself moving back and forth between graphical programs and the commands listed in this book.
Every distribution of Linux is slightly different, but you'll find that the commands we document are the ones you use most of the time, and that they work the same on all distributions. Basic commands, programming utilities, system administration, and network administration are all covered. However, some areas were so big that we had to leave them out. The many applications that depend on the X Window System didn't make the cut. Nor did the many useful programming languages like Java, Perl, and Python with which users can vastly expand the capabilities of their systems. XML isn't covered here either. These subjects would stretch the book out of its binding.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Sources and Licenses
Some distributions contain the source code for Linux; it is also easily available for download at http://www.kernel.org and elsewhere. Source code is similarly available for all the utilities on Linux (unless your vendor offers a commercial application or library as a special enhancement). You may never bother looking at the source code, but it's key to Linux's strength. Under the Linux license, the source code has to be provided by the vendor, and it permits those who are competent at such things to fix bugs, provide advice about the system's functioning, and submit improvements that benefit everyone. The license is the GNU project's well-known General Public License, also known as the GPL or "copyleft," invented and popularized by the Free Software Foundation.
The FSF, founded by Richard Stallman, is a phenomenon that many people might believe to be impossible if it did not exist. (The same goes for Linux, in fact—15 years ago, who would have imagined a robust operating system developed by collaborators over the Internet and made freely redistributable?) One of the most popular editors on Unix, GNU Emacs, comes from the FSF. So do gcc and g++ (C and C++ compilers), which for a while set the standard in the industry for optimization and fast code. One of the largest projects within GNU is the GNOME desktop, which encompasses several useful general-purpose libraries and applications that use these libraries to provide consistent behavior and interoperability.
Dedicated to the sharing of software, the FSF provides all its code and documentation on the Internet and allows anyone with a whim for enhancements to alter the source code. One of its projects is the Debian distribution of Linux.
To prevent hoarding, the FSF requires that the source code for all enhancements be distributed under the same GPL that it uses. This encourages individuals or companies to make improvements and share them with others. The only thing someone cannot do is add enhancements and then try to sell the product as commercial software—that is, to withhold the source code. That would be taking advantage of the FSF and the users. You can find the GPL in any software covered by that license, or online at
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Beginner's Guide
If you're just beginning to work on a Linux system, the abundance of commands might prove daunting. To help orient you, the following lists present a sampling of commands on various topics.
ftp
File Transfer Protocol.
login
Sign on.
rlogin
Sign on to remote system.
rsh
Run shell or single command on remote system (not particularly secure).
ssh
Run shell or single command on remote system (secure).
talk
Exchange messages interactively with other terminals.
telnet
Connect to another system.
tftp
Trivial File Transfer Protocol.
uudecode
Decode file prepared for mailing by uuencode.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 2: System and Network Administration Overview
Following are lists of commonly used system administration commands.
hwclock
Manage hardware clock.
rdate
Get time from network time server.
zdump
Print list of time zones.
zic
Create time conversion information files.
apmd
Advanced Power Management daemon.
atd
Queue commands for later execution.
bootpd
Internet Boot Protocol daemon.
fingerd
Finger daemon.
ftpd
File Transfer Protocol daemon.
identd
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Common Commands
Following are lists of commonly used system administration commands.
hwclock
Manage hardware clock.
rdate
Get time from network time server.
zdump
Print list of time zones.
zic
Create time conversion information files.
apmd
Advanced Power Management daemon.
atd
Queue commands for later execution.
bootpd
Internet Boot Protocol daemon.
fingerd
Finger daemon.
ftpd
File Transfer Protocol daemon.
identd
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Overview of Networking
Networks connect computers so that the different systems can share information. For users and system administrators, Unix systems have traditionally provided a set of simple but valuable network services that let you check whether systems are running, refer to files residing on remote systems, communicate via electronic mail, and so on.
For most commands to work over a network, each system must be continuously running a server process in the background, silently waiting to handle the user's request. This kind of process is called a daemon . Common examples, on which you rely for the most basic functions of your Linux system, are named (which translates between numeric IP addresses and more human-readable alphanumeric names), lpd (which sends documents to a printer, possibly over a network), and ftpd (which allows you to connect to another machine via ftp).
Most Unix networking commands are based on Internet protocols. These are standardized ways of communicating across a network on hierarchical layers. The protocols range from addressing and packet routing at a relatively low layer to finding users and executing user commands at a higher layer.
The basic user commands that most systems support over Internet protocols are generally called TCP/IP commands, named after the two most common protocols. You can use all of these commands to communicate with other Unix systems besides Linux systems. Many can also be used to communicate with non-Unix systems, as a wide variety of systems support TCP/IP.
This section also covers NFS and NIS—which allow for transparent file and information sharing across networks—and sendmail.
ftpd
Server for file transfers.
gated
Manage routing tables between networks.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Overview of TCP/IP
TCP/IP is a set of communications protocols that define how different types of computers talk to one another. It's named for its two most common protocols, the Transmission Control Protocol and the Internet Protocol. The Internet Protocol moves data between hosts: it splits data into packets, which are then forwarded to machines via the network. The Transmission Control Protocol ensures that the packets in a message are reassembled in the correct order at their final destination and that any missing datagrams are re-sent until they are correctly received. Other protocols provided as part of TCP/IP include:
Address Resolution Protocol (ARP)
Translates between Internet and local hardware addresses (Ethernet, etc.)
Internet Control Message Protocol (ICMP)
Error-message and control protocol
Point-to-Point Protocol (PPP)
Enables TCP/IP (and other protocols) to be carried across both synchronous and asynchronous point-to-point serial links
Reverse Address Resolution Protocol (RARP)
Translates between local hardware and Internet addresses (opposite of ARP)
Simple Mail Transport Protocol (SMTP)
Used by sendmail to send mail via TCP/IP
Simple Network Management Protocol (SNMP)
Performs distributed network management functions via TCP/IP
User Datagram Protocol (UDP)
Provides data transfer, but without the reliable delivery capabilities of TCP
TCP/IP is covered in-depth in the three-volume set Internetworking with TCP/IP (Prentice Hall). The commands in this chapter and the next are described in more detail in TCP/IP Network Administration and Linux Network Administrator's Guide both published by O'Reilly.
In the architecture of TCP/IP protocols, data is passed down the stack (toward the Network Access Layer) when it is sent to the network, and up the stack when it is received from the network (see Figure 2-1).
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Overview of Firewalls and Masquerading
A firewall computer is a secure system that sits between an internal network and an external network (i.e., the Internet). It is configured with a set of rules that it uses to determine what traffic is allowed to pass and what traffic is barred. While a firewall is generally intended to protect the network from malicious or even accidentally harmful traffic from the outside, it can also be configured to monitor traffic leaving the network. As the sole entry point into the system, the firewall makes it easier to construct defenses and monitor activity.
The firewall can also be set up to present a single IP address to the outside world, even though multiple IP addresses may be used internally. This is known as masquerading . Masquerading can act as additional protection, hiding the very existence of a network. It also saves the trouble and expense of obtaining multiple IP addresses.
IP firewalling and masquerading are implemented in Linux Version 2.4 with netfilter , also known as iptables . In Linux Version 2.2, they are implemented with the ipchains facility. The 2.0 kernels used a command called ipfwadm, which will not be covered here. The two newer commands are very similar, but differ in some of the organization of their rules. The firewalling facilities built into the 2.4 kernel are also designed to be extensible—if there is some function missing from the implementation, you can add it.
Most distributions come with firewall support already built into the kernel. If this is not the case in your distribution, you need to compile firewall support into the kernel by running make config with the 2.4 kernel and selecting the following network options:
  • Network packet filtering (replaces ipchains)
  • TCP/IP networking
Then select the following options from the IP: Netfilter Configuration menu:
  • IP tables support (required for filtering/masq/NAT)
  • Packet filtering
There are several extended target and matching rule modules you may wish to compile as well. The behavior of those extension modules is described under the
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Overview of NFS
The Network File System (NFS) is a distributed filesystem that allows users to mount remote filesystems as if they were local. NFS uses a client/server model in which a server exports directories to be shared, and clients mount the directories to access the files in them. NFS eliminates the need to keep copies of files on several machines by letting the clients all share a single copy of a file on the server. NFS is an RPC-based application-level protocol. For more information on the architecture of network protocols, see Section 2.3 earlier in this chapter.
To set up NFS clients and servers you must start the NFS daemons on the servers, export filesystems from the NFS servers, and mount the filesystems on the clients. The /etc/exports file is the NFS server configuration file; it controls which files and directories are exported and what kinds of access are allowed. Names and addresses for clients that should be allowed or denied access to NFS are kept in the /etc/hosts.allow and /etc/hosts.deny files.
NFS server daemons, called nfsd daemons, run on the server and accept RPC calls from clients. NFS servers also run the mountd daemon to handle mount requests. On the client, caching and buffering are handled by biod , the block I/O daemon. The portmap daemon maps RPC program numbers to the appropriate TCP/IP port numbers.
To set up an NFS server, first check that all the hosts that will mount your filesystem can reach your host. Next, edit the /etc/exports file on the server. Each entry in this file indicates the name of a directory to be exported, domain names of machines that will have access to that particular mount point, and any options specific to that machine. A typical entry looks like:
/projects hostname1(rw) hostname2(ro)
If you are running mountd, the files will be exported as the permissions in /etc/exports allow. See the exports manpage for all available export options.
To enable an NFS client, mount a remote filesystem after NFS is started, either by using the
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Overview of NIS
The Network Information System (NIS) refers to the service formerly known as Sun Yellow Pages (YP). It is used to make configuration information consistent on all machines in a network. It does this by designating a single host as the master of all the system administration files and databases and distributing this information to all other hosts on the network. The information is compiled into databases called maps. NIS is built on the RPC protocol. There are currently two NIS servers freely available for Linux, yps and ypserv. We describe ypserv in this book.
In NIS, there are two types of servers—master servers and slave servers. Master servers are responsible for maintaining the maps and distributing them to the slave servers. The files are then available locally to requesting processes.
An NIS domain is a group of hosts that use the same set of maps. The maps are contained in a subdirectory of /var/yp having the same name as the domain. The machines in a domain share password, host, and group file information. NIS domain names are set with the domainname command.
NIS stores information in database files called maps . Each map consists of a pair of dbm database files, one containing a directory of keys (a bitmap of indices) and the other containing data values. The non-ASCII structure of dbm files necessitates using NIS tools such as yppush to move maps between machines.
The file /var/yp/YP_MAP_X_LATE contains a complete listing of active NIS maps as well as NIS aliases for NIS maps. All maps must be listed in this file in order for NIS to serve them.
The following utilities are used to administer NIS maps:
makedbm
Make dbm files. Modify only ypserv's map and any nondefault maps.
ypinit
Build and install NIS databases. Manipulate maps when NIS is being initialized. Should not be used when NIS is already running.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Administering NIS
NIS is enabled by setting up NIS servers and NIS clients. The descriptions given here describe NIS setup using ypserv, which does not support a master/slave server configuration. All NIS commands depend on the RPC portmap program, so make sure it is installed and running before setting up NIS.
Setting up an NIS server involves the following steps:
  1. Set a domain name for NIS using domainname
  2. Edit the ypMakefile, which identifies which databases to build and what sources to use in building them
  3. Copy the ypMakefile to /var/yp/Makefile
  4. Run make from the /var/yp directory, which builds the databases and initializes the server
  5. Start ypserv, the NIS server daemon
Setting up an NIS client involves only the following steps:
  1. Set the domain name for NIS using domainname, which should be the same name used by the NIS server
  2. Run ypbind
NIS networks have two kinds of user accounts: distributed and local. Distributed accounts must be administered from the master machine; they provide information that is uniform on each machine in an NIS domain. Changes made to distributed accounts are distributed via NIS maps. Local accounts are administered from the local computer; they provide account information unique to a specific machine. They are not affected by NIS maps, and changes made to local accounts do not affect NIS. When NIS is installed, preexisting accounts default to local accounts.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
RPC and XDR
RPC (Remote Procedure Call) is the session protocol used by both NFS and NIS. It allows a host to make a procedure call that appears to be local but is really executed remotely on another machine on the network. RPC is implemented as a library of procedures, plus a network standard for ordering bytes and data structures called XDR (eXternal Data Representation).
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 3: Linux Commands
This chapter presents the Linux user, programmer, and system administration commands. These are entered into a shell at the console or on a virtual terminal on a graphical desktop.
Each entry is labeled with the command name on the outer edge of the page. The syntax line is followed by a brief description and a list of available options. Many commands come with examples at the end of the entry. If you need only a quick reminder or suggestion about a command, you can skip directly to the examples.
Typographic conventions for describing command syntax are listed in the Preface. For help in locating commands, see the index at the back of this book.
We've tried to be as thorough as possible in listing options. The basic command information and most options should be correct; however, there are many Linux distributions and many versions of commands. New options are added and sometimes old options are dropped. You may, therefore, find some differences between the options you find described here and the ones on your system. When there seems to be a discrepancy, check the manpage. For most commands you can also use the option —help to get a brief usage message. (Even when it isn't a valid option, it will usually result in an "invalid option" error along with the usage message.)
Traditionally, commands take single-letter options preceded by a single hyphen, like -d. A more recent convention allows long options preceded by two hyphens, like —debug. Often, a feature can be invoked through either the old style or the new style of options.
aclocal
aclocal [options]
GNU autoconf tool. Place m4 macro definitions needed by autoconf into a single file. The aclocal command first scans for macro definitions in m4 files in its default directory (/usr/share/aclocal on some systems) and in the file acinclude.m4. It next scans for macros used in the configure.in file. It generates an aclocal.m4 file that contains definitions of all m4 macros required by autoconf.
Options
--acdir=
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Alphabetical Summary of Commands
aclocal
aclocal [options]
GNU autoconf tool. Place m4 macro definitions needed by autoconf into a single file. The aclocal command first scans for macro definitions in m4 files in its default directory (/usr/share/aclocal on some systems) and in the file acinclude.m4. It next scans for macros used in the configure.in file. It generates an aclocal.m4 file that contains definitions of all m4 macros required by autoconf.
Options
--acdir= dir
Look for macro files in directory dir instead of the default directory.
--help
Print help message, then exit.
--output= file
Save output to file instead of aclocal.m4.
--print-ac-dir
Print the name of the directory to be searched for m4 files, then exit.
--verbose
Print names of files being processed.
--version
Print version number, then exit.
-I dir
Additionally, search directory dir for m4 macro definitions.
addr2line
addr2line [options] [addresses]
Translate hexadecimal program addresses into filenames and line numbers for the executable given with the -e option, or a.out if -e is not specified. If addresses are given on the command line, display the filename and line number for each address. Otherwise, read the addresses from standard input and display the results on standard output (useful for use in a pipe). addr2line prints two question marks ( ??) if it cannot determine a filename, and 0 if it cannot determine the line number. addr2line is used for debugging.
Options
-b bfdname, --target= bfdname
Set the binary file format using its binary file descriptor name,
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 4: Boot Methods
This chapter describes some techniques for booting your Linux system. Depending on your hardware and whether you want to run any other operating systems, you can configure the system to boot Linux automatically or to provide a choice between several operating systems. Choosing between operating systems is generally referred to as dual booting , but you can actually boot more than two.
Once your Linux system is installed, rebooting the system is generally pretty straightforward. But with the wide variety of hardware and software in use, there are many possibilities for configuring your boot process. The most common choices are:
  • Boot Linux from a floppy or bootable CD, leaving any other operating system to boot from the hard drive.
  • Use the Linux Loader, LILO. This is the traditional method of booting and lets you boot both Linux and other operating systems.
  • Use the Grand Unified Bootloader (GRUB), the GNU graphical boot loader and command shell. Like LILO, GRUB lets you boot both Linux and other operating systems. For now, GRUB runs only on i386-based systems.
  • Run Loadlin, which is an MS-DOS program that boots Linux from within DOS.
Other boot managers that can load Linux are available, but we don't discuss them here. We also won't talk further about booting from a floppy or CD, except to say that whatever method you choose for booting, be sure to have a working boot disk available for emergency use. In particular, don't experiment with the files and options in this chapter unless you have a boot disk, because any error could leave you unable to boot from the hard disk. Note, though, that one of the advantages of using GRUB is that if there is a problem booting from the menu, it drops you down to the command-line interface so you can enter commands directly and try to recover. Also, see Section 4.3.1.1 for information on making a GRUB boot floppy.
On an x86-based PC, the first sector of every hard disk is known as the boot sector and contains the partition table for that disk and possibly also code for booting an operating system. The boot sector of the first hard disk is known as the
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
The Boot Process
On an x86-based PC, the first sector of every hard disk is known as the boot sector and contains the partition table for that disk and possibly also code for booting an operating system. The boot sector of the first hard disk is known as the master boot record (MBR) because when you boot the system, the BIOS transfers control to a program that lives on that sector along with the partition table. That code is the boot loader , the code that initiates an operating system. When you add Linux to the system, you need to modify the boot loader, replace it, or boot from a floppy or CD to start Linux.
In Linux, each disk and each partition on the disk is treated as a device. So, for example, the entire first hard disk is known as /dev/hda and the entire second hard disk is /dev/hdb. The first partition of the first hard drive is /dev/hda1, and the second partition is /dev/hda2. The first partition of the second hard drive is /dev/hdb1, and so on. If your drives are SCSI instead of IDE, the naming works the same way except that the devices are /dev/sda, /dev/sda1, and so on. Thus, if you want to specify that the Linux partition is the second partition of the first hard drive (as in the examples in this chapter), you refer to it as /dev/hda2. Note, though, that GRUB has its own disk naming convention, described in Section 4.3.
Once you've made the decision to install LILO or GRUB, you still need to decide how it should be configured. If you want your system to dual-boot Linux and Windows 95/98/ME, you can install LILO or GRUB on the MBR and set it up to let you select the system to boot. Dual-booting Linux and Windows NT/2000/XP is not quite as straightforward because they use the Windows NT loader, which is installed on the MBR and expects to be the one in charge. The standard solution described in this chapter is to add Linux as an option in the NT loader and install LILO or GRUB in the Linux partition as a secondary boot loader. The result is that the NT loader transfers control to the secondary loader, which then boots Linux. See Section 4.6 later in this chapter for more information. You can also install one of the Linux boot loaders in the MBR and use it to boot Windows—see the "Linux+WindowsNT" and the "Multiboot with GRUB" mini-HOWTOs if you're interested in doing that.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
LILO: The Linux Loader
In addition to booting Linux, LILO can boot other operating systems, such as MS-DOS, Windows 95/98/ME, or any of the BSD systems. During installation, the major Linux distributions provide the opportunity to install LILO; it can also be installed later if necessary. LILO can be installed on the MBR of your hard drive or as a secondary boot loader on the Linux partition. LILO consists of several pieces, including the boot loader itself, a configuration file (/etc/lilo.conf), a map file (/boot/map) containing the location of the kernel, and the lilo command (/sbin/lilo), which reads the configuration file and uses the information to create or update the map file and to install the files LILO needs.
One thing to remember about LILO is that it has two aspects: the boot loader and the lilo command. The lilo command configures and installs the boot loader and updates it as necessary. The boot loader is the code that executes at system boot time and boots Linux or another operating system.
The lilo command reads the LILO configuration file, /etc/lilo.conf , to get the information it needs to install LILO. Among other things, it builds a map file containing the locations of all disk sectors needed for booting.
Note that any time you change /etc/lilo.conf or rebuild or move a kernel image, you need to rerun lilo to rebuild the map file and update LILO.
The configuration file starts with a section of global options, described in the next section. Global options are those that apply to every system boot, regardless of what operating system you are booting. Here is an example of a global section (a hash sign, #, begins a comment):
boot=/dev/hda           # The boot device is /dev/hda 
map=/boot/map           # Save the map file as /boot/map
install=/boot/boot.b    # The file to install as the new boot sector
prompt                  # Always display the boot prompt
timeout=30              # Set a 3-second (30 tenths of a second) timeout
Following the global section, there is one section of options for each Linux kernel and for each non-Linux operating system that you want LILO to be able to boot. Each of these sections is referred to as an
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
GRUB: The Grand Unified Bootloader
Like LILO, the GRUB boot loader can load other operating systems in addition to Linux. GRUB was written by Erich Boleyn to boot operating systems on PC-based hardware, and is now developed and maintained by the GNU project. GRUB was intended to boot operating systems that conform to the Multiboot Specification, which was designed to create one booting method that would work on any conforming PC-based operating system. In addition to multiboot-conforming systems, GRUB can boot directly to Linux, FreeBSD, OpenBSD, and NetBSD. It can also boot other operating systems such as Microsoft Windows indirectly, through the use of a chainloader . The chainloader loads an intermediate file, and that file loads the operating system's boot loader.
GRUB provides a graphical menu interface. It also provides a command interface that is accessible both while the system is booting (the native command environment) and from the command line once Linux is running.
While LILO works perfectly well, especially if you usually boot the default image, GRUB has some advantages. The graphical menu interface shows you exactly what your choices are for booting so you don't have to remember them. It also lets you easily edit an entry on the fly, or drop down into the command interface. In addition, if you are using the menu interface and something goes wrong, GRUB automatically puts you into the command interface so you can attempt to recover and boot manually. Another advantage of GRUB is that if you install a new kernel or update the configuration file, that's all you have to do; with LILO, you also have to remember to rerun the lilo command to reinstall the boot loader. On the other hand, if you are used to LILO, don't need to see the prompts often, and have a stable system, LILO is quick and convenient.
A GRUB installation consists of at least two and sometimes three executables, known as stages . The stages are:
Stage 1
Stage 1 is the piece of GRUB that resides in the MBR or the boot sector of another partition or drive. Since the main portion of GRUB is too large to fit into the 512 bytes of a boot sector, Stage 1 is used to transfer control to the next stage, either Stage 1.5 or Stage 2.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
GRUB Commands
The following sections describe two sets of commands. Both can be used at the GRUB command line. In addition, the first set can be used in the global section of the menu, and the second can be used in individual menu entries. A few commands can be used only on the GRUB shell command line; this is noted in the command entry. The commands default, fallback, hiddenmenu, timeout, and title are available only in the configuration file, for use with the menu interface. They are described in Section 4.3.2.
When running commands, if you find that you aren't sure how to complete a pathname, you can use the Tab key to find the possible completions. For example:
grub> blocklist (hd0,1)/grub/[Tab]
Possible files are: grub.conf splash.xpm.gz menu.lst device.map stage1 
stage2 e2fs_stage1_5 fat_stage1_5 ffs_stage1_5 jfs_stage1_5 minix_stage1_5 
reiserfs_stage1_5 vstafs_stage1_5 xfs_stage1_5
grub> blocklist (hd0,1)/grub/stage2
(hd0,1)33306+24,33332+231
The commands available at the command line and in the global section of the configuration file are as follows.
bootp
bootp [--with-configfile]
Initialize a network device via the Bootstrap Protocol (BOOTP). This command is available only if GRUB was compiled with netboot support. If --with-configfile is specified, GRUB automatically loads a configuration file specified by your BOOTP server.
color
color normal [highlight]
Specify colors for the menu. normal represents the color used for normal menu text, while highlight represents the color used to highlight the line the cursor is on. Both normal and highlight are specified as two symbolic color names, for foreground and background color, separated by a slash. For example:
color light-gray/blue cyan/black
You can prefix the foreground color with blink- (e.g., blink-cyan/red) to get a blinking foreground. The colors black, blue, green, cyan, red, magenta, brown, and light-gray can be specified for foreground or background. Additional colors that can be used only for the foreground are dark-gray, light-blue, light-green, light-cyan, light-red, light-magenta, yellow, and white.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Loadlin: Booting from MS-DOS
Loadlin is a Linux boot loader that you run from within a bootable MS-DOS partition. The system must be in real DOS mode, not in an MS-DOS window running under Windows. No installation is required; you simply copy the executable file loadlin.exe from the Loadlin distribution to your MS-DOS partition. You also need a compressed Linux kernel (e.g., vmlinuz), which you can load from a floppy, from the DOS partition, or from a RAM disk. For example:
C:> loadlin c:\vmlinuz root=/dev/hda2
         
This example loads the Linux kernel image vmlinuz, passing it the boot parameter root=/dev/hda2, telling the kernel that the Linux root partition is /dev/hda2. (If you are using a RAM disk, see Section 4.7 later in this chapter.)
If you want to use Loadlin with Windows 95/98/ME, see the Loadlin User Guide and the Loadlin+Win95/98/ME mini-HOWTO.
Loadlin can be run directly from the DOS prompt, as in the example, or it can be invoked from CONFIG.SYS or AUTOEXEC.BAT. Like LILO, Loadlin takes both options that direct its operation and options (also referred to as parameters) that it passes to the kernel.
There are two ways to specify options: in a DOS file or on the Loadlin command line.
You can store Loadlin options in a file and invoke the bootloader as follows:
LOADLIN @params
            
where params is a DOS file that contains the options you want Loadlin to run with. The Loadlin distribution comes with a sample parameter file, test.par, that you can use as a basis for creating your own. Each line in a parameter file contains one parameter. If you want to specify the name of the Linux kernel to use (the image= parameter), it must be the first entry in the file. Comments start with a hash sign (#). The entries in the parameter file can be overridden or appended on the command line. For example, to override the value of vga set in the parameter file:
C:> LOADLIN @myparam vga=normal
            
Another way to run Loadlin is to include options on the command line. The syntax is:
LOADLIN [zimage_file] [options] [boot_params]
zimage_file
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Dual-Booting Linux and Windows NT/2000/XP
As mentioned earlier, when you run Windows NT, its boot loader expects to be the one in charge; therefore, the standard way to dual-boot Windows NT and Linux is to add Linux as an option on the NT boot menu. This section describes how to do that. The information provided here also applies to Windows 2000 and Windows XP, which use the NT loader.
To set up dual booting with the NT loader, you need to provide the loader with a copy of the Linux boot sector. We'll describe how to do that on a computer running Windows NT with an NTFS filesystem (note that Windows NT should be installed on your system already). See the NT OS Loader+Linux mini-HOWTO for more information and other alternatives.
You should have a Linux boot floppy or CD available so that if necessary you can boot Linux before the NT boot loader has been modified. You also should have a DOS-formatted floppy to transfer the boot sector to the Windows NT partition. If you are running LILO and it is already installed, you may need to modify /etc/lilo.conf as described later. Otherwise, install LILO or GRUB to the boot sector of the Linux partition; once the Linux boot manager is installed and you have a configuration file, you can set up the system for dual booting.
The following instructions assume your Linux partition is on /dev/hda2. If Linux is on another partition in your system, be sure to replace /dev/hda2 in the following examples with the correct partition. The instructions also assume that you have a floppy drive to make a diskette for transferring the boot sector to your NTFS filesystem. If you don't have a floppy drive, you will have to use some other means of doing the transfer. If you have an NT FAT partition, you can mount that on Linux and transfer the file there. Other possibilities include putting it on a CD, transferring it over a network to another system while you reboot to NT, or even emailing it to yourself and reading it from the NT side.
  1. If you are running LILO, specify the Linux root partition as your boot device in /etc/lilo.conf. If you are editing /etc/lilo.conf
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Boot-Time Kernel Options
The earlier sections of this chapter described some of the options you can specify when you boot Linux. There are many more options that can be specified. This section touches on the ways to pass options to the kernel and then describes some of the kinds of parameters you might want to use. The parameters in this section affect the kernel and therefore apply regardless of which boot loader you use.
As always with Unix systems, there are a number of choices for the boot process i