Gentoo Archives: gentoo-doc-cvs

From: Lukasz Damentko <rane@×××××××××××.org>
To: gentoo-doc-cvs@l.g.o
Subject: [gentoo-doc-cvs] cvs commit: lpi-101-advanced-p4.xml
Date: Sun, 01 Jan 2006 09:01:43
Message-Id: 200601010901.k0191Kf5022984@robin.gentoo.org
1 rane 06/01/01 09:01:19
2
3 Added: xml/htdocs/doc/en/articles lpi-101-advanced-p4.xml
4 lpi-101-intermediate-p3.xml
5 Log:
6 #115044, two new articles, xmlified by Damian Kuras (ShadoWW)
7
8 Revision Changes Path
9 1.1 xml/htdocs/doc/en/articles/lpi-101-advanced-p4.xml
10
11 file : http://www.gentoo.org/cgi-bin/viewcvs.cgi/xml/htdocs/doc/en/articles/lpi-101-advanced-p4.xml?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=gentoo
12 plain: http://www.gentoo.org/cgi-bin/viewcvs.cgi/xml/htdocs/doc/en/articles/lpi-101-advanced-p4.xml?rev=1.1&content-type=text/plain&cvsroot=gentoo
13
14 Index: lpi-101-advanced-p4.xml
15 ===================================================================
16 <?xml version="1.0" encoding="UTF-8"?>
17 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
18 <!-- $Header: -->
19
20 <guide link="/doc/en/articles/lpi-101-advanced-p4.xml" disclaimer="articles">
21 <title>LPI certification 101 (release 2) exam prep, Part 4</title>
22
23 <author title="Author">
24 <mail link="drobbins@g.o">Daniel Robbins</mail>
25 </author>
26 <author title="Author">
27 <mail link="chouser@g.o">Chris Houser</mail>
28 </author>
29 <author title="Author">
30 <mail link="agriffis@g.o">Aron Griffis</mail>
31 </author>
32
33 <abstract>
34 In this tutorial, we'll introduce all popular filesystem on Linux. We'll teach
35 you how to mount and unmount devices. In next chapter you'll know how to boot
36 the system and how to work with runlevels. In next section of this tutorial,
37 we'll introduce filesystem quotas, we will teach you how to set them and how to
38 configure them. By the end of this tutorial you'll know a system logs.
39 </abstract>
40
41 <!-- The original version of this article was first published on IBM
42 developerWorks, and is property of Westtech Information Services. This
43 document is an updated version of the original article, and contains
44 various improvements made by the Gentoo Linux Documentation team -->
45
46 <version>1.0</version>
47 <date>2005-12-17</date>
48
49 <chapter>
50 <title>Before you start</title>
51 <section>
52 <title>About this tutorial</title>
53 <body>
54
55 <p>
56 Welcome to "Advanced administration," the last of four tutorials designed to
57 prepare you for the Linux Professional Institute's 101 (release 2) exam. In
58 this tutorial (Part 4), we'll bolster your knowledge of advanced Linux
59 administration skills by covering a variety of topics including Linux
60 filesystems, the Linux boot process, runlevels, filesystem quotas, and system
61 logs.
62 </p>
63
64 <p>
65 This tutorial is particularly appropriate for someone who may be serving as the
66 primary sysadmin for the first time, since we cover a lot of low-level issues
67 that all system administrators should know. If you are new to Linux, we
68 recommend that you start with <uri
69 link="/doc/en/articles/lpi-101-fundamentals-p1.xml">Part 1</uri> and work
70 through the series from there. For some, much of this material will be new, but
71 more experienced Linux users may find this tutorial to be a great way of
72 "rounding out" their foundational Linux system administration skills and
73 preparing for the next LPI certification level.
74 </p>
75
76 <p>
77 By the end of this series of tutorials (eight in all covering the LPI 101 and
78 102 exams), you will have the knowledge you need to become a Linux Systems
79 Administrator and will be ready to attain an LPIC Level 1 certification from
80 the Linux Professional Institute if you so choose.
81 </p>
82
83 <p>
84 For those who have taken the <uri
85 link="http://www-106.ibm.com/developerworks/edu/l-dw-linuxlpi4-i.html">release
86 1 version</uri> of this tutorial for reasons other than LPI exam preparation,
87 you probably don't need to take this one. However, if you do plan to take the
88 exams, you should strongly consider reading this revised tutorial.
89 </p>
90
91 <p>
92 The LPI logo is a trademark of Linux Professional Institute.
93 </p>
94
95 </body>
96 </section>
97 <section>
98 <title>About the authors</title>
99 <body>
100
101 <p>
102 For technical questions about the content of this tutorial, contact the
103 authors:
104 </p>
105
106 <ul>
107 <li>Daniel Robbins, at <mail>drobbins@g.o</mail></li>
108 <li>Chris Houser, at <mail>chouser@g.o</mail></li>
109 <li>Aron Griffis, at <mail>agriffis@g.o</mail>.</li>
110 </ul>
111
112 <p>
113 Daniel Robbins lives in Albuquerque, New Mexico, and is the Chief Architect of
114 <uri link="http://www.gentoo.org">Gentoo Technologies, Inc.</uri>, the creator
115 of Gentoo Linux, an advanced Linux for the PC, and the Portage system, a
116 next-generation ports system for Linux. He has also served as a contributing
117 author for the Macmillan books Caldera OpenLinux Unleashed, SuSE Linux
118 Unleashed, and Samba Unleashed. Daniel has been involved with computers in some
119 fashion since the second grade, when he was first exposed to the Logo
120 programming language as well as a potentially dangerous dose of Pac Man. This
121 probably explains why he has since served as a Lead Graphic Artist at SONY
122 Electronic Publishing/Psygnosis. Daniel enjoys spending time with his wife,
123 Mary, and their daughter, Hadassah.
124 </p>
125
126 <p>
127 Chris Houser, known to his friends as "Chouser," has been a UNIX proponent
128 since 1994 when joined the administration team for the computer science network
129 at Taylor University in Indiana, where he earned his Bachelor's degree in
130 Computer Science and Mathematics. Since then, he has gone on to work in Web
131 application programming, user interface design, professional video software
132 support, and now Tru64 UNIX device driver programming at <uri
133 link="http://www.compaq.com/">Compaq</uri>. He has also contributed to various
134 free software projects, most recently to <uri
135 link="http://www.gentoo.org">Gentoo Linux</uri>. He lives with his wife and two
136 cats in New Hampshire.
137 </p>
138
139 <p>
140 Aron Griffis graduated from Taylor University with a degree in Computer Science
141 and an award that proclaimed him the "Future Founder of a Utopian UNIX
142 Commune". Working towards that goal, Aron is employed by <uri
143 link="http://www.compaq.com/">Compaq</uri> writing network drivers for Tru64
144 UNIX, and spending his spare time plunking out tunes on the piano or developing
145 <uri link="http://www.gentoo.org">Gentoo Linux</uri>. He lives with his wife
146 Amy (also a UNIX engineer) in Nashua, NH.
147 </p>
148
149 </body>
150 </section>
151 </chapter>
152
153 <chapter>
154 <title>Filesystems, partitions, and block devices</title>
155 <section>
156 <title>Introduction to block devices</title>
157 <body>
158
159 <p>
160 In this section, we'll take a good look at disk-oriented aspects of Linux,
161 including Linux filesystems, partitions, and block devices. Once you're familar
162 with the ins and outs of disks and filesystems, we'll guide you through the
163 process of setting up partitions and filesystems on Linux.
164 </p>
165
166 <p>
167 To begin, I'll introduce "block devices". The most famous block device is
168 probably the one that represents the first IDE drive in a Linux system:
169 </p>
170
171 <pre caption="First IDE drive in Linux">
172 /dev/hda
173 </pre>
174
175 <p>
176 If your system uses SCSI drives, then your first hard drive will be:
177 </p>
178
179 <pre caption="First SCSI drive in Linux">
180 /dev/sda
181 </pre>
182
183 </body>
184 </section>
185 <section>
186 <title>Layers of abstraction</title>
187 <body>
188
189 <p>
190 The block devices above represent an abstract interface to the disk. User
191 programs can use these block devices to interact with your disk without
192 worrying about whether your drivers are IDE, SCSI, or something else. The
193 program can simply address the storage on the disk as a bunch of contiguous,
194 randomly-accessible 512-byte blocks.
195 </p>
196
197 </body>
198 </section>
199 <section>
200 <title>Partitions</title>
201 <body>
202
203 <p>
204 Under Linux, we create filesystems by using a special command called
205 <c>mkfs</c> (or <c>mke2fs</c>, <c>mkreiserfs</c>, etc.), specifying a
206 particular block device as a command-line argument.
207 </p>
208
209 <p>
210 However, although it is theoretically possible to use a "whole disk" block
211 device (one that represents the entire disk) like <path>/dev/hda</path> or
212 <path>/dev/sda</path> to house a single filesystem, this is almost never done
213 in practice. Instead, full disk block devices are split up into smaller, more
214 manageable block devices called partititons. Partitions are created using a
215 tool called <c>fdisk</c>, which is used to create and edit the partition table
216 that's stored on each disk. The partition table defines exactly how to split up
217 the full disk.
218 </p>
219
220 </body>
221 </section>
222 <section>
223 <title>Introducing fdisk</title>
224 <body>
225
226 <p>
227 We can take a look at a disk's partition table by running <c>fdisk</c>,
228 specifying a block device that represents a full disk as an argument.
229 </p>
230
231 <note>
232 Alternate interfaces to the disk's partition table include <c>cfdisk</c>,
233 <c>parted</c>, and <c>partimage</c>. I recommend that you avoid using
234 <c>cfdisk</c> (despite what the fdisk manual page may say) because it sometimes
235 calculates disk geometry incorrectly.
236 </note>
237
238 <pre caption="Using fdisk on IDE drive">
239 # <i>fdisk /dev/hda</i>
240 </pre>
241
242 <pre caption="Using fidks on SCSI drive">
243 # <i>fdisk /dev/sda</i>
244 </pre>
245
246 <impo>
247 You should <e>not</e> save or make any changes to a disk's partition table if
248 any of its partitions contain filesystems that are in use or contain important
249 data. Doing so will generally cause data on the disk to be lost.
250 </impo>
251
252 </body>
253 </section>
254 <section>
255 <title>Inside fdisk</title>
256 <body>
257
258 <p>
259 Once in <c>fdisk</c>, you'll be greeted with a prompt that looks like this:
260 </p>
261
262 <pre caption="fidsk greeting prompt">
263 Command (m for help):
264 </pre>
265
266 <p>
267 Type <c>p</c> to display your disk's current partition configuration:
268 </p>
269
270 <pre caption="Displaying current parition configuration">
271 Command (m for help): p
272
273 Disk /dev/hda: 240 heads, 63 sectors, 2184 cylinders
274 Units = cylinders of 15120 * 512 bytes
275
276 Device Boot Start End Blocks Id System
277 /dev/hda1 1 14 105808+ 83 Linux
278 /dev/hda2 15 49 264600 82 Linux swap
279 /dev/hda3 50 70 158760 83 Linux
280 /dev/hda4 71 2184 15981840 5 Extended
281 /dev/hda5 71 209 1050808+ 83 Linux
282 /dev/hda6 210 348 1050808+ 83 Linux
283 /dev/hda7 349 626 2101648+ 83 Linux
284 /dev/hda8 627 904 2101648+ 83 Linux
285 /dev/hda9 905 2184 9676768+ 83 Linux
286
287 Command (m for help):
288 </pre>
289
290 <p>
291 This particular disk is configured to house seven Linux filesystems (each with
292 a corresponding partition listed as "Linux") as well as a swap partition
293 (listed as "Linux swap").
294 </p>
295
296 </body>
297 </section>
298 <section>
299 <title>Block device and partitioning overview</title>
300 <body>
301
302 <p>
303 Notice the name of the corresponding partition block devices on the left side,
304 starting with <path>/dev/hda1</path> and going up to <path>/dev/hda9</path>. In
305 the early days of the PC, partitioning software only allowed a maximum of four
306 partitions (called primary partitions). This was too limiting, so a workaround
307 called extended partitioning was created. An extended partition is very similar
308 to a primary partition, and counts towards the primary partition limit of four.
309 However, extended partitions can hold any number of so-called logical
310 partitions inside them, providing an effective means of working around the four
311 partition limit.
312 </p>
313
314 </body>
315 </section>
316 <section>
317 <title>Partitioning overview, continued</title>
318 <body>
319
320 <p>
321 All partitions hda5 and higher are logical partitions. The numbers 1 through 4
322 are reserved for primary or extended partitions.
323 </p>
324
325 <p>
326 In our example, hda1 through hda3 are primary partitions. hda4 is an extended
327 partition that contains logical partitions hda5 through hda9. You would never
328 actually use <path>/dev/hda4</path> for storing any filesystems directly -- it
329 simply acts as a container for partitions hda5 through hda9.
330 </p>
331
332 </body>
333 </section>
334 <section>
335 <title>Partition types</title>
336 <body>
337
338 <p>
339 Also, notice that each partition has an "Id," also called a partition type.
340 Whenever you create a new partition, you should ensure that the partition type
341 is set correctly. 83 is the correct partition type for partitions that will be
342 housing Linux filesystems, and 82 is the correct partition type for Linux swap
343 partitions. You set the partition type using the t option in <c>fdisk</c>. The
344 Linux kernel uses the partition type setting to auto-detect fileystems and swap
345 devices on the disk at boot-time.
346 </p>
347
348 </body>
349 </section>
350 <section>
351 <title>Using fdisk to set up partitions</title>
352 <body>
353
354 <p>
355 Now that you've had your introduction to the way disk partitioning is done
356 under Linux, it's time to walk through the process of setting up disk
357 partitions and filesystems for a new Linux installation. In this process, we
358 will configure a disk with new partitions and then create filesystems on them.
359 These steps will provide us with a completely clean disk with no data on it
360 that can then be used as a basis for a new Linux installation.
361 </p>
362
363 <impo>
364 To follow these steps, you need to have a hard drive that does not contain any
365 important data, since these steps will <e>erase</e> the data on your disk. If
366 this is all new to you, you may want to consider just reading the steps, or
367 using a Linux boot disk on a test system so that no data will be at risk.
368 </impo>
369
370 </body>
371 </section>
372 <section>
373 <title>What the partitioned disk will look like</title>
374 <body>
375
376 <p>
377 After we walk through the process of creating partitions on your disk, your
378 partition configuration will look like this:
379 </p>
380
381 <pre caption="Look of our disk after creating partitions">
382 Disk /dev/hda: 30.0 GB, 30005821440 bytes
383 240 heads, 63 sectors/track, 3876 cylinders
384 Units = cylinders of 15120 * 512 = 7741440 bytes
385
386 Device Boot Start End Blocks Id System
387 /dev/hda1 * 1 14 105808+ 83 Linux
388 /dev/hda2 15 81 506520 82 Linux swap
389 /dev/hda3 82 3876 28690200 83 Linux
390
391 Command (m for help):
392 </pre>
393
394 </body>
395 </section>
396 <section>
397 <title>Sample partition commentary</title>
398 <body>
399
400 <p>
401 In our suggested "newbie" partition configuration, we have three partitions.
402 The first one (<path>/dev/hda1</path>) at the beginning of the disk is a small
403 partition called a boot partition. The boot partition's purpose is to hold all
404 the critical data related to booting -- GRUB boot loader information (if you
405 will be using GRUB) as well as your Linux kernel(s). The boot partition gives
406 us a safe place to store everything related to booting Linux. During normal
407 day-to-day Linux use, your boot partition should remain unmounted for safety.
408 If you are setting up a SCSI system, your boot partition will likely end up
409 being <path>/dev/sda1</path>.
410 </p>
411
412 <p>
413 It's recommended to have boot partitions (containing everything necessary for
414 the boot loader to work) at the beginning of the disk. While not necessarily
415 required anymore, it is a useful tradition from the days when the LILO boot
416 loader wasn't able to load kernels from filesystems that extended beyond disk
417 cylinder 1024.
418 </p>
419
420 <p>
421 The second partition (<path>/dev/hda2</path>) s used for swap space. The kernel
422 uses swap space as virtual memory when RAM becomes low. This partition,
423 relatively speaking, isn't very big either, typically somewhere around 512 MB.
424 If you're setting up a SCSI system, this partition will likely end up being
425 called <path>/dev/hda2</path>.
426 </p>
427
428 <p>
429 The third partition (<path>/dev/hda3</path>) is quite large and takes up the
430 rest of the disk. This partition is called our root partition and will be used
431 to store your main filesystem that houses the main Linux filesystem. On a SCSI
432 system, this partition would likely end up being <path>/dev/hda3</path>.
433 </p>
434
435 </body>
436 </section>
437 <section>
438 <title>Getting started</title>
439 <body>
440
441 <p>
442 Okay, now to create the partitions as in the example and table above. First,
443 enter fdisk by typing <c>fdisk /dev/hda</c> or <c>fdisk /dev/sda</c>, depending
444 on whether you're using IDE or SCSI. Then, type <c>p</c> to view your
445 current partition configuration. Is there anything on the disk that you need to
446 keep? If so, stop now. If you continue with these directions, all existing data
447 on your disk will be erased.
448 </p>
449
450 <impo>
451 Following the instructions below will cause all prior data on your disk to be
452 erased! If there is anything on your drive, please be sure that it is
453 non-critical information that you don't mind losing. Also make sure that you
454 have selected the correct drive so that you don't mistakenly wipe data from the
455 wrong drive.
456 </impo>
457
458 </body>
459 </section>
460 <section>
461 <title>Zapping existing partitions</title>
462 <body>
463
464 <p>
465 Now, it's time to delete any existing partitions. To do this, type d and hit
466 enter. You will then be prompted for the partition number you would like to
467 delete. To delete a pre-existing <path>/dev/hda1</path>, you would type:
468 </p>
469
470 <pre caption="Deleting pre-existing partition">
471 Command (m for help): <i>d</i>
472 Partition number (1-4): <i>1</i>
473 </pre>
474
475 <p>
476 The partition has been scheduled for deletion. It will no longer show up if you
477 type <c>p</c>, but it will not be erased until your changes have been saved. If
478 you made a mistake and want to abort without saving your changes, type <c>q</c>
479 immediately and hit enter and your partition will not be deleted.
480 </p>
481
482 <p>
483 Now, assuming that you do indeed want to wipe out all the partitions on your
484 system, repeatedly type <c>p</c> to print out a partition listing and then type
485 <c>d</c> and the number of the partition to delete it. Eventually, you'll end
486 up with a partition table with nothing in it:
487 </p>
488
489 <pre caption="Drives look after cleaning it">
490
491 Disk /dev/hda: 30.0 GB, 30005821440 bytes
492 240 heads, 63 sectors/track, 3876 cylinders
493 Units = cylinders of 15120 * 512 = 7741440 bytes
494
495 Device Boot Start End Blocks Id System
496
497 Command (m for help):
498 </pre>
499
500 </body>
501 </section>
502 <section>
503 <title>Creating a boot partition</title>
504 <body>
505
506 <p>
507 Now that the in-memory partition table is empty, we're ready to create a boot
508 partition. To do this, type <c>n</c> to create a new partition, then <c>p</c>
509 to tell fdisk you want a primary partition. Then type <c>1</c> to create the
510 first primary partition. When prompted for the first cylinder, hit enter. When
511 prompted for the last cylinder, type <c>+100M</c> to create a partition 100MB
512 in size. Here's the output from these steps:
513 </p>
514
515 <pre caption="Creating a boot partition">
516 Command (m for help): <i>n</i>
517 Command action
518 e extended
519 p primary partition (1-4)
520 <i>p</i>
521 Partition number (1-4): <i>1</i>
522 First cylinder (1-3876, default 1):
523 Using default value 1
524 Last cylinder or +size or +sizeM or +sizeK (1-3876, default 3876): <i>+100M</i>
525 </pre>
526
527 <p>
528 Now, when you type <c>p</c>, you should see the following partition printout:
529 </p>
530
531 <pre caption="Partition printout">
532 Command (m for help): <i>p</i>
533
534 Disk /dev/hda: 30.0 GB, 30005821440 bytes
535 240 heads, 63 sectors/track, 3876 cylinders
536 Units = cylinders of 15120 * 512 = 7741440 bytes
537
538 Device Boot Start End Blocks Id System
539 /dev/hda1 1 14 105808+ 83 Linux
540 </pre>
541
542 </body>
543 </section>
544 <section>
545 <title>Creating the swap partition</title>
546 <body>
547
548 <p>
549 Next, let's create the swap partition. To do this, type <c>n</c> to create a
550 new partition, then <c>p</c> to tell fdisk that you want a primary partition.
551 Then type <c>2</c> to create the second primary partition,
552 <path>/dev/hda2</path> in our case. When prompted for the first cylinder, hit
553 enter. When prompted for the last cylinder, type <c>+512M</c> to create a
554 partition 512MB in size. After you've done this, type <c>t</c> to set the
555 partition type, and then type <c>82</c> to set the partition type to "Linux
556 Swap." After completing these steps, typing <c>p</c> should display a partition
557 table that looks similar to this:
558 </p>
559
560 <pre caption="Partition table">
561 Command (m for help): <i>p</i>
562
563 Disk /dev/hda: 30.0 GB, 30005821440 bytes
564 240 heads, 63 sectors/track, 3876 cylinders
565 Units = cylinders of 15120 * 512 = 7741440 bytes
566
567 Device Boot Start End Blocks Id System
568 /dev/hda1 1 14 105808+ 83 Linux
569 /dev/hda2 15 81 506520 82 Linux swap
570 </pre>
571
572 </body>
573 </section>
574 <section>
575 <title>Making it bootable</title>
576 <body>
577
578 <p>
579 Finally, we need to set the "bootable" flag on our boot partition and then
580 write our changes to disk. To tag <path>/dev/hda1</path> as a "bootable"
581 partition, type <c>a</c> at the menu and then type 1 for the partition number.
582 If you type <c>p</c> now, you'll now see that <path>/dev/hda1</path> has an "*"
583 in the "Boot" column. Now, let's write our changes to disk. To do this, type
584 <c>w</c> and hit enter. Your disk partitions are now properly configured for
585 the installation of Linux.
586 </p>
587
588 <note>
589 If fdisk instructs you to do so, please reboot to allow your system to detect
590 the new partition configuration.
591 </note>
592
593 </body>
594 </section>
595 <section>
596 <title>Extended and logical partitioning</title>
597 <body>
598
599 <p>
600 In the above example, we created a single primary partition that will contain a
601 filesystem used to store all our data. This means that after installing Linux,
602 this main filesystem will get mounted at "<path>/</path>" and will contain a
603 tree of directories that contain all our files.
604 </p>
605
606 <p>
607 While this is a common way to set up a Linux system, there is another approach
608 that you should be familiar with. This approach uses multiple partitions that
609 house multiple filesystems and are then "linked" together to form a cohesive
610 filesystem tree. For example, it is common to put <path>/home</path> and
611 <path>/var</path> on their own filesystems.
612 </p>
613
614 <p>
615 We could have made hda2 into an extended rather than a primary partition. Then,
616 we could have created the hda5, hda6, and hda7 logical partitions (which would
617 technically be contained "inside" hda2), which would house the <path>/</path>,
618 <path>/home</path>, and <path>/var</path> filesystems respectively.
619 </p>
620
621 <p>
622 You can learn more about these types of multi-filesystem configurations by
623 studying the resources listed on the next page.
624 </p>
625
626 </body>
627 </section>
628 <section>
629 <title>Partitioning resources</title>
630 <body>
631
632 <p>
633 For more information on partitioning, take a look at the following partitioning
634 tips:
635 </p>
636
637 <ul>
638 <li>
639 <uri link="/doc/en/articles/partition-planning-tips.xml">Partition planning
640 tips</uri>
641 </li>
642 <li>
643 <uri link="/doc/en/articles/partitioning-p2.xml">Partitioning in action:
644 consolidating data</uri>
645 </li>
646 <li>
647 <uri link="/doc/en/articles/partitioning-p1.xml">Partitioning in action:
648 moving /home</uri>.
649 </li>
650 </ul>
651
652 </body>
653 </section>
654 <section>
655 <title>Creating filesystems</title>
656 <body>
657
658 <p>
659 Now that the partitions have been created, it's time to set up filesystems on
660 the boot and root partitions so that they can be mounted and used to store
661 data. We will also configure the swap partition to serve as swap storage.
662 </p>
663
664 <p>
665 Linux supports a variety of different types of filesystems; each type has its
666 strengths and weaknesses and its own set of performance characteristics. We
667 will cover the creation of ext2, ext3, XFS, JFS, and ReiserFS filesystems in
668 this tutorial. Before we create filesystems on our example system, let's
669 briefly review the various filesystems available under Linux. We'll go into
670 more detail on the filesystems later in the tutorial.
671 </p>
672
673 </body>
674 </section>
675 <section>
676 <title>The ext2 filesystem</title>
677 <body>
678
679 <p>
680 ext2 is the tried-and-true Linux filesystem, but it doesn't have metadata
681 journaling, which means that routine ext2 filesystem checks at startup time can
682 be quite time-consuming. There is now quite a selection of newer-generation
683 journaled filesystems that can be checked for consistency very quickly and are
684 thus generally preferred over their non-journaled counterparts. Journaled
685 filesystems prevent long delays when you boot your system and your filesystem
686 happens to be in an inconsistent state.
687 </p>
688
689 </body>
690 </section>
691 <section>
692 <title>The ext3 filesystem</title>
693 <body>
694
695 <p>
696 ext3 is the journaled version of the ext2 filesystem, providing metadata
697 journaling for fast recovery in addition to other enhanced journaling modes,
698 such as full data and ordered data journaling. ext3 is a very good and reliable
699 filesystem. It offers generally decent performance under most conditions.
700 Because it does not extensively employ the use of "trees" in its internal
701 design, it doesn't scale very well, meaning that it is not an ideal choice for
702 very large filesystems or situations where you will be handling very large
703 files or large quantities of files in a single directory. But when used within
704 its design parameters, ext3 is an excellent filesystem.
705 </p>
706
707 <p>
708 One of the nice things about ext3 is that an existing ext2 filesystem can be
709 upgraded "in-place" to ext3 quite easily. This allows for a seamless upgrade
710 path for existing Linux systems that are already using ext2.
711 </p>
712
713 </body>
714 </section>
715 <section>
716 <title>The ReiserFS filesystem</title>
717 <body>
718
719 <p>
720 ReiserFS is a B-tree-based filesystem that has very good overall performance
721 and greatly outperforms both ext2 and ext3 when dealing with small files (files
722 less than 4k), often by a factor of 10x-15x. ReiserFS also scales extremely
723 well and has metadata journaling. As of kernel 2.4.18+, ReiserFS is now
724 rock-solid and highly recommended for use both as a general-purpose filesystem
725 and for extreme cases such as the creation of large filesystems, the use of
726 many small files, very large files, and directories containing tens of
727 thousands of files. ReiserFS is the filesystem we recommend by default for all
728 non-boot partitions.
729 </p>
730
731 </body>
732 </section>
733 <section>
734 <title>The XFS filesystem</title>
735 <body>
736
737 <p>
738 XFS is a filesystem with metadata journaling. It comes with a robust
739 feature-set and is optimized for scalability. We only recommend using this
740 filesystem on Linux systems with high-end SCSI and/or fibre channel storage and
741 a uninterruptible power supply. Because XFS aggressively caches in-transit data
742 in RAM, improperly designed programs (those that don't take proper precautions
743 when writing files to disk (and there are quite a few of them) can lose a good
744 deal of data if the system goes down unexpectedly.
745 </p>
746
747 </body>
748 </section>
749 <section>
750 <title>The JFS filesystem</title>
751 <body>
752
753 <p>
754 JFS is IBM's own high performance journaling filesystem. It has recently become
755 production-ready, and we would like to see a longer track record before
756 commenting either positively nor negatively on its general stability at this
757 point.
758 </p>
759
760 </body>
761 </section>
762 <section>
763 <title>Filesystem recommendations</title>
764 <body>
765
766 <p>
767 If you're looking for the most rugged journaling filesystem, use ext3. If
768 you're looking for a good general-purpose high-performance filesystem with
769 journaling support, use ReiserFS; both ext3 and ReiserFS are mature, refined
770 and recommended for general use.
771 </p>
772
773 <p>
774 Based on our example above, we will use the following commands to initialize
775 all our partitions for use:
776 </p>
777
778 <pre caption="Initlizing partitions">
779 # <i>mke2fs -j /dev/hda1</i>
780 # <i>mkswap /dev/hda2</i>
781 # <i>mkreiserfs /dev/hda3</i>
782 </pre>
783
784 <p>
785 We choose ext3 for our <path>/dev/hda1</path> boot partition because it is a
786 robust journaling filesystem supported by all major boot loaders. We used
787 <c>mkswap</c> for our <path>/dev/hda2</path> swap partition -- the choice is
788 obvious here. And for our main root filesystem on <path>/dev/hda3</path> we
789 choose ReiserFS, since it is a solid journaling filesystem offering excellent
790 performance. Now, go ahead and initialize your partitions.
791 </p>
792
793 </body>
794 </section>
795 <section>
796 <title>Making swap</title>
797 <body>
798
799 <p>
800 <c>mkswap</c> is the command that used to initialize swap partitions:
801 </p>
802
803 <pre caption="Initalizing swap partition">
804 # <i>mkswap /dev/hda2</i>
805 </pre>
806
807 <p>
808 Unlike regular filesystems, swap partitions aren't mounted. Instead, they are
809 enabled using the <c>swapon</c> command:
810 </p>
811
812 <pre caption="Enabling swap partition">
813 # <i>swapon /dev/hdc6</i>
814 </pre>
815
816 <p>
817 Your Linux system's startup scripts will take care of automatically enabling
818 your swap partitions. Therefore, the <c>swapon</c> command is generally only
819 needed when you need to immediately add some swap that you just created. To
820 view the swap devices currently enabled, type <c>cat /proc/swaps</c>.
821 </p>
822
823 </body>
824 </section>
825 <section>
826 <title>Creating ext2, ext3, and ReiserFS filesystems</title>
827 <body>
828
829 <p>
830 You can use the <c>mke2fs</c> command to create ext2 filesystems:
831 </p>
832
833 <pre caption="Creating ext2 filesystem">
834 # <i>mke2fs /dev/hda1</i>
835 </pre>
836
837 <p>
838 If you would like to use ext3, you can create ext3 filesystems using <c>mke2fs
839 -j</c>:
840 </p>
841
842 <pre caption="Creating ext3 filesystem">
843 # <i>mke2fs /dev/hda3</i>
844 </pre>
845
846 <note>
847 You can find out more about using ext3 under Linux 2.4 on <uri
848 link="http://www.zip.com.au/~akpm/linux/ext3/ext3-usage.html">this site</uri>
849 maintained by Andrew Morton.
850 </note>
851
852 <p>
853 To create ReiserFS filesystems, use the <c>mkreiserfs</c> command:
854 </p>
855
856 <pre caption="Creating ReiserFS filesystem">
857 # <i>mkreiserfs /dev/hda3</i>
858 </pre>
859
860 </body>
861 </section>
862 <section>
863 <title>Creating XFS and JFS filesystems</title>
864 <body>
865
866 <p>
867 To create an XFS filesystem, use the <c>mkfs.xfs</c> command:
868 </p>
869
870 <pre caption="Creating XFS filesystem">
871 # <i>mkfs.xfs /dev/hda3</i>
872 </pre>
873
874 <note>
875 You may want to add a couple of additional flags to the mkfs.xfs command: <c>-d
876 agcount=3 -l size=32m</c>. The <c>-d agcount=3</c> command will lower the
877 number of allocation groups. XFS will insist on using at least one
878 allocation group per 4GB of your partition, so, for example, if you have a 20GB
879 partition you will need a minimum agcount of 5. The <c>l size=32m</c> command
880 increases the journal size to 32MB, increasing performance.
881 </note>
882
883 <p>
884 To create JFS filesystems, use the <c>mkfs.jfs</c> command:
885 </p>
886
887 <pre caption="Creating JFS filesystem">
888 # <i>mkfs.jfs /dev/hda3</i>
889 </pre>
890
891 </body>
892 </section>
893 <section>
894 <title>Mounting filesystems</title>
895 <body>
896
897 <p>
898 Once the filesystem is created, we can mount it using the <c>mount</c> command:
899 </p>
900
901 <pre caption="Mounting filesystem">
902 # <i>mount /dev/hda3 /mnt</i>
903 </pre>
904
905 <p>
906 To mount a filesystem, specify the partition block device as a first argument
907 and a "mountpoint" as a second argument. The new filesystem will be "grafted
908 in" at the mountpoint. This also has the effect of "hiding" any files that were
909 in the <path>/mnt</path> directory on the parent filesystem. Later, when the
910 filesystem is unmounted, these files will reappear. After executing the mount
911 command, any files created or copied inside <path>/mnt</path> will be stored on
912 the new ReiserFS filesystem you mounted.
913 </p>
914
915 <p>
916 Let's say we wanted to mount our boot partition inside <path>/mnt</path>. We
917 could do this by performing the following steps:
918 </p>
919
920 <pre caption="Mounting boot partition in /mnt">
921 # <i>mkdir /mnt/boot</i>
922 # <i>mount /dev/hda1 /mnt/boot</i>
923 </pre>
924
925 <p>
926 Now, our boot filesystem is available inside /mnt/boot. If we create files
927 inside <path>/mnt/boot</path>, they will be stored on our ext3 filesystem that
928 physically resides on <path>/dev/hda1</path>. If we create file inside
929 <path>/mnt</path> but not <path>/mnt/boot</path>, then they will be stored on
930 our ReiserFS filesystem that resides on <path>/dev/hda3</path>. And if we
931 create files outside of <path>/mnt</path>, they will not be stored on either
932 filesystem but on the filesystem of our current Linux system or boot disk.
933 </p>
934
935 <p>
936 To see what filesystems are mounted, type <c>mount</c> by itself. Here is the
937 output of <c>mount</c> on one of our currently-running Linux system, which has
938 partitions configured identically to those in the example above:
939 </p>
940
941 <pre caption="Output of mount command">
942 /dev/root on / type reiserfs (rw,noatime)
943 none on /dev type devfs (rw)
944 proc on /proc type proc (rw)
945 tmpfs on /dev/shm type tmpfs (rw)
946 usbdevfs on /proc/bus/usb type usbdevfs (rw)
947 /dev/hde1 on /boot type ext3 (rw,noatime)
948 </pre>
949
950 <p>
951 You can also view similar information by typing cat <path>/proc/mounts</path>.
952 The "root" filesystem, <path>/dev/hda3</path> gets mounted automatically by the
953 kernel at boot-time, and gets the symbolic name <path>/dev/hda3</path>. On our
954 system, both <path>/dev/hda3</path> and <path>/dev/root</path> point to the
955 same underlying block device using a symbolic link:
956 </p>
957
958 <pre caption="Symbolic links">
959 # <i>ls -l /dev/root</i>
960 lr-xr-xr-x 1 root root 33 Mar 26 20:39 /dev/root -> ide/host0/bus0/target0/lun0/part3
961
962 # <i>ls -l /dev/hda3</i>
963 lr-xr-xr-x 1 root root 33 Mar 26 20:39 /dev/hde3 -> ide/host0/bus0/target0/lun0/part3
964 </pre>
965
966 </body>
967 </section>
968 <section>
969 <title>Even more mounting stuff</title>
970 <body>
971
972 <p>
973 So, what is this "<path>/dev/ide/host0</path>...." file? Systems like mine that
974 use the devfs device-management filesystem for <path>/dev</path> have longer
975 official names for the partition and disk block devices than Linux used to have
976 in the past. For example, <path>/dev/ide/host0/bus1/target0/lun0/part7</path>
977 is the official name for <path>/dev/hdc7</path>, and <path>/dev/hdc7</path>
978 itself is just a symlink pointing to the official block device. You can
979 determine if your system is using devfs by checking to see if the
980 <path>/dev/.devfsd</path> file exists; if so, then devfs is active.
981 </p>
982
983 <p>
984 When using the mount command to mount filesystems, it attempts to auto-detect
985 the filesystem type. Sometimes, this may not work and you will need to specify
986 the to-be-mounted filesystem type manually using the -t option, as follows:
987 </p>
988
989 <pre caption="Mounting ext3 filesystem manually with -t option">
990 # <i>mount /dev/hda1 /mnt/boot -t ext3</i>
991 </pre>
992
993 <p>or</p>
994
995 <pre caption="Mouting reiserfs filesystem manually with -t option">
996 # <i>mount /dev/hda3 /mnt -t reiserfs</i>
997 </pre>
998
999 </body>
1000 </section>
1001 <section>
1002 <title>Mount options</title>
1003 <body>
1004
1005 <p>
1006 It's also possible to customize various attributes of the to-be-mounted
1007 filesystem by specifying mount options. For example, you can mount a filesystem
1008 as "read-only" by using the "ro" option:
1009 </p>
1010
1011 <pre caption="Mouting filesystem as read-only">
1012 # <i>mount /dev/hdc6 /mnt -o ro</i>
1013 </pre>
1014
1015 <p>
1016 With <path>/dev/hdc6</path> mounted read-only, no files can be modified in
1017 <path>/mnt</path> -- only read. If your filesystem is already mounted
1018 "read/write" and you want to switch it to read-only mode, you can use the
1019 "remount" option to avoid having to unmount and remount the filesystem again:
1020 </p>
1021
1022 <pre caption="Using remount option">
1023 # <i>mount /mnt -o remount,ro</i>
1024 </pre>
1025
1026 <p>
1027 Notice that we didn't need to specify the partition block device because the
1028 filesystem is already mounted and <c>mount</c> knows that <path>/mnt</path> is
1029 associated with <path>/dev/hdc6</path>. To make the filesystem writeable again,
1030 we can remount it as read-write:
1031 </p>
1032
1033 <pre caption="Remounting filesystem as read-write">
1034 # <i>mount /mnt -o remount,rw</i>
1035 </pre>
1036
1037 <p>
1038 Note that these remount commands will not complete successfully if any process
1039 has opened any files or directories in <path>/mnt</path>. To familiarize
1040 yourself with all the mount options available under Linux, type <c>man
1041 mount</c>.
1042 </p>
1043
1044 </body>
1045 </section>
1046 <section>
1047 <title>Introducing fstab</title>
1048 <body>
1049
1050 <p>
1051 So far, we've seen how partition an example disk and mount filesystems manually
1052 from a boot disk. But once we get a Linux system installed, how do we configure
1053 that Linux system to mount the right filesystems at the right time? For
1054 example, Let's say that we installed Gentoo Linux on our current example
1055 filesystem configuration. How would our system know how to to find the root
1056 filesystem on <path>/dev/hda3</path>? And if any other filesystems -- like swap
1057 -- needed to be mounted at boot time, how would it know which ones?
1058 </p>
1059
1060 <p>
1061 Well, the Linux kernel is told what root filesystem to use by the boot loader,
1062 and we'll take a look at the linux boot loaders later in this tutorial. But for
1063 everything else, your Linux system has a file called <path>/etc/fstab</path>
1064 that tells it about what filesystems are available for mounting. Let's take a
1065 look at it.
1066 </p>
1067
1068 </body>
1069 </section>
1070 <section>
1071 <title>A sample fstab</title>
1072 <body>
1073
1074 <p>
1075 Let's take a look at a sample <path>/etc/fstab</path> file:
1076 </p>
1077
1078 <pre caption="Sample /etc/fstab file">
1079 &lt;fs&gt; &lt;mountpoint&gt; &lt;type&gt; &lt;opts&gt; &lt;dump/pass&gt;
1080
1081 /dev/hda1 /boot ext3 noauto,noatime 1 1
1082 /dev/hda3 / reiserfs noatime 0 0
1083 /dev/hda2 none swap sw 0 0
1084 /dev/cdrom /mnt/cdrom iso9660 noauto,ro,user 0 0
1085 # /proc should always be enabled
1086 proc /proc proc defaults 0 0
1087 </pre>
1088
1089 <p>
1090 Above, each non-commented line in <path>/etc/fstab</path> specifies a partition
1091 block device, a mountpoint, a filesystem type, the filesystem options to use
1092 when mounting the filesystem, and two numeric fields. The first numeric field
1093 is used to tell the <c>dump</c> backup command the filesystems that should be
1094 backed up. Of course, if you are not planning to use <c>dump</c> on your
1095 system, then you can safely ignore this field. The last field is used by the
1096 <c>fsck</c> filesystem integrity checking program, and tells it the order in
1097 which your filesystems should be checked at boot. We'll touch on <c>fsck</c>
1098 again in a few panels.
1099 </p>
1100
1101 <p>
1102 Look at the <path>/dev/hda1</path> line; you'll see that <path>/dev/hda1</path>
1103 is an ext3 filesystem that should be mounted at the <path>/boot</path>
1104 mountpoint. Now, look at <path>/dev/hda1</path>'s mount options in the opts
1105 column. The noauto option tells the system to not mount <path>/dev/hda1</path>
1106 automatically at boot time; without this option, <path>/dev/hda1</path> would
1107 be automatically mounted to <path>/boot</path> at system boot time.
1108 </p>
1109
1110 <p>
1111 Also note the noatime option, which turns off the recording of atime (last
1112 access time) information on the disk. This information is generally not needed,
1113 and turning off atime updates has a positive effect on filesystem performance.
1114 </p>
1115
1116 <p>
1117 Now, take a look at the <path>/proc</path> line and notice the defaults option.
1118 Use defaults whenever you want a filesystem to be mounted with just the
1119 standard mount options. Since <path>/etc/fstab</path> has multiple fields, we
1120 can't simply leave the option field blank.
1121 </p>
1122
1123 <p>
1124 Also notice the <path>/etc/fstab</path> line for <path>/dev/hda2</path>. This
1125 line defines <path>/dev/hda2</path> as a swap device. Since swap devices aren't
1126 mounted like filesystems, none is specified in the mountpoint field. Thanks to
1127 this <path>/etc/fstab</path> entry, our <path>/dev/hda2</path> swap device will
1128 be enabled automatically when the system starts up.
1129 </p>
1130
1131 <p>
1132 With an <path>/etc/fstab</path> entry for <path>/dev/cdrom</path> like the one
1133 above, mounting the CD-ROM drive becomes easier. Instead of typing:
1134 </p>
1135
1136 <pre caption="Mounting CD-ROM without entry in fstab">
1137 # <i>mount -t iso9660 /dev/cdrom /mnt/cdrom -o ro</i>
1138 </pre>
1139
1140 <p>
1141 We can now type:
1142 </p>
1143
1144 <pre caption="Mounting CD-ROM with entry in fstab">
1145 # <i>mount /dev/cdrom</i>
1146 </pre>
1147
1148 <p>
1149 In fact, using <path>/etc/fstab</path> allows us to take advantage of the user
1150 option. The user mount option tells the system to allow this particular
1151 filesystem to be mounted by any user. This comes in handy for removable media
1152 devices like CD-ROM drives. Without this fstab mount option, only the root user
1153 would be able to use the CD-ROM drive.
1154 </p>
1155
1156 </body>
1157 </section>
1158 <section>
1159 <title>Unmounting filesystems</title>
1160 <body>
1161
1162 <p>
1163 Generally, all mounted filesystems are unmounted automatically by the system
1164 when it is rebooted or shut down. When a filesystem is unmounted, any cached
1165 filesystem data in memory is flushed to the disk.
1166 </p>
1167
1168 <p>
1169 However, it's also possible to unmount filesystems manually. Before a
1170 filesystem can be unmounted, you first need to ensure that there are no
1171 processes running that have open files on the filesystem in question. Then, use
1172 the <c>umount</c> command, specifying either the device name or mount point as
1173 an argument:
1174 </p>
1175
1176 <pre caption="Using umount command">
1177 # <i>umount /mnt</i>
1178 </pre>
1179
1180 <p>
1181 or
1182 </p>
1183
1184 <pre caption="Using umount command">
1185 # <i>umount /dev/hda3</i>
1186 </pre>
1187
1188 <p>
1189 Once unmounted, any files in <path>/mnt</path> that were "covered" by the
1190 previously-mounted filesystem will now reappear.
1191 </p>
1192
1193 </body>
1194 </section>
1195 <section>
1196 <title>Introducing fsck</title>
1197 <body>
1198
1199 <p>
1200 If your system crashes or locks up for some reason, the system won't have an
1201 opportunity to cleanly unmount your filesystems. When this happens, the
1202 filesystems are left in an inconsistent (unpredictable) state. When the system
1203 reboots, the <c>fsck</c> program will detect that the filesystems were not
1204 cleanly unmounted and will want to perform a consistency check of filesystems
1205 listed in <path>/etc/fstab</path>.
1206 </p>
1207
1208 <impo>
1209 For a filesystem to be checked by <c>fsck</c> it must have a non-zero number in
1210 the "pass" field (the last field) in <path>/etc/fstab</path>. Typically, the
1211 root filesystem is set to a passno of 1, specifying that it should be checked
1212 first. All other filesystems that should be checked at startup time should have
1213 a passno of 2 or higher. For some journaling filesystems like ReiserFS, it is
1214 safe to have a passno of 0 since the journaling code (and not an external
1215 <c>fsck</c>) takes care of making the filesystem consistent again.
1216 </impo>
1217
1218 <p>
1219 Sometimes, you may find that after a reboot <c>fsck</c> is unable to fully
1220 repair a partially damaged filesystem. In these instances, all you need to do
1221 is to bring your system down to single-user mode and run <c>fsck</c> manually,
1222 supplying the partition block device as an argument. As <c>fsck</c> performs
1223 its filesystem repairs, it may ask you whether to fix particular filesystem
1224 defects. In general, you should say <c>y</c> (yes) to all these questions and
1225 allow <c>fsck</c> to do its thing.
1226 </p>
1227
1228 </body>
1229 </section>
1230 <section>
1231 <title>Problems with fsck</title>
1232 <body>
1233
1234 <p>
1235 One of the problems with <c>fsck</c> scans is that they can take quite a while
1236 to complete, since the entirety of a filesystem's metadata (internal data
1237 structure) needs to be scanned in order to ensure that it's consistent. With
1238 extremely large filesystems, it is not unusual for an exhaustive fsck to take
1239 more than an hour.
1240 </p>
1241
1242 <p>
1243 In order to solve this problem, a new type of filesystem was designed, called a
1244 journaling filesystem. Journaling filesystems record an on-disk log of recent
1245 changes to the filesystem metadata. In the event of a crash, the filesystem
1246 driver inspects the log. Because the log contains an accurate account of recent
1247 changes on disk, only these parts of the filesystem metadata need to be checked
1248 for errors. Thanks to this important design difference, checking a journalled
1249 filesystem for consistency typically takes just a matter of seconds, regardless
1250 of filesystem size. For this reason, journaling filesystems are gaining
1251 popularity in the Linux community. For more information on journaling
1252 filesystems, see the <uri
1253 link="http://www-106.ibm.com/developerworks/library/l-fs.html">Advanced
1254 filesystem implementor's guide, part 1: Journaling and ReiserFS</uri>.
1255 </p>
1256
1257 <p>
1258 Let's cover the major filesystems available for Linux, along with their
1259 associated commands and options.
1260 </p>
1261
1262 </body>
1263 </section>
1264 <section>
1265 <title>The ext2 filesystem</title>
1266 <body>
1267
1268 <p>
1269 The ext2 filesystem has been the standard Linux filesystem for many years. It
1270 has generally good performance for most applications, but it does not offer any
1271 journaling capability. This makes it unsuitable for very large filesystems,
1272 since <c>fsck</c> can take an extremely long time. In addition, ext2 has some
1273 built-in limitations due to the fact that every ext2 filesystem has a fixed
1274 number of inodes that it can hold. That being said, ext2 is generally
1275 considered to be an extremely robust and efficient non-journalled filesystem.
1276 </p>
1277
1278 <ul>
1279 <li>In kernels: 2.0+</li>
1280 <li>journaling: no</li>
1281 <li>mkfs command: mke2fs</li>
1282 <li>mkfs example: mke2fs /dev/hdc7</li>
1283 <li>related commands: debugfs, tune2fs, chattr</li>
1284 <li>performance-related mount options: noatime.</li>
1285 </ul>
1286
1287 </body>
1288 </section>
1289 <section>
1290 <title>The ext3 filesystem</title>
1291 <body>
1292
1293 <p>
1294 The ext3 filesystem uses the same on-disk format as ext2, but adds journaling
1295 capabilities. In fact, of all the Linux filesystems, ext3 has the most
1296 extensive journaling support, supporting not only metadata journaling but also
1297 ordered journaling (the default) and full metadata+data journaling. These
1298 "special" journaling modes help to ensure data integrity, not just short fscks
1299 like other journaling implementations. For this reason, ext3 is the best
1300 filesystem to use if data integrity is an absolute first priority. However,
1301 these data integrity features do impact performance somewhat. In addition,
1302 because ext3 uses the same on-disk format as ext2, it still suffers from the
1303 same scalability limitations as its non-journalled cousin. Ext3 is a good
1304 choice if you're looking for a good general-purpose journalled filesystem that
1305 is also very robust.
1306 </p>
1307
1308 <ul>
1309 <li>In kernels: 2.4.16+</li>
1310 <li>journaling: metadata, ordered data writes, full metadata+data</li>
1311 <li>mkfs command: mke2fs -j</li>
1312 <li>mkfs example: mke2fs -j /dev/hdc7</li>
1313 <li>related commands: debugfs, tune2fs, chattr</li>
1314 <li>performance-related mount options: noatime</li>
1315 <li>
1316 other mount options:
1317 <ul>
1318 <li>data=writeback (disable journaling)</li>
1319 <li>
1320 data=ordered (the default, metadata journaling and data is written out
1321 to disk with metadata)
1322 </li>
1323 <li>
1324 data=journal (full data journaling for data and metadata integrity. Halves
1325 write performance.)
1326 </li>
1327 </ul>
1328 </li>
1329 <li>
1330 ext3 resources:
1331 <ul>
1332 <li>
1333 <uri
1334 link="http://www.zip.com.au/~akpm/linux/ext3/">Andrew Morton's ext3
1335 page</uri>
1336 </li>
1337 <li>
1338 <uri
1339 link="http://www.zip.com.au/~akpm/linux/ext3/ext3-usage.html">Andrew
1340 Morton's excellent ext3 usage documentation (recommended)</uri>
1341 </li>
1342 <li>
1343 <uri
1344 link="http://www-106.ibm.com/developerworks/linux/library/l-fs7/">#
1345 Advanced filesystem implementor's guide, part 7: Introducing ext3</uri>
1346 </li>
1347 <li>
1348 <uri
1349 link="http://www.gentoo.org/doc/en/articles/l-afig-p8.xml">Advanced
1350 filesystem implementor's guide, part 8: Surprises in ext3.</uri>
1351 </li>
1352 </ul>
1353 </li>
1354 </ul>
1355
1356 </body>
1357 </section>
1358 <section>
1359 <title>The ReiserFS filesystem</title>
1360 <body>
1361
1362 <p>
1363 ReiserFS is a relatively new filesystem that has been designed with the goal of
1364 providing very good small file performance, very good general performance and
1365 being very scalable. In general, ReiserFS offers very good performance in most
1366 all situations. ReiserFS is preferred by many for its speed and scalability.
1367 </p>
1368
1369 <ul>
1370 <li>In kernels: 2.4.0+ (2.4.18+ strongly recommended)</li>
1371 <li>journaling: metadata</li>
1372 <li>mkfs command: mkreiserfs</li>
1373 <li>mkfs example: mkreiserfs /dev/hdc7</li>
1374 <li>performance-related mount options: noatime, notail</li>
1375 <li>
1376 ReiserFS Resources:
1377 <ul>
1378 <li><uri link="http://www.namesys.com/">The home of ReiserFS</uri></li>
1379 <li>
1380 <uri
1381 link="http://www-106.ibm.com/developerworks/library/l-fs.html">Advanced
1382 filesystem implementor's guide, part 1: Journaling and ReiserFS</uri>
1383 </li>
1384 <li>
1385 <uri
1386 link="http://www-106.ibm.com/developerworks/library/l-fs2.html">Advanced
1387 filesystem implementor's guide, part 2: Using ReiserFS and Linux
1388 2.4.</uri>
1389 </li>
1390 </ul>
1391 </li>
1392 </ul>
1393
1394 </body>
1395 </section>
1396 <section>
1397 <title>The XFS filesystem</title>
1398 <body>
1399
1400 <p>
1401 The XFS filesystem is an enterprise-class journaling filesystem being ported to
1402 Linux by SGI. XFS is a full-featured, scalable, journaled file-system that is a
1403 good match for high-end, reliable hardware (since it relies heavily on caching
1404 data in RAM.) but not a good match for low-end hardware.
1405 </p>
1406
1407 <ul>
1408 <li>In kernels: 2.5.34+ only, requires patch for 2.4 series</li>
1409 <li>journaling: metadata</li>
1410 <li>mkfs command: mkfs.xfs</li>
1411 <li>mkfs example: mkfs.xfs /dev/hdc7</li>
1412 <li>performance-related mount options: noatime</li>
1413 <li>
1414 XFS Resources:
1415 <ul>
1416 <li>
1417 <uri
1418 link="http://oss.sgi.com/projects/xfs/">The home of XFS (sgi.com)</uri>
1419 </li>
1420 <li>
1421 <uri
1422 link="http://www-106.ibm.com/developerworks/library/l-fs9.html">Advanced
1423 filesystem implementor's guide, part 9: Introducing XFS</uri>
1424 </li>
1425 <li>
1426 <uri
1427 link="http://www-106.ibm.com/developerworks/library/l-fs10.html">Advanced
1428 filesystem implementor's guide, part 10: Deploying XFS.</uri>
1429 </li>
1430 </ul>
1431 </li>
1432 </ul>
1433
1434 </body>
1435 </section>
1436 <section>
1437 <title>The JFS filesystem</title>
1438 <body>
1439
1440 <p>
1441 JFS is a high-performance journaling filesystem ported to Linux by IBM. JFS is
1442 used by IBM enterprise servers and is designed for high-performance
1443 applications. You can learn more about JFS at <uri
1444 link="http://www-124.ibm.com/developerworks/oss/jfs/index.html">the JFS project
1445 Web site</uri>.
1446 </p>
1447
1448 <ul>
1449 <li>In kernels: 2.4.20+</li>
1450 <li>journaling: metadata</li>
1451 <li>mkfs command: mkfs.jfs</li>
1452 <li>mkfs example: mkfs.jfs /dev/hdc7</li>
1453 <li>performance-related mount options: noatime</li>
1454 <li>
1455 JFS Resources: <uri
1456 link="http://www-124.ibm.com/developerworks/oss/jfs/index.html">the JFS
1457 project Web site (IBM).</uri>
1458 </li>
1459 </ul>
1460
1461 </body>
1462 </section>
1463 <section>
1464 <title>VFAT</title>
1465 <body>
1466
1467 <p>
1468 The VFAT filesystem isn't really a filesystem that you would choose for storing
1469 Linux files. Instead, it's a DOS-compatible filesystem driver that allows you
1470 to mount and exchange data with DOS and Windows FAT-based filesystems. The VFAT
1471 filesystem driver is present in the standard Linux kernel.
1472 </p>
1473
1474 </body>
1475 </section>
1476 </chapter>
1477
1478 <chapter>
1479 <title>Booting the system</title>
1480 <section>
1481 <title>About this section</title>
1482 <body>
1483
1484 <p>
1485 This section introduces the Linux boot procedure. We'll cover the concept of a
1486 boot loader, how to set kernel options at boot, and how to examine the boot log
1487 for errors.
1488 </p>
1489
1490 </body>
1491 </section>
1492 <section>
1493 <title>The MBR</title>
1494 <body>
1495
1496 <p>
1497 The boot process is similar for all machines, regardless of which distribution
1498 is installed. Consider the following example hard disk:
1499 </p>
1500
1501 <pre caption="Structure of a hard disk">
1502 +----------------+
1503 | MBR |
1504 +----------------+
1505 | Partition 1: |
1506 | Linux root (/) |
1507 | containing |
1508 | kernel and |
1509 | system. |
1510 +----------------+
1511 | Partition 2: |
1512 | Linux swap |
1513 +----------------+
1514 | Partition 3: |
1515 | Windows 3.0 |
1516 | (last booted |
1517 | in 1992) |
1518 +----------------+
1519 </pre>
1520
1521 <p>
1522 First, the computer's BIOS reads the first few sectors of your hard disk. These
1523 sectors contain a very small program, called the "Master Boot Record," or
1524 "MBR." The MBR has stored the location of the Linux kernel on the hard disk
1525 (partition 1 in the example above), so it loads the kernel into memory and
1526 starts it.
1527 </p>
1528
1529 </body>
1530 </section>
1531 <section>
1532 <title>The kernel boot process</title>
1533 <body>
1534
1535 <p>
1536 The next thing you see (although it probably flashes by quickly) is a line
1537 similar to the following:
1538 </p>
1539
1540 <pre caption="Boot process line">
1541 Linux version 2.4.16 (root@×××××××××××××.org) (gcc version 2.95.3 20010315 (release)) #1 Sat Jan 12 19:23:04 EST 2002
1542 </pre>
1543
1544 <p>
1545 This is the first line printed by the kernel when it starts running. The first
1546 part is the kernel version, followed by the identification of the user that
1547 built the kernel (usually root), the compiler that built it, and the timestamp
1548 when it was built.
1549 </p>
1550
1551 <p>
1552 Following that line is a whole slew of output from the kernel regarding the
1553 hardware in your system: the processor, PCI bus, disk controller, disks, serial
1554 ports, floppy drive, USB devices, network adapters, sound cards, and possibly
1555 others will each in turn report their status.
1556 </p>
1557
1558 </body>
1559 </section>
1560 <section>
1561 <title>/sbin/init</title>
1562 <body>
1563
1564 <p>
1565 When the kernel finishes loading, it starts a program called <c>init</c>. This
1566 program remains running until the system is shut down. It is always assigned
1567 process ID 1, as you can see:
1568 </p>
1569
1570 <pre caption="init process ID">
1571 $ <i>ps --pid 1</i>
1572 PID TTY TIME CMD
1573 1 ? 00:00:04 init.system
1574 </pre>
1575
1576 <p>
1577 The <c>init</c> program boots the rest of your distribution by running a series
1578 of scripts. These scripts typically live in <path>/etc/rc.d/init.d</path> or
1579 <path>/etc/init.d</path>, and they perform services such as setting the
1580 system's hostname, checking the filesystem for errors, mounting additional
1581 filesystems, enabling networking, starting print services, etc. When the
1582 scripts complete, <c>init</c> starts a program called <c>getty</c> which
1583 displays the login prompt, and you're good to go!
1584 </p>
1585
1586 </body>
1587 </section>
1588 <section>
1589 <title>Digging in: LILO</title>
1590 <body>
1591
1592 <p>
1593 Now that we've taken a quick tour through the booting process, let's look more
1594 closely at the first part: the MBR and loading the kernel. The maintenance of
1595 the MBR is the responsibility of the "boot loader." The two most popular boot
1596 loaders for x86-based Linux are "LILO" (LInux LOader) and "GRUB" (GRand Unified
1597 Bootloader).
1598 </p>
1599
1600 <p>
1601 Of the two, LILO is the older and more common boot loader. LILO's presence on
1602 your system is reported at boot, with the short "LILO boot:" prompt. Note that
1603 you may need to hold down the shift key during boot to get the prompt, since
1604 often a system is configured to whiz straight through without stopping.
1605 </p>
1606
1607 <p>
1608 There's not much fanfare at the LILO prompt, but if you press the &lt;tab&gt;
1609 key, you'll be presented with a list of potential kernels (or other operating
1610 systems) to boot. Often there's only one in the list. You can boot one of them
1611 by typing it and pressing &lt;enter&gt;. Alternatively you can simply press
1612 &lt;enter&gt; and the first item on the list will boot by default.
1613 </p>
1614
1615 </body>
1616 </section>
1617 <section>
1618 <title>Using LILO</title>
1619 <body>
1620
1621 <p>
1622 Occasionally you may want to pass an option to the kernel at boot time. Some of
1623 the more common options are <c>root=</c> to specify an alternative root
1624 filesystem, <c>init=</c> to specify an alternative init program (such as
1625 <c>init=/bin/sh</c> to rescue a misconfigured system), and <c>mem=</c> to
1626 specify the amount of memory in the system (for example <c>mem=512M</c> in the
1627 case that Linux only autodetects 128M). You could pass these to the kernel at
1628 the LILO boot prompt:
1629 </p>
1630
1631 <pre caption="LILO boot prompt">
1632 LILO boot: linux root=/dev/hdb2 init=/bin/sh mem=512M
1633 </pre>
1634
1635 <p>
1636 If you need to regularly specify command-line options, you might consider
1637 adding them to <path>/etc/lilo.conf</path>. The format of that file is
1638 described in the <path>lilo.conf</path>(5) man-page.
1639 </p>
1640
1641 </body>
1642 </section>
1643 <section>
1644 <title>An important LILO gotcha</title>
1645 <body>
1646
1647 <p>
1648 Before moving on to GRUB, there is an important gotcha to LILO. Whenever you
1649 make changes to <path>/etc/lilo.conf</path>, or whenever you install a new
1650 kernel, you must run <c>lilo</c>. The <c>lilo</c> program rewrites the MBR to
1651 reflect the changes you made, including recording the absolute disk location of
1652 the kernel. The example here makes use of the -v flag for verboseness:
1653 </p>
1654
1655 <pre caption="Using lilo command with -v flag">
1656 # <i>lilo -v</i>
1657 LILO version 21.4-4, Copyright (C) 1992-1998 Werner Almesberger
1658 'lba32' extensions Copyright (C) 1999,2000 John Coffman
1659
1660 Reading boot sector from /dev/hda
1661 Merging with /boot/boot.b
1662 Mapping message file /boot/message
1663 Boot image: /boot/vmlinuz-2.2.16-22
1664 Added linux *
1665 /boot/boot.0300 exists - no backup copy made.
1666 Writing boot sector.
1667 </pre>
1668
1669 </body>
1670 </section>
1671 <section>
1672 <title>Digging in: GRUB</title>
1673 <body>
1674
1675 <p>
1676 The GRUB boot loader could be considered the next generation of boot loader,
1677 following LILO. Most visibly to users, it provides a menu interface instead of
1678 LILO's primitive prompt. For system administrators, the changes are more
1679 significant. GRUB supports more operating systems than LILO, provides some
1680 password-based security in the boot menu, and is easier to administer.
1681 </p>
1682
1683 <p>
1684 GRUB is usually installed with the <c>grub-install</c> command. Once installed,
1685 GRUB's menu is administrated by editing the file
1686 <path>/boot/grub/grub.conf</path>. Both of these tasks are beyond the scope of
1687 this document; you should read the GRUB info pages before attempting to install
1688 or administrate GRUB.
1689 </p>
1690
1691 </body>
1692 </section>
1693 <section>
1694 <title>Using GRUB</title>
1695 <body>
1696
1697 <p>
1698 To give parameters to the kernel, you can press <c>e</c> at the boot menu. This
1699 provides you with the opportunity to edit (by again pressing <c>e</c>) either
1700 the name of the kernel to load or the parameters passed to it. When you're
1701 finished editing, press &lt;enter&gt; then <c>b</c> to boot with your changes.
1702 </p>
1703
1704 </body>
1705 </section>
1706 <section>
1707 <title>dmesg</title>
1708 <body>
1709
1710 <p>
1711 The boot messages from the kernel and init scripts typically scroll by quickly.
1712 You might notice an error, but it's gone before you can properly read it. In
1713 that case, there are two places you can look after the system boots to see what
1714 went wrong (and hopefully get an idea how to fix it).
1715 </p>
1716
1717 <p>
1718 If the error occurred while the kernel was loading or probing hardware devices,
1719 you can retrieve a copy of the kernel's log using the <c>dmesg</c> command:
1720 </p>
1721
1722 <pre caption="Retrieving kernel's log using dmesg command">
1723 Linux version 2.4.16 (root@×××××××××××××.org) (gcc version 2.95.3 20010315 (release)) #1 Sat Jan 12 19:23:04 EST 2002
1724 </pre>
1725
1726 <p>
1727 Hey, we recognize that line! It's the first line the kernel prints when it
1728 loads. Indeed, if you pipe the output of <c>dmesg</c> into a pager, you can
1729 view all of the messages the kernel printed on boot, plus any messages the
1730 kernel has printed to the console in the meantime.
1731 </p>
1732
1733 </body>
1734 </section>
1735 <section>
1736 <title>/var/log/messages</title>
1737 <body>
1738
1739 <p>
1740 The second place to look for information is in the
1741 <path>/var/log/messages</path> file. This file is recorded by the syslog
1742 daemon, which accepts input from libraries, daemons, and the kernel. Each line
1743 in the messages file is timestamped. This file is a good place to look for
1744 errors that occurred during the init scripts stage of booting. For example, to
1745 see the last few messages from the nameserver:
1746 </p>
1747
1748 <pre caption="greping /var/log/messages file">
1749 # <i>grep named /var/log/messages | tail -3</i>
1750 Jan 12 20:17:41 time /usr/sbin/named[350]: listening on IPv4 interface lo, 127.0.0.1#53
1751 Jan 12 20:17:41 time /usr/sbin/named[350]: listening on IPv4 interface eth0, 10.0.0.1#53
1752 Jan 12 20:17:41 time /usr/sbin/named[350]: running
1753 </pre>
1754
1755 </body>
1756 </section>
1757 <section>
1758 <title>Additional information</title>
1759 <body>
1760
1761 <p>
1762 Additional information related to this section can be found here:
1763 </p>
1764
1765 <ul>
1766 <li>
1767 Tutorial: <uri
1768 link="http://www-106.ibm.com/developerworks/edu/l-dw-linuxgrub-i.html">Getting
1769 to know GRUB</uri>
1770 </li>
1771 <li><uri link="http://en.tldp.org/HOWTO/LILO.html">LILO Mini-HOWTO</uri></li>
1772 <li><uri link="http://www.gnu.org/software/grub/">GRUB home</uri></li>
1773 <li>
1774 Kernel command-line options in
1775 <path>/usr/src/linux/Documentation/kernel-parameters.txt</path>.
1776 </li>
1777 </ul>
1778
1779 </body>
1780 </section>
1781 </chapter>
1782
1783 <chapter>
1784 <title>Runlevels</title>
1785 <section>
1786 <title>Single-user mode</title>
1787 <body>
1788
1789 <p>
1790 Recall from the section regarding boot loaders that it's possible to pass
1791 parameters to the kernel when it boots. One of the most often used parameters
1792 is <c>s</c>, which causes the system to start in "single-user" mode. This mode
1793 usually mounts only the root filesystem, starts a minimal subset of the init
1794 scripts, and starts a shell rather than providing a login prompt.
1795 Additionally, networking is not configured, so there is no chance of external
1796 factors affecting your work.
1797 </p>
1798
1799 </body>
1800 </section>
1801 <section>
1802 <title>Understanding single-user mode</title>
1803 <body>
1804
1805 <p>
1806 So what "work" can be done with the system in such a state? To answer this
1807 question, we have to realize a vast difference between Linux and Windows.
1808 Windows is designed to normally be used by one person at a time, sitting at the
1809 console. It is effectively always in "single-user" mode. Linux, on the other
1810 hand, is used more often to serve network applications, or provide shell or X
1811 sessions to remote users on the network. These additional variables are not
1812 desirable when you want to perform maintenance operations such as restoring
1813 from backup, creating or modifying filesystems, upgrading the system from CD,
1814 etc. In these cases you should use single-user mode.
1815 </p>
1816
1817 </body>
1818 </section>
1819 <section>
1820 <title>Runlevels</title>
1821 <body>
1822
1823 <p>
1824 In fact, it's not actually necessary to reboot in order to reach single-user
1825 mode. The <c>init</c> program manages the current mode, or "runlevel," for the
1826 system. The standard runlevels for a Linux system are defined as follows:
1827 </p>
1828
1829 <ul>
1830 <li>0: Halt the computer</li>
1831 <li>1 or s: Single-user mode</li>
1832 <li>2: Multi-user, no network</li>
1833 <li>3: Multi-user, text console</li>
1834 <li>4: Multi-user, graphical console</li>
1835 <li>5: same as 4</li>
1836 <li>6: Reboot the computer.</li>
1837 </ul>
1838
1839 <p>
1840 These runlevels vary between distributions, so be sure to consult your distro's
1841 documentation.
1842 </p>
1843
1844 </body>
1845 </section>
1846 <section>
1847 <title>telinit</title>
1848 <body>
1849
1850 <p>
1851 To change to single-user mode, use the <c>telinit</c> command, which instructs
1852 <c>init</c> to change runlevels:
1853 </p>
1854
1855 <pre caption="Using telinit command">
1856 # <i>telinit 1</i>
1857 </pre>
1858
1859 <p>
1860 You can see from the table above that you can also shutdown or reboot the
1861 system in this manner. <c>telinit 0</c> will halt the computer; <c>telinit
1862 6</c> will reboot the computer. When you issue the <c>telinit</c> command to
1863 change runlevels, a subset of the <c>init</c> scripts will run to either shut
1864 down or start up system services.
1865 </p>
1866
1867 </body>
1868 </section>
1869 <section>
1870 <title>Runlevel etiquette</title>
1871 <body>
1872
1873 <p>
1874 However, note that this is rather rude if there are users on the system at the
1875 time (who may be quite angry with you). The <c>shutdown</c> command provides a
1876 method for changing runlevels in a way that treats users reasonably. Similarly
1877 to the <c>kill</c> command's ability to send a variety of signals to a process,
1878 <c>shutdown</c> can be used to halt, reboot, or change to single-user mode. For
1879 example, to change to single-user mode in 5 minutes:
1880 </p>
1881
1882 <pre caption="Changing to single-user mode with 5 minutes delay">
1883 # <i>shutdown 5</i>
1884 Broadcast message from root (pts/2) (Tue Jan 15 19:40:02 2002):
1885 The system is going DOWN to maintenance mode in 5 minutes!
1886 </pre>
1887
1888 <p>
1889 If you press &lt;control-c&gt; at this point, you can cancel the pending switch
1890 to single-user mode. The message above would appear on all terminals on the
1891 system, so users have a reasonable amount of time to save their work and log
1892 off. (Some might argue whether or not 5 minutes is "reasonable")
1893 </p>
1894
1895 </body>
1896 </section>
1897 <section>
1898 <title>"Now" and halt</title>
1899 <body>
1900
1901 <p>
1902 If you're the only person on the system, you can use "now" instead of an
1903 argument in minutes. For example, to reboot the system right now:
1904 </p>
1905
1906 <pre caption="Using shutdown command with now option">
1907 # <i>shutdown -r now</i>
1908 </pre>
1909
1910 <p>
1911 No chance to hit &lt;control-c&gt; in this case; the system is already on its
1912 way down. Finally, the -h option halts the system:
1913 </p>
1914
1915 <pre caption="Halting the system">
1916 # <i>shutdown -h 1</i>
1917 Broadcast message from root (pts/2) (Tue Jan 15 19:50:58 2002):
1918 The system is going DOWN for system halt in 1 minute!
1919 </pre>
1920
1921 </body>
1922 </section>
1923 <section>
1924 <title>The default runlevel</title>
1925 <body>
1926
1927 <p>
1928 You've probably gathered at this point that the <c>init</c> program is quite
1929 important on a Linux system. You can configure <c>init</c> by editing the file
1930 <path>/etc/initttab</path>, which is described in the inittab(5) man-page.
1931 We'll just touch on one key line in this file:
1932 </p>
1933
1934 <pre caption="Editing init configuration file">
1935 # <i>grep ^id: /etc/inittab</i>
1936 id:3:initdefault:
1937 </pre>
1938
1939 <p>
1940 On my system, runlevel 3 is the default runlevel. It can be useful to change
1941 this value if you prefer your system to boot immediately into a graphical login
1942 (usually runlevel 4 or 5). To do so, simply edit the file and change the value
1943 on that line. But be careful! If you change it to something invalid, you'll
1944 probably have to employ the <c>init=/bin/sh</c> trick we mentioned earlier.
1945 </p>
1946
1947 </body>
1948 </section>
1949 <section>
1950 <title>Additional information</title>
1951 <body>
1952
1953 <p>
1954 Additional information related to this section can be found at:
1955 </p>
1956
1957 <ul>
1958 <li>
1959 <uri
1960 link="http://www.redhat.com/docs/manuals/linux/RHL-7.2-Manual/ref-guide/s1-init-boot-shutdown-init.html">
1961 Sysvinit docs at Red Hat</uri>
1962 </li>
1963 <li>
1964 <uri link="http://www.linuxdoc.org/LDP/sag/init.html">Linux System
1965 Administrator's Guide section on init</uri>.
1966 </li>
1967 </ul>
1968
1969 </body>
1970 </section>
1971 </chapter>
1972
1973 <chapter>
1974 <title>Filesystem quotas</title>
1975 <section>
1976 <title>Introducing quotas</title>
1977 <body>
1978
1979 <p>
1980 Quotas are a feature of Linux that let you track disk usage by user or by
1981 group. They're useful for preventing any single user or group from using an
1982 unfair portion of a filesystem, or from filling it up altogether. Quotas can
1983 only be enabled and managed by the root user. In this section, I'll describe
1984 how to set up quotas on your Linux system and manage them effectively.
1985 </p>
1986
1987 </body>
1988 </section>
1989 <section>
1990 <title>Kernel support</title>
1991 <body>
1992
1993 <p>
1994 Quotas are a feature of the filesystem; therefore, they require kernel support.
1995 The first thing you'll need to do is verify that you have quota support in your
1996 kernel. You can do this using grep:
1997 </p>
1998
1999 <pre caption="Checking kernel configuration for quota support">
2000 # <i>cd /usr/src/linux</i>
2001 # <i>grep -i quota .config</i>
2002 CONFIG_QUOTA=y
2003 CONFIG_XFS_QUOTA=y
2004 </pre>
2005
2006 <p>
2007 If this command returns something less conclusive (such as CONFIG_QUOTA is not
2008 set) then you should rebuild your kernel to include quota support. This is not
2009 a difficult process, but is outside of the scope of this section of the
2010 tutorial. If you're unfamiliar with the steps to build and install a new
2011 kernel, you might consider referencing this <uri
2012 link="/doc/en/articles/linux-kernel-compiling.xml">tutorial</uri>.
2013 </p>
2014
2015 </body>
2016 </section>
2017 <section>
2018 <title>Filesystem support</title>
2019 <body>
2020
2021 <p>
2022 Before diving into the administration of quotas, please note that quota support
2023 on Linux as of the 2.4.x kernel series is not complete. There are currently
2024 problems with quotas in the ext2 and ext3 filesystems, and ReiserFS does not
2025 appear to support quotas at all. This tutorial bases its examples on XFS, which
2026 seems to properly <uri
2027 link="http://oss.sgi.com/projects/xfs/faq.html#quotaswork">support
2028 quotas</uri>.
2029 </p>
2030
2031 </body>
2032 </section>
2033 <section>
2034 <title>Configuring quotas</title>
2035 <body>
2036
2037 <p>
2038 To begin configuring quotas on your system, you should edit
2039 <path>/etc/fstab</path> to mount the affected filesystems with quotas enabled.
2040 For our example, we use an XFS filesystem mounted with user and group quotas
2041 enabled:
2042 </p>
2043
2044 <pre caption="Configuring quotas">
2045 # <i>grep quota /etc/fstab</i>
2046 /usr/users /mnt/hdc1 xfs usrquota,grpquota,noauto 0 0
2047 # <i>mount /usr/users</i>
2048 </pre>
2049
2050 <p>
2051 Note that the usrquota and grpquota options don't necessarily enable quotas on
2052 a filesystem. You can make sure quotas are enabled using the <c>quotaon</c>
2053 command:
2054 </p>
2055
2056 <pre caption="Enabling quotas">
2057 # <i>quotaon /usr/users</i>
2058 </pre>
2059
2060 <p>
2061 There is a corresponding <c>quotaoff</c> command should you desire to disable
2062 quotas in the future:
2063 </p>
2064
2065 <pre caption="Disabling quotas">
2066 # <i>quotaoff /usr/users</i>
2067 </pre>
2068
2069 <p>
2070 But for the moment, if you're trying some of the examples in this tutorial, be
2071 sure to have quotas enabled.
2072 </p>
2073
2074 </body>
2075 </section>
2076 <section>
2077 <title>The quota command</title>
2078 <body>
2079
2080 <p>
2081 The <c>quota</c> command displays a user's disk usage and limits for all of the
2082 filesystems currently mounted. The -v option includes in the list filesystems
2083 where quotas are enabled, but no storage is currently allocated to the user.
2084 </p>
2085
2086 <pre caption="Using quota command">
2087 # <i>quota -v</i>
2088
2089 Disk quotas for user root (uid 0):
2090 Filesystem blocks quota limit grace files quota limit grace
2091 /dev/hdc1 0 0 0 3 0 0
2092 </pre>
2093
2094 <p>
2095 The first column, blocks, shows how much disk space the root user is currently
2096 using on each filesystem listed. The following columns, quota and limit, refer
2097 to the limits currently in place for disk space. We will explain the difference
2098 between quota and limit, and the meaning of the grace column later on. The
2099 files column shows how many files the root user owns on the particular
2100 filesystem. The following quota and limit columns refer to the limits for
2101 files.
2102 </p>
2103
2104 </body>
2105 </section>
2106 <section>
2107 <title>Viewing quota</title>
2108 <body>
2109
2110 <p>
2111 Any user can use the <c>quota</c> command to view their own quota report as
2112 shown in the previous example. However only the root user can look at the
2113 quotas for other users and groups. For example, say we have a filesystem,
2114 <path>/dev/hdc1</path> mounted on <path>/usr/users</path>, with two users: jane
2115 and john. First, let's look at jane's disk usage and limits.
2116 </p>
2117
2118 <pre caption="Viewing quota for user">
2119 # <i>quota -v jane</i>
2120
2121 Disk quotas for user jane (uid 1003):
2122 Filesystem blocks quota limit grace files quota limit grace
2123 /dev/hdc1 4100 0 0 6 0 0
2124 </pre>
2125
2126 <p>
2127 In this example, we see that jane's quotas are set to zero, which indicates no
2128 limit.
2129 </p>
2130
2131 </body>
2132 </section>
2133 <section>
2134 <title>edquota</title>
2135 <body>
2136
2137 <p>
2138 Now let's say we want to give the user jane a quota. We do this with the
2139 <c>edquota</c> command. Before we start editing quotas, let's see how much
2140 space we have available on <path>/usr/users</path>:
2141 </p>
2142
2143 <pre caption="Checking available space on /usr/users">
2144 # <i>df /usr/users</i>
2145
2146 Filesystem 1k-blocks Used Available Use% Mounted on
2147 /dev/hdc1 610048 4276 605772 1% /usr/users
2148 </pre>
2149
2150 <p>
2151 This isn't a particularly large filesystem, only 600MB or so. It seems prudent
2152 to give jane a quota so that she can't use more than her fair share. When you
2153 run <c>edquota</c>, a temporary file is created for each user or group you
2154 specify on the command line.
2155 </p>
2156
2157 <p>
2158 The <c>edquota</c> command puts you in an editor, which enables you to add
2159 and/or modify quotas via this temporary file.
2160 </p>
2161
2162 <pre caption="Modifying quota">
2163 # <i>edquota jane</i>
2164
2165 Disk quotas for user jane (uid 1003):
2166 Filesystem blocks soft hard inodes soft hard
2167 /dev/hdc1 4100 0 0 6 0 0
2168 </pre>
2169
2170 <p>
2171 Similar to the output from the <c>quota</c> command above, the blocks and
2172 inodes columns in this temporary file refer to the disk space and number of
2173 files jane is currently using. You cannot modify the number of blocks or
2174 inodes; any attempt to do so will be summarily discarded by the system. The
2175 soft and hard columns show jane's quota, which we can see is currently
2176 unlimited (again, zero indicates no quota).
2177 </p>
2178
2179 </body>
2180 </section>
2181 <section>
2182 <title>Understanding edquota</title>
2183 <body>
2184
2185 <p>
2186 The soft limit is the maximum amount of disk usage that jane has allocated to
2187 her on the filesystem (in other words, her quota). If jane uses more disk
2188 space than is allocated in her soft limit, she will be issued warnings about
2189 her quota violation via e-mail. The hard limit indicates the absolute limit on
2190 disk usage, which a user can't exceed. If jane tries to use more disk space
2191 than is specified in the hard limit, she will get a "Disk quota exceeded"
2192 error and will not be able to complete the operation.
2193 </p>
2194
2195 </body>
2196 </section>
2197 <section>
2198 <title>Making changes</title>
2199 <body>
2200
2201 <p>
2202 So here we change jane's soft and hard limits and save the file:
2203 </p>
2204
2205 <pre caption="Changed soft and hard limits">
2206
2207 Disk quotas for user jane (uid 1003):
2208 Filesystem blocks soft hard inodes soft hard
2209 /dev/hdc1 4100 10000 11500 6 2000 2500
2210 </pre>
2211
2212 <p>
2213 Running the <c>quota</c> command, we can inspect our modifications:
2214 </p>
2215
2216 <pre caption="Checking quota for user jane">
2217 # <i>quota jane</i>
2218
2219 Disk quotas for user jane (uid 1003):
2220 Filesystem blocks quota limit grace files quota limit grace
2221 /dev/hdc1 4100 10000 11500 6 2000 2500
2222 </pre>
2223
2224 </body>
2225 </section>
2226 <section>
2227 <title>Copying quotas</title>
2228 <body>
2229
2230 <p>
2231 You'll remember that we also have another user, john, on this filesystem. If
2232 we want to give john the same quota as jane, we can use the -p option to
2233 <c>edquota</c>, which uses jane's quotas as a prototype for all following users
2234 on the command line. This is an easy way to set up quotas for groups of users.
2235 </p>
2236
2237 <pre caption="Coping quotas">
2238 # <i>edquota -p jane john</i>
2239 # <i>quota john</i>
2240
2241 Disk quotas for user john (uid 1003):
2242 Filesystem blocks quota limit grace files quota limit grace
2243 /dev/hdc1 0 10000 11500 1 2000 2500
2244 </pre>
2245
2246 </body>
2247 </section>
2248 <section>
2249 <title>Group restrictions</title>
2250 <body>
2251
2252 <p>
2253 We can also use <c>edquota</c> to restrict the allocation of disk space based
2254 on the group ownership of files. For example, to edit the quotas for the users
2255 group:
2256 </p>
2257
2258 <pre caption="Editing quotas for the users group">
2259 # <i>edquota -g users</i>
2260 Disk quotas for group users (gid 100): Filesystem blocks soft hard inodes soft hard /dev/hdc1 4100 500000 510000 7 100000 125000
2261 </pre>
2262
2263 <p>
2264 Then to view the modified quotas for the users group:
2265 </p>
2266
2267 <pre caption="Viewing modified quotas">
2268 # <i>quota -g users</i>
2269 Disk quotas for group users (gid 100): Filesystem blocks quota limit grace files quota limit grace /dev/hdc1 4100 500000 510000 7 100000 125000
2270 </pre>
2271
2272 </body>
2273 </section>
2274 <section>
2275 <title>The repquota command</title>
2276 <body>
2277
2278 <p>
2279 Looking at each users' quotas using the <c>quota</c> command can be tedious if
2280 you have many users on a filesytem. The <c>repquota</c> command summarizes the
2281 quotas for a filesystem into a nice report. For example, to see the quotas for
2282 all users and groups on <path>/usr/users</path>:
2283 </p>
2284
2285 <pre caption="Summarizing quotas">
2286 # <i>repquota -ug /usr/users</i>
2287 *** Report for user quotas on device /dev/hdc1
2288 Block grace time: 7days; Inode grace time: 7days
2289 Block limits File limits
2290 User used soft hard grace used soft hard grace
2291 ----------------------------------------------------------------------
2292 root -- 0 0 0 3 0 0
2293 john -- 0 10000 11500 1 2000 2500
2294 jane -- 4100 10000 11500 6 2000 2500
2295
2296 *** Report for group quotas on device /dev/hdc1
2297 Block grace time: 7days; Inode grace time: 7days
2298 Block limits File limits
2299 Group used soft hard grace used soft hard grace
2300 ----------------------------------------------------------------------
2301 root -- 0 0 0 3 0 0
2302 users -- 4100 500000 510000 7 100000 125000
2303 </pre>
2304
2305 </body>
2306 </section>
2307 <section>
2308 <title>Repquota options</title>
2309 <body>
2310
2311 <p>
2312 There are a couple of other options to repquota that are worth mentioning.
2313 <c>repquota -a</c> will report on all currently mounted read-write filesystems
2314 that have quotas enabled. <c>repquota -n</c> will not resolve uids and gids to
2315 names. This can speed up the output for large lists.
2316 </p>
2317
2318 </body>
2319 </section>
2320 <section>
2321 <title>Monitoring quotas</title>
2322 <body>
2323
2324 <p>
2325 If you are a system administrator, you will want to have a way to monitor
2326 quotas to ensure that they are not being exceeded. An easy way to do this is
2327 to use <c>warnquota</c>. The <c>warnquota</c> command sends e-mail to users who
2328 have exceeded their soft limit. Typically <c>warnquota</c> is run as a
2329 cron-job.
2330 </p>
2331
2332 <p>
2333 When a user exceeds his or her soft limit, the grace column in the output from
2334 the <c>quota</c> command will indicate the grace period -- how long before the
2335 soft limit is enforced for that filesystem.
2336 </p>
2337
2338 <pre caption="Checking grace period">
2339 Disk quotas for user jane (uid 1003):
2340 Filesystem blocks quota limit grace files quota limit grace
2341 /dev/hdc1 10800* 10000 11500 7days 7 2000 2500
2342 </pre>
2343
2344 <p>
2345 By default, the grace period for blocks and inodes is seven days.
2346 </p>
2347
2348 </body>
2349 </section>
2350 <section>
2351 <title>Modifying the grace period</title>
2352 <body>
2353
2354 <p>
2355 You can modify the grace period for filesystems using <c>equota</c>:
2356 </p>
2357
2358 <pre caption="Modyfing grace period">
2359 # <i>edquota -t</i>
2360 </pre>
2361
2362 <p>
2363 This puts you in an editor of a temporary file that looks like this:
2364 </p>
2365
2366 <pre caption="Looks of a grace editor">
2367 Grace period before enforcing soft limits for users:
2368 Time units may be: days, hours, minutes, or seconds
2369 Filesystem Block grace period Inode grace period
2370 /dev/hdc1 7days 7days
2371 </pre>
2372
2373 <p>
2374 The text in the file is nicely explanatory. Be sure to leave your users enough
2375 time to receive their warning e-mail and find some files to delete!
2376 </p>
2377
2378 </body>
2379 </section>
2380 <section>
2381 <title>Checking quotas on boot</title>
2382 <body>
2383
2384 <p>
2385 You may also want to check quotas on boot. You can do this using a script to
2386 run the <c>quotacheck</c> command; there is an example script in the <uri
2387 link="http://en.tldp.org/HOWTO/Quota.html">Quota Mini HOWTO</uri>. The
2388 <c>quotacheck</c> command also has the ability to repair damaged quota files;
2389 familiarize yourself with it by reading the quotacheck(8) man-page.
2390 </p>
2391
2392 <p>
2393 Also remember what we mentioned previously regarding <c>quotaon</c> and
2394 <c>quotaoff</c>. You should incorporate <c>quotaon</c> into your boot script so
2395 that quotas are enabled. To enable quotas on all filesystems where quotas are
2396 supported, use the -a option:
2397 </p>
2398
2399 <pre caption="Using -a option">
2400 # <i>quotaon -a</i>
2401 </pre>
2402
2403 </body>
2404 </section>
2405 </chapter>
2406
2407 <chapter>
2408 <title>System logs</title>
2409 <section>
2410 <title>Introducing syslogd</title>
2411 <body>
2412
2413 <p>
2414 The syslog daemon provides a mature client-server mechanism for logging
2415 messages from programs running on the system. Syslog receives a message from a
2416 daemon or program, categorizes the message by priority and type, then logs it
2417 according to administrator-configurable rules. The result is a robust and
2418 unified approach to managing logs.
2419 </p>
2420
2421 </body>
2422 </section>
2423 <section>
2424 <title>Reading logs</title>
2425 <body>
2426
2427 <p>
2428 Let's jump right in and look at the contents of a syslog-recorded log file.
2429 Afterward, we can come back to syslog configuration. The FHS (see <uri
2430 link="/doc/en/articles/lpi-101-administration-p2.xml">Part 2</uri> of this
2431 tutorial series) mandates that log files be placed in <path>/var/log</path>.
2432 Here we use the <c>tail</c> command to display the last 10 lines in the
2433 "messages" file:
2434 </p>
2435
2436 <pre caption="Reading logs">
2437 # <i>cd /var/log</i>
2438 # <i>tail messages</i>
2439 Jan 12 20:17:39 bilbo init: Entering runlevel: 3
2440 Jan 12 20:17:40 bilbo /usr/sbin/named[337]: starting BIND 9.1.3
2441 Jan 12 20:17:40 bilbo /usr/sbin/named[337]: using 1 CPU
2442 Jan 12 20:17:41 bilbo /usr/sbin/named[350]: loading configuration from '/etc/bind/named.conf'
2443 Jan 12 20:17:41 bilbo /usr/sbin/named[350]: no IPv6 interfaces found
2444 Jan 12 20:17:41 bilbo /usr/sbin/named[350]: listening on IPv4 interface lo, 127.0.0.1#53
2445 Jan 12 20:17:41 bilbo /usr/sbin/named[350]: listening on IPv4 interface eth0, 10.0.0.1#53
2446 Jan 12 20:17:41 bilbo /usr/sbin/named[350]: running
2447 Jan 12 20:41:58 bilbo gnome-name-server[11288]: starting
2448 Jan 12 20:41:58 bilbo gnome-name-server[11288]: name server starting
2449 </pre>
2450
2451 <p>
2452 You may remember from the text-processing whirlwind that the <c>tail</c>
2453 command displays the last lines in a file. In this case, we can see that the
2454 nameserver named was recently started on this system, which is named bilbo. If
2455 we were deploying IPv6, we might notice that named found no IPv6 interfaces,
2456 indicating a potential problem. Additionally, we can see that a user may have
2457 recently started GNOME, indicated by the presence of gnome-name-server.
2458 </p>
2459
2460 </body>
2461 </section>
2462 <section>
2463 <title>Tailing log files</title>
2464 <body>
2465
2466 <p>
2467 An experienced system administrator might use <c>tail -f</c> to follow the
2468 output to a log file as it occurs:
2469 </p>
2470
2471 <pre caption="Using tail -f command">
2472 # <i>tail -f /var/log/messages</i>
2473 </pre>
2474
2475 <p>
2476 For example, in the case of debugging our theoretical IPv6 problem, running the
2477 above command in one terminal while stopping and starting named would
2478 immediately display the messages from that daemon. This can be a useful
2479 technique when debugging. Some administrators even like to keep a constantly
2480 running <c>tail -f</c> messages in a terminal where they can keep an eye on
2481 system events.
2482 </p>
2483
2484 </body>
2485 </section>
2486 <section>
2487 <title>Grepping logs</title>
2488 <body>
2489
2490 <p>
2491 Another useful technique is to search a log file using the <c>grep</c> utility,
2492 described in <uri link="/doc/en/articles/lpi-101-administration-p2.xml">Part
2493 2</uri> of this tutorial series. In the above case, we might use grep to find
2494 where "named" behavior has changed:
2495 </p>
2496
2497 <pre caption="Grepping logs">
2498 # <i>grep named /var/log/messages</i>
2499 </pre>
2500
2501 </body>
2502 </section>
2503 <section>
2504 <title>Log overview</title>
2505 <body>
2506
2507 <p>
2508 The following summarizes the log files typically found in <path>/var/log</path>
2509 and maintained by syslog:
2510 </p>
2511
2512 <ul>
2513 <li>
2514 <path>messages</path>: Informational and error messages from general system
2515 programs and daemons
2516 </li>
2517 <li>
2518 <path>secure</path>: Authentication messages and errors, kept separate from
2519 <path>messages</path> for extra security
2520 </li>
2521 <li><path>maillog</path>: Mail-related messages and errors</li>
2522 <li><path>cron</path>: Cron-related messages and errors</li>
2523 <li><path>spooler</path>: UUCP and news-related messages and errors.</li>
2524 </ul>
2525
2526 </body>
2527 </section>
2528 <section>
2529 <title>syslog.conf</title>
2530 <body>
2531
2532 <p>
2533 As a matter of fact, now would be a good time to investigate the syslog
2534 configuration file, <path>/etc/syslog.conf</path>. (Note: If you don't have