2 The FreeBSD Documentation Project
4 $FreeBSD: doc/en_US.ISO8859-1/books/handbook/config/chapter.sgml,v 1.154 2004/06/08 11:41:49 den Exp $
5 $DragonFly: doc/en/books/handbook/config/chapter.sgml,v 1.9 2005/09/06 00:28:13 reed Exp $
8 <chapter id="config-tuning">
12 <firstname>Chern</firstname>
13 <surname>Lee</surname>
14 <contrib>Written by </contrib>
19 <firstname>Mike</firstname>
20 <surname>Smith</surname>
21 <contrib>Based on a tutorial written by </contrib>
26 <firstname>Matt</firstname>
27 <surname>Dillon</surname>
28 <contrib>Also based on tuning(7) written by </contrib>
33 <title>Configuration and Tuning</title>
35 <sect1 id="config-synopsis">
36 <title>Synopsis</title>
38 <indexterm><primary>system configuration</primary></indexterm>
39 <indexterm><primary>system optimization</primary></indexterm>
41 <para>One of the important aspects of &os; is system configuration.
42 Correct system configuration will help prevent headaches during future upgrades.
43 This chapter will explain much of the &os; configuration process,
44 including some of the parameters which
45 can be set to tune a &os; system.
48 <para>After reading this chapter, you will know:
52 <para>How to efficiently work with
53 file systems and swap partitions.</para>
56 <para>The basics of <filename>rc.conf</filename> configuration and
57 <filename>rc.d</filename> startup systems.</para>
60 <para>How to configure and test a network card.</para>
63 <para>How to configure virtual hosts on your network devices.</para>
66 <para>How to use the various configuration files in
67 <filename>/etc</filename>.</para>
70 <para>How to tune &os; using <command>sysctl</command>
74 <para>How to tune disk performance and modify kernel
80 <para>Before reading this chapter, you should:
84 <para>Understand &unix; and &os; basics (<xref
85 linkend="basics">).</para>
88 <para>Be familiar with keeping &os; sources up to date
89 (<xref linkend="updating-setup">), and
90 the basics of kernel configuration/compilation
91 (<xref linkend="kernelconfig">).</para>
97 <sect1 id="configtuning-initial">
98 <title>Initial Configuration</title>
101 <title>Partition Layout</title>
103 <indexterm><primary>partition layout</primary></indexterm>
105 <primary><filename>/etc</filename></primary>
108 <primary><filename>/var</filename></primary>
111 <primary><filename>/usr</filename></primary>
115 <title>Base Partitions</title>
117 <para>When laying out file systems with &man.disklabel.8;
119 drives transfer data faster from the outer
121 Thus smaller and heavier-accessed file systems
122 should be closer to the outside of the drive, while
123 larger partitions like <filename>/usr</filename> should be placed
124 toward the inner. It is a good idea to create
125 partitions in a similar order to: root, swap,
126 <filename>/var</filename>, <filename>/usr</filename>.</para>
128 <para>The size of <filename>/var</filename>
129 reflects the intended machine usage.
130 <filename>/var</filename> is used to hold
131 mailboxes, log files, and printer spools. Mailboxes and log
132 files can grow to unexpected sizes depending
133 on how many users exist and how long log
134 files are kept. Most users would never require a gigabyte,
135 but remember that <filename>/var/tmp</filename>
136 must be large enough to contain packages.
139 <para>The <filename>/usr</filename> partition holds much
140 of the files required to support the system, the &man.ports.7;
141 collection (recommended) and the source code (optional). Both
142 of which are optional at install time.
143 At least 2 gigabytes would be recommended for this partition.</para>
145 <para>When selecting partition sizes, keep the space
146 requirements in mind. Running out of space in
147 one partition while barely using another can be a
150 <!-- todo: reed: fix this for the new installer, if it applies
151 <note><para>Some users have found that &man.sysinstall.8;'s
152 <literal>Auto-defaults</literal> partition sizer will
153 sometimes select smaller than adequate <filename>/var</filename>
154 and <filename>/</filename> partitions. Partition wisely and
155 generously.</para></note>
160 <sect3 id="swap-design">
161 <title>Swap Partition</title>
163 <indexterm><primary>swap sizing</primary></indexterm>
164 <indexterm><primary>swap partition</primary></indexterm>
166 <para>As a rule of thumb, the swap partition should be
167 about double the size of system memory (RAM). For example,
168 if the machine has 128 megabytes of memory,
169 the swap file should be 256 megabytes. Systems with
170 less memory may perform better with more swap.
171 Less than 256 megabytes of swap is not recommended and
172 memory expansion should be considered.
173 The kernel's VM paging algorithms are tuned to
174 perform best when the swap partition is at least two times the
175 size of main memory. Configuring too little swap can lead to
176 inefficiencies in the VM page scanning code and might create
177 issues later if more memory is added.</para>
179 <para>On larger systems with multiple SCSI disks (or
180 multiple IDE disks operating on different controllers), it is
181 recommend that a swap is configured on each drive (up
182 to four drives). The swap partitions should be
183 approximately the same size. The kernel can handle arbitrary
184 sizes but internal data structures scale to 4 times the
185 largest swap partition. Keeping the swap partitions near the
186 same size will allow the kernel to optimally stripe swap space
188 Large swap sizes are fine, even if swap is not
189 used much. It might be easier to recover
190 from a runaway program before being forced to reboot.</para>
194 <title>Why Partition?</title>
196 <para>Several users think a single large partition will be fine,
197 but there are several reasons why this is a bad idea.
198 First, each partition has different operational
199 characteristics and separating them allows the file system to
200 tune accordingly. For example, the root
201 and <filename>/usr</filename> partitions are read-mostly, without
202 much writing. While a lot of reading and writing could
203 occur in <filename>/var</filename> and
204 <filename>/var/tmp</filename>.</para>
206 <para>By properly partitioning a system, fragmentation
207 introduced in the smaller write heavy partitions
208 will not bleed over into the mostly-read partitions.
209 Keeping the write-loaded partitions closer to
212 increase I/O performance in the partitions where it occurs
213 the most. Now while I/O
214 performance in the larger partitions may be needed,
215 shifting them more toward the edge of the disk will not
216 lead to a significant performance improvement over moving
217 <filename>/var</filename> to the edge.
218 Finally, there are safety concerns. A smaller, neater root
219 partition which is mostly read-only has a greater
220 chance of surviving a bad crash.</para>
226 <sect1 id="configtuning-core-configuration">
227 <title>Core Configuration</title>
230 <primary>rc files</primary>
231 <secondary><filename>rc.conf</filename></secondary>
234 <para>The principal location for system configuration information
235 is within <filename>/etc/rc.conf</filename>. This file
236 contains a wide range of configuration information, principally
237 used at system startup to configure the system. Its name
238 directly implies this; it is configuration information for the
239 <filename>rc*</filename> files.</para>
241 <para>An administrator should make entries in the
242 <filename>rc.conf</filename> file to
243 override the default settings from
244 <filename>/etc/defaults/rc.conf</filename>. The defaults file
245 should not be copied verbatim to <filename>/etc</filename> - it
246 contains default values, not examples. All system-specific
247 changes should be made in the <filename>rc.conf</filename>
250 <para>A number of strategies may be applied in clustered
251 applications to separate site-wide configuration from
252 system-specific configuration in order to keep administration
253 overhead down. The recommended approach is to place site-wide
254 configuration into another file,
255 such as <filename>/etc/rc.conf.site</filename>, and then include
256 this file into <filename>/etc/rc.conf</filename>, which will
257 contain only system-specific information.</para>
259 <para>As <filename>rc.conf</filename> is read by &man.sh.1; it is
260 trivial to achieve this. For example:</para>
263 <listitem><para>rc.conf:</para>
264 <programlisting> . rc.conf.site
265 hostname="node15.example.com"
266 network_interfaces="fxp0 lo0"
267 ifconfig_fxp0="inet 10.1.1.1"</programlisting></listitem>
268 <listitem><para>rc.conf.site:</para>
269 <programlisting> defaultrouter="10.1.1.254"
271 blanktime="100"</programlisting></listitem>
274 <para>The <filename>rc.conf.site</filename> file can then be
275 distributed to every system using <command>rsync</command> or a
276 similar program, while the <filename>rc.conf</filename> file
277 remains unique.</para>
279 <para>Upgrading the system using
280 <command>make world</command> will not overwrite the
281 <filename>rc.conf</filename>
282 file, so system configuration information will not be lost.</para>
286 <sect1 id="configtuning-appconfig">
287 <title>Application Configuration</title>
289 <para>Typically, installed applications have their own
290 configuration files, with their own syntax, etc. It is
291 important that these files be kept separate from the base
292 system, so that they may be easily located and managed by the
293 package management tools.</para>
295 <indexterm><primary>/usr/local/etc</primary></indexterm>
297 <para>Typically, these files are installed in
298 <filename>/usr/local/etc</filename>. In the case where an
299 application has a large number of configuration files, a
300 subdirectory will be created to hold them.</para>
302 <para>Normally, when a port or package is installed, sample
303 configuration files are also installed. These are usually
304 identified with a <filename>.default</filename> suffix. If there
306 configuration files for the application, they will be created by
307 copying the <filename>.default</filename> files.</para>
309 <para>For example, consider the contents of the directory
310 <filename>/usr/local/etc/apache</filename>:</para>
312 <literallayout class="monospaced">-rw-r--r-- 1 root wheel 2184 May 20 1998 access.conf
313 -rw-r--r-- 1 root wheel 2184 May 20 1998 access.conf.default
314 -rw-r--r-- 1 root wheel 9555 May 20 1998 httpd.conf
315 -rw-r--r-- 1 root wheel 9555 May 20 1998 httpd.conf.default
316 -rw-r--r-- 1 root wheel 12205 May 20 1998 magic
317 -rw-r--r-- 1 root wheel 12205 May 20 1998 magic.default
318 -rw-r--r-- 1 root wheel 2700 May 20 1998 mime.types
319 -rw-r--r-- 1 root wheel 2700 May 20 1998 mime.types.default
320 -rw-r--r-- 1 root wheel 7980 May 20 1998 srm.conf
321 -rw-r--r-- 1 root wheel 7933 May 20 1998 srm.conf.default</literallayout>
323 <para>The file sizes show that only the <filename>srm.conf</filename>
324 file has been changed. A later update of the <application>Apache</application> port would not
325 overwrite this changed file.</para>
329 <sect1 id="configtuning-starting-services">
330 <title>Starting Services</title>
332 <indexterm><primary>services</primary></indexterm>
334 <para>It is common for a system to host a number of services.
335 These may be started in several different fashions, each having
336 different advantages.</para>
338 <indexterm><primary>/usr/local/etc/rc.d</primary></indexterm>
340 <para>Software installed from a port or the packages collection
341 will often place a script in
342 <filename>/usr/local/etc/rc.d</filename> which is invoked at
343 system startup with a <option>start</option> argument, and at
344 system shutdown with a <option>stop</option> argument.
345 This is the recommended way for
346 starting system-wide services that are to be run as
347 <username>root</username>, or that
348 expect to be started as <username>root</username>.
349 These scripts are registered as
350 part of the installation of the package, and will be removed
351 when the package is removed.</para>
353 <para>A generic startup script in
354 <filename>/usr/local/etc/rc.d</filename> looks like:</para>
356 <programlisting>#!/bin/sh
361 /usr/local/bin/foobar
364 kill -9 `cat /var/run/foobar.pid`
367 echo "Usage: `basename $0` {start|stop}" >&2
375 <para>The startup scripts of &os; will look in
376 <filename>/usr/local/etc/rc.d</filename> for scripts that have an
377 <literal>.sh</literal> extension and are executable by
378 <username>root</username>. Those scripts that are found are called with
379 an option <option>start</option> at startup, and <option>stop</option>
380 at shutdown to allow them to carry out their purpose. So if you wanted
381 the above sample script to be picked up and run at the proper time during
382 system startup, you should save it to a file called
383 <filename>FooBar.sh</filename> in
384 <filename>/usr/local/etc/rc.d</filename> and make sure it is
385 executable. You can make a shell script executable with &man.chmod.1;
386 as shown below:</para>
388 <screen>&prompt.root; <userinput>chmod 755 <replaceable>FooBar.sh</replaceable></userinput></screen>
390 <para>Some services expect to be invoked by &man.inetd.8; when a
391 connection is received on a suitable port. This is common for
392 mail reader servers (POP and IMAP, etc.). These services are
393 enabled by editing the file <filename>/etc/inetd.conf</filename>.
394 See &man.inetd.8; for details on editing this file.</para>
396 <para>Some additional system services may not be covered by the
397 toggles in <filename>/etc/rc.conf</filename>. These are
398 traditionally enabled by placing the command(s) to invoke them
399 in <filename>/etc/rc.local</filename> (which does not exist by default).
400 Note that <filename>rc.local</filename> is
401 generally regarded as the location of last resort; if there is a
402 better place to start a service, do it there.</para>
404 <note><para>Do <emphasis>not</emphasis> place any commands in
405 <filename>/etc/rc.conf</filename>. To start daemons, or
406 run any commands at boot time, place a script in
407 <filename>/usr/local/etc/rc.d</filename> instead.</para>
410 <para>It is also possible to use the &man.cron.8; daemon to start
411 system services. This approach has a number of advantages, not
412 least being that because &man.cron.8; runs these processes as the
413 owner of the <command>crontab</command>, services may be started
414 and maintained by non-<username>root</username> users.</para>
416 <para>This takes advantage of a feature of &man.cron.8;: the
417 time specification may be replaced by <literal>@reboot</literal>,
419 cause the job to be run when &man.cron.8; is started shortly after
423 <sect1 id="configtuning-cron">
427 <firstname>Tom</firstname>
428 <surname>Rhodes</surname>
429 <contrib>Contributed by </contrib>
434 <title>Configuring the <command>cron</command> Utility</title>
436 <indexterm><primary>cron</primary>
437 <secondary>configuration</secondary></indexterm>
439 <para>One of the most useful utilities in &os; is &man.cron.8;. The
440 <command>cron</command> utility runs in the background and constantly
441 checks the <filename>/etc/crontab</filename> file. The <command>cron</command>
442 utility also checks the <filename>/var/cron/tabs</filename> directory, in
443 search of new <filename>crontab</filename> files. These
444 <filename>crontab</filename> files store information about specific
445 functions which <command>cron</command> is supposed to perform at
446 certain times.</para>
448 <para>The <command>cron</command> utility uses two different
449 types of configuration files, the system crontab and user crontabs. The
450 only difference between these two formats is the sixth field. In the
451 system crontab, the sixth field is the name of a user for the command
452 to run as. This gives the system crontab the ability to run commands
453 as any user. In a user crontab, the sixth field is the command to run,
454 and all commands run as the user who created the crontab; this is an
455 important security feature.</para>
458 <para>User crontabs allow individual users to schedule tasks without the
459 need for root privileges. Commands in a user's crontab run with the
460 permissions of the user who owns the crontab.</para>
462 <para>The <username>root</username> user can have a user crontab just like
463 any other user. This one is different from
464 <filename>/etc/crontab</filename> (the system crontab). Because of the
465 system crontab, there's usually no need to create a user crontab
466 for <username>root</username>.</para>
469 <para>Let us take a look at the <filename>/etc/crontab</filename> file
470 (the system crontab):</para>
473 <!-- todo: add up-to-date crontab -->
474 <programlisting># /etc/crontab - root's crontab for &os;
476 # $&os;: src/etc/crontab,v 1.32 2002/11/22 16:13:39 tom Exp $
477 # <co id="co-comments">
480 PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin <co id="co-env">
484 #minute hour mday month wday who command <co id="co-field-descr">
487 */5 * * * * root /usr/libexec/atrun <co id="co-main">
491 <callout arearefs="co-comments">
492 <para>Like most &os; configuration files, the <literal>#</literal>
493 character represents a comment. A comment can be placed in
494 the file as a reminder of what and why a desired action is performed.
495 Comments cannot be on the same line as a command or else they will
496 be interpreted as part of the command; they must be on a new line.
497 Blank lines are ignored.</para>
500 <callout arearefs="co-env">
501 <para>First, the environment must be defined. The equals
502 (<literal>=</literal>) character is used to define any environment
503 settings, as with this example where it is used for the <envar>SHELL</envar>,
504 <envar>PATH</envar>, and <envar>HOME</envar> options. If the shell line is
505 omitted, <command>cron</command> will use the default, which is
506 <command>sh</command>. If the <envar>PATH</envar> variable is
507 omitted, no default will be used and file locations will need to
508 be absolute. If <envar>HOME</envar> is omitted, <command>cron</command>
509 will use the invoking users home directory.</para>
512 <callout arearefs="co-field-descr">
513 <para>This line defines a total of seven fields. Listed here are the
514 values <literal>minute</literal>, <literal>hour</literal>,
515 <literal>mday</literal>, <literal>month</literal>, <literal>wday</literal>,
516 <literal>who</literal>, and <literal>command</literal>. These
517 are almost all self explanatory. <literal>minute</literal> is the time in minutes the
518 command will be run. <literal>hour</literal> is similar to the <literal>minute</literal> option, just in
519 hours. <literal>mday</literal> stands for day of the month. <literal>month</literal> is similar to <literal>hour</literal>
520 and <literal>minute</literal>, as it designates the month. The <literal>wday</literal> option stands for
521 day of the week. All these fields must be numeric values, and follow
522 the twenty-four hour clock. The <literal>who</literal> field is special,
523 and only exists in the <filename>/etc/crontab</filename> file.
524 This field specifies which user the command should be run as.
525 When a user installs his or her <filename>crontab</filename> file, they
526 will not have this option. Finally, the <literal>command</literal> option is listed.
527 This is the last field, so naturally it should designate the command
528 to be executed.</para>
531 <callout arearefs="co-main">
532 <para>This last line will define the values discussed above. Notice here
533 we have a <literal>*/5</literal> listing, followed by several more
534 <literal>*</literal> characters. These <literal>*</literal> characters
535 mean <quote>first-last</quote>, and can be interpreted as
536 <emphasis>every</emphasis> time. So, judging by this line,
537 it is apparent that the <command>atrun</command> command is to be invoked by
538 <username>root</username> every five minutes regardless of what
539 day or month it is. For more information on the <command>atrun</command> command,
540 see the &man.atrun.8; manual page.</para>
542 <para>Commands can have any number of flags passed to them; however,
543 commands which extend to multiple lines need to be broken with the backslash
544 <quote>\</quote> continuation character.</para>
548 <para>This is the basic set up for every
549 <filename>crontab</filename> file, although there is one thing
550 different about this one. Field number six, where we specified
551 the username, only exists in the system
552 <filename>/etc/crontab</filename> file. This field should be
553 omitted for individual user <filename>crontab</filename>
557 <sect2 id="configtuning-installcrontab">
558 <title>Installing a Crontab</title>
561 <para>You must not use the procedure described here to
562 edit/install the system crontab. Simply use your favorite
563 editor: the <command>cron</command> utility will notice that the file
564 has changed and immediately begin using the updated version.
565 If you use <command>crontab</command> to load the
566 <filename>/etc/crontab</filename> file you may get an error
567 like <errorname>root: not found</errorname> because of the
568 system crontab's additional user field.</para>
571 <para>To install a freshly written user
572 <filename>crontab</filename>, first use your favorite editor to create
573 a file in the proper format, and then use the
574 <command>crontab</command> utility. The most common usage
577 <screen>&prompt.user; <userinput>crontab crontab-file</userinput></screen>
579 <para>In this example, <filename>crontab-file</filename> is the filename
580 of a <filename>crontab</filename> that was previously created.</para>
582 <para>There is also an option to list installed
583 <filename>crontab</filename> files: just pass the
584 <option>-l</option> option to <command>crontab</command> and look
585 over the output.</para>
587 <para>For users who wish to begin their own crontab file from scratch,
588 without the use of a template, the <command>crontab -e</command>
589 option is available. This will invoke the selected editor
590 with an empty file. When the file is saved, it will be
591 automatically installed by the <command>crontab</command> command.
594 <para>If you later want to remove your user <filename>crontab</filename>
595 completely, use <command>crontab</command> with the <option>-r</option>
602 <sect1 id="configtuning-rcNG">
606 <firstname>Tom</firstname>
607 <surname>Rhodes</surname>
608 <contrib>Contributed by </contrib>
614 <title>Using rc under &os;</title>
616 <indexterm><primary>rcNG</primary></indexterm>
618 <para>&os; uses the &netbsd;
619 <filename>rc.d</filename> system for system initialization.
620 Users should notice the files listed in the
621 <filename>/etc/rc.d</filename> directory. Many of these files
622 are for basic services which can be controlled with the
623 <option>start</option>, <option>stop</option>,
624 and <option>restart</option> options.
625 For instance, &man.sshd.8; can be restarted with the following
628 <screen>&prompt.root; <userinput>/etc/rc.d/sshd restart</userinput></screen>
630 <para>This procedure is similar for other services. Of course,
631 services are usually started automatically as specified in
632 &man.rc.conf.5;. For example, enabling the Network Address
633 Translation daemon at startup is as simple as adding the
634 following line to <filename>/etc/rc.conf</filename>:</para>
636 <programlisting>natd_enable="YES"</programlisting>
638 <para>If a <option>natd_enable="NO"</option> line is already
639 present, then simply change the <option>NO</option> to
640 <option>YES</option>. The rc scripts will automatically load
641 any other dependent services during the next reboot, as
642 described below.</para>
644 <para>Since the <filename>rc.d</filename> system is primarily
645 intended to start/stop services at system startup/shutdown time,
646 the standard <option>start</option>,
647 <option>stop</option> and <option>restart</option> options will only
648 perform their action if the appropriate
649 <filename>/etc/rc.conf</filename> variables are set. For
650 instance the above <command>sshd restart</command> command will
651 only work if <varname>sshd_enable</varname> is set to
652 <option>YES</option> in <filename>/etc/rc.conf</filename>. To
653 <option>start</option>, <option>stop</option> or
654 <option>restart</option> a service regardless of the settings in
655 <filename>/etc/rc.conf</filename>, the commands should be
656 prefixed with <quote>force</quote>. For instance to restart
657 <command>sshd</command> regardless of the current
658 <filename>/etc/rc.conf</filename> setting, execute the following
661 <screen>&prompt.root; <userinput>/etc/rc.d/sshd forcerestart</userinput></screen>
663 <para>It is easy to check if a service is enabled in
664 <filename>/etc/rc.conf</filename> by running the appropriate
665 <filename>rc.d</filename> script with the option
666 <option>rcvar</option>. Thus, an administrator can check that
667 <command>sshd</command> is in fact enabled in
668 <filename>/etc/rc.conf</filename> by running:</para>
670 <screen>&prompt.root; <userinput>/etc/rc.d/sshd rcvar</userinput>
672 $sshd_enable=YES</screen>
675 <para>The second line (<literal># sshd</literal>) is the output
676 from the <command>rc.d</command> script, not a
677 <username>root</username> prompt.</para>
680 <para>To determine if a service is running, a
681 <option>status</option> option is available. For instance to
682 verify that <command>sshd</command> is actually started:</para>
684 <screen>&prompt.root; <userinput>/etc/rc.d/sshd status</userinput>
685 sshd is running as pid 433.</screen>
687 <para>It is also possible to <option>reload</option> a service.
688 This will attempt to send a signal to an individual service, forcing the
689 service to reload its configuration files. In most cases this
690 means sending the service a <literal>SIGHUP</literal>
693 <para>The <application>rcNG</application> structure is used both
694 for network services and system initialization. Some services are run
695 only at boot; and the RCNG system is what triggers them.
697 <para>Many system services depend on other services to function
698 properly. For example, NIS and other RPC-based services may
699 fail to start until after the <command>rpcbind</command>
700 (portmapper) service has started. To resolve this issue,
701 information about dependencies and other meta-data is included
702 in the comments at the top of each startup script. The
703 &man.rcorder.8; program is then used to parse these comments
704 during system initialization to determine the order in which
705 system services should be invoked to satisfy the dependencies.
706 The following words may be included at the top of each startup
711 <para><literal>PROVIDE</literal>: Specifies the services this file provides.</para>
715 <para><literal>REQUIRE</literal>: Lists services which are required for this
716 service. This file will run <emphasis>after</emphasis>
717 the specified services.</para>
721 <para><literal>BEFORE</literal>: Lists services which depend on this service.
722 This file will run <emphasis>before</emphasis>
723 the specified services.</para>
727 <para>KEYWORD: When &man.rcorder.8; uses the <option>-k</option>
728 option, then only the rc.d files matching this keyword are used.
731 <para>Previously this was used to define *BSD dependent features.
734 For example, when using <option>-k shutdown</option>, only the
735 <filename>rc.d</filename> scripts defining the
736 <literal>shutdown</literal> keyword are used.
739 <para>With the <option>-s</option> option, &man.rcorder.8 will
740 skip any <filename>rc.d</filename> script defining the
741 corresponding keyword to skip. For example, scripts defining the
742 <literal>nostart</literal> keyword are skipped at boot time.</para>
746 <para>By using this method, an administrator can easily control system
747 services without the hassle of <quote>runlevels</quote> like
748 some other &unix; operating systems.</para>
750 <para>Additional information about the &os;
751 <filename>rc.d</filename> system can be found in the &man.rc.8;,
752 &man.rc.conf.5;, and &man.rc.subr.8; manual pages.</para>
755 <sect1 id="config-network-setup">
759 <firstname>Marc</firstname>
760 <surname>Fonvieille</surname>
761 <contrib>Contributed by </contrib>
762 <!-- 6 October 2002 -->
767 <title>Setting Up Network Interface Cards</title>
769 <indexterm><primary>network card configuration</primary></indexterm>
771 <para>Nowadays we can not think about a computer without thinking
772 about a network connection. Adding and configuring a network
773 card is a common task for any &os; administrator.</para>
776 <title>Locating the Correct Driver</title>
779 <primary>network card configuration</primary>
780 <secondary>locating the driver</secondary>
783 <para>Before you begin, you should know the model of the card
784 you have, the chip it uses, and whether it is a PCI or ISA card.
785 &os; supports a wide variety of both PCI and ISA cards.
786 Check the Hardware Compatibility List for your release to see
787 if your card is supported.</para>
789 <para>Once you are sure your card is supported, you need
790 to determine the proper driver for the card. The file
791 <filename>/usr/src/sys/i386/conf/LINT</filename> will give you
792 the list of network interfaces drivers with some information
793 about the supported chipsets/cards. If you have doubts about
794 which driver is the correct one, read the manual page of the
795 driver. The manual page will give you more information about
796 the supported hardware and even the possible problems that
799 <para>If you own a common card, most of the time you will not
800 have to look very hard for a driver. Drivers for common
801 network cards are present in the <filename>GENERIC</filename>
802 kernel, so your card should show up during boot, like so:</para>
804 <screen>dc0: <82c169 PNIC 10/100BaseTX> port 0xa000-0xa0ff mem 0xd3800000-0xd38
805 000ff irq 15 at device 11.0 on pci0
806 dc0: Ethernet address: 00:a0:cc:da:da:da
807 miibus0: <MII bus> on dc0
808 ukphy0: <Generic IEEE 802.3u media interface> on miibus0
809 ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
810 dc1: <82c169 PNIC 10/100BaseTX> port 0x9800-0x98ff mem 0xd3000000-0xd30
811 000ff irq 11 at device 12.0 on pci0
812 dc1: Ethernet address: 00:a0:cc:da:da:db
813 miibus1: <MII bus> on dc1
814 ukphy1: <Generic IEEE 802.3u media interface> on miibus1
815 ukphy1: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto</screen>
817 <para>In this example, we see that two cards using the &man.dc.4;
818 driver are present on the system.</para>
820 <para>To use your network card, you will need to load the proper
821 driver. This may be accomplished in one of two ways. The
822 easiest way is to simply load a kernel module for your network
823 card with &man.kldload.8;. A module is not available for all
824 network card drivers (ISA cards and cards using the &man.ed.4;
825 driver, for example). Alternatively, you may statically compile
826 the support for your card into your kernel. Check
827 <filename>/usr/src/sys/i386/conf/LINT</filename> and the
828 manual page of the driver to know what to add in your kernel
829 configuration file. For more information about recompiling your
830 kernel, please see <xref linkend="kernelconfig">. If your card
831 was detected at boot by your kernel (<filename>GENERIC</filename>)
832 you do not have to build a new kernel.</para>
836 <title>Configuring the Network Card</title>
839 <primary>Network card configuration</primary>
840 <secondary>configuration</secondary>
843 <para>Once the right driver is loaded for the network card, the
844 card needs to be configured. As with many other things, the
845 network card may have been configured at installation time.</para>
847 <para>To display the configuration for the network interfaces on
848 your system, enter the following command:</para>
850 <screen>&prompt.user; <userinput>ifconfig</userinput>
851 dc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
852 inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255
853 ether 00:a0:cc:da:da:da
854 media: Ethernet autoselect (100baseTX <full-duplex>)
856 dc1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
857 inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
858 ether 00:a0:cc:da:da:db
859 media: Ethernet 10baseT/UTP
861 lp0: flags=8810<POINTOPOINT,SIMPLEX,MULTICAST> mtu 1500
862 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
863 inet 127.0.0.1 netmask 0xff000000
864 tun0: flags=8010<POINTOPOINT,MULTICAST> mtu 1500</screen>
867 <para>Note that entries concerning IPv6
868 (<literal>inet6</literal> etc.) were omitted in this
872 <para>In this example, the following devices were
877 <para><devicename>dc0</devicename>: The first Ethernet
882 <para><devicename>dc1</devicename>: The second Ethernet
887 <para><devicename>lp0</devicename>: The parallel port
892 <para><devicename>lo0</devicename>: The loopback device</para>
896 <para><devicename>tun0</devicename>: The tunnel device used by
897 <application>ppp</application></para>
901 <para>&os; uses the driver name followed by the order in
902 which one the card is detected at the kernel boot to name the
903 network card, starting the count at zero. For example,
904 <devicename>sis2</devicename> would be the third network card
905 on the system using the &man.sis.4; driver.</para>
907 <para>In this example, the <devicename>dc0</devicename> device is
908 up and running. The key indicators are:</para>
912 <para><literal>UP</literal> means that the card is configured
917 <para>The card has an Internet (<literal>inet</literal>)
918 address (in this case
919 <hostid role="ipaddr">192.168.1.3</hostid>).</para>
923 <para>It has a valid subnet mask (<literal>netmask</literal>;
924 <hostid role="netmask">0xffffff00</hostid> is the same as
925 <hostid role="netmask">255.255.255.0</hostid>).</para>
929 <para>It has a valid broadcast address (in this case,
930 <hostid role="ipaddr">192.168.1.255</hostid>).</para>
934 <para>The MAC address of the card (<literal>ether</literal>)
935 is <hostid role="mac">00:a0:cc:da:da:da</hostid></para>
939 <para>The physical media selection is on autoselection mode
940 (<literal>media: Ethernet autoselect (100baseTX
941 <full-duplex>)</literal>). We see that
942 <devicename>dc1</devicename> was configured to run with
943 <literal>10baseT/UTP</literal> media. For more
944 information on available media types for a driver, please
945 refer to its manual page.</para>
949 <para>The status of the link (<literal>status</literal>)
950 is <literal>active</literal>, i.e. the carrier is detected.
951 For <devicename>dc1</devicename>, we see
952 <literal>status: no carrier</literal>. This is normal when
953 an ethernet cable is not plugged into the card.</para>
957 <para>If the &man.ifconfig.8; output had shown something similar
960 <screen>dc0: flags=8843<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
961 ether 00:a0:cc:da:da:da</screen>
963 <para>it would indicate the card has not been configured.</para>
965 <para>To configure your card, you need <username>root</username>
966 privileges. The network card configuration can be done from the
967 command line with &man.ifconfig.8; as root.</para>
970 &prompt.root; <userinput>ifconfig dc0 inet 192.168.1.3 netmask 255.255.255.0</userinput>
974 <para>Manually configuring the care has the disadvantage that you
975 would have to do it after each reboot of the system. The file
976 <filename>/etc/rc.conf</filename> is where to add the network
977 card's configuration.</para>
979 <para>Open <filename>/etc/rc.conf</filename> in your favorite
980 editor. You need to add a line for each network card present on
981 the system, for example in our case, we added these lines:</para>
983 <programlisting>ifconfig_dc0="inet 192.168.1.3 netmask 255.255.255.0"
984 ifconfig_dc1="inet 10.0.0.1 netmask 255.255.255.0 media 10baseT/UTP"</programlisting>
986 <para>You have to replace <devicename>dc0</devicename>,
987 <devicename>dc1</devicename>, and so on, with
988 the correct device for your cards, and the addresses with the
989 proper ones. You should read the card driver and
990 &man.ifconfig.8; manual pages for more details about the allowed
991 options and also &man.rc.conf.5; manual page for more
992 information on the syntax of
993 <filename>/etc/rc.conf</filename>.</para>
995 <para>If you configured the network during installation, some
996 lines about the network card(s) may be already present. Double
997 check <filename>/etc/rc.conf</filename> before adding any
1000 <para>You will also have to edit the file
1001 <filename>/etc/hosts</filename> to add the names and the IP
1002 addresses of various machines of the LAN, if they are not already
1003 there. For more information please refer to &man.hosts.5;
1004 and to <filename>/usr/share/examples/etc/hosts</filename>.</para>
1008 <title>Testing and Troubleshooting</title>
1010 <para>Once you have made the necessary changes in
1011 <filename>/etc/rc.conf</filename>, you should reboot your
1012 system. This will allow the change(s) to the interface(s) to
1013 be applied, and verify that the system restarts without any
1014 configuration errors.</para>
1016 <para>Once the system has been rebooted, you should test the
1017 network interfaces.</para>
1020 <title>Testing the Ethernet Card</title>
1023 <primary>network card configuration</primary>
1024 <secondary>testing the card</secondary>
1027 <para>To verify that an Ethernet card is configured correctly,
1028 you have to try two things. First, ping the interface itself,
1029 and then ping another machine on the LAN.</para>
1031 <para>First test the local interface:</para>
1033 <screen>&prompt.user; <userinput>ping -c5 192.168.1.3</userinput>
1034 PING 192.168.1.3 (192.168.1.3): 56 data bytes
1035 64 bytes from 192.168.1.3: icmp_seq=0 ttl=64 time=0.082 ms
1036 64 bytes from 192.168.1.3: icmp_seq=1 ttl=64 time=0.074 ms
1037 64 bytes from 192.168.1.3: icmp_seq=2 ttl=64 time=0.076 ms
1038 64 bytes from 192.168.1.3: icmp_seq=3 ttl=64 time=0.108 ms
1039 64 bytes from 192.168.1.3: icmp_seq=4 ttl=64 time=0.076 ms
1041 --- 192.168.1.3 ping statistics ---
1042 5 packets transmitted, 5 packets received, 0% packet loss
1043 round-trip min/avg/max/stddev = 0.074/0.083/0.108/0.013 ms</screen>
1045 <para>Now we have to ping another machine on the LAN:</para>
1047 <screen>&prompt.user; <userinput>ping -c5 192.168.1.2</userinput>
1048 PING 192.168.1.2 (192.168.1.2): 56 data bytes
1049 64 bytes from 192.168.1.2: icmp_seq=0 ttl=64 time=0.726 ms
1050 64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=0.766 ms
1051 64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=0.700 ms
1052 64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.747 ms
1053 64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=0.704 ms
1055 --- 192.168.1.2 ping statistics ---
1056 5 packets transmitted, 5 packets received, 0% packet loss
1057 round-trip min/avg/max/stddev = 0.700/0.729/0.766/0.025 ms</screen>
1059 <para>You could also use the machine name instead of
1060 <hostid role="ipaddr">192.168.1.2</hostid> if you have set up the
1061 <filename>/etc/hosts</filename> file.</para>
1065 <title>Troubleshooting</title>
1068 <primary>network card configuration</primary>
1069 <secondary>troubleshooting</secondary>
1072 <para>Troubleshooting hardware and software configurations is always
1073 a pain, and a pain which can be alleviated by checking the simple
1074 things first. Is your network cable plugged in? Have you properly
1075 configured the network services? Did you configure the firewall
1076 correctly? Is the card you are using supported by &os;? Always
1077 check the hardware notes before sending off a bug report. Update
1078 your version of &os; to the latest PREVIEW version. Check the
1079 mailing list archives, or perhaps search the Internet.</para>
1081 <para>If the card works, yet performance is poor, it would be
1082 worthwhile to read over the &man.tuning.7; manual page. You
1083 can also check the network configuration as incorrect network
1084 settings can cause slow connections.</para>
1086 <para>Some users experience one or two <quote>device
1087 timeouts</quote>, which is normal for some cards. If they
1088 continue, or are bothersome, you may wish to be sure the
1089 device is not conflicting with another device. Double check
1090 the cable connections. Perhaps you may just need to get
1091 another card.</para>
1093 <para>At times, users see a few <errorname>watchdog timeout</errorname>
1094 errors. The first thing to do here is to check your network
1095 cable. Many cards require a PCI slot which supports Bus
1096 Mastering. On some old motherboards, only one PCI slot allows
1097 it (usually slot 0). Check the network card and the
1098 motherboard documentation to determine if that may be the
1101 <para><errorname>No route to host</errorname> messages occur if the
1102 system is unable to route a packet to the destination host.
1103 This can happen if no default route is specified, or if a
1104 cable is unplugged. Check the output of <command>netstat
1105 -rn</command> and make sure there is a valid route to the host
1106 you are trying to reach. If there is not, read on to <xref
1107 linkend="advanced-networking">.</para>
1109 <para><errorname>ping: sendto: Permission denied</errorname> error
1110 messages are often caused by a misconfigured firewall. If
1111 <command>ipfw</command> is enabled in the kernel but no rules
1112 have been defined, then the default policy is to deny all
1113 traffic, even ping requests! Read on to <xref
1114 linkend="firewalls"> for more information.</para>
1116 <para>Sometimes performance of the card is poor, or below average.
1117 In these cases it is best to set the media selection mode
1118 from <literal>autoselect</literal> to the correct media selection.
1119 While this usually works for most hardware, it may not resolve
1120 this issue for everyone. Again, check all the network settings,
1121 and read over the &man.tuning.7; manual page.</para>
1127 <sect1 id="configtuning-virtual-hosts">
1128 <title>Virtual Hosts</title>
1130 <indexterm><primary>virtual hosts</primary></indexterm>
1131 <indexterm><primary>IP aliases</primary></indexterm>
1133 <para>A very common use of &os; is virtual site hosting, where
1134 one server appears to the network as many servers. This is
1135 achieved by assigning multiple network addresses to a single
1138 <para>A given network interface has one <quote>real</quote> address,
1139 and may have any number of <quote>alias</quote> addresses.
1141 normally added by placing alias entries in
1142 <filename>/etc/rc.conf</filename>.</para>
1144 <para>An alias entry for the interface <devicename>fxp0</devicename>
1147 <programlisting>ifconfig_fxp0_alias0="inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"</programlisting>
1149 <para>Note that alias entries must start with alias0 and proceed
1150 upwards in order, (for example, _alias1, _alias2, and so on).
1151 The configuration process will stop at the first missing number.
1154 <para>The calculation of alias netmasks is important, but
1155 fortunately quite simple. For a given interface, there must be
1156 one address which correctly represents the network's netmask.
1157 Any other addresses which fall within this network must have a
1158 netmask of all <literal>1</literal>s.</para>
1160 <para>For example, consider the case where the
1161 <devicename>fxp0</devicename> interface is
1162 connected to two networks, the <hostid role="ipaddr">10.1.1.0</hostid>
1163 network with a netmask of <hostid role="netmask">255.255.255.0</hostid>
1164 and the <hostid role="ipaddr">202.0.75.16</hostid> network with
1165 a netmask of <hostid role="netmask">255.255.255.240</hostid>.
1166 We want the system to appear at <hostid role="ipaddr">10.1.1.1</hostid>
1167 through <hostid role="ipaddr">10.1.1.5</hostid> and at
1168 <hostid role="ipaddr">202.0.75.17</hostid> through
1169 <hostid role="ipaddr">202.0.75.20</hostid>.</para>
1171 <para>The following entries configure the adapter correctly for
1172 this arrangement:</para>
1174 <programlisting> ifconfig_fxp0="inet 10.1.1.1 netmask 255.255.255.0"
1175 ifconfig_fxp0_alias0="inet 10.1.1.2 netmask 255.255.255.255"
1176 ifconfig_fxp0_alias1="inet 10.1.1.3 netmask 255.255.255.255"
1177 ifconfig_fxp0_alias2="inet 10.1.1.4 netmask 255.255.255.255"
1178 ifconfig_fxp0_alias3="inet 10.1.1.5 netmask 255.255.255.255"
1179 ifconfig_fxp0_alias4="inet 202.0.75.17 netmask 255.255.255.240"
1180 ifconfig_fxp0_alias5="inet 202.0.75.18 netmask 255.255.255.255"
1181 ifconfig_fxp0_alias6="inet 202.0.75.19 netmask 255.255.255.255"
1182 ifconfig_fxp0_alias7="inet 202.0.75.20 netmask 255.255.255.255"</programlisting>
1186 <sect1 id="configtuning-configfiles">
1187 <title>Configuration Files</title>
1190 <title><filename>/etc</filename> Layout</title>
1191 <para>There are a number of directories in which configuration
1192 information is kept. These include:</para>
1194 <informaltable frame="none">
1198 <entry><filename>/etc</filename></entry>
1199 <entry>Generic system configuration information; data here is
1200 system-specific.</entry>
1203 <entry><filename>/etc/defaults</filename></entry>
1204 <entry>Default versions of system configuration files.</entry>
1207 <entry><filename>/etc/mail</filename></entry>
1208 <entry>Extra &man.sendmail.8; configuration, other
1209 MTA configuration files.
1213 <entry><filename>/etc/ppp</filename></entry>
1214 <entry>Configuration for both user- and kernel-ppp programs.
1218 <entry><filename>/etc/namedb</filename></entry>
1219 <entry>Default location for &man.named.8; data. Normally
1220 <filename>named.conf</filename> and zone files are stored
1224 <entry><filename>/usr/local/etc</filename></entry>
1225 <entry>Configuration files for installed applications.
1226 May contain per-application subdirectories.</entry>
1229 <entry><filename>/usr/local/etc/rc.d</filename></entry>
1230 <entry>Start/stop scripts for installed applications.</entry>
1233 <entry><filename>/var/db</filename></entry>
1234 <entry>Automatically generated system-specific database files,
1235 such as the package database, the locate database, and so
1244 <title>Hostnames</title>
1246 <indexterm><primary>hostname</primary></indexterm>
1247 <indexterm><primary>DNS</primary></indexterm>
1250 <title><filename>/etc/resolv.conf</filename></title>
1253 <primary><filename>resolv.conf</filename></primary>
1256 <para><filename>/etc/resolv.conf</filename> dictates how &os;'s
1257 resolver accesses the Internet Domain Name System (DNS).</para>
1259 <para>The most common entries to <filename>resolv.conf</filename> are:
1262 <informaltable frame="none">
1266 <entry><literal>nameserver</literal></entry>
1267 <entry>The IP address of a name server the resolver
1268 should query. The servers are queried in the order
1269 listed with a maximum of three.</entry>
1272 <entry><literal>search</literal></entry>
1273 <entry>Search list for hostname lookup. This is normally
1274 determined by the domain of the local hostname.</entry>
1277 <entry><literal>domain</literal></entry>
1278 <entry>The local domain name.</entry>
1284 <para>A typical <filename>resolv.conf</filename>:</para>
1286 <programlisting>search example.com
1287 nameserver 147.11.1.11
1288 nameserver 147.11.100.30</programlisting>
1290 <note><para>Only one of the <literal>search</literal> and
1291 <literal>domain</literal> options should be used.</para></note>
1293 <para>If you are using DHCP, &man.dhclient.8; usually rewrites
1294 <filename>resolv.conf</filename> with information received from the
1299 <title><filename>/etc/hosts</filename></title>
1301 <indexterm><primary>hosts</primary></indexterm>
1303 <para><filename>/etc/hosts</filename> is a simple text
1304 database reminiscent of the old Internet. It works in
1305 conjunction with DNS and NIS providing name to IP address
1306 mappings. Local computers connected via a LAN can be placed
1307 in here for simplistic naming purposes instead of setting up
1308 a &man.named.8; server. Additionally,
1309 <filename>/etc/hosts</filename> can be used to provide a
1310 local record of Internet names, reducing the need to query
1311 externally for commonly accessed names.</para>
1313 <programlisting># $&os;$
1316 # This file should contain the addresses and aliases
1317 # for local hosts that share this file.
1318 # In the presence of the domain name service or NIS, this file may
1319 # not be consulted at all; see /etc/nsswitch.conf for the resolution order.
1322 ::1 localhost localhost.my.domain myname.my.domain
1323 127.0.0.1 localhost localhost.my.domain myname.my.domain
1326 # Imaginary network.
1327 #10.0.0.2 myname.my.domain myname
1328 #10.0.0.3 myfriend.my.domain myfriend
1330 # According to RFC 1918, you can use the following IP networks for
1331 # private nets which will never be connected to the Internet:
1333 # 10.0.0.0 - 10.255.255.255
1334 # 172.16.0.0 - 172.31.255.255
1335 # 192.168.0.0 - 192.168.255.255
1337 # In case you want to be able to connect to the Internet, you need
1338 # real official assigned numbers. PLEASE PLEASE PLEASE do not try
1339 # to invent your own network numbers but instead get one from your
1340 # network provider (if any) or from the Internet Registry (ftp to
1341 # rs.internic.net, directory `/templates').
1344 <para><filename>/etc/hosts</filename> takes on the simple format
1347 <programlisting>[Internet address] [official hostname] [alias1] [alias2] ...</programlisting>
1349 <para>For example:</para>
1351 <programlisting>10.0.0.1 myRealHostname.example.com myRealHostname foobar1 foobar2</programlisting>
1353 <para>Consult &man.hosts.5; for more information.</para>
1358 <title>Log File Configuration</title>
1360 <indexterm><primary>log files</primary></indexterm>
1363 <title><filename>syslog.conf</filename></title>
1365 <indexterm><primary>syslog.conf</primary></indexterm>
1367 <para><filename>syslog.conf</filename> is the configuration file
1368 for the &man.syslogd.8; program. It indicates which types
1369 of <command>syslog</command> messages are logged to particular
1372 <programlisting># $&os;$
1374 # Spaces ARE valid field separators in this file. However,
1375 # other *nix-like systems still insist on using tabs as field
1376 # separators. If you are sharing this file between systems, you
1377 # may want to use only tabs as field separators here.
1378 # Consult the syslog.conf(5) manual page.
1379 *.err;kern.debug;auth.notice;mail.crit /dev/console
1380 *.notice;kern.debug;lpr.info;mail.crit;news.err /var/log/messages
1381 security.* /var/log/security
1382 mail.info /var/log/maillog
1383 lpr.info /var/log/lpd-errs
1384 cron.* /var/log/cron
1386 *.notice;news.err root
1389 # uncomment this to log all writes to /dev/console to /var/log/console.log
1390 #console.info /var/log/console.log
1391 # uncomment this to enable logging of all log messages to /var/log/all.log
1392 #*.* /var/log/all.log
1393 # uncomment this to enable logging to a remote log host named loghost
1395 # uncomment these if you're running inn
1396 # news.crit /var/log/news/news.crit
1397 # news.err /var/log/news/news.err
1398 # news.notice /var/log/news/news.notice
1400 *.* /var/log/slip.log
1402 *.* /var/log/ppp.log</programlisting>
1404 <!-- todo: reed: this should be documented in book -->
1405 <para>Consult the &man.syslog.conf.5; manual page for more
1410 <title><filename>newsyslog.conf</filename></title>
1412 <indexterm><primary>newsyslog.conf</primary></indexterm>
1414 <para><filename>newsyslog.conf</filename> is the configuration
1415 file for &man.newsyslog.8;, a program that is normally scheduled
1416 to run by &man.cron.8;. &man.newsyslog.8; determines when log
1417 files require archiving or rearranging.
1418 <filename>logfile</filename> is moved to
1419 <filename>logfile.0</filename>, <filename>logfile.0</filename>
1420 is moved to <filename>logfile.1</filename>, and so on.
1421 Alternatively, the log files may be archived in &man.gzip.1; format
1422 causing them to be named: <filename>logfile.0.gz</filename>,
1423 <filename>logfile.1.gz</filename>, and so on.</para>
1425 <para><filename>newsyslog.conf</filename> indicates which log
1426 files are to be managed, how many are to be kept, and when
1427 they are to be touched. Log files can be rearranged and/or
1428 archived when they have either reached a certain size, or at a
1429 certain periodic time/date.</para>
1431 <programlisting># configuration file for newsyslog
1432 # $&os;$
1434 # filename [owner:group] mode count size when [ZB] [/pid_file] [sig_num]
1435 /var/log/cron 600 3 100 * Z
1436 /var/log/amd.log 644 7 100 * Z
1437 /var/log/kerberos.log 644 7 100 * Z
1438 /var/log/lpd-errs 644 7 100 * Z
1439 /var/log/maillog 644 7 * @T00 Z
1440 /var/log/sendmail.st 644 10 * 168 B
1441 /var/log/messages 644 5 100 * Z
1442 /var/log/all.log 600 7 * @T00 Z
1443 /var/log/slip.log 600 3 100 * Z
1444 /var/log/ppp.log 600 3 100 * Z
1445 /var/log/security 600 10 100 * Z
1446 /var/log/wtmp 644 3 * @01T05 B
1447 /var/log/daily.log 640 7 * @T00 Z
1448 /var/log/weekly.log 640 5 1 $W6D0 Z
1449 /var/log/monthly.log 640 12 * $M1D0 Z
1450 /var/log/console.log 640 5 100 * Z</programlisting>
1452 <!-- todo: reed: this should be documented in book -->
1453 <para>Consult the &man.newsyslog.8; manual page for more
1459 <title><filename>sysctl.conf</filename></title>
1461 <indexterm><primary>sysctl.conf</primary></indexterm>
1462 <indexterm><primary>sysctl</primary></indexterm>
1464 <para><filename>sysctl.conf</filename> looks much like
1465 <filename>rc.conf</filename>. Values are set in a
1466 <literal>variable=value</literal>
1467 form. The specified values are set after the system goes into
1468 multi-user mode. Not all variables are settable in this mode.</para>
1470 <para>A sample <filename>sysctl.conf</filename> turning off logging
1471 of fatal signal exits and letting Linux programs know they are really
1472 running under &os;:</para>
1474 <programlisting>kern.logsigexit=0 # Do not log fatal signal exits (e.g. sig 11)
1475 compat.linux.osname=&os;
1476 <!-- todo: reed: check this -->
1477 compat.linux.osrelease=4.3-STABLE</programlisting>
1481 <sect1 id="configtuning-sysctl">
1482 <title>Tuning with sysctl</title>
1484 <indexterm><primary>sysctl</primary></indexterm>
1486 <primary>tuning</primary>
1487 <secondary>with sysctl</secondary>
1490 <para>&man.sysctl.8; is an interface that allows you to make changes
1491 to a running &os; system. This includes many advanced
1492 options of the TCP/IP stack and virtual memory system that can
1493 dramatically improve performance for an experienced system
1494 administrator. Over five hundred system variables can be read
1495 and set using &man.sysctl.8;.</para>
1497 <para>At its core, &man.sysctl.8; serves two functions: to read and
1498 to modify system settings.</para>
1500 <para>To view all readable variables:</para>
1502 <screen>&prompt.user; <userinput>sysctl -a</userinput></screen>
1504 <para>To read a particular variable, for example,
1505 <varname>kern.maxproc</varname>:</para>
1507 <screen>&prompt.user; <userinput>sysctl kern.maxproc</userinput>
1508 kern.maxproc: 1044</screen>
1510 <para>To set a particular variable, use the intuitive
1511 <replaceable>variable</replaceable>=<replaceable>value</replaceable>
1514 <screen>&prompt.root; <userinput>sysctl kern.maxfiles=5000</userinput>
1515 kern.maxfiles: 2088 -> 5000</screen>
1517 <para>Settings of sysctl variables are usually either strings,
1518 numbers, or booleans (a boolean being <literal>1</literal> for yes
1519 or a <literal>0</literal> for no).</para>
1521 <sect2 id="sysctl-readonly">
1525 <firstname>Tom</firstname>
1526 <surname>Rhodes</surname>
1527 <contrib>Contributed by </contrib>
1528 <!-- 31 January 2003 -->
1532 <title>&man.sysctl.8; Read-only</title>
1534 <para>In some cases it may be desirable to modify read-only &man.sysctl.8;
1535 values. While this is not recommended, it is also sometimes unavoidable.</para>
1537 <para>For instance on some laptop models the &man.cardbus.4; device will
1538 not probe memory ranges, and fail with errors which look similar to:</para>
1540 <screen>cbb0: Could not map register memory
1541 device_probe_and_attach: cbb0 attach returned 12</screen>
1543 <para>Cases like the one above usually require the modification of some
1544 default &man.sysctl.8; settings which are set read only. To overcome
1545 these situations a user can put &man.sysctl.8; <quote>OIDs</quote>
1546 in their local <filename>/boot/loader.conf</filename>. Default
1547 settings are located in the <filename>/boot/defaults/loader.conf</filename>
1550 <para>Fixing the problem mentioned above would require a user to set
1551 <option>hw.pci.allow_unsupported_io_range=1</option> in the aforementioned
1552 file. Now &man.cardbus.4; will work properly.</para>
1557 <sect1 id="configtuning-disk">
1558 <title>Tuning Disks</title>
1561 <title>Sysctl Variables</title>
1564 <title><varname>vfs.vmiodirenable</varname></title>
1567 <primary><varname>vfs.vmiodirenable</varname></primary>
1570 <para>The <varname>vfs.vmiodirenable</varname> sysctl variable
1571 may be set to either 0 (off) or 1 (on); it is 1 by default.
1572 This variable controls how directories are cached by the
1573 system. Most directories are small, using just a single
1574 fragment (typically 1 K) in the file system and less
1575 (typically 512 bytes) in the buffer cache.
1576 However, when operating in the default mode the buffer
1577 cache will only cache a fixed number of directories even if
1578 you have a huge amount of memory. Turning on this sysctl
1579 allows the buffer cache to use the VM Page Cache to cache the
1580 directories, making all the memory available for caching
1581 directories. However,
1582 the minimum in-core memory used to cache a directory is the
1583 physical page size (typically 4 K) rather than 512
1584 bytes. We recommend turning this option on if you are running
1585 any services which manipulate large numbers of files. Such
1586 services can include web caches, large mail systems, and news
1587 systems. Turning on this option will generally not reduce
1588 performance even with the wasted memory but you should
1589 experiment to find out.</para>
1593 <title><varname>vfs.write_behind</varname></title>
1596 <primary><varname>vfs.write_behind</varname></primary>
1599 <para>The <varname>vfs.write_behind</varname> sysctl variable
1600 defaults to <literal>1</literal> (on). This tells the file system
1601 to issue media writes as full clusters are collected, which
1602 typically occurs when writing large sequential files. The idea
1603 is to avoid saturating the buffer cache with dirty buffers when
1604 it would not benefit I/O performance. However, this may stall
1605 processes and under certain circumstances you may wish to turn it
1610 <title><varname>vfs.hirunningspace</varname></title>
1613 <primary><varname>vfs.hirunningspace</varname></primary>
1616 <para>The <varname>vfs.hirunningspace</varname> sysctl variable
1617 determines how much outstanding write I/O may be queued to disk
1618 controllers system-wide at any given instance. The default is
1619 usually sufficient but on machines with lots of disks you may
1620 want to bump it up to four or five <emphasis>megabytes</emphasis>.
1621 Note that setting too high a value (exceeding the buffer cache's
1622 write threshold) can lead to extremely bad clustering
1623 performance. Do not set this value arbitrarily high! Higher
1624 write values may add latency to reads occurring at the same time.
1627 <para>There are various other buffer-cache and VM page cache
1628 related sysctls. We do not recommend modifying these values.
1629 The VM system does an extremely good job of
1630 automatically tuning itself.</para>
1634 <title><varname>vm.swap_idle_enabled</varname></title>
1637 <primary><varname>vm.swap_idle_enabled</varname></primary>
1640 <para>The <varname>vm.swap_idle_enabled</varname> sysctl variable
1641 is useful in large multi-user systems where you have lots of
1642 users entering and leaving the system and lots of idle processes.
1643 Such systems tend to generate a great deal of continuous pressure
1644 on free memory reserves. Turning this feature on and tweaking
1645 the swapout hysteresis (in idle seconds) via
1646 <varname>vm.swap_idle_threshold1</varname> and
1647 <varname>vm.swap_idle_threshold2</varname> allows you to depress
1648 the priority of memory pages associated with idle processes more
1649 quickly then the normal pageout algorithm. This gives a helping
1650 hand to the pageout daemon. Do not turn this option on unless
1651 you need it, because the tradeoff you are making is essentially
1652 pre-page memory sooner rather than later; thus eating more swap
1653 and disk bandwidth. In a small system this option will have a
1654 determinable effect but in a large system that is already doing
1655 moderate paging this option allows the VM system to stage whole
1656 processes into and out of memory easily.</para>
1660 <title><varname>hw.ata.wc</varname></title>
1663 <primary><varname>hw.ata.wc</varname></primary>
1666 <para>IDE drives lie about when a write completes. With IDE write
1667 caching turned on, IDE hard drives not only write data
1668 to disk out of order, but will sometimes delay writing some
1669 blocks indefinitely when under heavy disk loads. A crash or
1670 power failure may cause serious file system corruption. Turning
1671 off write caching will remove the danger of this data loss, but
1672 will also cause disk operations to proceed
1673 <emphasis>very slowly.</emphasis> Change this only if prepared
1674 to suffer with the disk slowdown.</para>
1676 <para>Changing this variable must be done from the
1677 boot loader at boot time. Attempting to do it after the
1678 kernel boots will have no effect.</para>
1680 <para>For more information, please see &man.ata.4; manual page.</para>
1685 <sect2 id="soft-updates">
1686 <title>Soft Updates</title>
1688 <indexterm><primary>Soft Updates</primary></indexterm>
1689 <indexterm><primary>tunefs</primary></indexterm>
1691 <para>The &man.tunefs.8; program can be used to fine-tune a
1692 file system. This program has many different options, but for
1693 now we are only concerned with toggling Soft Updates on and
1694 off, which is done by:</para>
1696 <screen>&prompt.root; <userinput>tunefs -n enable /filesystem</userinput>
1697 &prompt.root; <userinput>tunefs -n disable /filesystem</userinput></screen>
1699 <para>A filesystem cannot be modified with &man.tunefs.8; while
1700 it is mounted. A good time to enable Soft Updates is before any
1701 partitions have been mounted, in single-user mode.</para>
1703 <note><para>It is possible to enable Soft Updates
1704 at filesystem creation time, through use of the <literal>-U</literal>
1705 option to &man.newfs.8;.</para></note>
1707 <para>Soft Updates drastically improves meta-data performance, mainly
1708 file creation and deletion, through the use of a memory cache. We
1709 recommend to use Soft Updates on all of your file systems. There
1710 are two downsides to Soft Updates that you should be aware of: First,
1711 Soft Updates guarantees filesystem consistency in the case of a crash
1712 but could very easily be several seconds (even a minute!) behind
1713 updating the physical disk. If your system crashes you may lose more
1714 work than otherwise. Secondly, Soft Updates delays the freeing of
1715 filesystem blocks. If you have a filesystem (such as the root
1716 filesystem) which is almost full, performing a major update, such as
1717 <command>make installworld</command>, can cause the filesystem to run
1718 out of space and the update to fail.</para>
1721 <title>More Details about Soft Updates</title>
1724 <primary>Soft Updates</primary>
1725 <secondary>details</secondary>
1728 <para>There are two traditional approaches to writing a file
1729 systems meta-data back to disk. (Meta-data updates are
1730 updates to non-content data like inodes or
1731 directories.)</para>
1733 <para>Historically, the default behavior was to write out
1734 meta-data updates synchronously. If a directory had been
1735 changed, the system waited until the change was actually
1736 written to disk. The file data buffers (file contents) were
1737 passed through the buffer cache and backed up
1738 to disk later on asynchronously. The advantage of this
1739 implementation is that it operates safely. If there is
1740 a failure during an update, the meta-data are always in a
1741 consistent state. A file is either created completely
1742 or not at all. If the data blocks of a file did not find
1743 their way out of the buffer cache onto the disk by the time
1744 of the crash, &man.fsck.8; is able to recognize this and
1745 repair the filesystem by setting the file length to
1746 0. Additionally, the implementation is clear and simple.
1747 The disadvantage is that meta-data changes are slow. An
1748 <command>rm -r</command>, for instance, touches all the files
1749 in a directory sequentially, but each directory
1750 change (deletion of a file) will be written synchronously
1751 to the disk. This includes updates to the directory itself,
1752 to the inode table, and possibly to indirect blocks
1753 allocated by the file. Similar considerations apply for
1754 unrolling large hierarchies (<command>tar -x</command>).</para>
1756 <para>The second case is asynchronous meta-data updates. This
1757 is the default for Linux/ext2fs and
1758 <command>mount -o async</command> for *BSD ufs. All
1759 meta-data updates are simply being passed through the buffer
1760 cache too, that is, they will be intermixed with the updates
1761 of the file content data. The advantage of this
1762 implementation is there is no need to wait until each
1763 meta-data update has been written to disk, so all operations
1764 which cause huge amounts of meta-data updates work much
1765 faster than in the synchronous case. Also, the
1766 implementation is still clear and simple, so there is a low
1767 risk for bugs creeping into the code. The disadvantage is
1768 that there is no guarantee at all for a consistent state of
1769 the filesystem. If there is a failure during an operation
1770 that updated large amounts of meta-data (like a power
1771 failure, or someone pressing the reset button),
1773 will be left in an unpredictable state. There is no opportunity
1774 to examine the state of the filesystem when the system
1775 comes up again; the data blocks of a file could already have
1776 been written to the disk while the updates of the inode
1777 table or the associated directory were not. It is actually
1778 impossible to implement a <command>fsck</command> which is
1779 able to clean up the resulting chaos (because the necessary
1780 information is not available on the disk). If the
1781 filesystem has been damaged beyond repair, the only choice
1782 is to use &man.newfs.8; on it and restore it from backup.
1785 <para>The usual solution for this problem was to implement
1786 <emphasis>dirty region logging</emphasis>, which is also
1787 referred to as <emphasis>journaling</emphasis>, although that
1788 term is not used consistently and is occasionally applied
1789 to other forms of transaction logging as well. Meta-data
1790 updates are still written synchronously, but only into a
1791 small region of the disk. Later on they will be moved
1792 to their proper location. Because the logging
1793 area is a small, contiguous region on the disk, there
1794 are no long distances for the disk heads to move, even
1795 during heavy operations, so these operations are quicker
1796 than synchronous updates.
1797 Additionally the complexity of the implementation is fairly
1798 limited, so the risk of bugs being present is low. A disadvantage
1799 is that all meta-data are written twice (once into the
1800 logging region and once to the proper location) so for
1801 normal work, a performance <quote>pessimization</quote>
1802 might result. On the other hand, in case of a crash, all
1803 pending meta-data operations can be quickly either rolled-back
1804 or completed from the logging area after the system comes
1805 up again, resulting in a fast filesystem startup.</para>
1807 <para>Kirk McKusick, the developer of Berkeley FFS,
1808 solved this problem with Soft Updates: all pending
1809 meta-data updates are kept in memory and written out to disk
1810 in a sorted sequence (<quote>ordered meta-data
1811 updates</quote>). This has the effect that, in case of
1812 heavy meta-data operations, later updates to an item
1813 <quote>catch</quote> the earlier ones if the earlier ones are still in
1814 memory and have not already been written to disk. So all
1815 operations on, say, a directory are generally performed in
1816 memory before the update is written to disk (the data
1817 blocks are sorted according to their position so
1818 that they will not be on the disk ahead of their meta-data).
1819 If the system crashes, this causes an implicit <quote>log
1820 rewind</quote>: all operations which did not find their way
1821 to the disk appear as if they had never happened. A
1822 consistent filesystem state is maintained that appears to
1823 be the one of 30 to 60 seconds earlier. The
1824 algorithm used guarantees that all resources in use
1825 are marked as such in their appropriate bitmaps: blocks and inodes.
1826 After a crash, the only resource allocation error
1827 that occurs is that resources are
1828 marked as <quote>used</quote> which are actually <quote>free</quote>.
1829 &man.fsck.8; recognizes this situation,
1830 and frees the resources that are no longer used. It is safe to
1831 ignore the dirty state of the filesystem after a crash by
1832 forcibly mounting it with <command>mount -f</command>. In
1833 order to free resources that may be unused, &man.fsck.8;
1834 needs to be run at a later time.</para>
1836 <para>The advantage is that meta-data operations are nearly as
1837 fast as asynchronous updates (i.e. faster than with
1838 <emphasis>logging</emphasis>, which has to write the
1839 meta-data twice). The disadvantages are the complexity of
1840 the code (implying a higher risk for bugs in an area that
1841 is highly sensitive regarding loss of user data), and a
1842 higher memory consumption. Additionally there are some
1843 idiosyncrasies one has to get used to.
1844 After a crash, the state of the filesystem appears to be
1845 somewhat <quote>older</quote>. In situations where
1846 the standard synchronous approach would have caused some
1847 zero-length files to remain after the
1848 <command>fsck</command>, these files do not exist at all
1849 with a Soft Updates filesystem because neither the meta-data
1850 nor the file contents have ever been written to disk.
1851 Disk space is not released until the updates have been
1852 written to disk, which may take place some time after
1853 running <command>rm</command>. This may cause problems
1854 when installing large amounts of data on a filesystem
1855 that does not have enough free space to hold all the files
1861 <sect1 id="configtuning-kernel-limits">
1862 <title>Tuning Kernel Limits</title>
1865 <primary>tuning</primary>
1866 <secondary>kernel limits</secondary>
1869 <sect2 id="file-process-limits">
1870 <title>File/Process Limits</title>
1872 <sect3 id="kern-maxfiles">
1873 <title><varname>kern.maxfiles</varname></title>
1876 <primary><varname>kern.maxfiles</varname></primary>
1879 <para><varname>kern.maxfiles</varname> can be raised or
1880 lowered based upon your system requirements. This variable
1881 indicates the maximum number of file descriptors on your
1882 system. When the file descriptor table is full,
1883 <errorname>file: table is full</errorname> will show up repeatedly
1884 in the system message buffer, which can be viewed with the
1885 <command>dmesg</command> command.</para>
1887 <para>Each open file, socket, or fifo uses one file
1888 descriptor. A large-scale production server may easily
1889 require many thousands of file descriptors, depending on the
1890 kind and number of services running concurrently.</para>
1892 <para><varname>kern.maxfile</varname>'s default value is
1893 dictated by the <option>MAXUSERS</option> option in your
1894 kernel configuration file. <varname>kern.maxfiles</varname> grows
1895 proportionally to the value of <option>MAXUSERS</option>. When
1896 compiling a custom kernel, it is a good idea to set this kernel
1897 configuration option according to the uses of your system. From
1898 this number, the kernel is given most of its pre-defined limits.
1899 Even though a production machine may not actually have 256 users
1900 connected at once, the resources needed may be similar to a
1901 high-scale web server.</para>
1903 <note><para>Setting <option>MAXUSERS</option> to
1904 <literal>0</literal> in your kernel configuration file will choose
1905 a reasonable default value based on the amount of RAM present in
1906 your system. It is set to 0 in the default GENERIC kernel.</para></note>
1911 <title><varname>kern.ipc.somaxconn</varname></title>
1914 <primary><varname>kern.ipc.somaxconn</varname></primary>
1917 <para>The <varname>kern.ipc.somaxconn</varname> sysctl variable
1918 limits the size of the listen queue for accepting new TCP
1919 connections. The default value of <literal>128</literal> is
1920 typically too low for robust handling of new connections in a
1921 heavily loaded web server environment. For such environments, it
1922 is recommended to increase this value to <literal>1024</literal> or
1923 higher. The service daemon may itself limit the listen queue size
1924 (e.g. &man.sendmail.8;, or <application>Apache</application>) but
1925 will often have a directive in its configuration file to adjust
1926 the queue size. Large listen queues also do a better job of
1927 avoiding Denial of Service (<abbrev>DoS</abbrev>) attacks.</para>
1932 <title>Network Limits</title>
1934 <para>The <option>NMBCLUSTERS</option> kernel configuration
1935 option dictates the amount of network Mbufs available to the
1936 system. A heavily-trafficked server with a low number of Mbufs
1937 will hinder &os;'s ability. Each cluster represents
1938 approximately 2 K of memory, so a value of 1024 represents 2
1939 megabytes of kernel memory reserved for network buffers. A
1940 simple calculation can be done to figure out how many are
1941 needed. If you have a web server which maxes out at 1000
1942 simultaneous connections, and each connection eats a 16 K receive
1943 and 16 K send buffer, you need approximately 32 MB worth of
1944 network buffers to cover the web server. A good rule of thumb is
1945 to multiply by 2, so 2x32 MB / 2 KB =
1946 64 MB / 2 kB = 32768. We recommend
1947 values between 4096 and 32768 for machines with greater amounts
1948 of memory. Under no circumstances should you specify an
1949 arbitrarily high value for this parameter as it could lead to a
1950 boot time crash. The <option>-m</option> option to
1951 &man.netstat.1; may be used to observe network cluster
1952 use. <varname>kern.ipc.nmbclusters</varname> loader tunable should
1953 be used to tune this at boot time.</para>
1955 <para>For busy servers that make extensive use of the
1956 &man.sendfile.2; system call, it may be necessary to increase
1957 the number of &man.sendfile.2; buffers via the
1958 <option>NSFBUFS</option> kernel configuration option or by
1959 setting its value in <filename>/boot/loader.conf</filename>
1960 (see &man.loader.8; for details). A common indicator that
1961 this parameter needs to be adjusted is when processes are seen
1962 in the <errorname>sfbufa</errorname> state. The sysctl
1963 variable <varname>kern.ipc.nsfbufs</varname> is a read-only
1964 glimpse at the kernel configured variable. This parameter
1965 nominally scales with <varname>kern.maxusers</varname>,
1966 however it may be necessary to tune accordingly.</para>
1969 <para>Even though a socket has been marked as non-blocking,
1970 calling &man.sendfile.2; on the non-blocking socket may
1971 result in the &man.sendfile.2; call blocking until enough
1972 <literal>struct sf_buf</literal>'s are made
1977 <title><varname>net.inet.ip.portrange.*</varname></title>
1980 <primary>net.inet.ip.portrange.*</primary>
1983 <para>The <varname>net.inet.ip.portrange.*</varname> sysctl
1984 variables control the port number ranges automatically bound to TCP
1985 and UDP sockets. There are three ranges: a low range, a default
1986 range, and a high range. Most network programs use the default
1987 range which is controlled by the
1988 <varname>net.inet.ip.portrange.first</varname> and
1989 <varname>net.inet.ip.portrange.last</varname>, which default to
1990 1024 and 5000, respectively. Bound port ranges are used for
1991 outgoing connections, and it is possible to run the system out of
1992 ports under certain circumstances. This most commonly occurs
1993 when you are running a heavily loaded web proxy. The port range
1994 is not an issue when running servers which handle mainly incoming
1995 connections, such as a normal web server, or has a limited number
1996 of outgoing connections, such as a mail relay. For situations
1997 where you may run yourself out of ports, it is recommended to
1998 increase <varname>net.inet.ip.portrange.last</varname> modestly.
1999 A value of <literal>10000</literal>, <literal>20000</literal> or
2000 <literal>30000</literal> may be reasonable. You should also
2001 consider firewall effects when changing the port range. Some
2002 firewalls may block large ranges of ports (usually low-numbered
2003 ports) and expect systems to use higher ranges of ports for
2004 outgoing connections — for this reason it is recommended that
2005 <varname>net.inet.ip.portrange.first</varname> be lowered.</para>
2009 <title>TCP Bandwidth Delay Product</title>
2012 <primary>TCP Bandwidth Delay Product Limiting</primary>
2013 <secondary><varname>net.inet.tcp.inflight_enable</varname></secondary>
2016 <para>The TCP Bandwidth Delay Product Limiting is similar to
2017 TCP/Vegas in <application>&netbsd;</application>.
2019 <indexterm><primary>&netbsd;</primary></indexterm>
2022 enabled by setting <varname>net.inet.tcp.inflight_enable</varname>
2023 sysctl variable to <literal>1</literal>. The system will attempt
2024 to calculate the bandwidth delay product for each connection and
2025 limit the amount of data queued to the network to just the amount
2026 required to maintain optimum throughput.</para>
2028 <para>This feature is useful if you are serving data over modems,
2029 Gigabit Ethernet, or even high speed WAN links (or any other link
2030 with a high bandwidth delay product), especially if you are also
2031 using window scaling or have configured a large send window. If
2032 you enable this option, you should also be sure to set
2033 <varname>net.inet.tcp.inflight_debug</varname> to
2034 <literal>0</literal> (disable debugging), and for production use
2035 setting <varname>net.inet.tcp.inflight_min</varname> to at least
2036 <literal>6144</literal> may be beneficial. However, note that
2037 setting high minimums may effectively disable bandwidth limiting
2038 depending on the link. The limiting feature reduces the amount of
2039 data built up in intermediate route and switch packet queues as
2040 well as reduces the amount of data built up in the local host's
2041 interface queue. With fewer packets queued up, interactive
2042 connections, especially over slow modems, will also be able to
2043 operate with lower <emphasis>Round Trip Times</emphasis>. However,
2044 note that this feature only effects data transmission (uploading
2045 / server side). It has no effect on data reception (downloading).
2048 <para>Adjusting <varname>net.inet.tcp.inflight_stab</varname> is
2049 <emphasis>not</emphasis> recommended. This parameter defaults to
2050 20, representing 2 maximal packets added to the bandwidth delay
2051 product window calculation. The additional window is required to
2052 stabilize the algorithm and improve responsiveness to changing
2053 conditions, but it can also result in higher ping times over slow
2054 links (though still much lower than you would get without the
2055 inflight algorithm). In such cases, you may wish to try reducing
2056 this parameter to 15, 10, or 5; and may also have to reduce
2057 <varname>net.inet.tcp.inflight_min</varname> (for example, to
2058 3500) to get the desired effect. Reducing these parameters
2059 should be done as a last resort only.</para>
2064 <sect1 id="adding-swap-space">
2065 <title>Adding Swap Space</title>
2067 <para>No matter how well you plan, sometimes a system does not run
2068 as you expect. If you find you need more swap space, it is
2069 simple enough to add. You have three ways to increase swap
2070 space: adding a new hard drive, enabling swap over NFS, and
2071 creating a swap file on an existing partition.</para>
2073 <sect2 id="new-drive-swap">
2074 <title>Swap on a New Hard Drive</title>
2076 <para>The best way to add swap, of course, is to use this as an
2077 excuse to add another hard drive. You can always use another
2078 hard drive, after all. If you can do this, go reread the
2079 discussion about swap space in <xref linkend="configtuning-initial">
2080 for some suggestions on how to best arrange your swap.</para>
2083 <sect2 id="nfs-swap">
2084 <title>Swapping over NFS</title>
2086 <para>Swapping over NFS is only recommended if you do not have a
2087 local hard disk to swap to. Even though &os; has an excellent
2088 NFS implementation, NFS swapping will be limited
2089 by the available network bandwidth and puts an additional
2090 burden on the NFS server.</para>
2093 <sect2 id="create-swapfile">
2094 <title>Swapfiles</title>
2096 <para>You can create a file of a specified size to use as a swap
2097 file. In our example here we will use a 64MB file called
2098 <filename>/usr/swap0</filename>. You can use any name you
2099 want, of course.</para>
2102 <title>Creating a Swapfile</title>
2106 <para>Be certain that your kernel configuration includes
2107 the vnode driver. It is <emphasis>not</emphasis> in recent versions of
2108 <filename>GENERIC</filename>.</para>
2110 <programlisting>pseudo-device vn 1 #Vnode driver (turns a file into a device)</programlisting>
2114 <para>Create a vn-device:</para>
2115 <screen>&prompt.root; <userinput>cd /dev</userinput>
2116 &prompt.root; <userinput>sh MAKEDEV vn0</userinput></screen>
2120 <para>Create a swapfile (<filename>/usr/swap0</filename>):</para>
2122 <screen>&prompt.root; <userinput>dd if=/dev/zero of=/usr/swap0 bs=1024k count=64</userinput></screen>
2126 <para>Set proper permissions on (<filename>/usr/swap0</filename>):</para>
2128 <screen>&prompt.root; <userinput>chmod 0600 /usr/swap0</userinput></screen>
2132 <para>Enable the swap file in <filename>/etc/rc.conf</filename>:</para>
2134 <programlisting>swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.</programlisting>
2139 <para>Reboot the machine or to enable the swap file immediately,
2142 <screen>&prompt.root; <userinput>vnconfig -e /dev/vn0b /usr/swap0 swap</userinput></screen>
2150 <sect1 id="acpi-overview">
2154 <firstname>Hiten</firstname>
2155 <surname>Pandya</surname>
2156 <contrib>Written by </contrib>
2159 <firstname>Tom</firstname>
2160 <surname>Rhodes</surname>
2165 <title>Power and Resource Management</title>
2167 <para>It is very important to utilize hardware resources in an
2168 efficient manner. Before <acronym>ACPI</acronym> was introduced,
2169 it was very difficult and inflexible for operating systems to manage
2170 the power usage and thermal properties of a system. The hardware was
2171 controlled by some sort of <acronym>BIOS</acronym> embedded
2172 interface, such as <emphasis>Plug and Play BIOS (PNPBIOS)</emphasis>, or
2173 <emphasis>Advanced Power Management (APM)</emphasis> and so on.
2174 Power and Resource Management is one of the key components of a modern
2175 operating system. For example, you may want an operating system to
2176 monitor system limits (and possibly alert you) in case your system
2177 temperature increased unexpectedly.</para>
2179 <para>In this section, we will provide
2180 comprehensive information about <acronym>ACPI</acronym>. References
2181 will be provided for further reading at the end. Please be aware
2182 that <acronym>ACPI</acronym> is available on &os; systems as a
2183 default kernel module. </para>
2185 <sect2 id="acpi-intro">
2186 <title>What Is ACPI?</title>
2188 <para>Advanced Configuration and Power Interface
2189 (<acronym>ACPI</acronym>) is a standard written by
2190 an alliance of vendors to provide a standard interface for
2191 hardware resources and power management (hence the name).
2192 It is a key element in <emphasis>Operating System-directed
2193 configuration and Power Management</emphasis>, i.e.: it provides
2194 more control and flexibility to the operating system
2195 (<acronym>OS</acronym>).
2196 Modern systems <quote>stretched</quote> the limits of the
2197 current Plug and Play interfaces (such as APM), prior to the introduction of
2198 <acronym>ACPI</acronym>. <acronym>ACPI</acronym> is the direct
2199 successor to <acronym>APM</acronym>
2200 (Advanced Power Management).</para>
2203 <sect2 id="acpi-old-spec">
2204 <title>Shortcomings of Advanced Power Management (APM)</title>
2206 <para>The <emphasis>Advanced Power Management (APM)</emphasis>
2207 facility control's the power usage of a system based on its
2208 activity. The APM BIOS is supplied by the (system) vendor and
2209 it is specific to the hardware platform. An APM driver in the
2210 OS mediates access to the <emphasis>APM Software Interface</emphasis>,
2211 which allows management of power levels.</para>
2213 <para>There are four major problems in APM. Firstly, power
2214 management is done by the (vendor-specific) BIOS, and the OS
2215 does not have any knowledge of it. One example of this, is when
2216 the user sets idle-time values for a hard drive in the APM BIOS,
2217 that when exceeded, it (BIOS) would spin down the hard drive,
2218 without the consent of the OS. Secondly, the APM logic is
2219 embedded in the BIOS, and it operates outside the scope of the
2220 OS. This means users can only fix problems in their APM BIOS by
2221 flashing a new one into the ROM; which, is a very dangerous
2222 procedure, and if it fails, it could leave the system in an
2223 unrecoverable state. Thirdly, APM is a vendor-specific
2224 technology, which, means that there is a lot or parity
2225 (duplication of efforts) and bugs found in one vendor's BIOS,
2226 may not be solved in others. Last but not the least, the APM
2227 BIOS did not have enough room to implement a sophisticated power
2228 policy, or one that can adapt very well to the purpose of the
2231 <para><emphasis>Plug and Play BIOS (PNPBIOS)</emphasis> was
2232 unreliable in many situations. PNPBIOS is 16-bit technology,
2233 so the OS has to use 16-bit emulation in order to
2234 <quote>interface</quote> with PNPBIOS methods.</para>
2236 <para>The &os; <acronym>APM</acronym> driver is documented in
2237 the &man.apm.4; manual page.</para>
2240 <sect2 id="acpi-config">
2241 <title>Configuring <acronym>ACPI</acronym></title>
2243 <para>The <filename>acpi.ko</filename> driver is loaded by default
2244 at start up by the &man.loader.8; and should <emphasis>not</emphasis>
2245 be compiled into the kernel. The reasoning behind this is that modules
2246 are easier to work with, say if switching to another <filename>acpi.ko</filename>
2247 without doing a kernel rebuild. This has the advantage of making testing easier.
2248 Another reason is that starting <acronym>ACPI</acronym> after a system has been
2249 brought up is not too useful, and in some cases can be fatal. In doubt, just
2250 disable <acronym>ACPI</acronym> all together. This driver should not and can not
2251 be unloaded because the system bus uses it for various hardware interactions.
2252 <acronym>ACPI</acronym> can be disabled with the &man.acpiconf.8; utility.
2253 In fact most of the interaction with <acronym>ACPI</acronym> can be done via
2254 &man.acpiconf.8;. Basically this means, if anything about <acronym>ACPI</acronym>
2255 is in the &man.dmesg.8; output, then most likely it is already running.</para>
2257 <note><para><acronym>ACPI</acronym> and <acronym>APM</acronym> cannot coexist and
2258 should be used separately. The last one to load will terminate if the driver
2259 notices the other running.</para></note>
2261 <para>In the simplest form, <acronym>ACPI</acronym> can be used to put the
2262 system into a sleep mode with &man.acpiconf.8;, the <option>-s</option>
2263 flag, and a <literal>1-5</literal> option. Most users will only need
2264 <literal>1</literal>. Option <literal>5</literal> will do a soft-off
2265 which is the same action as:</para>
2267 <screen>&prompt.root; <userinput>halt -p</userinput></screen>
2269 <para>The other options are available. Check out the &man.acpiconf.8;
2270 manual page for more information.</para>
2274 <sect1 id="ACPI-debug">
2278 <firstname>Nate</firstname>
2279 <surname>Lawson</surname>
2280 <contrib>Written by </contrib>
2285 <firstname>Peter</firstname>
2286 <surname>Schultz</surname>
2287 <contrib>With contributions from </contrib>
2290 <firstname>Tom</firstname>
2291 <surname>Rhodes</surname>
2296 <title>Using and Debugging &os; <acronym>ACPI</acronym></title>
2298 <para><acronym>ACPI</acronym> is a fundamentally new way of
2299 discovering devices, managing power usage, and providing
2300 standardized access to various hardware previously managed
2301 by the <acronym>BIOS</acronym>. Progress is being made toward
2302 <acronym>ACPI</acronym> working on all systems, but bugs in some
2303 motherboards' <firstterm><acronym>ACPI</acronym> Machine
2304 Language</firstterm> (<acronym>AML</acronym>) bytecode,
2305 incompleteness in &os;'s kernel subsystems, and bugs in the Intel
2306 <acronym>ACPI-CA</acronym> interpreter continue to appear.</para>
2308 <para>This document is intended to help you assist the &os;
2309 <acronym>ACPI</acronym> maintainers in identifying the root cause
2310 of problems you observe and debugging and developing a solution.
2311 Thanks for reading this and we hope we can solve your system's
2314 <sect2 id="ACPI-submitdebug">
2315 <title>Submitting Debugging Information</title>
2318 <para>Before submitting a problem, be sure you are running the latest
2319 <acronym>BIOS</acronym> version and, if available, embedded
2320 controller firmware version.</para>
2323 <para>For those of you that want to submit a problem right away,
2324 please send the following information to
2325 &a.bugs.name;</para>
2329 <para>Description of the buggy behavior, including system type
2330 and model and anything that causes the bug to appear. Also,
2331 please note as accurately as possible when the bug began
2332 occurring if it is new for you.</para>
2336 <para>The dmesg output after <quote>boot
2337 <option>-v</option></quote>, including any error messages
2338 generated by you exercising the bug.</para>
2342 <para>dmesg output from <quote>boot
2343 <option>-v</option></quote> with <acronym>ACPI</acronym>
2344 disabled, if disabling it helps fix the problem.</para>
2348 <para>Output from <quote>sysctl hw.acpi</quote>. This is also
2349 a good way of figuring out what features your system
2354 <para><acronym>URL</acronym> where your
2355 <firstterm><acronym>ACPI</acronym> Source Language</firstterm>
2356 (<acronym>ASL</acronym>)
2357 can be found. Do <emphasis>not</emphasis> send the
2358 <acronym>ASL</acronym> directly to the list as it can be
2359 very large. Generate a copy of your <acronym>ASL</acronym>
2360 by running this command:</para>
2362 <screen>&prompt.root; <userinput>acpidump -t -d > <replaceable>name</replaceable>-<replaceable>system</replaceable>.asl</userinput></screen>
2364 <para>(Substitute your login name for
2365 <replaceable>name</replaceable> and manufacturer/model for
2366 <replaceable>system</replaceable>. Example:
2367 <filename>njl-FooCo6000.asl</filename>)</para>
2373 <sect2 id="ACPI-background">
2374 <title>Background</title>
2376 <para><acronym>ACPI</acronym> is present in all modern computers
2377 that conform to the ia32 (x86), ia64 (Itanium), and amd64 (AMD)
2378 architectures. The full standard has many features including
2379 <acronym>CPU</acronym> performance management, power planes
2380 control, thermal zones, various battery systems, embedded
2381 controllers, and bus enumeration. Most systems implement less
2382 than the full standard. For instance, a desktop system usually
2383 only implements the bus enumeration parts while a laptop might
2384 have cooling and battery management support as well. Laptops
2385 also have suspend and resume, with their own associated
2388 <para>An <acronym>ACPI</acronym>-compliant system has various
2389 components. The <acronym>BIOS</acronym> and chipset vendors
2390 provide various fixed tables (e.g., <acronym>FADT</acronym>)
2391 in memory that specify things like the <acronym>APIC</acronym>
2392 map (used for <acronym>SMP</acronym>), config registers, and
2393 simple configuration values. Additionally, a table of bytecode
2394 (the <firstterm>Differentiated System Description Table</firstterm>
2395 <acronym>DSDT</acronym>) is provided that specifies a
2396 tree-like name space of devices and methods.</para>
2398 <para>The <acronym>ACPI</acronym> driver must parse the fixed
2399 tables, implement an interpreter for the bytecode, and modify
2400 device drivers and the kernel to accept information from the
2401 <acronym>ACPI</acronym> subsystem. For &os;, Intel has
2402 provided an interpreter (<acronym>ACPI-CA</acronym>) that is
2403 shared with Linux and &netbsd;.
2405 <indexterm><primary>&netbsd;</primary></indexterm>
2408 <acronym>ACPI-CA</acronym> source code is
2409 <filename role="directory">src/sys/contrib/dev/acpica-unix-YYYYMMDD</filename>,
2410 where YYYYMMDD is the release date of the ACPI-CA source code. The
2411 glue code that allows <acronym>ACPI-CA</acronym> to work on
2412 &os; is in <filename>src/sys/dev/acpica5/Osd</filename>. Finally,
2413 drivers that implement various <acronym>ACPI</acronym> devices
2414 are found in <filename role="directory">src/sys/dev/acpica5</filename>,
2415 and architecture-dependent code resides in
2416 <filename role="directory">/sys/<replaceable>arch</replaceable>/acpica5</filename>.
2420 <sect2 id="ACPI-comprob">
2421 <title>Common Problems</title>
2423 <para>For <acronym>ACPI</acronym> to work correctly, all the parts
2424 have to work correctly. Here are some common problems, in order
2425 of frequency of appearance, and some possible workarounds or
2429 <title>Suspend/Resume</title>
2431 <para><acronym>ACPI</acronym> has three suspend to
2432 <acronym>RAM</acronym> (<acronym>STR</acronym>) states,
2433 <literal>S1</literal>-<literal>S3</literal>, and one suspend
2434 to disk state (<literal>STD</literal>), called
2435 <literal>S4</literal>. <literal>S5</literal> is
2436 <quote>soft off</quote> and is the normal state your system
2437 is in when plugged in but not powered up.
2438 <literal>S4</literal> can actually be implemented two separate
2439 ways. <literal>S4</literal><acronym>BIOS</acronym> is a
2440 <acronym>BIOS</acronym>-assisted suspend to disk.
2441 <literal>S4</literal><acronym>OS</acronym> is implemented
2442 entirely by the operating system.</para>
2444 <para>Start by checking <command>sysctl</command>
2445 <option>hw.acpi</option> for the suspend-related items. Here
2446 are the results for my Thinkpad:</para>
2448 <screen>hw.acpi.supported_sleep_state: S3 S4 S5</screen>
2449 <screen>hw.acpi.s4bios: 0</screen>
2451 <para>This means that I can use <command>acpiconf -s</command>
2452 to test <literal>S3</literal>,
2453 <literal>S4</literal><acronym>OS</acronym>, and
2454 <literal>S5</literal>. If <option>s4bios</option> was one
2455 (<literal>1</literal>), I would have
2456 <literal>S4</literal><acronym>BIOS</acronym>
2457 support instead of <literal>S4</literal>
2458 <acronym>OS</acronym>.</para>
2460 <para>When testing suspend/resume, start with
2461 <literal>S1</literal>, if supported. This state is most
2462 likely to work since it doesn't require much driver support.
2463 No one has implemented <literal>S2</literal> but if you have
2464 it, it's similar to <literal>S1</literal>. The next thing
2465 to try is <literal>S3</literal>. This is the deepest
2466 <acronym>STR</acronym> state and requires a lot of driver
2467 support to properly reinitialize your hardware. If you have
2468 problems resuming, feel free to email the &a.bugs.name; list but
2469 do not expect the problem to be resolved since there are a lot
2470 of drivers/hardware that need more testing and work.</para>
2472 <para>To help isolate the problem, remove as many drivers from
2473 your kernel as possible. If it works, you can narrow down
2474 which driver is the problem by loading drivers until it fails
2475 again. Typically binary drivers like
2476 <filename>nvidia.ko</filename>, <application>X11</application>
2477 display drivers, and <acronym>USB</acronym> will have the most
2478 problems while Ethernet interfaces usually work fine. If you
2479 can load/unload the drivers ok, you can automate this by
2480 putting the appropriate commands in
2481 <filename>/etc/rc.suspend</filename> and
2482 <filename>/etc/rc.resume</filename>. There is a
2483 commented-out example for unloading and loading a driver. Try
2484 setting <option>hw.acpi.reset_video</option> to zero (0) if
2485 your display is messed up after resume. Try setting longer or
2486 shorter values for <option>hw.acpi.sleep_delay</option> to see
2487 if that helps.</para>
2489 <para>Another thing to try is load a recent Linux distribution
2490 with <acronym>ACPI</acronym> support and test their
2491 suspend/resume support on the same hardware. If it works
2492 on Linux, it's likely a &os; driver problem and narrowing down
2493 which driver causes the problems will help us fix the problem.
2494 Note that the <acronym>ACPI</acronym> maintainers do not
2495 usually maintain other drivers (e.g sound,
2496 <acronym>ATA</acronym>, etc.) so any work done on tracking
2497 down a driver problem should probably eventually be posted
2498 to the &a.bugs.name; list and mailed to the driver
2499 maintainer. If you are feeling adventurous, go ahead and
2500 start putting some debugging &man.printf.3;s in a problematic
2501 driver to track down where in its resume function it
2504 <para>Finally, try disabling <acronym>ACPI</acronym> and
2505 enabling <acronym>APM</acronym> instead. If suspend/resume
2506 works with <acronym>APM</acronym>, you may be better off
2507 sticking with <acronym>APM</acronym>, especially on older
2508 hardware (pre-2000). It took vendors a while to get
2509 <acronym>ACPI</acronym> support correct and older hardware is
2510 more likely to have <acronym>BIOS</acronym> problems with
2511 <acronym>ACPI</acronym>.</para>
2515 <title>System Hangs (temporary or permanent)</title>
2517 <para>Most system hangs are a result of lost interrupts or an
2518 interrupt storm. Chipsets have a lot of problems based on how
2519 the <acronym>BIOS</acronym> configures interrupts before boot,
2520 correctness of the <acronym>APIC</acronym>
2521 (<acronym>MADT</acronym>) table, and routing of the
2522 <firstterm>System Control Interrupt</firstterm>
2523 (<acronym>SCI</acronym>).</para>
2525 <para>Interrupt storms can be distinguished from lost interrupts
2526 by checking the output of <command>vmstat -i</command>
2527 and looking at the line that has
2528 <literal>acpi0</literal>. If the counter is increasing at more
2529 than a couple per second, you have an interrupt storm. If the
2530 system appears hung, try breaking to <acronym>DDB</acronym>
2531 (<keycombo action="simul"><keycap>CTRL</keycap>
2532 <keycap>ALT</keycap><keycap>ESC</keycap></keycombo> on
2533 console) and type <option>show interrupts</option>.</para>
2535 <para>Your best hope when dealing with interrupt problems is to
2536 try disabling <acronym>APIC</acronym> support with
2537 <literal>hint.apic.0.disabled="1"</literal> in
2538 <filename>loader.conf</filename>.</para>
2542 <title>Panics</title>
2544 <para>Panics are relatively rare for <acronym>ACPI</acronym> and
2545 are the top priority to be fixed. The first step is to
2546 isolate the steps to reproduce the panic (if possible)
2547 and get a backtrace. Follow the advice for enabling
2548 <option>options DDB</option> and setting up a serial console
2549 (see <xref linkend="serialconsole-ddb">)
2550 or setting up a &man.dump.8; partition. You can get a
2551 backtrace in <acronym>DDB</acronym> with
2552 <option>tr</option>. If you have to handwrite the
2553 backtrace, be sure to at least get the lowest five (5) and top
2554 five (5) lines in the trace.</para>
2556 <para>Then, try to isolate the problem by booting with
2557 <acronym>ACPI</acronym> disabled. If that works, you can
2558 isolate the <acronym>ACPI</acronym> subsystem by using various
2559 values of <option>debug.acpi.disable</option>. See the
2560 &man.acpi.4; manual page for some examples.</para>
2564 <title>System Powers Up After Suspend or Shutdown</title>
2565 <para>First, try setting
2566 <option>hw.acpi.disable_on_poweroff=</option><quote>0</quote>
2567 in &man.loader.conf.5;. This keeps <acronym>ACPI</acronym>
2568 from disabling various events during the shutdown process.
2569 Some systems need this value set to <quote>1</quote> (the
2570 default) for the same reason. This usually fixes
2571 the problem of a system powering up spontaneously after a
2572 suspend or poweroff.</para>
2576 <title>Other Problems</title>
2578 <para>If you have other problems with <acronym>ACPI</acronym>
2579 (working with a docking station, devices not detected, etc.),
2580 please email a description to the mailing list as well;
2581 however, some of these issues may be related to unfinished
2582 parts of the <acronym>ACPI</acronym> subsystem so they might
2583 take a while to be implemented. Please be patient and
2584 prepared to test patches we may send you.</para>
2588 <sect2 id="ACPI-aslanddump">
2589 <title><acronym>ASL</acronym>, <command>acpidump</command>, and
2590 <acronym>IASL</acronym></title>
2592 <para>The most common problem is the <acronym>BIOS</acronym>
2593 vendors providing incorrect (or outright buggy!) bytecode. This
2594 is usually manifested by kernel console messages like
2597 <screen>ACPI-1287: *** Error: Method execution failed [\\_SB_.PCI0.LPC0.FIGD._STA] (Node 0xc3f6d160), AE_NOT_FOUND</screen>
2599 <para>Often, you can resolve these problems by updating your
2600 <acronym>BIOS</acronym> to the latest revision. Most console
2601 messages are harmless but if you have other problems like
2602 battery status not working, they're a good place to start
2603 looking for problems in the <acronym>AML</acronym>. The
2604 bytecode, known as <acronym>AML</acronym>, is compiled from a
2605 source language called <acronym>ASL</acronym>. The
2606 <acronym>AML</acronym> is found in the table known as the
2607 <acronym>DSDT</acronym>. To get a copy of your
2608 <acronym>ASL</acronym>, use &man.acpidump.8;. You should use
2609 both the <option>-t</option> (show contents of the fixed tables)
2610 and <option>-d</option> (disassemble <acronym>AML</acronym> to
2611 <acronym>ASL</acronym>) options. See the
2612 <link linkend="ACPI-submitdebug">Submitting Debugging
2613 Information</link> section for an example syntax.</para>
2615 <para>The simplest first check you can do is to recompile your
2616 <acronym>ASL</acronym> to check for errors. Warnings can
2617 usually be ignored but errors are bugs that will usually prevent
2618 <acronym>ACPI</acronym> from working correctly. To recompile
2619 your <acronym>ASL</acronym>, issue the following command:</para>
2621 <screen>&prompt.root; <userinput>iasl your.asl</userinput></screen>
2624 <sect2 id="ACPI-fixasl">
2625 <title>Fixing Your <acronym>ASL</acronym></title>
2627 <para>In the long run, our goal is for almost everyone to have
2628 <acronym>ACPI</acronym> work without any user intervention. At
2629 this point, however, we are still developing workarounds for
2630 common mistakes made by the <acronym>BIOS</acronym> vendors.
2631 The Microsoft interpreter (<filename>acpi.sys</filename> and
2632 <filename>acpiec.sys</filename>) does not strictly check for
2633 adherence to the standard, and thus many <acronym>BIOS</acronym>
2634 vendors who only test <acronym>ACPI</acronym> under Windows
2635 never fix their <acronym>ASL</acronym>. We hope to continue to
2636 identify and document exactly what non-standard behavior is
2637 allowed by Microsoft's interpreter and replicate it so &os; can
2638 work without forcing users to fix the <acronym>ASL</acronym>.
2639 As a workaround and to help us identify behavior, you can fix
2640 the <acronym>ASL</acronym> manually. If this works for you,
2641 please send a &man.diff.1; of the old and new
2642 <acronym>ASL</acronym> so we can possibly work around the buggy
2643 behavior in <acronym>ACPI-CA</acronym> and thus make your fix
2646 <para>Here is a list of common error messages, their cause, and
2647 how to fix them:</para>
2650 <title>_OS dependencies</title>
2652 <para>Some <acronym>AML</acronym> assumes the world consists of
2653 various Windows versions. You can tell &os; to claim it is
2654 any <acronym>OS</acronym> to see if this fixes problems you
2655 may have. An easy way to override this is to set
2656 <option>hw.acpi.osname</option>=<quote>Windows 2001</quote>
2657 in <filename>/boot/loader.conf</filename> or other similar
2658 strings you find in the <acronym>ASL</acronym>.</para>
2661 <title>Missing Return statements</title>
2663 <para>Some methods do not explicitly return a value as the
2664 standard requires. While <acronym>ACPI-CA</acronym>
2665 does not handle this, &os; has a workaround that allows it to
2666 return the value implicitly. You can also add explicit
2667 Return statements where required if you know what value should
2668 be returned. To force <command>iasl</command> to compile the
2669 <acronym>ASL</acronym>, use the <option>-f</option>
2674 <title>Overriding the Default <acronym>AML</acronym></title>
2676 <para>After you customize <filename>your.asl</filename>, you
2677 will want to compile it, run:</para>
2679 <screen>&prompt.root; <userinput>iasl your.asl</userinput></screen>
2681 <para>You can add the <option>-f</option> flag to force creation
2682 of the <acronym>AML</acronym>, even if there are errors during
2683 compilation. Remember that some errors (e.g., missing Return
2684 statements) are automatically worked around by the
2687 <para><filename>DSDT.aml</filename> is the default output
2688 filename for <command>iasl</command>. You can load this
2689 instead of your <acronym>BIOS</acronym>'s buggy copy (which
2690 is still present in flash memory) by editing
2691 <filename>/boot/loader.conf</filename> as
2694 <programlisting>acpi_dsdt_load="YES"
2695 acpi_dsdt_name="/boot/DSDT.aml"</programlisting>
2697 <para>Be sure to copy your <filename>DSDT.aml</filename> to the
2698 <filename role="directory">/boot</filename> directory.</para>
2701 <sect2 id="ACPI-debugoutput">
2702 <title>Getting Debugging Output From
2703 <acronym>ACPI</acronym></title>
2705 <para>The <acronym>ACPI</acronym> driver has a very flexible
2706 debugging facility. It allows you to specify a set of subsystems
2707 as well as the level of verbosity. The subsystems you wish to
2708 debug are specified as <quote>layers</quote> and are broken down
2709 into <acronym>ACPI-CA</acronym> components (ACPI_ALL_COMPONENTS)
2710 and <acronym>ACPI</acronym> hardware support (ACPI_ALL_DRIVERS).
2711 The verbosity of debugging output is specified as the
2712 <quote>level</quote> and ranges from ACPI_LV_ERROR (just report
2713 errors) to ACPI_LV_VERBOSE (everything). The
2714 <quote>level</quote> is a bitmask so multiple options can be set
2715 at once, separated by spaces. In practice, you will want to use
2716 a serial console to log the output if it is so long
2717 it flushes the console message buffer. </para>
2719 <para>Debugging output is not enabled by default. To enable it,
2720 add <option>options ACPI_DEBUG</option> to your kernel config
2721 if <acronym>ACPI</acronym> is compiled into the kernel. You can
2722 add <option>ACPI_DEBUG=1</option> to your
2723 <filename>/etc/make.conf</filename> to enable it globally. If
2724 it is a module, you can recompile just your
2725 <filename>acpi.ko</filename> module as follows:</para>
2727 <screen>&prompt.root; <userinput>cd /sys/dev/acpica5
2728 && make clean &&
2729 make ACPI_DEBUG=1</userinput></screen>
2731 <para>Install <filename>acpi.ko</filename> in
2732 <filename role="directory">/boot/kernel</filename> and add your
2733 desired level and layer to <filename>loader.conf</filename>.
2734 This example enables debug messages for all
2735 <acronym>ACPI-CA</acronym> components and all
2736 <acronym>ACPI</acronym> hardware drivers
2737 (<acronym>CPU</acronym>, <acronym>LID</acronym>, etc.) It will
2738 only output error messages, the least verbose level.</para>
2740 <programlisting>debug.acpi.layer="ACPI_ALL_COMPONENTS ACPI_ALL_DRIVERS"
2741 debug.acpi.level="ACPI_LV_ERROR"</programlisting>
2743 <para>If the information you want is triggered by a specific event
2744 (say, a suspend and then resume), you can leave out changes to
2745 <filename>loader.conf</filename> and instead use
2746 <command>sysctl</command> to specify the layer and level after
2747 booting and preparing your system for the specific event. The
2748 <command>sysctl</command>s are named the same as the tunables
2749 in <filename>loader.conf</filename>.</para>
2752 <sect2 id="ACPI-References">
2753 <title>References</title>
2755 <para>More information about <acronym>ACPI</acronym> may be found
2756 in the following locations:</para>
2760 <para>The &a.freebsd.acpi; (This is FreeBSD-specific; posting
2761 &os; questions here may not generate much of an answer.)</para>
2765 <para>The <acronym>ACPI</acronym> Mailing List Archives (FreeBSD)
2766 <ulink url="http://lists.freebsd.org/pipermail/freebsd-acpi/"></ulink></para>
2770 <para>The old <acronym>ACPI</acronym> Mailing List Archives (FreeBSD)
2771 <ulink url="http://home.jp.FreeBSD.org/mail-list/acpi-jp/"></ulink></para>
2775 <para>The <acronym>ACPI</acronym> 2.0 Specification
2776 <ulink url="http://acpi.info/spec.htm"></ulink></para>
2780 <para>&os; Manual pages:
2783 &man.acpidb.8;</para>
2788 url="http://www.cpqlinux.com/acpi-howto.html#fix_broken_dsdt">
2789 <acronym>DSDT</acronym> debugging resource</ulink>.
2790 (Uses Compaq as an example but generally useful.)</para>
2800 sgml-declaration: "../chapter.decl"
2803 sgml-always-quote-attributes: t
2804 sgml-parent-document: ("../book.sgml" "part" "chapter")