<!doctype book PUBLIC "-//OASIS//DTD DocBook V4.2//EN" []>
<book label="index">
  <bookinfo>
   <date>$Date: 2001/12/03 19:00:35 $</date>
   <title>The Linux System Administrator's Guide</title>
    <subtitle>Version 0.8</subtitle>
    <author>
    	<firstname>Lars</firstname>
    	<surname>Wirzenius</surname>
	<affiliation>
		<address>
		<email>liw@iki.fi</email>
		</address>
	</affiliation>
    </author>
    <author>
    	<firstname>Joanna</firstname>
    	<surname>Oja</surname>
	<affiliation>
		<address>
		<email>viu@iki.fi</email>
		</address>
	</affiliation>
    </author>
    <author>
    	<firstname>Stephen</firstname>
	<surname>Stafford</surname>
	<affiliation>
		<address>
		<email>stephen@clothcat.demon.co.uk</email>
		</address>
	</affiliation>
     </author>
    <author>
    	<firstname>Alex</firstname>
	<surname>Weeks</surname>
	<affiliation>
		<address>
		<email>weeks_alex@yahoo.com.NOSPAM</email>
		</address>
	</affiliation>
     </author>


    <abstract> 
    <para>An introduction to system administration of a 
Linux system for novices.</para> </abstract>

    <legalnotice>

	<para>Copyright 1993--1998 Lars Wirzenius.</para>
	<para>Copyright 1998--2001 Joanna Oja.</para>
	<para>Copyright 2001--2003 Stephen Stafford.</para>
	<para>Copyright 2003--Present Stephen Stafford & Alex Weeks.</para>

	<para>Trademarks are owned by their owners.</para>

	<para>Permission is granted to copy, distribute and/or modify this
        document under the terms of the GNU Free Documentation License,
	Version 1.1; with no Invariant Sections, with no Front-Cover Texts,
	and with no Back-Cover Texts.  A copy of the license is included in
	the section entitled "GNU Free Documentation
	License".</para>

    </legalnotice>
    
  </bookinfo>
  
  <toc></toc>

<preface> <title>Source and pre-formatted versions available</title>
	<para>The source code and other machine readable formats
	of this book can be found on the Internet via anonymous FTP at the
	Linux Documentation Project home page <ulink
	url="http://www.tldp.org/">http://www.tldp.org/</ulink>, or
	at the home page of this book at <ulink
	url="http://www.taylexson.org/sag//">http://www.taylexson.org/sag/</ulink>.
	Available are at least HTML and PDF formats.</para>
</preface>


<chapter>
<title>Introduction</title>
	<blockquote><para><quote>In the beginning, the file was without
	form, and void; and emptiness was upon the face of the bits.
	And the Fingers of the Author moved upon the face of the
	keyboard.  And the Author said, Let there be words, and there
	were words.</quote></para></blockquote>

	<para>The Linux System Administrator's Guide,
	describes the system administration aspects of using Linux.
	It is intended for people who know next to nothing about system
	administration (those saying ``what is it?''), but who have already
	mastered at least the basics of normal usage.  This manual
	doesn't tell you how to install Linux; that is described in the
	Installation and Getting Started document. See below for more
	information about Linux manuals.</para>

	<para>System administration covers all the things that you have to
	do to keep a computer system in usable order.  It includes
	things like backing up files (and restoring them if necessary),
	installing new programs, creating accounts for users (and deleting
	them when no longer needed), making certain that the filesystem
	is not corrupted, and so on.  If a computer were, say, a house,
	system administration would be called maintenance, and would
	include cleaning, fixing broken windows, and other such things.
	</para>

	<para>The structure of this manual is such that many of the
	chapters should be usable independently, so if you need information
	about backups, for example, you can read just that chapter. However,
	this manual is	first and foremost a tutorial and can be read
	sequentially or as a whole.</para>

	<para>This manual is not intended to be used completely 
	independently. Plenty of the rest of the Linux documentation is also
	important for system administrators.  After all, a system
	administrator is just a user with special privileges and duties.
	Very useful resources are the manual pages, which should always be
	consulted when you are not familiar with a command.  If you do not
	know which command you need, then the <command>apropos</command>
	command can be used.  Consult its manual page for more details.</para>

	<para>While this manual is targeted at Linux, a general principle
	has been that it should be useful with other UNIX based operating
	systems as well.  Unfortunately, since there is so much variance
	between different versions of UNIX in general, and in system
	administration in particular, there is little hope to cover
	all variants.  Even covering all possibilities for Linux is
	difficult, due to the nature of its development.</para>
	
	<para>There is no one official Linux distribution, so different
	people have different setups and many people have a setup they
	have built up themselves.  This book is not targeted at any
	one distribution.  Distributions can and do vary considerably.
	When possible, differences have been noted and alternatives
	given.</para>
	
	<para>In trying to describe how things work, rather than just
	listing ``five easy steps'' for each task, there is much information
	here that is not necessary for everyone, but those parts are marked
	as such and can be skipped if you use a preconfigured system.
	Reading everything will, naturally, increase your understanding of
	the system and should make using and administering it more
	productive.
		
		<footnote><para>Understanding is the key to success with
		Linux.  This book could just provide recipes, but what
		would you do when confronted by a problem this book had
		no recipe for?  If the book can provide understanding
		then recipes are not required, they will be self evident
		</para></footnote>
	</para>

	<para>Like all other Linux related development, the work 
	to write this manual was done on a volunteer basis: I did it because
	I thought it might be fun and because I felt it should be done.
	However, like all volunteer work, there is a limit to how much time,
	knowledge and experience people have.  This means that the manual is
	not necessarily as good as it would be if a wizard had been paid
	handsomely to write it
	and had spent millennia to perfect it.  Be warned.</para>

	<para>One particular point where corners have been cut is that 
	many things that are already well documented in other freely
	available manuals are not always covered here.  This applies
	especially to program specific documentation, such as all the
	details of using <command>mkfs</command>.  Only the purpose of the
	program and as much of its usage as is necessary for the purposes of
	this manual is described.  For further information, consult these
	other manuals.  Usually, all of the referred to documentation is
	part of the full Linux
	documentation set.</para>
</chapter>

<chapter>
<title>About This Book</title>
<sect1>
<title>Acknowledgments</title>
<sect2><title>Joanna's acknowledgments</title>

	<para>Lars has tried to make this manual as good as possible
	and I would like, as a current maintainer, to keep up the good
	work. I would really like to hear from you if you have any
	ideas on how to make it better. Bad language, factual errors,
	ideas for new areas to cover, rewritten sections, information
	about how various UNIX versions do things, I am interested in
	all of it. My contact information is available via the World
	Wide Web at <ulink url="http://www.iki.fi/viu/">
	http://www.iki.fi/viu/</ulink>.
	</para>
	
	<para>Many people have helped me with this book, directly or
	indirectly.  I would like to especially thank Matt Welsh for
	inspiration and LDP leadership, Andy Oram for getting me to work
	again with much-valued feedback, Olaf Kirch for showing me that it
	can be done, and Adam Richter at Yggdrasil and others for showing
	me that other people can find it interesting as well.</para>

	<para>Stephen Tweedie, H. Peter Anvin, Remy Card, Theodore
	Ts'o, and Stephen Tweedie have let me borrow their work (and
	thus make the book look thicker and much more impressive):
	a comparison between the xia and ext2 filesystems, the device
	list and a description of the ext2 filesystem. These aren't
	part of the book any more.  I am most grateful for this, and
	very apologetic for the earlier versions that sometimes lacked
	proper attribution.</para>

	<para>In addition, I would like to thank Mark Komarinski for
	sending his material in 1993 and the many system administration
	columns in Linux Journal.  They are quite informative and
	inspirational.</para>

	<para>Many useful comments have been sent by a large number
	of people.  My miniature black hole of an archive doesn't let
	me find all their names, but some of them are, in alphabetical
	order: Paul Caprioli, Ales Cepek, Marie-France Declerfayt,
	Dave Dobson, Olaf Flebbe, Helmut Geyer, Larry Greenfield and
	his father, Stephen Harris, Jyrki Havia, Jim Haynes, York Lam,
	Timothy Andrew Lister, Jim Lynch, Michael J. Micek, Jacob Navia,
	Dan Poirier, Daniel Quinlan, Jouni K Sepp&auml;nen, Philippe Steindl,
	G.B. Stotte.  My apologies to anyone I have forgotten.</para>
</sect2>

<sect2><title>Stephen's acknowledgments</title>
	<para>I would like to thank Lars and Joanna for their hard 
	work on the guide.</para>
	
	<para>In a guide like this one there are likely to be at least 
	some minor inaccuracies.  And there are almost certainly going to 
	be sections that become out of date from time to time.  If you 
	notice any of this then please let me know by sending me an email 
	to: <email>bagpuss@debian.org</email>.	I will take virtually
	any form of input (diffs, just plain text, html, whatever), I am 
	in no way above allowing others to help	me maintain such a large 
	text as this :) </para>
	
	<para>Many thanks to Helen Topping Shaw for getting the red pen out 
	and making the text far better than it would otherwise have been.  
	Also thanks are due just for being wonderful.</para>
	
	<para>The current web home of the guide is 
	<ulink url="http://people.debian.org/~bagpuss">
	http://people.debian.org/~bagpuss
	</ulink></para>
</sect2>
<sect2>
<title>Alex's Acknowledgments</title>
	<para>I would like to thank Lars, Joanna, and Stephen for all the 
	great work that they have done on this document over the years.  I
	only hope that my contribution will be worthy of continuing the work
	they started.</para>
	
	<para>There have been many people who have helped me on my journey
	through the "Windows-Free" world, the person I feel I need to thank the
	most is my first true UN*X mentor, Mike Velasco.  Back in a time before
	SCO became a "dirty word", Mike helped me on the path of tar's, cpio's,
	and many, many man pages.  Thanks Mike! You are the 'Sofa King'.<para>
</sect2>
</sect1>

<sect1>
<title>Typographical Conventions</title>

	<para>Throughout this book, I have tried to use uniform
	typographical conventions.  Hopefully they aid readability.  If
	you can suggest any improvements please contact me.</para>

	<para>Filenames are expressed as:
	<filename>/usr/share/doc/foo</filename>.</para>

	<para>Command names are expressed as: <command>fsck</command>

	<para>Email addresses are expressed as:
	<email>stephen@clothcat.demon.co.uk</email></para>

	<para>URLs are expressed as: <ulink
	url="http://www.tldp.org">http://www.tldp.org</ulink>
	</para>

	<para>I will add to this section as things come up whilst
	editing.  If you notice anything that should be added then
	please let me know.</para>
</sect1>
</chapter>

<chapter>
<title>Overview of a Linux System</title>

	<blockquote><para><quote>God saw everything that he
	had made, and saw that it was very good. </quote> --  Bible
	King James Version.  Genesis 1:31</para></blockquote>

	<para>This chapter gives an overview of a Linux system.  First,
	the major services provided by the operating system are described.
	Then, the programs that implement these services are described
	with a considerable lack of detail.  The purpose of this chapter
	is to give an understanding of the system as a whole, so that
	each part is described in detail elsewhere.</para>

<sect1>
<title>Various parts of an operating system</title>

	<para>A UNIX operating system consists
	of a <glossterm>kernel</glossterm> and some
	<glossterm>system programs</glossterm>.  There are also some
	<glossterm>application programs</glossterm> for doing work.
	The kernel is the heart of the operating system.
	
		<footnote><para>In fact, it is often mistakenly considered
		to be the operating system itself, but it is not.
		An operating system provides many more services than a
		plain kernel.</footnote>
		
	It keeps track of files on the disk, starts programs and runs them
	concurrently, assigns memory and other resources to various
	processes, receives packets from and sends packets to the network,
	and so on.  The kernel does very little by itself, but it provides
	tools with which all services can be built.  It also prevents anyone
	from accessing the hardware directly, forcing everyone to use the
	tools it provides.
		<footnote><para>I always think of this as a form of encapsulation
		which may help those of you with an object oriented programming
		background to visualize it better.</para></footnote>
	This way the kernel provides some protection for users from each
	other.  The tools provided by the kernel are used via
	<glossterm>system calls<glossterm>.  See manual page section 2 for more 
	information on these.  </para>

	<para>The system programs use the tools provided by the kernel to
	implement the various services required from an operating system.
	System programs, and all other programs, run `on top of the
	kernel', in what is called the <glossterm>user mode</glossterm>.
	The difference between system and application programs is
	one of intent: applications are intended for getting useful
	things done (or for playing, if it happens to be a game),
	whereas system programs are needed to get the system working.
	A word processor is an application; <command>mount</command>
	is a system program.  The difference is often somewhat blurry,
	however, and is important only to compulsive categorizers.</para>

	<para>An operating system can also contain compilers and their
	corresponding libraries (GCC and the C library in particular under
	Linux), although not all programming languages need be part of
	the operating system.  Documentation, and sometimes even games,
	can also be part of it.  Traditionally, the operating system has
	been defined by the contents of the installation tape or disks;
	with Linux it is not as clear since it is spread all over the
	FTP sites of the world.</para>

</sect1>

<sect1>
<title>Important parts of the kernel</title>

	<para>The Linux kernel consists of several important parts: process
	management, memory management, hardware device drivers, filesystem
	drivers, network management, and various other bits and pieces.
	<xref linkend="kerneloverview">
	shows some of them.</para>

		<figure id="kerneloverview" float="1">
		<title>Some of the more important parts of the Linux kernel</title>
		<graphic fileref="overview-kernel.png">
		</figure>

	<para>Probably the most important parts of the kernel (nothing else
	works without them) are memory management and 
	process management.  Memory management takes care of assigning
	memory areas and swap space areas to processes, parts of the
	kernel, and for the buffer cache.  Process management creates
	processes, and implements multitasking by switching the
	active process on the processor.</para>

	<para>At the lowest level, the kernel contains a hardware device
	driver for each kind of hardware it supports.  Since the world is
	full of different kinds of hardware, the number of hardware device
	drivers is large.  There are often many otherwise similar pieces
	of hardware that differ in how they are controlled by software.
	The similarities make it possible to have general classes of
	drivers that support similar operations; each member of the class
	has the same interface to the rest of the kernel but differs in
	what it needs to do to implement them.	For example, all disk
	drivers look alike to the rest of the kernel, i.e., they all
	have operations like `initialize the drive', `read sector N',
	and `write sector N'.</para>

	<para>Some software services provided by the kernel itself have
	similar properties, and can therefore be abstracted into classes.
	For example, the various network protocols have been abstracted
	into one programming interface, the BSD socket library.  Another
	example is the <glossterm>virtual filesystem</glossterm> (VFS)
	layer that abstracts the filesystem operations away from their
	implementation.  Each filesystem type provides an implementation
	of each filesystem operation.  When some entity tries to use
	a filesystem, the request goes via the VFS, which routes the
	request to the proper filesystem driver.</para>

</sect1>

<sect1>
<title>Major services in a UNIX system</title>

	<para>This section describes some of the more important UNIX
	services, but without much detail.  They are described more
	thoroughly in later chapters.</para>

<sect2>
<title><command>init</command></title>

	<para>The single most important service in a UNIX system is
	provided by <command>init</command>.  <command>init</command>
	is started as the first process of every UNIX system, as the last
	thing the kernel does when it boots.  When <command>init</command>
	starts, it continues the boot process by doing various startup
	chores (checking and mounting filesystems, starting daemons,
	etc).</para>

	<para>The exact list of things that <command>init</command>
	does depends on which flavor it is; there are several to choose
	from.  <command>init</command> usually provides the concept of
	<glossterm>single user mode</glossterm>, in which no one can
	log in and root uses a shell at the console; the usual mode is
	called <glossterm>multiuser mode</glossterm>.  Some flavors
	generalize this as <glossterm>run levels</glossterm>; single
	and multiuser modes are considered to be two run levels, and
	there can be additional ones as well, for example, to run X on
	the console.</para>

	<para>Linux allows for up to 10
	<glossterm>runlevels</glossterm>, 0-9, but usually only some of
	these are defined by default.  Runlevel 0 is defined as ``system
	halt''.  Runlevel 1 is defined as ``single user mode''.
	Runlevel 6 is defined as ``system reboot''.  Other runlevels are
	dependent on how your particular distribution has defined them,
	and they vary significantly between distributions.  Looking at 
	the contents of <filename>/etc/inittab</filename> usually will
	give some hint what the predefined runlevels are and what they
	have been defined as.</para>

	<para>In normal operation, <command>init</command> makes sure
	<command>getty</command> is working (to allow users to log in),
	and to adopt orphan processes (processes whose parent has died; in
	UNIX <emphasis>all</emphasis> processes <emphasis>must</emphasis>
	be in a single tree, so orphans must be adopted).</para>

	<para>When the system is shut down, it is <command>init</command>
	that is in charge of killing all other processes, unmounting all
	filesystems and stopping the processor, along with anything else
	it has been configured to do.</para>

</sect2>

<sect2>
<title>Logins from terminals</title>

	<para>Logins from terminals (via serial lines) and the console
	(when not running X) are provided by the <command>getty</command>
	program.  <command>init</command> starts a separate instance of
	<command>getty</command> for each terminal upon which logins are to
	be allowed.  <command>getty</command> reads the username and runs
	the <command>login</command> program, which reads the password.  If
	the username and password are correct, <command>login</command> runs
	the shell. When the shell terminates, i.e., the user logs out, or
	when <command>login</command> terminated because the username and
	password didn't match, <command>init</command> notices this and
	starts a new instance of <command>getty</command>. The kernel has no
	notion of logins, this is all handled by the
	<glossterm>system programs</glossterm>.</para>

</sect2>

<sect2>
<title>Syslog</title>

	<para>The kernel and many <glossterm>system programs</glossterm>
	produce error, warning, and other messages.  It is often important
	that these messages can be viewed later, even much later, so they
	should be written to a file.  The program doing this is
	<command>syslog</command>.  It can be configured to sort the
	messages to different files according to writer or degree of
	importance.  For example, kernel messages are often directed to a
	separate file from the others, since kernel messages are often more
	important and need to be read
	regularly to spot problems.</para>
	
</sect2>

<sect2>
<title>Periodic command execution: <command>cron</command> and
<command>at</command></title>

	<para>Both users and system administrators often need
	to run commands periodically.  For example, the system administrator
	might want to run a command to clean the directories with temporary
	files (<filename>/tmp</filename> and <filename>/var/tmp</filename>)
	from old files, to keep the disks from filling up, since not all
	programs clean up after
	themselves correctly.</para>

	<para>The <command>cron</command> service is set up to do this.
	Each user can have a <filename>crontab</filename> file, where she
	lists the commands she wishes to execute and the times they should
	be executed.  The <command>cron</command> daemon takes care of
	starting the commands when specified.</para>

	<para>The <command>at</command> service is similar to
	<command>cron</command>, but it is once only: the command is
	executed at the given time, but it is not repeated.</para>

	<para>See the manual pages cron(1), crontab(1), crontab(5), at(1) and
	atd(8) for more in depth information.</para>
</sect2>

<sect2>
<title>Graphical user interface</title>

	<para>UNIX and Linux don't incorporate the user interface
	into the kernel; instead, they let it be implemented by user level
	programs.  This applies for both text mode and graphical
	environments.</para>

	<para>This arrangement makes the system more flexible, but has
	the disadvantage that it is simple to implement a different user
	interface for each program, making the system harder to
	learn.</para>

	<para>The graphical environment primarily used with Linux
	is called the X Window System (X for short).  X also does
	not implement a user interface; it only implements a window
	system, i.e., tools with which a graphical user interface can
	be implemented.  Some popular window managers are: fvwm, icewm,
	blackbox and windowmaker.  There are also two popular desktop
	managers, KDE and Gnome.</para>

</sect2>

<sect2>
<title>Networking</title>

	<para>Networking is the act of connecting two or more computers
	so that they can communicate with each other.  The actual methods
	of connecting and communicating are slightly complicated, but
	the end result is very useful.</para>

	<para>UNIX operating systems have many networking features.
	Most basic services (filesystems, printing, backups, etc) can
	be done over the network.  This can make system administration
	easier, since it allows centralized administration, while
	still reaping in the benefits of microcomputing and distributed
	computing, such as lower costs and better fault tolerance.</para>

	<para>However, this book merely glances at networking; see the
	<citetitle>Linux Network Administrators' Guide</citetitle>
	<ulink url="http://www.tldp.org/LDP/nag2/index.html">
	http://www.tldp.org/LDP/nag2/index.html</ulink> for
	more information, including a basic description of how networks
	operate.</para>

</sect2>

<sect2>
<title>Network logins</title>

	<para>Network logins work a little differently than normal logins.
	There is a separate physical serial line for each terminal via
	which it is possible to log in.  For each person logging in via
	the network, there is a separate virtual network connection,
	and there can be any number of these.
	
		<footnote><para>Well, at least there can be many.  Network
		bandwidth still being a scarce resource, there is still
		some practical upper limit to the number of concurrent
		logins via one network connection.  </para></footnote>
		
	It is therefore not possible to run a separate
	<command>getty</command> for each possible virtual connection.
	There are also several different ways to log in via a network,
	<command>telnet</command> and <command>rlogin</command> being
	the major ones in TCP/IP networks.
		<footnote><para>These days many Linux system administrators 
		consider <command>telnet</command> and <command>rlogin
		</command> to be insecure and prefer <command>ssh
		</command>, the ``secure shell'', which encrypts traffic 
		going over the network, thereby making it far less likely 
		that the malicious can ``sniff'' your connection and gain 
		sensitive data like usernames and passwords.  It is
		highly recommended you use <command>ssh</command> rather than
		<command>telnet</command> or <command>rlogin</command>.  
		</para></footnote>
	</para>

	<para>Network logins have, instead of a herd of
	<command>getty</command>s, a single daemon per way of logging in
	(<command>telnet</command> and <command>rlogin</command> have
	separate daemons) that listens for all incoming login attempts.
	When it notices one, it starts a new instance of itself to
	handle that single attempt; the original instance continues to
	listen for other attempts.  The new instance works similarly
	to <command>getty</command>.</para>

</sect2>

<sect2>
<title>Network file systems</title>
	<para>One of the more useful things that can be done with
	networking services is sharing files via a <glossterm>network
	file system</glossterm>.  The one usually used is called the
	Network File System, or NFS, developed by Sun.</para>

	<para>With a network file system any file operations done by
	a program on one machine are sent over the network to another
	computer.  This fools the program to think that all the files
	on the other computer are actually on the computer the program
	is running on.	This makes information sharing extremely simple,
	since it requires no modifications to programs.</para>

	<para>Another popular way of sharing files is Samba <ulink
	url="http://www.samba.org">http://www.samba.org</ulink>.  This
	protocol allows the sharing of files with MS Windows machines
	(via Network Neighbourhood).  It also allows the sharing of
	printers across machines.</para>
</sect2>

<sect2>
<title>Mail</title>
	<para>Electronic mail is the most popularly used method for
	communicating via computer.  An electronic letter is stored in a
	file using a special format, and special mail programs are used
	to send and read the letters.</para>

	<para>Each user has an <glossterm>incoming mailbox</glossterm>
	(a file in the special format), where all new mail is stored.
	When someone sends mail, the mail program locates the receiver's
	mailbox and appends the letter to the mailbox file.  If the
	receiver's mailbox is in another machine, the letter is sent to
	the other machine, which delivers it to the mailbox as it best
	sees fit.</para>

	<para>The mail system consists of many programs.  The
	delivery of mail to local or remote mailboxes is done by one
	program (the <glossterm>mail transfer agent</glossterm> (MTA), 
	e.g., <command>sendmail</command>
	or <command>smail</command>), while the programs users use
	are many and varied (<glossterm>mail user agent</glossterm> (MUA),
	e.g., <command>pine</command>, <command>mutt</command>
	or <command>elm</command>).  The mailboxes are usually stored
	in <filename>/var/spool/mail</filename>.</para>

</sect2>

<sect2>
<title>Printing</title>
	<para>Only one person can use a printer at one time, but it is
	uneconomical not to share printers between users.  The printer is
	therefore managed by software that implements a <glossterm>print
	queue</glossterm>: all print jobs are put into a queue and
	whenever the printer is done with one job, the next one is sent
	to it automatically.  This relieves the users from organizing
	the print queue and fighting over control of the printer.
		<footnote><para>Instead, they form a new queue
		<emphasis>at</emphasis> the printer, waiting for their
		printouts, since no one ever seems to be able to get the
		queue software to know exactly when anyone's printout is
		really finished.  This is a great boost to intra-office
		social relations.</para></footnote>
	</para>

	<para>The print queue software also <glossterm>spools</glossterm>
	the printouts on disk, i.e., the text is kept in a file while
	the job is in the queue.  This allows an application program
	to spit out the print jobs quickly to the print queue software;
	the application does not have to wait until the job is actually
	printed to continue.  This is really convenient, since it
	allows one to print out one version, and not have to wait for
	it to be printed before one can make a completely revised new
	version.</para>

</sect2>

<sect2>
<title>The filesystem layout</title>
	<para>The filesystem is divided into many parts;
	usually along the lines of a root filesystem with
	<filename>/bin</filename>, <filename>/lib</filename>,
	<filename>/etc</filename>, <filename>/dev</filename>, and
	a few others; a <filename>/usr</filename> filesystem with
	programs and unchanging data; a <filename>/var</filename>
	filesystem with changing data (such as log files); and a
	<filename>/home</filename> filesystem for everyone's personal
	files.	Depending on the hardware configuration and the decisions
	of the system administrator, the division can be different;
	it can even be all in one filesystem.</para>

	<para><xref linkend="dir-tree-overview"> describes the filesystem
	layout in some little detail; the Filesystem Hierarchy Standard covers it
	in somewhat more detail.
		<footnote><para><ulink url="http://www.pathname.com/fhs/">
		http://www.pathname.com/fhs/</ulink></para></footnote>
	</para>
</sect2>
</sect1>
</chapter>


<chapter id="dir-tree-overview">
<title>Overview of the Directory Tree</title>

	<blockquote><para><quote> Two days later, there was Pooh, sitting
	on his branch, dangling his legs, and there, beside him, were
	four pots of honey...</quote> (A.A. Milne) </para></blockquote>

	<para>This chapter describes the important parts of a standard Linux
	directory tree, based on the Filesystem Hierarchy Standard. It
	outlines the normal way of breaking the directory tree into separate
	filesystems with different purposes and gives the motivation behind
	this particular split.  Not all Linux distributions follow this
	standard slavishly, but it is generic enough to give you an
	overview.</para>

<sect1>
<title>Background</title>

	<para>This chapter is loosely based on the <citetitle>Filesystems
	Hierarchy Standard</citetitle> (FHS)
       	    <footnote><para><ulink url="hhtp://www.pathname.com/fhs/">
	    http://www.pathname.com/fhs/</ulink></para></footnote>	
	version 2.1, which attempts to
	set a standard for how the directory tree in a Linux
	    
	    <footnote><para>Or any Unix like system.  For example the BSD
	    derivatives.</para></footnote> 

	system is organized. Such a standard has the advantage that it will
	be easier to write or port software for Linux, and to administer
	Linux machines, since everything should be in standardized places.
	There is no authority behind the standard that forces anyone to
	comply with it, but it has gained the support of many Linux
	distributions. It is not a good idea to break with the FHS without
	very compelling reasons.  The FHS attempts to follow Unix tradition
	and current trends, making Linux systems familiar to those with
	experience with other Unix systems, and vice versa.</para>

	<para>This chapter is not as detailed as the FHS.  A system
	administrator should also read the full FHS for a complete
	understanding.</para>

	<para>This chapter does not explain all files in detail. The
	intention is not to describe every file, but to give an overview of
	the system from a filesystem point of view. Further information on
	each file is available elsewhere in this manual or in the Linux
	manual pages.</para>

	<para>The full directory tree is intended to be breakable into
	smaller parts, each capable of being on its own disk or partition,
	to accommodate to disk size limits and to ease backup and other
	system administration tasks.  The major parts are the root
	(<filename>/</filename>), <filename>/usr</filename>,
	<filename>/var</filename>, and <filename>/home</filename>
	filesystems (see <xref linkend="fstree">).  Each part has a
	different purpose. The directory tree has been designed so that it
	works well in a network of Linux machines which may share some parts
	of the filesystems over a read-only device (e.g., a CD-ROM), or over
	the network with NFS.</para>

		<figure id="fstree" float="1"> <title>Parts of a Unix
		directory tree. Dashed lines indicate partition 
		limits.</title> <graphic fileref="fstree.png">
		</figure>
	
	<para>The roles of the different parts of the directory tree are
	described below.

	<itemizedlist>
	
		<listitem> <para>The root filesystem is specific for
		each machine (it is generally stored on a local disk,
		although it could be a ramdisk or network drive as well) and
		contains the files that are necessary for booting the system
		up, and to bring it up to such a state that the other
		filesystems may be mounted.  The contents of the root
		filesystem will therefore be sufficient for the single user
		state.	It will also contain tools for fixing a broken
		system, and for recovering lost files
		from backups.</para> </listitem>

		<listitem><para> The <filename>/usr</filename> filesystem
		contains all commands, libraries, manual pages, and other
		unchanging files needed during normal operation. No files in
		<filename>/usr</filename> should be specific for any given
		machine, nor should they be modified during normal use. This
		allows the files to be shared over the network, which can be
		cost-effective since it saves disk space (there can easily
		be hundreds of megabytes, increasingly multiple gigabytes in
		<filename>/usr</filename>).  It can make administration
		easier (only the master <filename>/usr</filename> needs to
		be changed when updating an application, not each machine
		separately) to have /usr network mounted.  Even if the
		filesystem is on a local disk, it could be mounted
		read-only, to lessen the chance of filesystem corruption 
		during a crash.</para></listitem>

		<listitem><para>The <filename>/var</filename>
		filesystem contains files that change, such as spool
		directories (for mail, news, printers, etc), log files,
		formatted manual pages, and temporary files. Traditionally
		everything in <filename>/var</filename> has been somewhere
		below <filename>/usr</filename>, but that made it impossible
		to mount <filename>/usr</filename>
		read-only.<para></listitem>

		<listitem><para> The <filename>/home</filename>
		filesystem contains the users' home directories, i.e., all
		the real data on the system.  Separating home directories to
		their own directory tree or filesystem makes backups easier;
		the other parts often do not have to be backed up, or at
		least not as often as they seldom change. A big
		<filename>/home</filename> might have to be broken across
		several filesystems, which requires adding an extra naming
		level below <filename>/home</filename>, for example
		<filename>/home/students</filename> and
		<filename>/home/staff</filename>.</para></listitem>

	</itemizedlist> </para>

	<para>Although the different parts have been called filesystems
	above, there is no requirement that they actually be on separate
	filesystems.  They could easily be kept in a single one if the
	system is a small single-user system and the user wants to keep
	things simple.	The directory tree might also be divided into
	filesystems differently, depending on how large the disks are, and
	how space is allocated for various purposes.  The important part,
	though, is that all the standard <emphasis>names</emphasis> work;
	even if, say, <filename>/var</filename> and
	<filename>/usr</filename> are actually on the same partition, the
	names <filename>/usr/lib/libc.a</filename> and
	<filename>/var/log/messages</filename> must work, for example by
	moving files below <filename>/var</filename> into
	<filename>/usr/var</filename>, and making <filename>/var</filename>
	a symlink to
	<filename>/usr/var</filename>.</para>

	<para>The Unix filesystem structure groups files according to 
	purpose, i.e., all commands are in one place, all data files in
	another, documentation in a third, and so on.  An alternative would
	be to group files files according to the program they belong to,
	i.e., all Emacs files would be in one directory, all TeX in another,
	and so on.  The problem with the latter approach is that it makes it
	difficult to share files (the program directory often contains both
	static and sharable and changing and non-sharable files), and
	sometimes to even find the files (e.g., manual pages in a huge
	number of places, and making the manual page programs find all of
	them is a maintenance
	nightmare).</para>

</sect1>

<sect1>
<title>The root filesystem</title>

	<para>The root filesystem should generally be small, since
	it contains very critical files and a small, infrequently
	modified filesystem has a better chance of not getting corrupted.
	A corrupted root filesystem will generally mean that the system
	becomes unbootable except with special measures (e.g., from a
	floppy), so you don't want to risk it.</para>

	<para>The root directory generally doesn't contain any files, except
	perhaps the standard boot image for the system, usually called
	<filename>/vmlinuz</filename>.  All other files are in 
	subdirectories in the root filesystems:

	<glosslist>

	<glossentry>
	<glossterm><filename>/bin</filename></glossterm>
	
		<glossdef><para>Commands needed during bootup
		that might be used by normal users (probably after
		bootup).</para></glossdef></glossentry>

	<glossentry> 
	<glossterm><filename>/sbin</filename></glossterm>

		<glossdef><para>Like <filename>/bin</filename>, but the
		commands are not intended for normal users, although they
		may use them if necessary and allowed.
		<filename>/sbin</filename> is not usually in the default
		path of normal users, but will be in root's default
		path.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/etc</filename></glossterm>
	
		<glossdef><para>Configuration files specific to the
		machine.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/root</filename></glossterm>

	        <glossdef><para>The home directory for user root.  This is
		usually not accessible to other users on the
		system</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/lib</filename></glossterm>

                <glossdef><para>Shared libraries needed by the programs on
		the root filesystem.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/lib/modules</filename></glossterm>

		<glossdef><para>Loadable kernel modules, especially those
		that are needed to boot the system when recovering from
		disasters (e.g., network and filesystem
		drivers).</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/dev</filename></glossterm>

                <glossdef><para>Device files.  Some of the more commonly
		used device files are examined in <xref linkend="device-list">
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/tmp</filename></glossterm>

		<glossdef><para>Temporary files.  Programs running after
		bootup should use <filename>/var/tmp</filename>, not
		<filename>/tmp</filename>, since the former is probably on a
		disk with more space.  Often /tmp will be a symbolic link to
		/var/tmp.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/boot</filename></glossterm>
		<glossdef><para>Files used by the bootstrap loader,
		e.g., LILO.  Kernel images are often kept here instead
		of in the root directory.  If there are many kernel
		images, the directory can easily grow rather big, and it
		might be better to keep it in a separate filesystem.
		Another reason would be to make sure the kernel
		images are within the first 1024 cylinders of an IDE
		disk.

		        <footnote><para>This 1024 cylinder limit is no
			longer true in most cases.  With modern BIOSes and
			later versions of LILO (the LInux LOader) the 1024
			cylinder limit can be passed with logical block
			addressing (LBA).  See the <command>lilo</command>
			manual page for more details.</para></footnote>
			
	       </para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/mnt</filename></glossterm>
		<glossdef><para>Mount point for temporary mounts by
		the system administrator.  Programs aren't supposed to mount
		on <filename>/mnt</filename> automatically.
		<filename>/mnt</filename> might be divided into
		subdirectories (e.g., <filename>/mnt/dosa</filename> might
		be the floppy drive using an MS-DOS filesystem, and
		<filename>/mnt/exta</filename> might be the same
		with an ext2 filesystem).</para></glossdef></glossentry>

	<glossentry> <glossterm><filename>/proc</filename>,
	<filename>/usr</filename>, <filename>/var</filename>,
	<filename>/home</filename></glossterm>

	<glossdef><para>Mount points
	for the other filesystems.

	        <footnote><para>Although <filename>/proc</filename> does not
		reside on any disk in reality.  See the section about
		<filename>/proc</filename> later in the
		chapter.</para></footnote>

	</para></glossdef></glossentry>

	</glosslist>
	</para>

</sect1>

<sect1>
<title>The <filename>/etc</filename> directory</title>

	<para>The <filename>/etc</filename> directory contains a lot
	of files.  Some of them are described below.  For others, you
	should determine which program they belong to and read the manual
	page for that program.	Many networking configuration files are
	in <filename>/etc</filename> as well, and are described in the
	<citetitle>Networking Administrators' Guide</citetitle>.

	<glosslist>
	
	<glossentry>
	<glossterm><filename>/etc/rc</filename> or 
<filename>/etc/rc.d</filename> or 
<filename>/etc/rc?.d</filename></glossterm>
		<glossdef><para>Scripts or directories of scripts
		to run at startup or when changing the run level.
		See <xref linkend="init"> for further
		information.  </para></glossdef></glossentry>

	<glossentry> 
	<glossterm><filename>/etc/passwd</filename></glossterm>

		<glossdef><para>The user database, with fields giving the
		username, real name, home directory, encrypted password, and
		other information about each user. The format is documented
		in the <command>passwd</command> manual page.  The encrypted
		passwords are much more commonly found in the
		<filename>/etc/shadow</filename> these days.  This means
		that almost everything about the user
		<emphasis>except</emphasis> the password is stored in the
		<filename>passwd</filename> file.  History and convention
		make a name change undesirable.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/etc/fdprm</filename></glossterm>
		<glossdef><para>Floppy disk parameter table.
		Describes what different floppy disk formats look
		like.  Used by <command>setfdprm</command>.  See the
		<command>setfdprm</command> manual page for more
		information.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/fstab</filename></glossterm>

		<glossdef><para>Lists the filesystems mounted automatically
		at startup by the <command>mount -a</command> command (in
		<filename>/etc/rc</filename> or equivalent startup file).
		Under Linux, also contains information about swap areas used
		automatically by <command>swapon -a</command>.  See <xref
		linkend="mount-and-umount"> and the <command>mount</command>
		manual page for more information.  Also
		<filename>fstab</filename> usually has its own manual page in
		section 5. </para></glossdef></glossentry>

	<glossentry> 
	<glossterm><filename>/etc/group</filename></glossterm>

		<glossdef><para>Similar to <filename>/etc/passwd</filename>,
		but describes groups instead of users.  See the
		<filename>group</filename> manual page in section 5 for more
		information. </para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/etc/inittab</filename></glossterm>
		<glossdef><para>Configuration file for
		<command>init</command>.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/issue</filename></glossterm>
		<glossdef><para>Output by <command>getty</command> before
		the login prompt.  Usually contains a short description or
		welcoming message to the system.  The contents are up to
		the system administrator.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/magic</filename></glossterm>
		<glossdef><para>The configuration file
		for <command>file</command>.  Contains the
		descriptions of various file formats based on
		which <command>file</command> guesses the type of
		the file.  See the <filename>magic</filename> and
		<command>file</command> manual pages for more information.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/motd</filename></glossterm>
		
		<glossdef><para>The message of the day, automatically
		output after a successful login.  Contents are up to the
		system administrator.  Often used for getting information
		to every user, such as warnings about planned downtimes.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/mtab</filename></glossterm>
		
		<glossdef><para>List of currently mounted filesystems.
		Initially set up by the bootup scripts, and updated
		automatically by the <command>mount</command>
		command.  Used when a list of mounted filesystems is
		needed, e.g., by the <command>df</command> command.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/shadow</filename></glossterm>

		<glossdef><para>Shadow password file on systems with shadow
		password software installed. Shadow passwords move the
		encrypted password from <filename>/etc/passwd</filename>
		into <filename>/etc/shadow</filename>; the latter is not
		readable by anyone except root.  This makes it harder to
		crack passwords.  If your distribution gives you a choice
		(many do) of whether or not to use shadow passwords then you
		are highly recommended to do
		so.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/etc/login.defs</filename></glossterm>

		<glossdef><para>Configuration file for the
		<command>login</command> command.  The
		<filename>login.defs</filename> file usually has a manual
		page in section 5. </para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/etc/printcap</filename></glossterm>

		<glossdef><para>Like <filename>/etc/termcap</filename>, but
		intended for printers.  However it uses different syntax.
		The <filename>printcap</filename> has a manual page in
		section 5. </para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/etc/profile</filename>, 
<filename>/etc/csh.login</filename>, 
<filename>/etc/csh.cshrc</filename></glossterm>
		<glossdef><para>Files executed at login or startup time
		by the Bourne or C shells.  These allow the system
		administrator to set global defaults for all users.
		See the manual pages for the respective shells.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/securetty</filename></glossterm>

		<glossdef><para>Identifies secure terminals, i.e., the
		terminals from which root is allowed to log in. Typically
		only the virtual consoles are listed, so that it becomes
		impossible (or at least harder) to gain superuser privileges
		by breaking into a system over a modem or a network.  Do not
		allow root logins over a network.  Prefer to log in as an
		unprivileged user and use <command>su</command> or
		<command>sudo</command> to gain root
		privileges.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/etc/shells</filename></glossterm>
		<glossdef><para>Lists trusted shells.  The
		<command>chsh</command> command allows users to change
		their login shell only to shells listed in this file.
		<command>ftpd</command>, the server process that provides
		FTP services for a machine, will check that the user's
		shell is listed in <filename>/etc/shells</filename>
		and will not let people log in unless the shell is
		listed there.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/etc/termcap</filename></glossterm>
		<glossdef><para>The terminal capability database.
		Describes by what ``escape sequences'' various terminals
		can be controlled.  Programs are written so that instead
		of directly outputting an escape sequence that only
		works on a particular brand of terminal, they look up
		the correct sequence to do whatever it is they want to
		do in <filename>/etc/termcap</filename>.  As a result
		most programs work with most kinds of terminals.
		See the <filename>termcap</filename>, curs_termcap,
		and <filename>terminfo</filename> manual pages for
		more information.  </para></glossdef></glossentry>

	</glosslist>
	</para>

</sect1>

<sect1>
<title>The <filename>/dev</filename> directory</title>

	<para>The <filename>/dev</filename> directory contains
	the special device files for all the devices.  The device files are
	named using special conventions; these are described in <xref
	linkend="device-list">.  The device files are created during
	installation, and later with the <command>/dev/MAKEDEV</command>
	script. The <command>/dev/MAKEDEV.local</command> is a script
	written by the system administrator that creates local-only device
	files or links (i.e. those that are not part of the standard
	<command>MAKEDEV</command>, such as device files for some
	non-standard device driver).</para>
	
</sect1>

<sect1>
<title>The <filename>/usr</filename> filesystem</title>

	<para>The <filename>/usr</filename> filesystem is often
	large, since all programs are installed there.	All files
	in <filename>/usr</filename> usually come from a Linux
	distribution; locally installed programs and other stuff goes
	below <filename>/usr/local</filename>.	This makes it possible
	to update the system from a new version of the distribution,
	or even a completely new distribution, without having to
	install all programs again.  Some of the subdirectories of
	<filename>/usr</filename> are listed below (some of the less
	important directories have been dropped; see the FSSTND for
	more information).

	<glosslist>
	
	<glossentry>
	<glossterm><filename>/usr/X11R6</filename></glossterm>

		<glossdef><para>The X Window System, all files. To simplify
		the development and installation of X, the X files have not
		been integrated into the rest of the system.  There is a
		directory tree below <filename>/usr/X11R6</filename> similar
		to that below <filename>/usr</filename> itself.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/usr/bin</filename></glossterm>

		<glossdef><para>Almost all user commands. Some commands are
		in <filename>/bin</filename> or in
		<filename>/usr/local/bin</filename>.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/usr/sbin</filename></glossterm>

		<glossdef><para>System administration commands that are not
		needed on the root filesystem, e.g., most server programs.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/usr/share/man</filename>, 
<filename>/usr/share/info</filename>, 
<filename>/usr/share/doc</filename></glossterm>

		<glossdef><para>Manual pages, GNU Info documents, and
		miscellaneous other documentation files, respectively.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/usr/include</filename></glossterm>
		<glossdef><para>Header files for the C
		programming language.  This should actually be below
		<filename>/usr/lib</filename> for consistency, but the
		tradition is overwhelmingly in support for this name.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/usr/lib</filename></glossterm>
		<glossdef><para>Unchanging data files for programs and
		subsystems, including some site-wide configuration
		files.	The name <filename>lib</filename> comes from library;
		originally libraries of programming subroutines
		were stored in <filename>/usr/lib</filename>.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/usr/local</filename></glossterm>

		<glossdef><para>The place for locally installed software and
		other files.  Distributions may not install anything in
		here.  It is reserved solely for the use of the local
		administrator.  This way he can be absolutely certain that
		no updates or upgrades to his distribution will overwrite
		any extra software he has installed
		locally.</para></glossdef></glossentry>

	</glosslist></para>

</sect1>

<sect1>
<title>The <filename>/var</filename> filesystem</title>

	<para>The <filename>/var</filename> contains data that is changed
	when the system is running normally.  It is specific for each
	system, i.e., not shared over the network with other computers.

	<glosslist>
	
	<glossentry>
	<glossterm><filename>/var/cache/man</filename></glossterm>

		<glossdef><para>A cache for man pages that are formatted on
		demand.  The source for manual pages is usually stored in
		<filename>/usr/share/man/man?/</filename> (where ? is the
		manual section.  See the manual page for
		<command>man</command> in section 7); some manual pages
		might come with a pre-formatted version, which might be
		stored in <filename>/usr/share/man/cat*</filename>. Other
		manual pages need to be formatted when they are first
		viewed; the formatted version is then stored in
		<filename>/var/cache/man</filename> so that the next person
		to view the same page won't have to wait for it to be
		formatted. </para></glossdef></glossentry>

        <glossentry>
	<glossterm><filename>/var/games</filename></glossterm>

	        <glossdef><para>Any variable data belonging to games in
		<filename>/usr</filename> should be placed here.  This is in
		case /usr is mounted read only.
		</para></glossdef></glossentry>


	<glossentry>
	<glossterm><filename>/var/lib</filename></glossterm>

		<glossdef><para>Files that change while the system is
		running normally.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/var/local</filename></glossterm>
		<glossdef><para>Variable data for programs that are
		installed in <filename>/usr/local</filename> (i.e.,
		programs that have been installed by the system
		administrator).  Note that even locally installed
		programs should use the other <filename>/var</filename>
		directories if they are appropriate, e.g.,
		<filename>/var/lock</filename>.</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/var/lock</filename></glossterm>
		<glossdef><para>Lock files.  Many programs
		follow a convention to create a lock file in
		<filename>/var/lock</filename> to indicate that they
		are using a particular device or file.	Other programs
		will notice the lock file and won't attempt to use the
		device or file.</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/var/log</filename></glossterm>

		<glossdef><para>Log files from various programs, especially
		<command>login</command>
		(<filename>/var/log/wtmp</filename>, which logs all logins
		and logouts into the system) and <command>syslog</command>
		(<filename>/var/log/messages</filename>, where all kernel
		and system program message are usually stored). Files in
		<filename>/var/log</filename> can often grow indefinitely,
		and may require cleaning at regular
		intervals.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/var/mail</filename></glossterm>

	        <glossdef><para>This is the FHS approved location for user
		mailbox files.  Depending on how far your distribution has
		gone towards FHS compliance, these files may still be held
		in <filename>/var/spool/mail</filename>.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/var/run</filename></glossterm>
		<glossdef><para>Files that contain information about the
		system that is valid until the system is next booted.
		For example, <filename>/var/run/utmp</filename>
		contains information about people currently logged
		in.</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/var/spool</filename></glossterm>

		<glossdef><para>Directories for news, printer queues, and
		other queued work. Each different spool has its own
		subdirectory below <filename>/var/spool</filename>, e.g.,
		the news spool is in <filename>/var/spool/news</filename>.
		Note that some installations which are not fully compliant
		with the latest version of the FHS may have user mailboxes
		under <filename>/var/spool/mail</filename>.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/var/tmp</filename></glossterm>
		<glossdef><para>Temporary files that are large
		or that need to exist for a longer time than
		what is allowed for <filename>/tmp</filename>.
		(Although the system administrator might not allow
		very old files in <filename>/var/tmp</filename>
		either.)</para></glossdef></glossentry>

	</glosslist></para>

</sect1>

<sect1>
<title>The <filename>/proc</filename> filesystem</title>

	<para>The <filename>/proc</filename> filesystem contains a
	illusionary filesystem.  It does not exist on a disk. Instead, the
	kernel creates it in memory.  It is used to provide information
	about the system (originally about processes, hence the name).  Some
	of the more important files and directories are explained below.
	The <filename>/proc</filename> filesystem is described in more
	detail in the <filename>proc</filename> manual page.

	<glosslist>
	
	<glossentry>
	<glossterm><filename>/proc/1</filename></glossterm>
		<glossdef><para>A directory with information about
		process number 1.  Each process has a directory below
		<filename>/proc</filename> with the name being its process
		identification number.	</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/proc/cpuinfo</filename></glossterm>
		<glossdef><para>Information about the processor,
		such as its type, make, model, and performance.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/devices</filename></glossterm>
		<glossdef><para>List of device drivers configured into the
		currently running kernel.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/dma</filename></glossterm>
		<glossdef><para>Shows which DMA channels are being used
		at the moment.	</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/filesystems</filename></glossterm>
		<glossdef><para>Filesystems configured into the kernel.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/interrupts</filename></glossterm>
		<glossdef><para>Shows which interrupts are
		in use, and how many of each there have been.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/ioports</filename></glossterm>
		<glossdef><para>Which I/O ports are in use at the moment.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/kcore</filename></glossterm>
		<glossdef><para>An image of the physical memory of
		the system.  This is exactly the same size as your
		physical memory, but does not really take up that much
		memory; it is generated on the fly as programs access it.
		(Remember: unless you copy it elsewhere, nothing under
		<filename>/proc</filename> takes up any disk space
		at all.)  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/kmsg</filename></glossterm>
		<glossdef><para>Messages output by the kernel.
		These are also routed to <command>syslog</command>.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/ksyms</filename></glossterm>
		<glossdef><para>Symbol table for the kernel.
		</para></glossdef></glossentry>	
	
	<glossentry>
	<glossterm><filename>/proc/loadavg</filename></glossterm>
		<glossdef><para>The `load average' of the system; three
		meaningless indicators of how much work the system has
		to do at the moment.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/meminfo</filename></glossterm>
		<glossdef><para>Information about memory usage, both
		physical and swap.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/modules</filename></glossterm>
		<glossdef><para>Which kernel modules are loaded at
		the moment.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/net</filename></glossterm>
		<glossdef><para>Status information about network
		protocols.  </para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/self</filename></glossterm>
		<glossdef><para>A symbolic link to the process
		directory of the program that is looking at
		<filename>/proc</filename>.  When two processes look at
		<filename>/proc</filename>, they get different links.
		This is mainly a convenience to make it easier
		for programs to get at their process directory.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/stat</filename></glossterm>
		<glossdef><para>Various statistics about the system, such
		as the number of page faults since the system was booted.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/uptime</filename></glossterm>
		<glossdef><para>The time the system has been up.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/proc/version</filename></glossterm>
		<glossdef><para>The kernel version.
		</para></glossdef></glossentry>
	
	</glosslist></para>

	<para>Note that while the above files tend to be easily readable
	text files, they can sometimes be formatted in a way that is not
	easily digestible.  There are many commands that do little more than
	read the above files and format them for easier understanding. For
	example, the <command>free</command> program reads
	<filename>/proc/meminfo</filename> and converts the amounts given in
	bytes to kilobytes (and adds a little more information, as
	well).</para>

</sect1>

</chapter>

<chapter id="device-list">
<title>Device Files</title>

<para>This chapter gives an overview of what a device file is, and how to
create one.  It also lists some of the more common device files.  The
canonical list of device files is
<filename>/usr/src/linux/Documentation/devices.txt</filename> if you have
the Linux kernel source code installed on your system.  The devices listed
here are correct as of kernel version 2.2.17.</para>

<sect1>
<title>The <command>MAKEDEV</command> Script</title>

        <para>Most device files will already be created and will be there
	ready to use after you install your Linux system.  If by some chance
	you need to create one which is not provided then you should first
	try to use the <command>MAKEDEV</command> script.  This script is
	usually located in <filename>/dev/MAKEDEV</filename> but might also
	have a copy (or a symbolic link) in
	<filename>/sbin/MAKEDEV</filename>.  If it turns out not to be in
	your path then you will need to specify the path to it
	explicitly.</para>
	
	<para>In general the command is used as:
	
	<screen>
	<prompt>#</prompt> <userinput>/dev/MAKEDEV -v ttyS0</userinput>
	<computeroutput>create ttyS0   c 4 64 root:dialout 0660</computeroutput>
	</screen>

	This will create the device file <filename>/dev/ttyS0</filename>
	with major node 4 and minor node 64 as a character device with
	access permissions 0660 with owner root and group dialout.</para>

	<para><filename>ttyS0</filename> is a serial port.  The major and
	minor node numbers are numbers understood by the kernel.  The kernel
	refers to hardware devices as numbers, this would be very difficult
	for us to remember, so we use filenames.  Access permissions of 0660
	means read and write permission for the owner (root in this case)
	and read and write permission for members of the group (dialout in 
	this case) with no access for anyone else.</para>
</sect1>

<sect1>
<title>The <command>mknod</command> command</title>

	<para><command>MAKEDEV</command> is the preferred way of creating
	device files which are not present.  However sometimes the
	<command>MAKEDEV</command> script will not know about the device
	file you wish to create.  This is where the <command>mknod</command>
	command comes in.  In order to use <command>mknod</command> you need
	to know the major and minor node numbers for the device you wish to
	create.  The <filename>devices.txt</filename> file in the kernel
	source documentation is the canonical source of this
	information.</para>

	<para>To take an example, let us suppose that our version of the
	<command>MAKEDEV</command> script does not know how to create the
	<filename>/dev/ttyS0</filename> device file.  We need to use
	<command>mknod</command> to create it.  We know from looking at the
	<filename>devices.txt</filename> file that it should be a character
	device with major number 4 and minor number 64.  So we now know all
	we need to create the file.

        <screen>
	<prompt>#</prompt> <userinput>mknod /dev/ttyS0 c 4 64</userinput>
	<prompt>#</prompt> <userinput>chown root.dialout /dev/ttyS0</userinput>
	<prompt>#</prompt> <userinput>chmod 0644 /dev/ttyS0</userinput>
	<prompt>#</prompt> <userinput>ls -l /dev/ttyS0</userinput>
<computeroutput>crw-rw----   1 root dialout    4,   64 Oct 23 18:23 /dev/ttyS0</computeroutput> 
	</screen>

	As you can see, many more steps are required to create the file.  In
	this example you can see the process required however.  It is
	unlikely in the extreme that the ttyS0 file would not be provided by
	the <command>MAKEDEV</command> script, but it suffices to illustrate
	the point.</para>
</sect1> 

<sect1>
<title>Device List</title>

	<para>This list which follows is by no means exhaustive or as
	detailed as it could be.  Many of these device files will need
	support compiled into your kernel for the hardware.  Read the kernel
	documentation to find details of any particular device.</para>
	
	<para>If you think there are other devices which should be included here but
	aren't then let me know.  I will try to include them in the next revision.</para>

        <glosslist>
	<glossentry>
	<glossterm><filename>/dev/dsp</filename></glossterm>

	    <glossdef><para>Digital Signal Processor.  Basically this forms
	    the interface between software which produces sound and your
	    soundcard.  It is a character device on major node 14 and minor
	    3.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/fd0</filename></glossterm>

	    <glossdef><para>The first floppy drive.  If you are lucky enough
	    to have several drives then they will be numbered sequentially.
	    It is a character device on major node 2 and minor
	    0.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/fb0</filename></glossterm>

	    <glossdef><para>The first framebuffer device. A framebuffer is
	    an abstraction layer between software and graphics hardware.
	    This means that applications do not need to know about what kind
	    of hardware you have but merely how to communicate with the
	    framebuffer driver's API (Application Programming Interface)
	    which is well defined and standardised.  The framebuffer is a
	    character device and is on major node 29 and minor
	    0.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/hda</filename></glossterm>

	    <glossdef><para><filename>/dev/hda</filename> is the master IDE
	    drive on the primary IDE controller.
	    <filename>/dev/hdb</filename> is the slave drive on the primary
	    controller.  <filename>/dev/hdc</filename> and
	    <filename>/dev/hdd</filename> are the master and slave devices
	    on the secondary controller respectively.  Each disk is divided
	    into partitions. Partitions 1-4 are primary partitions and
	    partitions 5 and above are logical partitions inside extended
	    partitions.  Therefore the device file which references each
	    partition is made up of several parts.  For example
	    <filename>/dev/hdc9</filename> references partition 9 (a logical
	    partition inside an extended partition type) on the master IDE
	    drive on the secondary IDE controller.  The major and minor node
	    numbers are somewhat complex.  For the first IDE controller all
	    partitions are block devices on major node 3.  The master drive
	    <filename>hda</filename> is at minor 0 and the slave drive
	    <filename>hdb</filename> is at minor 64.  For each partition
	    inside the drive add the partition number to the minor node
	    number for the drive.  For example
	    <filename>/dev/hdb5</filename> is major 3, minor 69 (64 + 5 =
	    69). Drives on the secondary interface are handled the same way,
	    but with major node 22.</para></glossdef></glossentry>

        <glossentry>
	<glossterm><filename>/dev/ht0</filename></glossterm>

	    <glossdef><para>The first IDE tape drive.  Subsequent drives are
	    numbered <filename>ht1</filename> etc.  They are character
	    devices on major node 37 and start at minor node 0 for
	    <filename>ht0</filename> 1 for <filename>ht1</filename>
	    etc.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/dev/js0</filename></glossterm>

	    <glossdef><para>The first analogue joystick.  Subsequent joysticks
	    are numbered <filename>js1</filename>, <filename>js2</filename>
	    etc.  Digital joysticks are called <filename>djs0</filename>,
	    <filename>djs1</filename> and so on.  They are character devices
	    on major node 15.  The analogue joysticks start at minor node 0
	    and go up to 127 (more than enough for even the most fanatic
	    gamer). Digital joysticks start at minor node
	    128.</para></glossdef></glossentry>

	<glossentry>
	<glossterm><filename>/dev/lp0</filename></glossterm>

	    <glossdef><para>The first parallel printer device.  Subsequent
	    printers are numbered <filename>lp1</filename>,
	    <filename>lp2</filename> etc.  They are character devices on
	    major mode 6 and minor nodes starting at 0 and numbered
	    sequentially.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/loop0</filename></glossterm>

	    <glossdef><para>The first loopback device.  Loopback devices are
	    used for mounting filesystems which are not located on other
	    block devices such as disks.  For example if you wish to mount
	    an iso9660 CD ROM image without burning it to CD then you need
	    to use a loopback device to do so.  This is usually transparent
	    to the user and is handled by the <command>mount</command>
	    command.  Refer to the manual pages for <command>mount</command>
	    and <command>losetup</command>.  The loopback devices are block
	    devices on major node 7 and with minor nodes starting at 0 and
	    numbered sequentially.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/md0</filename></glossterm>

	    <glossdef><para>First metadisk group.  Metadisks are related to
	    RAID (Redundant Array of Independent Disks) devices.  Please
	    refer to the various RAID HOWTOs at the LDP for more details.
	    Metadisk devices are block devices on major node 9 with minor
	    nodes starting at 0 and numbered
	    sequentially.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/mixer</filename></glossterm>

	    <glossdef><para>This is part of the OSS (Open Sound System)
	    driver. Refer to the OSS documentation at <ulink
	    url="http://www.opensound.com">http://www.opensound.com</ulink>
	    for more details.  It is a character device on major node 14,
	    minor node 0.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/null</filename></glossterm>

	    <glossdef><para>The bit bucket.  A black hole where you can send
	    data for it never to be seen again.  Anything sent to
	    <filename>/dev/null</filename> will disappear.  This can be
	    useful if, for example, you wish to run a command but not have
	    any feedback appear on the terminal.  It is a character device
	    on major node 1 and minor node 3.</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><filename>/dev/psaux</filename></glossterm>

	    <glossdef><para>The PS/2 mouse port.  This is a character device
	    on major node 10, minor node 1.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/pda</filename></glossterm>

	    <glossdef><para>Parallel port IDE disks.  These are named
	    similarly to disks on the internal IDE controllers
	    (<filename>/dev/hd*</filename>).  They are block devices on major
	    node 45. Minor nodes need slightly more explanation here.  The
	    first device is <filename>/dev/pda</filename> and it is on minor
	    node 0.  Partitions on this device are found by adding the
	    partition number to the minor number for the device.  Each
	    device is limited to 15 partitions each rather than 63 (the
	    limit for internal IDE disks).  <filename>/dev/pdb</filename>
	    minor nodes start at 16, <filename>/dev/pdc</filename> at 32 and
	    <filename>/dev/pdd</filename> at 48.  So for example the minor
	    node number for <filename>/dev/pdc6</filename> would be 38 (32 +
	    6 = 38).  This scheme limits you to 4 parallel disks of 15
	    partitions each.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/pcd0</filename></glossterm>

	    <glossdef><para>Parallel port CD ROM drives.  These are numbered
	    from 0 onwards.  All are block devices on major node 46.
	    <filename>/dev/pcd0</filename> is on minor node 0 with
	    subsequent drives being on minor nodes 1, 2, 3
	    etc.</para></glossdef></glossentry>


        <glossentry>
	<glossterm><filename>/dev/pt0</filename></glossterm>
	
	    <glossdef><para>Parallel port tape devices.  Tapes do not have
	    partitions so these are just numbered sequentially.  They are
	    character devices on major node 96.  The minor node numbers
	    start from 0 for <filename>/dev/pt0</filename>, 1 for
	    <filename>/dev/pt1</filename>, and so on.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/parport0</filename></glossterm>
	
	    <glossdef><para>The raw parallel ports.  Most devices which are
	    attached to parallel ports have their own drivers.  This is a
	    device to access the port directly.  It is a character device on
	    major node 99 with minor node 0.  Subsequent devices after the
	    first are numbered sequentially incrementing the minor
	    node.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/random</filename> or <filename>/dev/urandom</filename></glossterm>
	
	    <glossdef><para>These are kernel random number generators.
	    <filename>/dev/random</filename> is a non-deterministic
	    generator which means that the value of the next number cannot
	    be guessed from the preceding ones.  It uses the entropy of the
	    system hardware to generate numbers.  When it has no more
	    entropy to use then it must wait until it has collected more
	    before it will allow any more numbers to be read from it.
	    <filename>/dev/urandom</filename> works similarly.  Initially it
	    also uses the entropy of the system hardware, but when there is
	    no more entropy to use it will continue to return numbers using
	    a pseudo random number generating formula.  This is considered
	    to be less secure for vital purposes such as cryptographic key
	    pair generation.  If security is your overriding concern then
	    use <filename>/dev/random</filename>, if speed is more important
	    then <filename>/dev/urandom</filename> works fine.  They are
	    character devices on major node 1 with minor nodes 8 for
	    <filename>/dev/random</filename> and 9 for
	    <filename>/dev/urandom</filename>.</para></glossdef></glossentry>
	    
	<glossentry>
	<glossterm><filename>/dev/zero</filename></glossterm>
	
	    <glossdef><para>This is a simple way of getting many 0s.  Every
	    time you read from this device it will return 0.  This can be
	    useful sometimes, for example when you want a file of fixed
	    length but don't really care what it contains.  It is a
	    character device on major node 1 and minor node
	    5.</para></glossdef></glossentry>
</glosslist>	
	    
</sect1>
</chapter>

<chapter>
<title>Using Disks and Other Storage Media</title>

	<blockquote><para><quote>On a clear disk you can seek forever.
	</quote></para></blockquote>

<!--
% the following metas need too much work for the next version
%
%	\meta copying a directory/disk verbatim
%
%	\meta disaster recovery: program to scan for ext2 superblocks
%
%	\meta explain lost+found; how to fix a filesystem; what to do when
%	there is a bad block; identifying the file that has the bad block
%	
%	\meta chart that shows characteristics of various fs: max size,
%	max file size, usable as root, max name length, speed, support
%
%	\meta 
%	Recovering from a bad MBR or super block.
%	Manually remounting (ro->rw, rw->ro, when, why)
%	automounting
%	MD patches
%	Why does Linux read/write disk in background?
%	how to mount a dos disk so that everyone can access it?
%	supermount
%	ide disks map away bad sectors (until they're too many, then
%	use badblocks)
%	mounting: mountee root becomes mount point, e.g. 
permissions/ownership
%	linux has maximum of 15 partitions (not inherent in partition
%		scheme!)
%	max ext2 part size is 2TB, file 2 GB
%	ext2 fragmentation
%	list important device files for disks et al as a table
-->

        <para>When you install or upgrade your system, you need to do a
        fair amount of work on your disks.  You have to make filesystems on
	your disks so that files can be stored on them and reserve
        space for the different parts of your system.</para>

        <para>This chapter explains all these initial activities.  Usually,
        once you get your system set up, you won't have to go through the
	work again, except for using floppies.  You'll need to come back to
	this chapter if you add a new disk or want to fine-tune your disk usage.<para>

        <para>The basic tasks in administering disks are:

	<itemizedlist>

	<listitem><para>
        Format your disk.  This does various things to prepare it for use,
	such as checking for bad sectors.  (Formatting is nowadays
	not necessary for most hard disks.)</para></listitem>

	<listitem><para>
        Partition a hard disk, if you want to use it for several activities
	that aren't supposed to interfere with one another. One reason for
	partitioning is to store different operating systems on the same
	disk.  Another reason is to keep user files separate from system
	files, which simplifies back-ups and helps protect the system files
	from corruption.
	</para></listitem>

	<listitem><para>
        Make a filesystem (of a suitable type) on each disk or partition.
	The disk means nothing to Linux until you make a filesystem; then
	files can be created and accessed on it.
	</para></listitem>

	<listitem><para>
        Mount different filesystems to form a single tree structure, either
	automatically, or manually as needed.  (Manually mounted filesystems
	usually need to be unmounted manually as well.)
	</para></listitem>

	</itemizedlist>

	<para><xref linkend="memory-management"> contains information
	about virtual memory and disk caching, of which you also need
	to be aware when using disks.</para>

<sect1>
<title>Two kinds of devices</title>

	<para>UNIX, and therefore Linux, recognizes two different
	kinds of device: random-access block devices (such as disks), and
	character devices (such as tapes and serial lines), some of which
	may be serial, and some random-access.  Each supported device is
	represented in the filesystem as a <glossterm>device
	file</glossterm>.  When you read or write a device file, the data
	comes from or goes to the device it represents.  This way no special
	programs (and no special application programming methodology, such
	as catching interrupts or polling a serial port) are necessary to
	access devices; for example, to send a file to the printer, one
	could just say

<screen>
<prompt>$</prompt> <userinput>cat filename &gt; /dev/lp1</userinput>
<prompt>$</prompt>
</screen>

	and the contents of the file are printed (the file must, of course,
	be in a form that the printer understands).  However, since it is
	not a good idea to have several people cat their files to the
	printer at the same time, one usually uses a special program to send
	the files to be printed (usually <command>lpr</command>). This
	program makes sure that only one file is being printed at a time,
	and will automatically send files to the printer as soon as it
	finishes with the previous file.  Something similar is needed for
	most devices.  In fact, one seldom needs to worry
	about device files at all.</para>

	<para>Since devices show up as files in the filesystem (in the
	<filename>/dev</filename> directory), it is easy to see just what
	device files exist, using <command>ls</command> or another suitable
	command.  In the output of <command>ls -l</command>, the first
	column contains the type of the file and its permissions.  For
	example, inspecting a serial device might give

<screen>
<prompt>$</prompt> <userinput>ls -l /dev/ttyS0</userinput>
<computeroutput>crw-rw-r--    1 root     dialout    4,  64 Aug 19 18:56 /dev/ttyS0</computeroutput>
<prompt>$</prompt>
</screen>

	The first character in the first column, i.e.,
	`<literal>c</literal>' in <literal>crw-rw-rw-</literal> above, tells
	an informed user the type of the file, in this case a character
	device.  For ordinary files, the first character is
	`<literal>-</literal>', for directories it is
	`<literal>d</literal>', and for block devices
	`<literal>b</literal>'; see the <command>ls</command> man page
	for further information.</para>

	<para>Note that usually all device files exist even though the
	device itself might be not be installed.  So just because you have a
	file <filename>/dev/sda</filename>, it doesn't mean that you really
	do have an SCSI hard disk.  Having all the device files makes the
	installation programs simpler, and makes it easier to add new
	hardware (there is no need to find out the correct parameters
	for and create the device files for the new device).</para>

</sect1>

<sect1>
<title>Hard disks</title>

	<para>This subsection introduces terminology related to hard
	disks.	If you already know the terms and concepts, you can skip
	this subsection.</para>

	<para>See <xref linkend="hd-schematic"> for a schematic picture
	of the important parts in a hard disk.	A hard disk consists of one
	or more circular <glossterm>platters</glossterm>,
	
		<footnote><para>The platters are made of a hard
		substance, e.g., aluminum, which gives the hard disk
		its name.</para></footnote>
		
	of which either or both <glossterm>surfaces</glossterm> are coated
	with a magnetic substance used for recording the data.	For each
	surface, there is a <glossterm>read-write head</glossterm> that
	examines or alters the recorded data.  The platters rotate on a
	common axis; typical rotation speed is 5400 or 7200 rotations per
	minute, although high-performance hard disks have higher speeds and
	older disks may have lower speeds. The heads move along the radius
	of the platters; this movement combined with the rotation of the
	platters allows the head to access all parts of the surfaces.</para>

	<para>The processor (CPU) and the actual disk communicate through
	a <glossterm>disk controller</glossterm>.  This relieves the rest of
	the computer from knowing how to use the drive, since the
	controllers for different types of disks can be made to use the same
	interface towards the rest of the computer.  Therefore, the computer
	can say just ``hey disk, give me what I want'', instead of a long
	and complex series of electric signals to move the head to the
	proper location and waiting for the correct position to come under
	the head and doing all the other unpleasant stuff necessary. (In
	reality, the interface to the controller is still complex, but much
	less so than it would otherwise be.) The controller may also do
	other things, such as caching, or automatic bad sector 
	replacement.</para>

	<para>The above is usually all one needs to understand about the
	hardware.  There are also other things, such as the motor that
	rotates the platters and moves the heads, and the electronics that
	control the operation of the mechanical parts, but they are mostly
	not relevant for understanding the working principles of a hard 
	disk.</para>

	<para>The surfaces are usually divided into concentric rings,
	called <glossterm>tracks</glossterm>, and these in turn are divided
	into <glossterm>sectors</glossterm>.  This division is used to
	specify locations on the hard disk and to allocate disk space to
	files.  To find a given place on the hard disk, one might say
	``surface 3, track 5, sector 7''.  Usually the number of sectors is
	the same for all tracks, but some hard disks put more sectors in
	outer tracks (all sectors are of the same physical size, so more of
	them fit in the longer outer tracks). Typically, a sector will hold
	512 bytes of data.  The disk itself
	can't handle smaller amounts of data than one sector.</para>

		<figure id="hd-schematic" float="1">
		<title>A schematic picture of a hard disk.</title>
		<graphic fileref="hd-schematic.png">
		</figure>

	<para>Each surface is divided into tracks (and sectors) in
	the same way.  This means that when the head for one surface is on a
	track, the heads for the other surfaces are also on the
	corresponding tracks.  All the corresponding tracks taken together
	are called a <glossterm>cylinder</glossterm>.	It takes time to
	move the heads from one track (cylinder) to another, so by placing
	the data that is often accessed together (say, a file) so that it is
	within one cylinder, it is not necessary to move the heads to read
	all of it.  This improves performance. It is not always possible to
	place files like this; files that are stored in several places on
	the disk are called
	<glossterm>fragmented</glossterm>.</para>

	<para>The number of surfaces (or heads, which is the same thing),
	cylinders, and sectors vary a lot; the specification of the number
	of each is called the <glossterm>geometry</glossterm> of a hard
	disk.  The geometry is usually stored in a special, battery-powered
	memory location called the <glossterm>CMOS RAM</glossterm>, from
	where the operating system can fetch it during bootup or driver 
	initialization.</para>

	<para>Unfortunately, the BIOS
	
		<footnote><para>The BIOS is some built-in software stored on
		ROM chips.  It takes care, among other things, of the
		initial stages of booting.</para></footnote>
		
	has a design limitation, which makes it impossible to specify a
	track number that is larger than 1024 in the CMOS RAM, which is too
	little for a large hard disk.  To overcome this, the hard disk
	controller lies about the geometry, and <glossterm>translates the
	addresses</glossterm> given by the computer into something that fits
	reality.  For example, a hard disk might have 8 heads, 2048 tracks,
	and 35 sectors per track.
	
		<footnote><para>The numbers are completely
		imaginary.</para></footnote>
		
	Its controller could lie to the computer and claim that it has 16
	heads, 1024 tracks, and 35 sectors per track, thus not exceeding the
	limit on tracks, and translates the address that the computer gives
	it by halving the head number, and doubling the track number.  The
	mathematics can be more complicated in reality, because the numbers
	are not as nice as here (but again, the details are not relevant for
	understanding the principle). This translation distorts the
	operating system's view of how the disk is organized, thus making it
	impractical to use the all-data-on-one-cylinder trick to boost 
	performance.</para>

	<para>The translation is only a problem for IDE disks.	SCSI disks
	use a sequential sector number (i.e., the controller translates a
	sequential sector number to a head, cylinder, and sector triplet),
	and a completely different method for the CPU to talk with the
	controller, so they are insulated from the problem. Note, however,
	that the computer might not know the real geometry of an SCSI disk 
	either.</para>

	<para>Since Linux often will not know the real geometry of a disk,
	its filesystems don't even try to keep files within a single
	cylinder.  Instead, it tries to assign sequentially numbered sectors
	to files, which almost always gives similar performance. The issue
	is further complicated by on-controller caches, and automatic 
	prefetches done by the controller.</para>

	<para>Each hard disk is represented by a separate device
	file.  There can (usually) be only two or four IDE hard disks. These
	are known as <filename>/dev/hda</filename>,
	<filename>/dev/hdb</filename>, <filename>/dev/hdc</filename>, and
	<filename>/dev/hdd</filename>, respectively.  SCSI hard disks are
	known as <filename>/dev/sda</filename>,
	<filename>/dev/sdb</filename>, and so on.  Similar naming
	conventions exist for other hard disk types; see <xref
	linkend="device-list"> for more information.  Note that the device
	files for the hard disks give access to the entire disk, with no
	regard to partitions (which will be discussed below), and it's easy
	to mess up the partitions or the data in them if you aren't careful.
	The disks' device files are usually used only to get access to the
	master boot record (which will also be discussed below).</para>

</sect1>

<sect1>
<title>Floppies</title>

	<para>A floppy disk consists of a flexible membrane covered on one
	or both sides with similar magnetic substance as a hard disk. The
	floppy disk itself doesn't have a read-write head, that is included
	in the drive.  A floppy corresponds to one platter in a hard disk,
	but is removable and one drive can be used to access different
	floppies, and the same floppy can be read by many drives, whereas
	the hard disk is one indivisible unit.</para>

	<para>Like a hard disk, a floppy is divided into tracks and sectors
	(and the two corresponding tracks on either side of a floppy
	form a cylinder), but there are many fewer of them than on a
	hard disk.</para>

	<para>A floppy drive can usually use several different types of disks;
	for example, a 3.5 inch drive can use both 720 kB and 1.44 MB disks.
	Since the drive has to operate a bit differently and the operating
	system must know how big the disk is, there are many device files
	for floppy drives, one per combination of drive and disk type.
	Therefore, <filename>/dev/fd0H1440</filename> is the first floppy 
	drive (fd0), which must be a 3.5 inch drive, using a 3.5 inch, high
	density disk (H) of size 1440 kB (1440), i.e., a normal 3.5 inch HD
	floppy.
	</para>

	<para>The names for floppy drives are complex, however, and Linux
	therefore has a special floppy device type that automatically
	detects the type of the disk in the drive.  It works by trying to
	read the first sector of a newly inserted floppy using different
	floppy types until it finds the correct one. This naturally requires
	that the floppy is formatted first. The automatic devices are called
	<filename>/dev/fd0</filename>, <filename>/dev/fd1</filename>, and so 
	on.</para>

	<para>The parameters the automatic device uses to access a disk can
	also be set using the program <command>setfdprm</command>.  This can
	be useful if you need to use disks that do not follow any usual
	floppy sizes, e.g., if they have an unusual number of sectors, or if
	the autodetecting for some reason fails and the proper device file is 
	missing.</para>

	<para>Linux can handle many nonstandard floppy disk formats
	in addition to all the standard ones.  Some of these require using
	special formatting programs.  We'll skip these disk types for now,
	but in the mean time you can examine the
	<filename>/etc/fdprm</filename> file.  It specifies the settings
	that <command>setfdprm</command> recognizes.</para>

	<para>The operating system must know when a disk has been changed in
	a floppy drive, for example, in order to avoid using cached data
	from the previous disk.  Unfortunately, the signal line that is used
	for this is sometimes broken, and worse, this won't always be
	noticeable when using the drive from within MS-DOS. If you are
	experiencing weird problems using floppies, this might be the
	reason.  The only way to correct it is to repair the floppy drive.</para>

</sect1>

<sect1>
<title>CD-ROMs</title>

	<para>A CD-ROM drive uses an optically read, plastic coated disk.
	The information is recorded on the surface of the disk
	
		<footnote><para>That is, the surface inside the disk, on 
		the metal disk inside the plastic coating.</para></footnote>
		
	in small `holes' aligned along a spiral from the center to the edge.
	The drive directs a laser beam along the spiral to read the disk.
	When the laser hits a hole, the laser is reflected in one way; when
	it hits smooth surface, it is reflected in another way.  This makes
	it easy to code bits, and therefore information.  The rest is easy, 
	mere mechanics.</para>

	<para>CD-ROM drives are slow compared to hard disks.  Whereas a
	typical hard disk will have an average seek time less than 15
	milliseconds, a fast CD-ROM drive can use tenths of a second for
	seeks.  The actual data transfer rate is fairly high at hundreds of
	kilobytes per second.  The slowness means that CD-ROM drives are not
	as pleasant to use as hard disks (some Linux distributions provide
	`live' filesystems on CD-ROMs, making it unnecessary to copy the
	files to the hard disk, making installation easier and saving a lot
	of hard disk space), although it is still possible.  For installing
	new software, CD-ROMs are very good, since maximum speed is not
	essential during installation.</para>

	<para>There are several ways to arrange data on a CD-ROM.  The most
	popular one is specified by the international standard ISO 9660.
	This standard specifies a very minimal filesystem, which is even
	more crude than the one MS-DOS uses.  On the other hand, it is so
	minimal that every operating system should be able to map it to its 
	native system.</para>

	<para>For normal UNIX use, the ISO 9660 filesystem is not usable, so
	an extension to the standard has been developed, called the Rock
	Ridge extension.  Rock Ridge allows longer filenames, symbolic
	links, and a lot of other goodies, making a CD-ROM look more or less
	like any contemporary UNIX filesystem. Even better, a Rock Ridge
	filesystem is still a valid ISO 9660 filesystem, making it usable by
	non-UNIX systems as well. Linux supports both ISO 9660 and the Rock
	Ridge extensions;  the extensions are recognized and used 
	automatically.</para>

	<para>The filesystem is only half the battle, however.  Most CD-ROMs 
	contain data that requires a special program to access, and most of
	these programs do not run under Linux (except, possibly, under
	dosemu, the Linux MS-DOS emulator, or wine, the Windows emulator.
	
	        <footnote><para>Ironically perhaps, wine actually stands
		for ``Wine Is Not an Emulator''.  Wine, more strictly, is an
		API (Application Program Interface) replacement. Please see
		the wine documentation at <ulink
		url="http://www.winehq.com">http://www.winehq.com</ulink>
		for more information.</para></footnote>
	
	There is also VMWare, a commercial product which emulates an
	entire x86 machine in software

                <footnote><para>See the VMWare website, <ulink
		url="http://www.vmware.com">http://www.vmware.com</ulink>
		for more information.</para></footnote>)
	
	.</para>

	<para>A CD-ROM drive is accessed via the corresponding device file.
	There are several ways to connect a CD-ROM drive to the computer:
	via SCSI, via a sound card, or via EIDE.  The hardware hacking
	needed to do this is outside the scope of this book, but the
	type of connection decides the device file.</para>
	
</sect1>

<sect1>
<title>Tapes</title>

	<para>A tape drive uses a tape, similar
	
		<footnote><para>But completely
		different, of course.</para></footnote>
		
	to cassettes used for music.  A tape is serial in nature, which
	means that in order to get to any given part of it, you first have
	to go through all the parts in between.  A disk can be accessed
	randomly, i.e., you can jump directly to any place on the disk.
	The serial access of tapes makes them slow.</para>

	<para>On the other hand, tapes are relatively cheap to make,
	since they do not need to be fast.  They can also easily be made
	quite long, and can therefore contain a large amount of data. This
	makes tapes very suitable for things like archiving and backups,
	which do not require large speeds, but benefit from
	low costs and large storage capacities.</para>

</sect1>

<sect1>
<title>Formatting</title>

	<para><glossterm>Formatting</glossterm> is the process of writing marks 
	on the magnetic media that are used to mark tracks and sectors.
	Before a disk is formatted, its magnetic surface is a complete mess
	of magnetic signals.  When it is formatted, some order is brought
	into the chaos by essentially drawing lines where the tracks go, and
	where they are divided into sectors.  The actual details are not
	quite exactly like this, but that is irrelevant.  What is important
	is that a disk cannot be used unless it has been formatted.</para>

	<para>The terminology is a bit confusing here: in MS-DOS and MS 
	Windows, the word formatting is used to cover also the process of
	creating a filesystem (which will be discussed below).  There, the
	two processes are often combined, especially for floppies.  When the
	distinction needs to be made, the real formatting is called
	<glossterm>low-level formatting</glossterm>, while making the 
	filesystem is called <glossterm>high-level formatting</glossterm>.
	In UNIX circles, the two are called formatting and making a
	filesystem, so that's what is used in this book as well.</para>

	<para>For IDE and some SCSI disks the formatting is actually
	done at the factory and doesn't need to be repeated; hence most
	people rarely need to worry about it.  In fact, formatting a hard
	disk can cause it to work less well, for example because a disk
	might need to be formatted in some very special way to
	allow automatic bad sector replacement to work.</para>

	<para>Disks that need to be or can be formatted often require a
	special program anyway, because the interface to the formatting
	logic inside the drive is different from drive to drive. The
	formatting program is often either on the controller BIOS, or is
	supplied as an MS-DOS program; neither of these can easily
	be used from within Linux.</para>

	<para>During formatting one might encounter bad spots on the
	disk, called <glossterm>bad blocks</glossterm> or <glossterm>bad
	sectors</glossterm>.  These are sometimes handled by the drive
	itself, but even then, if more of them develop, something needs to
	be done to avoid using those parts of the disk.  The logic to do
	this is built into the filesystem; how to add the information into
	the filesystem is described below.  Alternatively, one might create
	a small partition that covers just the bad part of the disk; this
	approach might be a good idea if the bad spot is very large, since
	filesystems can sometimes have trouble with very large bad areas.</para>

	<para>Floppies are formatted with <command>fdformat</command>.  The 
	floppy device file to use is given as the parameter.  For example,
	the following command would format a high density, 3.5 inch floppy
	in the first floppy drive:

        <screen>
	<prompt>$</prompt> <userinput>fdformat /dev/fd0H1440</userinput>
	<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity 
	1440 kB.</computeroutput>
	<computeroutput>Formatting ... done</computeroutput>
	<computeroutput>Verifying ... done</computeroutput>
	<prompt>$</prompt>
	</screen>

	Note that if you want to use an autodetecting device (e.g.,
	<filename>/dev/fd0</filename>), you <emphasis>must</emphasis> set 
	the parameters of the device with <command>setfdprm</command> first.
	To achieve the same effect as above, one would have to do the
	following:

        <screen>
	<prompt>$</prompt> <userinput>setfdprm /dev/fd0 1440/1440</userinput>
	<prompt>$</prompt> <userinput>fdformat /dev/fd0</userinput>
	<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity 
	1440 kB.</computeroutput>
	<computeroutput>Formatting ... done</computeroutput>
	<computeroutput>Verifying ... done</computeroutput>
	<prompt>$</prompt>
	</screen>

	It is usually more convenient to choose the correct device file that
	matches the type of the floppy.  Note that it is unwise to format
	floppies to contain more information than what they are
	designed for.</para>

	<para><command>fdformat</command> will also validate the floppy, 
	i.e., check it for bad blocks.  It will try a bad block several
	times (you can usually hear this, the drive noise changes
	dramatically). If the floppy is only marginally bad (due to dirt on
	the read/write head, some errors are false signals),
	<command>fdformat</command> won't complain, but a real error will
	abort the validation process. The kernel will print log messages for
	each I/O error it finds; these will go to the console or, if
	<command>syslog</command> is being used, to the file
	<filename>/usr/log/messages</filename>.  <command>fdformat</command>
	itself won't tell where the error is (one usually doesn't care,
	floppies are cheap enough that a bad one is automatically thrown
	away).

        <screen>
	<prompt>$</prompt> <userinput>fdformat /dev/fd0H1440</userinput>
	<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity 
	1440 kB.</computeroutput>
	<computeroutput>Formatting ... done</computeroutput>
	<computeroutput>Verifying ... read: Unknown error</computeroutput>
	<prompt>$</prompt>
	</screen>

	The <command>badblocks</command> command can be used to search any 
	disk or partition for bad blocks (including a floppy).  It does not
	format the disk, so it can be used to check even existing
	filesystems.  The example below checks a 3.5 inch floppy with two
	bad blocks.

        <screen>
	<prompt>$</prompt> <userinput>badblocks /dev/fd0H1440 1440</userinput>
	<computeroutput>718</computeroutput>
	<computeroutput>719</computeroutput>
	<prompt>$</prompt>
	</screen>

	<command>badblocks</command> outputs the block numbers of the bad
	blocks it finds.  Most filesystems can avoid such bad blocks. They
	maintain a list of known bad blocks, which is initialised when the
	filesystem is made, and can be modified later.	The initial search
	for bad blocks can be done by the <command>mkfs</command> command
	(which initializes the filesystem), but later checks should be done
	with <command>badblocks</command> and the new blocks should be added
	with <command>fsck</command>.	We'll describe
	<command>mkfs</command>
	and <command>fsck</command> later.</para>

	<para>Many modern disks automatically notice bad blocks, and attempt
	to fix them by using a special, reserved good block instead. This is
	invisible to the operating system.  This feature should be
	documented in the disk's manual, if you're curious if it is
	happening.  Even such disks can fail, if the number of bad blocks
	grows too large, although chances are that by then the disk
	will be so rotten as to be unusable.</para>

</sect1>

<sect1>
<title>Partitions</title>

	<para>A hard disk can be divided into several
	<glossterm>partitions</glossterm>.  Each partition functions as if
	it were a separate hard disk.  The idea is that if you have one hard
	disk, and want to have, say, two operating systems on it, you can
	divide the disk into two partitions.  Each operating system uses its
	partition as it wishes and doesn't touch the other ones.  This way
	the two operating systems can co-exist peacefully on the same hard
	disk. Without partitions one would have to buy a hard disk for each 
	operating system.</para>

	<para>Floppies are not usually partitioned.  There is no technical reason
	against this, but since they're so small, partitions would be useful
	only very rarely.  CD-ROMs are usually also not partitioned, since
	it's easier to use them as one big disk, and there is seldom a need
	to have several operating systems on one.</para>

<sect2>
<title>The MBR, boot sectors and partition table</title>

	<para>The information about how a hard disk has been partitioned
	is stored in its first sector (that is, the first sector of the
	first track on the first disk surface).  The first sector is the
	<glossterm>master boot record</glossterm> (MBR) of the disk; this is
	the sector that the BIOS reads in and starts when the machine is
	first booted.  The master boot record contains a small program that
	reads the partition table, checks which partition is active (that
	is, marked bootable), and reads the first sector of that partition,
	the partition's <glossterm>boot sector</glossterm> (the MBR is also
	a boot sector, but it has a special status and therefore a special
	name).  This boot sector contains another small program that reads
	the first part of the operating system stored on that partition
	(assuming it is bootable), and then starts it.</para>

	<para>The partitioning scheme is not built into the hardware, or
	even into the BIOS.  It is only a convention that many operating
	systems follow.  Not all operating systems do follow it, but they
	are the exceptions.  Some operating systems support partitions, but
	they occupy one partition on the hard disk, and use their internal
	partitioning method within that partition.  The latter type exists
	peacefully with other operating systems (including Linux), and does
	not require any special measures, but an operating system that
	doesn't support partitions cannot co-exist on the same disk with any 
	other operating system.</para>

	<para>As a safety precaution, it is a good idea to write down the
	partition table on a piece of paper, so that if it ever corrupts you
	don't have to lose all your files.  (A bad partition table can be
	fixed with <command>fdisk</command>).  The relevant information is
	given by the <command>fdisk -l</command> command:

        <screen>
	<prompt>$</prompt> <userinput>fdisk -l /dev/hda</userinput>
	<computeroutput></computeroutput>
	<computeroutput>Disk /dev/hda: 15 heads, 57 sectors, 790 cylinders</computeroutput>
	<computeroutput>Units = cylinders of 855 * 512 bytes</computeroutput>
	<computeroutput></computeroutput>
	<computeroutput>   Device Boot  Begin   Start     End  Blocks   Id  System</computeroutput>
	<computeroutput>/dev/hda1           1       1      24   10231+  82  Linux swap</computeroutput>
	<computeroutput>/dev/hda2          25      25      48   10260   83  Linux native</computeroutput>
	<computeroutput>/dev/hda3          49      49     408  153900   83  Linux native</computeroutput>
	<computeroutput>/dev/hda4         409     409     790  163305    5  Extended</computeroutput>
	<computeroutput>/dev/hda5         409     409     744  143611+  83  Linux native</computeroutput>
	<computeroutput>/dev/hda6         745     745     790   19636+  83  Linux native</computeroutput>
	<prompt>$</prompt>
	</screen>

</sect2>

<sect2>
<title>Extended and logical partitions</title>

	<para>The original partitioning scheme for PC hard disks allowed
	only four partitions.  This quickly turned out to be too little in
	real life, partly because some people want more than four operating
	systems (Linux, MS-DOS, OS/2, Minix, FreeBSD, NetBSD, or Windows/NT,
	to name a few), but primarily because sometimes it is a good idea to
	have several partitions for one operating system.  For example, swap
	space is usually best put in its own partition for Linux instead of
	in the main Linux partition for reasons of speed (see below).</para>

	<para>To overcome this design problem, <glossterm>extended 
	partitions</glossterm> were invented.  This trick allows
	partitioning a <glossterm>primary partition</glossterm> into
	sub-partitions.  The primary partition thus subdivided is the
	<glossterm>extended partition</glossterm>; the sub-partitions are
	<glossterm>logical partitions</glossterm>.  They behave like primary
	partitions, but are created differently.  There is no speed
	difference between them.</para>

	<para>The partition structure of a hard disk might look like that
	in <xref linkend="hard-disk-layout">.  The disk is divided into
	three primary partitions, the second of which is divided into two
	logical partitions.  Part of the disk is not partitioned at all.
	The disk as a whole and each primary partition has a boot sector.</para>

		<figure id="hard-disk-layout" float="1">
		<title>A sample hard disk partitioning.</title>
		<graphic fileref="hd-layout.png">
		</figure>

</sect2>

<sect2>
<title>Partition types</title>

	<para>The partition tables (the one in the MBR, and the ones for
	extended partitions) contain one byte per partition that identifies
	the type of that partition.  This attempts to identify the operating
	system that uses the partition, or what it uses it for.  The purpose
	is to make it possible to avoid having two operating systems
	accidentally using the same partition.  However, in reality,
	operating systems do not really care about the partition type byte;
	e.g., Linux doesn't care at all what it is.  Worse, some of them use
	it incorrectly; e.g., at least some versions of DR-DOS ignore the
	most significant bit of the byte, while others don't.</para>

	<para>There is no standardization agency to specify what each byte
	value means, but some commonly accepted ones are included in in
	<xref linkend="partition-ids">.  A more complete list is available
	in the Linux <command>fdisk</command> program.</para>

	<table id="partition-ids"> 
	<title>Partition types (from the Linux <command>fdisk</command> program).</title>
	
	<tgroup cols=6>
	<tbody>
	
	<row>
	<entry>0</entry> <entry>Empty</entry>
	<entry>40</entry> <entry>Venix 80286</entry>
	<entry>94</entry> <entry>Amoeba BBT</entry>
	</row>
	
	<row>
	<entry>1</entry> <entry>DOS 12-bit FAT</entry>
	<entry>51</entry> <entry>Novell?</entry>
	<entry>a5</entry> <entry>BSD/386</entry>
	</row>
	
	<row>
	<entry>2</entry> <entry>XENIX root</entry>
	<entry>52</entry> <entry>Microport</entry>
	<entry>b7</entry> <entry>BSDI fs</entry>
	</row>
	
	<row>
	<entry>3</entry> <entry>XENIX usr</entry>
	<entry>63</entry> <entry>GNU HURD</entry>
	<entry>b8</entry> <entry>BSDI swap</entry>
	</row>
	
	<row>
	<entry>4</entry> <entry>DOS 16-bit FAT &lt;32M</entry>
	<entry>64</entry> <entry>Novell</entry>
	<entry>c7</entry> <entry>Syrinx</entry>
	</row>
	
	<row>
	<entry>5</entry> <entry>Extended</entry>
	<entry>75</entry> <entry>PC/IX</entry>
	<entry>db</entry> <entry>CP/M</entry>
	</row>
	
	<row>
	<entry>6</entry> <entry>DOS 16-bit &gt;=32M</entry>
	<entry>80</entry> <entry>Old MINIX</entry>
	<entry>e1</entry> <entry>DOS access</entry>
	</row>
	
	<row>
	<entry>7</entry> <entry>OS/2 HPFS</entry>
	<entry>81</entry> <entry>Linux/MINIX</entry>
	<entry>e3</entry> <entry>DOS R/O</entry>
	</row>
	
	<row>
	<entry>8</entry> <entry>AIX</entry>
	<entry>82</entry> <entry>Linux swap</entry>
	<entry>f2</entry> <entry>DOS secondary</entry>
	</row>
	
	<row>
	<entry>9</entry> <entry>AIX bootable</entry>
	<entry>83</entry> <entry>Linux native</entry>
	<entry>ff</entry> <entry>BBT</entry>
	</row>
	
	<row>
	<entry>a</entry> <entry>OS/2 Boot Manager</entry>
	<entry>93</entry> <entry>Amoeba</entry>
	<entry></entry> <entry></entry>
	</row>
	
	</tbody>
	</tgroup>
	</table>

</sect2>

<sect2>
<title>Partitioning a hard disk</title>

	<para>There are many programs for creating and removing
	partitions.  Most operating systems have their own, and it can be a
	good idea to use each operating system's own, just in case it does
	something unusual that the others can't. Many of the programs are
	called <command>fdisk</command>, including the Linux one, or
	variations thereof.  Details on using the Linux
	<command>fdisk</command> are given on its man page.  The
	<command>cfdisk</command> command is similar to
	<command>fdisk</command>, but has a nicer (full screen) user 
	interface.</para>

	<para>When using IDE disks, the boot partition (the partition
	with the bootable kernel image files) must be completely within the
	first 1024 cylinders.  This is because the disk is used via the BIOS
	during boot (before the system goes into protected mode), and BIOS
	can't handle more than 1024 cylinders. It is sometimes possible to
	use a boot partition that is only partly within the first 1024
	cylinders.  This works as long as all the files that are read with
	the BIOS are within the first 1024 cylinders.  Since this is
	difficult to arrange, it is <emphasis>a very bad idea</emphasis> to
	do it; you never know when a kernel update or disk defragmentation
	will result in an unbootable system.  Therefore, make sure your boot
	partition is completely within the first 1024 cylinders
		
		<footnote><para>This may no longer be true with newer
		versions of LILO that support LBA (Logical Block
		Addressing).  Consult the documentation for your
		distribution to see if it has a version of LILO where
		LBA is supported.</para></footnote>
	
	.</para>

	<para>Some newer versions of the BIOS and IDE disks can, in fact,
	handle disks with more than 1024 cylinders.  If you have such a
	system, you can forget about the problem; if you aren't quite
	sure of it, put it within the first 1024 cylinders.</para>

	<para>Each partition should have an even number of sectors,
	since the Linux filesystems use a 1 kilobyte block size, i.e., two
	sectors.  An odd number of sectors will result in the last sector
	being unused.  This won't result in any problems, but it is ugly,
	and some versions of <command>fdisk</command> will warn about it.</para>

	<para>Changing a partition's size usually requires first backing up
	everything you want to save from that partition (preferably the
	whole disk, just in case), deleting the partition, creating new
	partition, then restoring everything to the new partition. If the
	partition is growing, you may need to adjust the sizes (and backup and 
	restore) of the adjoining partitions as well.</para>

	<para>Since changing partition sizes is painful, it is preferable to
	get the partitions right the first time, or have an effective and
	easy to use backup system.  If you're installing from a media that
	does not require much human intervention (say, from CD-ROM, as
	opposed to floppies), it is often easy to play with different
	configuration at first. Since you don't already have data to back
	up, it is not so painful to modify partition sizes several times.</para>

	<para>There is a program for MS-DOS, called
	<command>fips</command>
		
		<footnote><para>The <command>fips</command> program is
		included in most Linux distributions.  The commercial
		partition manager ``Partition Magic'' also has a similar
		facility but with a nicer interface.  Please do remember
		that partitioning is dangerous.  Make
		<emphasis>sure</emphasis> you have a recent backup of
		any important data before you try changing partition
		sizes ``on the fly''.  The GNU program
		<command>parted</command> can resize other types of
		partitions as well as MS-DOS, but sometimes in a limited
		manner.  Consult the <command>parted</command> documentation
		before using it, better safe than sorry.
		</para></footnote>
	
	, which resizes an MS-DOS partition without requiring the backup and
	restore, but for other filesystems it is still necessary.</para>

</sect2>

<sect2>
<title>Device files and partitions</title>

	<para>Each partition and extended partition has its own
	device file.  The naming convention for these files is that a
	partition's number is appended after the name of the whole disk,
	with the convention that 1-4 are primary partitions (regardless of
	how many primary partitions there are) and number greater than 5 are
	logical partitions (regardless of within which primary partition
	they reside).  For example, <filename>/dev/hda1</filename> is the
	first primary partition on the first IDE hard disk, and
	<filename>/dev/sdb7</filename> is the third extended partition on
	the second SCSI hard disk.</para>

</sect2>

</sect1>

<sect1>
<title>Filesystems</title>

<sect2>
<title>What are filesystems?</title>

	<para>A <glossterm>filesystem</glossterm> is the methods and
	data structures that an operating system uses to keep track of files
	on a disk or partition; that is, the way the files are organized on
	the disk.  The word is also used to refer to a partition or disk
	that is used to store the files or the type of the filesystem.
	Thus, one might say ``I have two filesystems'' meaning one has two
	partitions on which one stores files, or that one is using the
	``extended filesystem'', meaning the type of the filesystem.</para>

        <para>The difference between a disk or partition and the 
	filesystem it contains is important.  A few programs (including,
	reasonably enough, programs that create filesystems) operate
	directly on the raw sectors of a disk or partition; if there is an
	existing file system there it will be destroyed or seriously
	corrupted.  Most programs operate on a filesystem, and therefore
	won't work on a partition that doesn't contain one (or that contains 
	one of the wrong type).</para>

	<para>Before a partition or disk can be used as a filesystem, it
	needs to be initialized, and the bookkeeping data structures need to
	be written to the disk.  This process is called
	<glossterm>making a filesystem</glossterm>.</para>

	<para>Most UNIX filesystem types have a similar general
	structure, although the exact details vary quite a bit. The central
	concepts are <glossterm>superblock</glossterm>,
	<glossterm>inode</glossterm>, <glossterm>data block</glossterm>,
	<glossterm>directory block</glossterm>, and <glossterm>indirection
	block</glossterm>.  The superblock contains information about the
	filesystem as a whole, such as its size (the exact information here
	depends on the filesystem).  An inode contains all information about
	a file, except its name.  The name is stored in the directory,
	together with the number of the inode. A directory entry consists of
	a filename and the number of the inode which represents the file.
	The inode contains the numbers of several data blocks, which are
	used to store the data in the file.  There is space only for a few
	data block numbers in the inode, however, and if more are needed,
	more space for pointers to the data blocks is allocated dynamically.
	These dynamically allocated blocks are indirect blocks; the name
	indicates that in order to find the data block, one has to find
	its number in the indirect block first.</para>

	<para>UNIX filesystems usually allow one to create a
	<glossterm>hole</glossterm> in a file (this is done with the 
	<function>lseek()</function> system call; check the manual page),
	which means that the filesystem just pretends that at a particular
	place in the file there is just zero bytes, but no actual disk
	sectors are reserved for that place in the file (this means that the
	file will use a bit less disk space). This happens especially often
	for small binaries, Linux shared libraries, some databases, and a
	few other special cases.  (Holes are implemented by storing a
	special value as the address of the data block in the indirect block
	or inode.  This special address means that no data block is
	allocated for that part of the file, ergo, there is a hole in the 
	file.)</para>

</sect2>

<sect2>
<title>Filesystems galore</title>

	<para>Linux supports several types of filesystems.  As of this
	writing the most important ones are:

	<glosslist>
	<glossentry>
	<glossterm>minix</glossterm>
		<glossdef><para>The oldest, presumed to be the most 
		reliable, but quite limited in features (some time stamps
		are missing, at most 30 character filenames) and restricted
		in capabilities (at most 64 MB per filesystem).
		</para></glossdef></glossentry>
		
	<glossentry>
	<glossterm>xia</glossterm>
		<glossdef><para>A modified version of the minix filesystem 
		that lifts the limits on the filenames and filesystem sizes,
		but does not otherwise introduce new features.  It is not
		very popular, but is reported to work very well.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm>ext3</glossterm>
		<glossdef><para>The ext3 filesystem has all the features of 
		the ext2 filesystem.  The difference is, journaling has been 
		added.  This improves performance and recovery time in case 
		of a system crash.  This has become more popular than ext2.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm>ext2</glossterm>
		<glossdef><para>The most featureful of the native Linux 
		filesystems.  It is designed to be easily upwards compatible, 
		so that new versions of the filesystem code do not require 
		re-making the existing filesystems.</para></glossdef>
		</glossentry>

	<glossentry>
	<glossterm>ext</glossterm>
		<glossdef><para>An older version of ext2 that wasn't upwards
		compatible.  It is hardly ever used in new installations any
		more, and most people have converted to ext2.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm>reiserfs</glossterm>
	        <glossdef><para>A more robust filesystem.  Journalling is
		used which makes data loss less likely.  Journalling is a
		mechanism whereby a record is kept of transaction which are
		to be performed, or which have been performed.  This allows
		the filesystem to reconstruct itself fairly easily after
		damage caused by, for example, improper
		shutdowns.</para></glossdef></glossentry>

	</para>

	<para>In addition, support for several foreign filesystems exists,
	to make it easier to exchange files with other operating systems.
	These foreign filesystems work just like native ones, except that
	they may be lacking in some usual UNIX features, or have curious
	limitations, or other oddities.

	<glosslist>

	<glossentry>
	<glossterm>msdos</glossterm>
		<glossdef><para>Compatibility with MS-DOS (and OS/2 and
		Windows NT) FAT filesystems.</para></glossdef></glossentry>

	<glossentry>
	<glossterm>umsdos</glossterm>
		<glossdef><para>Extends the msdos filesystem driver under
		Linux to get long filenames, owners, permissions, links, and
		device files. This allows a normal msdos filesystem to be
		used as if it were a Linux one, thus removing the need for a
		separate partition for Linux.</para></glossdef></glossentry>
		
	<glossentry>
	<glossterm>vfat</glossterm>
		<glossdef><para>This is an extension of the FAT filesystem
		known as FAT32.  It supports larger disk sizes than FAT.
		Most MS Windows disks are vfat.</para></glossdef>
	</glossentry>

	<glossentry>
	<glossterm>iso9660</glossterm>
		<glossdef><para>The standard CD-ROM filesystem; the popular
		Rock Ridge extension to the CD-ROM standard that allows
		longer file names is supported automatically.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm>nfs</glossterm>
		<glossdef><para>A networked filesystem that allows sharing a
		filesystem between many computers to allow easy access to
		the files from all of them.</para></glossdef></glossentry>

	<glossentry>
	<glossterm>smbfs</glossterm>
		<glossdef><para>A networks filesystem which allows sharing
		of a filesystem with an MS Windows computer.  It is
		compatible with the Windows file sharing protocols.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm>hpfs</glossterm>
		<glossdef><para>The OS/2 filesystem.
		</para></glossdef></glossentry>

	<glossentry>
	<glossterm>sysv</glossterm>
		<glossdef><para>SystemV/386, Coherent, and Xenix filesystems.
		</para></glossdef></glossentry>

	</glosslist>
	</para>

	<para>The choice of filesystem to use depends on the situation.  If
	compatibility or other reasons make one of the non-native
	filesystems necessary, then that one must be used.  If one can
	choose freely, then it is probably wisest to use ext3, since it has
	all the features of ext2, and is a journaled filesystem.</para>

	<para>There is also the proc filesystem, usually accessible as
	the <filename>/proc</filename> directory, which is not really a
	filesystem at all, even though it looks like one.  The proc
	filesystem makes it easy to access certain kernel data structures,
	such as the process list (hence the name). It makes these data
	structures look like a filesystem, and that filesystem can be
	manipulated with all the usual file tools.  For example, to get a
	listing of all processes one might use the command

<screen>
<prompt>$</prompt> <userinput>ls -l /proc</userinput>
<computeroutput>total 0
dr-xr-xr-x   4 root     root            0 Jan 31 20:37 1
dr-xr-xr-x   4 liw      users           0 Jan 31 20:37 63
dr-xr-xr-x   4 liw      users           0 Jan 31 20:37 94
dr-xr-xr-x   4 liw      users           0 Jan 31 20:37 95
dr-xr-xr-x   4 root     users           0 Jan 31 20:37 98
dr-xr-xr-x   4 liw      users           0 Jan 31 20:37 99
-r--r--r--   1 root     root            0 Jan 31 20:37 devices
-r--r--r--   1 root     root            0 Jan 31 20:37 dma
-r--r--r--   1 root     root            0 Jan 31 20:37 filesystems
-r--r--r--   1 root     root            0 Jan 31 20:37 interrupts
-r--------   1 root     root      8654848 Jan 31 20:37 kcore
-r--r--r--   1 root     root            0 Jan 31 11:50 kmsg
-r--r--r--   1 root     root            0 Jan 31 20:37 ksyms
-r--r--r--   1 root     root            0 Jan 31 11:51 loadavg
-r--r--r--   1 root     root            0 Jan 31 20:37 meminfo
-r--r--r--   1 root     root            0 Jan 31 20:37 modules
dr-xr-xr-x   2 root     root            0 Jan 31 20:37 net
dr-xr-xr-x   4 root     root            0 Jan 31 20:37 self
-r--r--r--   1 root     root            0 Jan 31 20:37 stat
-r--r--r--   1 root     root            0 Jan 31 20:37 uptime
-r--r--r--   1 root     root            0 Jan 31 20:37 
version</computeroutput>
<prompt>$</prompt>
</screen>

	(There will be a few extra files that don't correspond to
	processes, though.  The above example has been shortened.)</para>

	<para>Note that even though it is called a filesystem, no part of 
	the proc filesystem touches any disk.  It exists only in the
	kernel's imagination.  Whenever anyone tries to look at any part of
	the proc filesystem, the kernel makes it look as if the part existed
	somewhere, even though it doesn't.  So, even though there is a
	multi-megabyte <filename>/proc/kcore</filename> file, it doesn't
	take any disk space. </sect2>

<sect2>
<title>Which filesystem should be used?</title>

	<para>There is usually little point in using many different
	filesystems.  Currently, ext3 is the most popular filesystem, because
	it is a journaled filesystem. Currently it is probably the wisest 
	choice.  Reiserfs is another popular choice because it to is journaled.
	Depending on the overhead for bookkeeping structures, speed, (perceived) 
	reliability, compatibility, and various other reasons, it may be 
	advisable to use another file system.  This needs to be decided on a 
	case-by-case basis.</para>	
	
	<para> A filesystem that uses journaling is also called a journaled
	filesystem.  A journaled filesystem maintains a log, or journal, of
	what has happened on a filesystem.  In the event of a system crash, or
	if your 2 year old son hits the power button like mine loves to do, a 
	journaled filesystem is designed to use the filesystem's logs to recreate 
	unsaved and lost data.  This makes data loss much less likely and 
	will likely become a standard feature in Linux filesystems.  However,
	do not get a false sense of security from this.  Like everything 
	else, errors can arise.  Always make sure to back up your data in the 
	event of an emergency.
	</para>
	
</sect2>

<sect2>
<title>Creating a filesystem</title>

	<para>Filesystems are created, i.e., initialized, with the 
	<command>mkfs</command> command.  There is actually a separate
	program for each filesystem type.  <command>mkfs</command> is just a
	front end that runs the appropriate program depending on the desired
	filesystem type.  The type is selected with the 
	<option>-t fstype</option> option.</para>

	<para>The programs called by <command>mkfs</command> have slightly
	different command line interfaces.  The common and most important
	options are summarized below; see the manual pages for more.

	<glosslist>
	<glossentry>
	<glossterm><option>-t fstype</option></glossterm>
		<glossdef><para>
		Select the type of the filesystem.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm><option>-c</option></glossterm>
		<glossdef><para>
		 Search for bad blocks and initialize the bad
		block list accordingly.
		</para></glossdef></glossentry>
	
	<glossentry>
	<glossterm>-l filename</glossterm>
		<glossdef><para>
		Read the initial bad block list from the name file.
		</para></glossdef></glossentry>
	</glosslist>
	</para>

	<para>To create an ext2 filesystem on a floppy, one would give the
	following commands:

<screen>
<prompt>$</prompt> <userinput>fdformat -n /dev/fd0H1440</userinput>
<computeroutput>Double-sided, 80 tracks, 18 sec/track. Total capacity 
1440 kB.
Formatting ... done</computeroutput>
<prompt>$</prompt> <userinput>badblocks /dev/fd0H1440 1440 $>$ 
bad-blocks</userinput>
<prompt>$</prompt> <userinput>mkfs -t ext2 -l bad-blocks 
/dev/fd0H1440</userinput>
<computeroutput>mke2fs 0.5a, 5-Apr-94 for EXT2 FS 0.5, 94/03/10
360 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1 block group
8192 blocks per group, 8192 fragments per group
360 inodes per group

Writing in