BUY THIS BOOK

Safari Books Online

What is this?

Looking to Reprint this content?


Linux in a Nutshell
Linux in a Nutshell, Third Edition By Ellen Siever, Stephen Spainhour, Jessica P. Hekman, Stephen Figgins
August 2000
Pages: 816

Cover | Table of Contents | Colophon


Table of Contents

Chapter 1: Introduction
In just a few years, 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. A freely redistributable clone of the Unix operating system, Linux is turning up everywhere. People use it for web servers, file servers, and workstations instead of--or alongside—systems from traditional Unix vendors as well as Windows NT. In addition to its role in large networks (because it's a friendly fellow that fits in very nicely with other operating systems), Linux is popular among Windows users who just want to try something that gives them more speed, more power, and more control.
The historical impact of Linux goes even beyond its own penetration into the markets of proprietary operating systems. Its success has inspired countless other free software or open source (http://opensource.org)projects, including Samba, GNOME, and a mind-boggling collection of innovative projects that you can browse at numerous sites like SourceForge (http://sourceforge.net).As both a platform for other developers and a development model, Linux gave a tremendous boost to the Free Software Foundation's GNU project, which in turn had furnished key software that made the development of Linux possible. In short, Linux is a central participant in the most exciting and productive free software movement ever seen.
If you haven't obtained Linux yet or have it but don't know exactly how to get started using it, see the preface.
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 (particularly on Intel systems, where it was originally developed) and be assured of fewer crashes; even its security is better than many commercial alternatives.
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 which they 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.
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 (particularly on Intel systems, where it was originally developed) and be assured of fewer crashes; even its security is better than many commercial alternatives.
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 which they 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 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 can bring back the spirit of working together—all the more so because the Internet is now widespread. And for the many who are too young to remember the first round of open systems (such as the hordes of students attracted to Linux) or whose prior experience has been woefully constricted by proprietary operating systems, now is the time to discover the wonders of freely distributable source code and infinitely adaptable interfaces.
The Linux kernel itself was originally designed by Linus Torvalds at the University of Helsinki in Finland and later developed through collaboration with countless volunteers worldwide. 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 the kernel as well as the applications and complete system environment.
Most Linux systems cannot be technically referred to as a "version of Unix," as they have not been submitted to the required tests and licensed properly.However, at least one Linux distribution has in fact been branded as POSIX.1. Linux offers all the common programming interfaces as 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.
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 a whole working system over phone lines is an absurd proposition. Over the years, therefore, commercial and noncommercial packages called distributions have emerged. The first 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 response 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 definitely supported at least as well as commercial software.
Intel is 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, the Alpha (created by Digital Equipment Corporation, now Compaq), the SPARC, and the MIPS chip.
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 supposed to be 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 or inconsistencies that persist in the original standard versions.
While GNU provided the programming utilities and standard commands like grep, most of the system and network administration tools on Linux came from the Berkeley Software Distribution (BSD). In addition, some people wrote tools specifically for Linux to deal with special issues such as filesystems that only Linux supports. 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 may want to make to your KDE, GNOME, or fvwm 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
Based originally 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. The current edition includes chapters on package managers (which make it easy to install, update, and remove related software files), on the KDE and GNOME desktops, and on the fvwm window manager, as well as new commands and expanded discussions of several topics such as CVS and bash.
Linux in a Nutshell doesn't teach you Linux--it is, after all, a quick reference—but novices as well as highly experienced users will find it of great value. When you have some idea what command you want but aren't sure just how it works or what combinations of options give you the exact output required, this book is the place to turn. It is also an eye-opener: it can make you aware of options that you never knew about before.
Like computer systems from the age in which Unix was born (the early 1970s), Linux is mostly a command-driven system. Most versions of Linux provide a few graphical tools, and several commercial products are available, but none of these graphical utilities are central to Linux. That is why this book, like the traditional Unix in a Nutshell reference, focuses on the shell and on commands you run from the shell.
Of course, Linux offers a windowing system—a very rich and flexible one, as befits a rich and flexible operating system. But a lot of the time you'll just open a simulated VT100 terminal (the xterm program) and enter commands into that. You'll find yourself moving back and forth between graphical programs and the commands listed in this book.
So the first thing you've got to do, once you're over the hurdle of installing Linux, is get to know the common utilities run from the shell prompt. If you know absolutely nothing about Unix, we recommend you read a basic guide (introductory chapters in the O'Reilly books Learning Red Hat Linux, Learning Debian GNU/Linux, and Running Linux can get you started). This book offers a context for understanding different kinds of commands (including commands for programming, system administration, and network administration) in Chapter 2, followed by the command reference itself in Chapter 3. Chapter 3 is obviously the central focus of the book, containing about one third its bulk.
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
When you get Linux, you also get the source code. The same goes for all the utilities on Linux (unless your vendor offered 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. The source code has to be provided by the vendor, under the Linux license, 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 all of us. The license is the 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 would believe to be impossible if it did not exist. (The same goes for Linux, in fact—10 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 used to set the standard for optimization and fast code. One of the largest projects within GNU is the GNOME desktop, which already encompasses several useful general-purpose libraries, window managers, and applications. The GNOME developers have big plans for providing an environment that integrates not only the applications on each user's system but also the services provided throughout a whole organization.
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.
In order 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 and 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.
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.
uuencode Encode file containing binary characters for mailing.
vacation Respond to mail automatically.
cmp Compare two files, byte by byte.
comm Compare items in two sorted files.
diff Compare two files, line by line.
diff3 Compare three files.
cat Concatenate files or display them.
chfn Change user information for finger, email, etc.
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.
netdate Set clock according to host's clock.
rdate Manage time server.
zdump Print list of time zones.
zic Create time conversion information files.
apmd Advanced Power Management daemon.
bootpd Internet Boot Protocol daemon.
fingerd Finger daemon.
ftpd File Transfer Protocol daemon.
gated Manage routing tables between networks.
identd Identify user running TCP/IP process.
imapd IMAP mailbox server daemon.
inetd Internet services daemon.
kerneld Provide automatic kernel module loading.
klogd Manage syslogd.
lpd Printer daemon.
mountd NFS mount request server.
named Internet domain name server.
nfsd NFS daemon.
pop2d POP server.
pop3d
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.
netdate Set clock according to host's clock.
rdate Manage time server.
zdump Print list of time zones.
zic Create time conversion information files.
apmd Advanced Power Management daemon.
bootpd Internet Boot Protocol daemon.
fingerd Finger daemon.
ftpd File Transfer Protocol daemon.
gated Manage routing tables between networks.
identd Identify user running TCP/IP process.
imapd IMAP mailbox server daemon.
inetd Internet services daemon.
kerneld Provide automatic kernel module loading.
klogd Manage syslogd.
lpd Printer daemon.
mountd NFS mount request server.
named Internet domain name server.
nfsd NFS daemon.
pop2d POP server.
pop3d POP server.
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, which 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 numeric IP addresses into the alphanumeric names that humans are so fond of), 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, because 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.
host Print host and zone information.
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 resent 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 et al.)
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)
Serial Line Internet Protocol (SLIP)
Carries IP over serial lines
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)
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 it may use multiple IP addresses 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.
The discussion of iptables applies to Version 2.4 Linux kernels. As this book was being written, both iptables and the 2.4 kernel were still in development. The final product may differ slightly from what we describe here. See the O'Reilly book Linux Network Administrator's Guide by Olaf Kirch and Terry Dawson or the the "Linux IPTABLES-HOWTO" for more information. This HOWTO, and a myriad of others, can be obtained from the the Linux Documentation Project web sites (see the preface).
IP firewalling and masquerading are implemented in Linux Version 2.2 with the ipchains utility and in Linux Version 2.4 with the iptables facility. The 2.0 kernels used a command called ipfwadm, which is included in the command section for older systems but will not be covered here. The two newer commands are very similar, but some of the organization of the rules they use is different. 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 could add it. See the "Linux netfilter Hacking HOWTO" for details on how to do this.
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.
Setting up NFS clients and servers involves starting the NFS daemons, exporting filesystems from the NFS servers, and mounting them 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 receiving services are kept in the /etc/hosts file.
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 to include the mount-point pathname of the filesystem to be exported. If you are running mountd, the files will be exported as the permissions in /etc/exports allow.
To enable an NFS client, mount a remote filesystem after NFS is started, either by using the mount command or by specifying default remote filesystems in /etc/fstab. A mount request calls the server's mountd daemon, which checks the access permissions of the client and returns a pointer to a filesystem. Once a directory is mounted, it remains attached to the local filesystem until it is dismounted with 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.
In NIS, there are two types of servers—master 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, hosts, 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 here in order for NIS to serve them.
The following utilities are used to administer NIS maps:
makedbm
Make dbm files. Modify only ypservers map and any nondefault maps.
ypinit
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:
  1. Setting a domain name for NIS using domainname
  2. Editing the ypMakefile, which identifies which databases to build and what sources to use in building them
  3. Copying the ypMakefile to /var/yp/Makefile
  4. Running make from the /var/yp directory, which builds the databases and initializes the server
  5. Starting ypserv, the NIS server daemon
Setting up an NIS client involves setting the domain name for NIS using domainname, which should be the same name used by the NIS server, and running 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. 11 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. 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.
agetty
agetty [options] port baudrate [term]
Description
System administration command. The Linux version of getty. Set terminal type, modes, speed, and line discipline. agetty is invoked by init. It is the second process in the series init-getty-login-shell, which ultimately connects a user with the Linux system. agetty reads the user's login name and invokes 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!
Alphabetical Summary of Commands
agetty
agetty [options] port baudrate [term]
Description
System administration command. The Linux version of getty. Set terminal type, modes, speed, and line discipline. agetty is invoked by init. It is the second process in the series init-getty-login-shell, which ultimately connects a user with the Linux system. agetty reads the user's login name and invokes the login command with the user's name as an argument. While reading the name, agetty attempts to adapt the system to the speed and type of device being used.
You must specify a port, which agetty will search for in the /dev directory. You may use -, in which case agetty reads from standard input. You must also specify baudrate, which may be a comma-separated list of rates, through which agetty will step. Optionally, you may specify the term, which is used to override the TERM environment variable.
Options
-h
Specify hardware, not software, flow control.
-i
Suppress printing of /etc/issue before printing the login prompt.
-l program
Specify the use of program instead of /bin/login.
-m
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 boot more than two (e.g., Linux and Windows 95/98/NT/2000). This chapter covers the following topics:
  • The boot process
  • LILO: the Linux loader
  • Loadlin: booting from MS-DOS
  • Dual booting Linux and Windows NT/2000
  • Boot-time kernel options
  • initrd: using a RAM disk
Once your Linux system is up and running, booting the system generally is pretty straightforward. But with the wide variety of hardware and software in use, there are many possibilities for configuring your boot process. The three most common choices are:
  • Boot Linux from a floppy, leaving any other operating system to boot from the hard drive.
  • Use the Linux Loader, LILO. This is probably the most common method of booting and lets you boot both Linux and other operating 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 in this chapter. We also won't talk further about booting from a floppy except to say that whatever method you choose for booting, you should be sure to have a working boot floppy available for emergency use. In particular, don't experiment with the files and options in this chapter unless you have a boot floppy, because any error could leave you unable to boot from the hard disk.
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
Once your Linux system is up and running, booting the system generally is pretty straightforward. But with the wide variety of hardware and software in use, there are many possibilities for configuring your boot process. The three most common choices are:
  • Boot Linux from a floppy, leaving any other operating system to boot from the hard drive.
  • Use the Linux Loader, LILO. This is probably the most common method of booting and lets you boot both Linux and other operating 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 in this chapter. We also won't talk further about booting from a floppy except to say that whatever method you choose for booting, you should be sure to have a working boot floppy available for emergency use. In particular, don't experiment with the files and options in this chapter unless you have a boot floppy, because any error could leave you unable to boot from the hard disk.
On an Intel-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 disk 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, if there is one, is
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
Once you've made the decision to install LILO, you still need to decide how it should be configured. If you want your system to dual boot Linux and Windows 95/98, you can install LILO on the master boot record (MBR) and set it up to let you select the system to boot. Dual booting Linux and Windows NT is not quite as straightforward, because Windows NT has its own loader on the MBR, and it expects to be the one in charge. Therefore, you need to make Linux an option in the NT loader and install LILO in the Linux partition as a secondary boot loader. The result is that the Windows NT loader transfers control to LILO, which then boots Linux. The same applies to Windows 2000, which uses the NT loader. See Section 4.4 later in this chapter for more information.
In addition to booting Linux, LILO can boot other operating systems, such as MS-DOS, Windows 95/98, or OS/2. 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 master boot record (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.
If LILO is installed on the MBR, it replaces the MS-DOS boot loader. If you have problems with your installation or you simply want to uninstall LILO and restore the original boot loader, you can do one of the following:
  • Boot Linux from a floppy disk and restore the backed-up boot sector:
    % /sbin/lilo -u
                   
  • Boot to DOS and run a special version of the fdisk command that rebuilds the MBR:
    C:> 
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 just need to 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.6 later in this chapter.)
If you want to use Loadlin with Windows 95/98, see the Loadlin User Guide and the Loadlin+Win95 mini-HOWTO for how to do that. Note that if your disk uses the FAT32 filesystem, the standard techniques for using Loadlin and Windows 95 won't work; if this is the case or if you aren't sure whether you have FAT16 or FAT32, it's important to read the mini-HOWTO before you proceed.
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 forms of the Loadlin syntax:
LOADLIN @params
LOADLIN [zimage_file] [options] [boot_params]
In the first form of the preceding syntax, 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
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
As we said earlier, when you run Windows NT, its boot loader expects to be the one in charge; therefore, the normal way to dual boot Windows NT and Linux is to add Linux as an option on the NT boot menu. The information in this section also applies to Windows 2000, which uses the NT loader.
To accomplish this, you need to provide the NT loader with a copy of the Linux boot sector. Here's how you 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 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 LILO is already installed, you may need to modify /etc/lilo.conf as described later. Otherwise, you'll either install LILO as part of the Linux installation, or you can install it with the QuickInst script that comes with LILO. Once LILO is installed, and you have a configuration file, you can set up the system for dual booting.
Note that the following instructions assume your Linux partition is on /dev/hda2. If Linux is on another partition, be sure to replace /dev/hda2 in the following examples with the correct partition.
  1. Specify the Linux root partition as your boot device. If you are editing /etc/lilo.conf manually, your entry will look like this:
    boot=/dev/hda2
    and will be the same as the root= entry.
  2. Run the lilo command to install LILO on the Linux root partition.
  3. At this point, if you need to reboot Linux, you'll have to use the boot floppy, because the NT loader hasn't been set up yet to boot Linux.
  4. From Linux, run the dd command to make a copy of the Linux boot sector:
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 Loadlin and LILO 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 itself. If you are using Loadlin, you can pass parameters to the kernel on the command line or in a file.
If LILO is your boot loader, you can add to or override the parameters specified in /etc/lilo.conf during the boot process as follows:
  • If prompt is set in /etc/lilo.conf, LILO always presents the boot prompt and waits for input. At the prompt, you can choose the operating system to be booted. If you choose Linux, you also can specify parameters.
  • If prompt isn't set, when the word "LILO" appears, press Control, Shift, or Alt, and the boot prompt appears. You also can press the Scroll Lock key before LILO is printed and not have to wait poised over the keyboard for the right moment.
  • At the boot prompt, specify the system you want to boot or press Tab to get a list of the available choices. You then can enter the name of the image to boot. For example:
    LILO boot: <press Tab>
    linux   test   dos
    boot: linux
                   
    You also can add boot command options:
    boot: linux single
                   
  • If you don't provide any input, LILO waits the amount of time specified in the delay parameter and then boots the default operating system with the default parameters as set in /etc/lilo.conf.
Some of the boot parameters have been mentioned earlier. Many of the others are hardware-specific and are too numerous to mention here. For a complete list of parameters and a discussion of the booting process, see the BootPrompt-HOWTO. Some of the parameters not shown earlier that you might find useful are listed next; many more are covered in the HOWTO. Most of the following parameters are used to provide information or instructions for the kernel, rather than to LILO.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
initrd: Using a RAM Disk
Modern Linux distributions use a modular kernel, which allows modules to be added without requiring that the kernel be rebuilt. If your root filesystem is on a device whose driver is a module, as is frequently true of SCSI disks, you can use the initrd facility, which provides a two-stage boot process, to first set up a temporary root filesystem in a RAM disk containing the modules you need to add (e.g., the SCSI driver) and then load the modules and mount the real root filesystem. The RAM disk containing the temporary filesystem is the special device file /dev/initrd.
Before you can use initrd, both RAM disk support (CONFIG_BLK_DEV_RAM=y) and initial RAM disk support (CONFIG_BLK_DEV_INITRD=y) must be compiled into the Linux kernel. Then you need to prepare the normal root filesystem and create the RAM disk image. Your Linux distribution may have utilities to do some of the setup for you; for example, the Red Hat distribution comes with the mkinitrd command, which builds the initrd image. For detailed information, see the initrd manpage and the file initrd.txt (the path may vary but is usually something like /usr/src/linux/Documentation/initrd.txt).
Once your Linux system has been set up for initrd, you can do one of the following, depending on which boot loader you are using:
  • If LILO is your boot loader, add the initrd option to the appropriate image section:
    image = /vmlinuz
      initrd = /boot/initrd  # The file to load as the contents of /dev/initrd
      ...
    Run the /sbin/lilo command, and you can reboot with initrd.
  • If you are using Loadlin, add the initrd option to the command line:
    loadlin c:\linux\vmlinuz initrd=c:\linux\initrd