HOW LINUX WORKS . Copyright 2004 by Brian Ward.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
Printed on recycled paper in the United States of America
1 2 3 4 5 6 7 8 9 10 - 07 06 05 04
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Linux is a registered trademark of Linus Torvalds. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
Publisher: William Pollock
Managing Editor: Karol Jurado
Cover and Interior Design: Octopod Studios
Technical Reviewer: Scott Schwartz
Copyeditor: Andy Carroll
Compositor: Wedobooks
Proofreader: Stephanie Provines
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
555 De Haro Street, Suite 250, San Francisco, CA 94107
phone: 415-863-9900; fax: 415-863-9950;
The information in this book is distributed on an "As Is" basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
Library of Congress Cataloguing-in-Publication Data
Ward, Brian.
How Linux works : what every superuser should know / Brian Ward.
p. cm.
Includes index.
ISBN 1-59327-035-6
1. Linux. 2. Operating systems (Computers). I. Title.
QA76.76.O63 W3654 2004
005.4'32--dc22
2004002692
PREFACE
This book is about learning how a Linux system works so that you can be an effective systems administrator, programmer, home user, researcher, or just someone who likes to have fun with their computer. If you want to know what you can do when you have root access, then this book is for you.
The first part of this book shows you the basic layout and workings of a Linux system, including the directory structure and boot process. From there, you will learn the basics of networking.
The next part of the book is dedicated to programming tools. You may wonder why programming tools are important to system operation; after all, other systems don't come with development software. Unix-like systems such as Linux are different; not only is it not at all unusual to build your own version of popular software, but shell scripts and similar tools are closely intertwined with the system.
With the basic topics out of the way, the last half of the book is dedicated to more specialized information, such as the kernel, printing, and user environments. In addition, there is a very special chapter dedicated to purchasing hardware suitable for Linux systems.
One of the nice things about Linux is that the system doesn't make any effort to hide itself from you. You don't have to worry about strange undocumented binary formats, catch-all configuration databases (such as the Windows Registry), and frustratingly opaque GUI setup tools. Furthermore, like its BSD cousins, Linux retains its users because it gives them the chance to customize their systems to a degree impossible on other platforms. This book shows you how.
Prerequisites
You do not have to know much about Linux or Unix to understand this book. Basic computer knowledge is more important than specifics. Here are the bare essentials:
You should know what files and directories are.
You should have Linux installed on a computer of your own, superuser (root) access, and a regular user account. The distribution that you choose does not matter. You need to be able to experiment with your machine as you read this book.
In addition, it helps if you have a little experience with the Unix shell. Without this background, it may take some time to get through the first chapter. You may also want to review binary and hexadecimal number systems for a few sections of the book.
Kernel Chapter
Some time ago, I wrote a document called the Kernel-HOWTO. Due to increased demands on my time, I had to give up maintainership, but I haven't forgotten the first Linux-related thing I ever wrote. as if it were a regular HOWTO document.
Acknowledgments
Thanks go to James Duncan, Douglas N. Arnold, Bill Fenner, Ken Hornstein, Scott Dickson, Dan Ehrlich, Felix Lee, Scott Schwartz, Gregory P. Smith, Dan Sully, Gina Steele, and, of course, everyone at No Starch Press.
Brian Ward
San Francisco, CA
Chapter 1. THE BASICS
This chapter is a guide to the Unix commands and utilities that you must know to get anything out of this book. This is preliminary material, and you may already know a substantial amount. Even if you think you're up to speed, though, take a few seconds to flip through the sections just to make sure.
You may be asking yourself, "I thought this was a book about Linux, not Unix?" Don't worry; this chapter is just getting you ready for working with the Linux system. Linux is a Unix flavor at heart. You will see the word "Unix" in this chapter more than "Linux" because you can take the information straight over to Solaris, BSD, and other Unix-flavored systems. Special care has been taken to avoid too many Linux-specific user interface extensions, not only so you will have a better background with other operating systems, but also because these extensions tend to be extremely unstable. You will be able to adapt to new Linux releases much more quickly if you know the core that does not change.
Although the material here may seem sparse, you need to convince yourself that Unix is not hard . Yes, most reports from the field are to the contrary, but in the end, Unix is nothing but a bunch of files and a few commands for manipulating those files. If you are familiar with other operating systems, you shouldn't have a problem. However, if you find the information in this preliminary chapter somewhat lacking, there are books with much more detail for beginners, such as UNIX for the Impatient [Abrahams] and Learning the UNIX Operating System [Peek].
About /bin/sh
The shell is one of the most important parts of a Unix system. A shell is a program that runs commands. For example, one of the shell's duties is to run the commands that users type. Shells also serve as small programming environments. Unix programmers often break common tasks into little components and rely on the shell to manage tasks and to piece things together.
Many important parts of the system are actually shell scripts text files that contain nothing but shell commands. If you have worked with MS-DOS, shell scripts may seem similar to .