Index: head/en_US.ISO8859-1/books/handbook/config/chapter.xml
===================================================================
--- head/en_US.ISO8859-1/books/handbook/config/chapter.xml	(revision 53654)
+++ head/en_US.ISO8859-1/books/handbook/config/chapter.xml	(revision 53655)
@@ -1,3524 +1,3524 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
 <!--
      The FreeBSD Documentation Project
 
      $FreeBSD$
 -->
 <chapter xmlns="http://docbook.org/ns/docbook"
   xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"
   xml:id="config-tuning">
 
   <info>
     <title>Configuration and Tuning</title>
 
     <authorgroup>
       <author>
 	<personname>
 	  <firstname>Chern</firstname>
 	  <surname>Lee</surname>
 	</personname>
 	<contrib>Written by </contrib>
       </author>
     </authorgroup>
 
     <authorgroup>
       <author>
 	<personname>
 	  <firstname>Mike</firstname>
 	  <surname>Smith</surname>
 	</personname>
 	<contrib>Based on a tutorial written by </contrib>
       </author>
     </authorgroup>
 
     <authorgroup>
       <author>
 	<personname>
 	  <firstname>Matt</firstname>
 	  <surname>Dillon</surname>
 	</personname>
 	<contrib>Also based on tuning(7) written by </contrib>
       </author>
     </authorgroup>
   </info>
 
   <sect1 xml:id="config-synopsis">
     <title>Synopsis</title>
 
     <indexterm>
       <primary>system configuration</primary>
     </indexterm>
     <indexterm>
       <primary>system optimization</primary>
     </indexterm>
 
     <para>One of the important aspects of &os; is proper system
       configuration.  This chapter explains much of the &os;
       configuration process, including some of the parameters which
       can be set to tune a &os; system.</para>
 
     <para>After reading this chapter, you will know:</para>
 
     <itemizedlist>
       <listitem>
 	<para>The basics of <filename>rc.conf</filename> configuration
 	  and <filename>/usr/local/etc/rc.d</filename> startup
 	  scripts.</para>
       </listitem>
 
       <listitem>
 	<para>How to configure and test a network card.</para>
       </listitem>
 
       <listitem>
 	<para>How to configure virtual hosts on network
 	  devices.</para>
       </listitem>
 
       <listitem>
 	<para>How to use the various configuration files in
 	  <filename>/etc</filename>.</para>
       </listitem>
 
       <listitem>
 	<para>How to tune &os; using &man.sysctl.8; variables.</para>
       </listitem>
 
       <listitem>
 	<para>How to tune disk performance and modify kernel
 	  limitations.</para>
       </listitem>
     </itemizedlist>
 
     <para>Before reading this chapter, you should:</para>
 
     <itemizedlist>
       <listitem>
 	<para>Understand &unix; and &os; basics
 	  (<xref linkend="basics"/>).</para>
       </listitem>
 
       <listitem>
 	<para>Be familiar with the basics of kernel configuration and
 	  compilation (<xref linkend="kernelconfig"/>).</para>
       </listitem>
     </itemizedlist>
   </sect1>
 
   <sect1 xml:id="configtuning-starting-services">
     <info>
       <title>Starting Services</title>
 
       <authorgroup>
 	<author>
 	  <personname>
 	    <firstname>Tom</firstname>
 	    <surname>Rhodes</surname>
 	  </personname>
 	  <contrib>Contributed by </contrib>
 	</author>
       </authorgroup>
     </info>
 
     <indexterm>
       <primary>services</primary>
     </indexterm>
 
     <para>Many users install third party software on &os; from the
       Ports Collection and require the installed services to be
       started upon system initialization.  Services, such as
       <package>mail/postfix</package> or
       <package>www/apache22</package> are just two of the many
       software packages which may be started during system
       initialization.  This section explains the procedures available
       for starting third party software.</para>
 
     <para>In &os;, most included services, such as &man.cron.8;, are
       started through the system startup scripts.</para>
 
     <sect2>
       <title>Extended Application Configuration</title>
 
       <para>Now that &os; includes <filename>rc.d</filename>,
 	configuration of application startup is easier and provides
 	more features.  Using the key words discussed in
 	<xref linkend="configtuning-rcd"/>, applications can be set to
 	start after certain other services and extra flags can be
 	passed through <filename>/etc/rc.conf</filename> in place of
 	hard coded flags in the startup script.  A basic script may
 	look similar to the following:</para>
 
       <programlisting>#!/bin/sh
 #
 # PROVIDE: utility
 # REQUIRE: DAEMON
 # KEYWORD: shutdown
 
 . /etc/rc.subr
 
 name=utility
 rcvar=utility_enable
 
 command="/usr/local/sbin/utility"
 
 load_rc_config $name
 
 #
 # DO NOT CHANGE THESE DEFAULT VALUES HERE
 # SET THEM IN THE /etc/rc.conf FILE
 #
 utility_enable=${utility_enable-"NO"}
 pidfile=${utility_pidfile-"/var/run/utility.pid"}
 
 run_rc_command "$1"</programlisting>
 
       <para>This script will ensure that the provided
 	<literal>utility</literal> will be started after the
 	<literal>DAEMON</literal> pseudo-service.  It also provides a
 	method for setting and tracking the process ID
 	(<acronym>PID</acronym>).</para>
 
       <para>This application could then have the following line placed
 	in <filename>/etc/rc.conf</filename>:</para>
 
       <programlisting>utility_enable="YES"</programlisting>
 
       <para>This method allows for easier manipulation of command
 	line arguments, inclusion of the default functions provided
 	in <filename>/etc/rc.subr</filename>, compatibility with
 	&man.rcorder.8;, and provides for easier configuration via
 	<filename>rc.conf</filename>.</para>
     </sect2>
 
     <sect2>
       <title>Using Services to Start Services</title>
 
       <para>Other services can be started using &man.inetd.8;.
 	Working with &man.inetd.8; and its configuration is
 	described in depth in
 	<xref linkend="network-inetd"/>.</para>
 
       <para>In some cases, it may make more sense to use
 	&man.cron.8; to start system services.  This approach
 	has a number of advantages as &man.cron.8; runs these
 	processes as the owner of the &man.crontab.5;.  This allows
 	regular users to start and maintain their own
 	applications.</para>
 
       <para>The <literal>@reboot</literal> feature of &man.cron.8;,
 	may be used in place of the time specification.  This causes
 	the job to run when &man.cron.8; is started, normally during
 	system initialization.</para>
     </sect2>
   </sect1>
 
   <sect1 xml:id="configtuning-cron">
     <info>
       <title>Configuring &man.cron.8;</title>
 
       <authorgroup>
 	<author>
 	  <personname>
 	    <firstname>Tom</firstname>
 	    <surname>Rhodes</surname>
 	  </personname>
 	  <contrib>Contributed by </contrib>
 	</author>
       </authorgroup>
     </info>
 
     <indexterm>
       <primary>cron</primary>
       <secondary>configuration</secondary>
     </indexterm>
 
     <para>One of the most useful utilities in &os; is
       <application>cron</application>.  This utility runs in the
       background and regularly checks
       <filename>/etc/crontab</filename> for tasks to execute and
       searches <filename>/var/cron/tabs</filename> for custom crontab
       files.  These files are used to schedule tasks which
       <application>cron</application> runs at the specified times.
       Each entry in a crontab defines a task to run and is known as a
       <firstterm>cron job</firstterm>.</para>
 
     <para>Two different types of configuration files are used: the
       system crontab, which should not be modified, and user crontabs,
       which can be created and edited as needed.  The format used by
       these files is documented in &man.crontab.5;.  The format of the
       system crontab, <filename>/etc/crontab</filename> includes a
       <literal>who</literal> column which does not exist in user
       crontabs.  In the system crontab,
       <application>cron</application> runs the command as the user
       specified in this column.  In a user crontab, all commands run
       as the user who created the crontab.</para>
 
     <para>User crontabs allow individual users to schedule their own
       tasks.  The <systemitem class="username">root</systemitem> user
       can also have a user <filename>crontab</filename> which can be
       used to schedule tasks that do not exist in the system
       <filename>crontab</filename>.</para>
 
     <para>Here is a sample entry from the system crontab,
       <filename>/etc/crontab</filename>:</para>
 
     <programlisting># /etc/crontab - root's crontab for FreeBSD
 #
 # <phrase its:translate="no">&dollar;FreeBSD&dollar;</phrase>
 # <co xml:id="co-comments"/>
 SHELL=/bin/sh
 PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin <co xml:id="co-env"/>
 #
 #minute	hour	mday	month	wday	who	command <co xml:id="co-field-descr"/>
 #
 */5	*	*	*	*	root	/usr/libexec/atrun <co xml:id="co-main"/></programlisting>
 
     <calloutlist>
       <callout arearefs="co-comments">
 	<para>Lines that begin with the <literal>#</literal> character
 	  are comments.  A comment can be placed in the file as a
 	  reminder of what and why a desired action is performed.
 	  Comments cannot be on the same line as a command or else
 	  they will be interpreted as part of the command; they must
 	  be on a new line.  Blank lines are ignored.</para>
       </callout>
 
       <callout arearefs="co-env">
 	<para>The equals (<literal>=</literal>) character is used to
 	  define any environment settings.  In this example, it is
 	  used to define the <envar>SHELL</envar> and
 	  <envar>PATH</envar>.  If the <envar>SHELL</envar> is
 	  omitted, <application>cron</application> will use the
 	  default Bourne shell.  If the <envar>PATH</envar> is
 	  omitted, the full path must be given to the command or
 	  script to run.</para>
       </callout>
 
       <callout arearefs="co-field-descr">
 	<para>This line defines the seven fields used in a system
 	  crontab: <literal>minute</literal>, <literal>hour</literal>,
 	  <literal>mday</literal>, <literal>month</literal>,
 	  <literal>wday</literal>, <literal>who</literal>, and
 	  <literal>command</literal>.  The <literal>minute</literal>
 	  field is the time in minutes when the specified command will
 	  be run, the <literal>hour</literal> is the hour when the
 	  specified command will be run, the <literal>mday</literal>
 	  is the day of the month, <literal>month</literal> is the
 	  month, and <literal>wday</literal> is the day of the week.
 	  These fields must be numeric values, representing the
 	  twenty-four hour clock, or a <literal>*</literal>,
 	  representing all values for that field.  The
 	  <literal>who</literal> field only exists in the system
 	  crontab and specifies which user the command should be run
 	  as.  The last field is the command to be executed.</para>
       </callout>
 
       <callout arearefs="co-main">
 	<para>This entry defines the values for this cron job.  The
 	  <literal>*/5</literal>, followed by several more
 	  <literal>*</literal> characters, specifies that
 	  <command>/usr/libexec/atrun</command> is invoked by
 	  <systemitem class="username">root</systemitem> every five
 	  minutes of every hour, of every day and day of the week, of
 	  every month.</para>
 
 	<para>Commands can include any number of switches.  However,
 	  commands which extend to multiple lines need to be broken
 	  with the backslash <quote>\</quote> continuation
 	  character.</para>
       </callout>
     </calloutlist>
 
     <sect2 xml:id="configtuning-installcrontab">
       <title>Creating a User Crontab</title>
 
       <para>To create a user crontab, invoke
 	<command>crontab</command> in editor mode:</para>
 
       <screen>&prompt.user; <userinput>crontab -e</userinput></screen>
 
       <para>This will open the user's crontab using the default text
 	editor.  The first time a user runs this command, it will open
 	an empty file.  Once a user creates a crontab, this command
 	will open that file for editing.</para>
 
       <para>It is useful to add these lines to the top of the crontab
 	file in order to set the environment variables and to remember
 	the meanings of the fields in the crontab:</para>
 
       <programlisting>SHELL=/bin/sh
 PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
 # Order of crontab fields
 # minute	hour	mday	month	wday	command</programlisting>
 
       <para>Then add a line for each command or script to run,
 	specifying the time to run the command.  This example runs the
 	specified custom Bourne shell script every day at two in the
 	afternoon.  Since the path to the script is not specified in
 	<literal>PATH</literal>, the full path to the script is
 	given:</para>
 
       <programlisting>0	14	*	*	*	/usr/home/dru/bin/mycustomscript.sh</programlisting>
 
       <tip>
 	<para>Before using a custom script, make sure it is executable
 	  and test it with the limited set of environment variables
 	  set by cron.  To replicate the environment that would be
 	  used to run the above cron entry, use:</para>
 
 	<programlisting>env -i SHELL=/bin/sh PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin HOME=/home/<replaceable>dru</replaceable> LOGNAME=<replaceable>dru</replaceable> <replaceable>/usr/home/dru/bin/mycustomscript.sh</replaceable></programlisting>
 
 	<para>The environment set by cron is discussed in
 	  &man.crontab.5;.  Checking that scripts operate correctly in
 	  a cron environment is especially important if they include
 	  any commands that delete files using wildcards.</para>
       </tip>
 
       <para>When finished editing the crontab, save the file.  It
 	will automatically be installed and
 	<application>cron</application> will read the crontab and run
 	its cron jobs at their specified times.  To list the cron jobs
 	in a crontab, use this command:</para>
 
       <screen>&prompt.user; <userinput>crontab -l</userinput>
 0	14	*	*	*	/usr/home/dru/bin/mycustomscript.sh</screen>
 
       <para>To remove all of the cron jobs in a user crontab:</para>
 
       <screen>&prompt.user; <userinput>crontab -r</userinput>
 remove crontab for dru? <userinput>y</userinput></screen>
     </sect2>
   </sect1>
 
   <sect1 xml:id="configtuning-rcd">
     <info>
       <title>Managing Services in &os;</title>
 
       <authorgroup>
 	<author>
 	  <personname>
 	    <firstname>Tom</firstname>
 	    <surname>Rhodes</surname>
 	  </personname>
 	  <contrib>Contributed by </contrib>
 	</author>
       </authorgroup>
     </info>
 
     <para>&os; uses the &man.rc.8; system of startup scripts during
       system initialization and for managing services.  The scripts
       listed in <filename>/etc/rc.d</filename> provide basic services
       which can be controlled with the <option>start</option>,
       <option>stop</option>, and <option>restart</option> options to
       &man.service.8;.  For instance, &man.sshd.8; can be restarted
       with the following command:</para>
 
     <screen>&prompt.root; <userinput>service sshd restart</userinput></screen>
 
     <para>This procedure can be used to start services on a running
       system.  Services will be started automatically at boot time
       as specified in &man.rc.conf.5;.  For example, to enable
       &man.natd.8; at system startup, add the following line to
       <filename>/etc/rc.conf</filename>:</para>
 
     <programlisting>natd_enable="YES"</programlisting>
 
     <para>If a <option>natd_enable="NO"</option> line is already
       present, change the <literal>NO</literal> to
       <literal>YES</literal>.  The &man.rc.8; scripts will
       automatically load any dependent services during the next boot,
       as described below.</para>
 
     <para>Since the &man.rc.8; system is primarily intended to start
       and stop services at system startup and shutdown time, the
       <option>start</option>, <option>stop</option> and
       <option>restart</option> options will only perform their action
       if the appropriate <filename>/etc/rc.conf</filename> variable
       is set.  For instance, <command>sshd restart</command> will
       only work if <varname>sshd_enable</varname> is set to
       <option>YES</option> in <filename>/etc/rc.conf</filename>.
       To <option>start</option>, <option>stop</option> or
       <option>restart</option> a service regardless of the settings
       in <filename>/etc/rc.conf</filename>, these commands should be
       prefixed with <quote>one</quote>.  For instance, to restart
       &man.sshd.8; regardless of the current
       <filename>/etc/rc.conf</filename> setting, execute the following
       command:</para>
 
     <screen>&prompt.root; <userinput>service sshd onerestart</userinput></screen>
 
     <para>To check if a service is enabled in
       <filename>/etc/rc.conf</filename>, run the appropriate
       &man.rc.8; script with <option>rcvar</option>.  This example
       checks to see if &man.sshd.8; is enabled in
       <filename>/etc/rc.conf</filename>:</para>
 
     <screen>&prompt.root; <userinput>service sshd rcvar</userinput>
 # sshd
 #
 sshd_enable="YES"
 #   (default: "")</screen>
 
     <note>
       <para>The <literal># sshd</literal> line is output from the
 	above command, not a
 	<systemitem class="username">root</systemitem> console.</para>
     </note>
 
     <para>To determine whether or not a service is running, use
       <option>status</option>.  For instance, to verify that
       &man.sshd.8; is running:</para>
 
     <screen>&prompt.root; <userinput>service sshd status</userinput>
 sshd is running as pid 433.</screen>
 
     <para>In some cases, it is also possible to
       <option>reload</option> a service.  This attempts to send a
       signal to an individual service, forcing the service to reload
       its configuration files.  In most cases, this means sending
       the service a <literal>SIGHUP</literal> signal.  Support for
       this feature is not included for every service.</para>
 
     <para>The &man.rc.8; system is used for network services and it
       also contributes to most of the system initialization.  For
       instance, when the
       <filename>/etc/rc.d/bgfsck</filename> script is executed, it
       prints out the following message:</para>
 
     <screen>Starting background file system checks in 60 seconds.</screen>
 
     <para>This script is used for background file system checks,
       which occur only during system initialization.</para>
 
     <para>Many system services depend on other services to function
       properly.  For example, &man.yp.8; and other
       <acronym>RPC</acronym>-based services may fail to start until
       after the &man.rpcbind.8; service has started.  To resolve this
       issue, information about dependencies and other meta-data is
       included in the comments at the top of each startup script.
       The &man.rcorder.8; program is used to parse these comments
       during system initialization to determine the order in which
       system services should be invoked to satisfy the
       dependencies.</para>
 
     <para>The following key word must be included in all startup
       scripts as it is required by &man.rc.subr.8; to
       <quote>enable</quote> the startup script:</para>
 
     <itemizedlist>
       <listitem>
 	<para><literal>PROVIDE</literal>: Specifies the services this
 	  file provides.</para>
       </listitem>
     </itemizedlist>
 
     <para>The following key words may be included at the top of each
       startup script.  They are not strictly necessary, but are
       useful as hints to &man.rcorder.8;:</para>
 
     <itemizedlist>
       <listitem>
 	<para><literal>REQUIRE</literal>: Lists services which are
 	  required for this service.  The script containing this key
 	  word will run <emphasis>after</emphasis> the specified
 	  services.</para>
       </listitem>
 
       <listitem>
 	<para><literal>BEFORE</literal>: Lists services which depend
 	  on this service.  The script containing this key word will
 	  run <emphasis>before</emphasis> the specified
 	  services.</para>
       </listitem>
     </itemizedlist>
 
     <para>By carefully setting these keywords for each startup script,
       an administrator has a fine-grained level of control of the
       startup order of the scripts, without the need for
       <quote>runlevels</quote> used by some &unix; operating
       systems.</para>
 
     <para>Additional information can be found in &man.rc.8; and
       &man.rc.subr.8;.  Refer to <link
 	xlink:href="&url.articles.rc-scripting;">this article</link>
       for instructions on how to create custom &man.rc.8;
       scripts.</para>
 
     <sect2 xml:id="configtuning-core-configuration">
       <title>Managing System-Specific Configuration</title>
 
       <indexterm>
 	<primary>rc files</primary>
 	<secondary><filename>rc.conf</filename></secondary>
       </indexterm>
 
       <para>The principal location for system configuration
 	information is <filename>/etc/rc.conf</filename>.  This file
 	contains a wide range of configuration information and it is
 	read at system startup to configure the system.  It provides
 	the configuration information for the
 	<filename>rc*</filename> files.</para>
 
       <para>The entries in <filename>/etc/rc.conf</filename> override
 	the default settings in
 	<filename>/etc/defaults/rc.conf</filename>.  The file
 	containing the default settings should not be edited.
 	Instead, all system-specific changes should be made to
 	<filename>/etc/rc.conf</filename>.</para>
 
       <para>A number of strategies may be applied in clustered
 	applications to separate site-wide configuration from
 	system-specific configuration in order to reduce
 	administration overhead.  The recommended approach is to place
 	system-specific configuration into
 	<filename>/etc/rc.conf.local</filename>.  For example, these
 	entries in <filename>/etc/rc.conf</filename> apply to all
 	systems:</para>
 
       <programlisting>sshd_enable="YES"
 keyrate="fast"
 defaultrouter="10.1.1.254"</programlisting>
 
       <para>Whereas these entries in
 	<filename>/etc/rc.conf.local</filename> apply to this system
 	only:</para>
 
       <programlisting>hostname="node1.example.org"
 ifconfig_fxp0="inet 10.1.1.1/8"</programlisting>
 
       <para>Distribute <filename>/etc/rc.conf</filename> to every
 	system using an application such as
 	<application>rsync</application> or
 	<application>puppet</application>, while
 	<filename>/etc/rc.conf.local</filename> remains
 	unique.</para>
 
       <para>Upgrading the system will not overwrite
 	<filename>/etc/rc.conf</filename>, so system configuration
 	information will not be lost.</para>
 
       <tip>
 	<para>Both <filename>/etc/rc.conf</filename> and
 	  <filename>/etc/rc.conf.local</filename>
 	  are parsed by &man.sh.1;.  This allows system operators to
 	  create complex configuration scenarios.  Refer to
 	  &man.rc.conf.5; for further information on this
 	  topic.</para>
       </tip>
     </sect2>
   </sect1>
 
   <sect1 xml:id="config-network-setup">
     <info>
       <title>Setting Up Network Interface Cards</title>
 
       <authorgroup>
 	<author>
 	  <personname>
 	    <firstname>Marc</firstname>
 	    <surname>Fonvieille</surname>
 	  </personname>
 	  <contrib>Contributed by </contrib>
 	</author>
       </authorgroup>
     </info>
 
     <indexterm>
       <primary>network cards</primary>
       <secondary>configuration</secondary>
     </indexterm>
 
     <para>Adding and configuring a network interface card
       (<acronym>NIC</acronym>)  is a common task for any &os;
       administrator.</para>
 
     <sect2>
       <title>Locating the Correct Driver</title>
 
       <indexterm>
 	<primary>network cards</primary>
 	<secondary>driver</secondary>
       </indexterm>
 
       <para>First, determine the model of the <acronym>NIC</acronym>
 	and the chip it uses.  &os; supports a wide variety of
 	<acronym>NIC</acronym>s.  Check the Hardware Compatibility
 	List for the &os; release to see if the <acronym>NIC</acronym>
 	is supported.</para>
 
       <para>If the <acronym>NIC</acronym> is supported, determine
 	the name of the &os; driver for the <acronym>NIC</acronym>.
 	Refer to <filename>/usr/src/sys/conf/NOTES</filename> and
 	<filename>/usr/src/sys/<replaceable>arch</replaceable>/conf/NOTES</filename>
 	for the list of <acronym>NIC</acronym> drivers with some
 	information about the supported chipsets.  When in doubt, read
 	the manual page of the driver as it will provide more
 	information about the supported hardware and any known
 	limitations of the driver.</para>
 
       <para>The drivers for common <acronym>NIC</acronym>s are already
 	present in the <filename>GENERIC</filename> kernel, meaning
 	the <acronym>NIC</acronym> should be probed during boot.  The
 	system's boot messages can be viewed by typing
 	<command>more /var/run/dmesg.boot</command> and using the
 	spacebar to scroll through the text.  In this example, two
 	Ethernet <acronym>NIC</acronym>s using the &man.dc.4; driver
 	are present on the system:</para>
 
       <screen>dc0: &lt;82c169 PNIC 10/100BaseTX&gt; port 0xa000-0xa0ff mem 0xd3800000-0xd38
 000ff irq 15 at device 11.0 on pci0
 miibus0: &lt;MII bus&gt; on dc0
 bmtphy0: &lt;BCM5201 10/100baseTX PHY&gt; PHY 1 on miibus0
 bmtphy0:  10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
 dc0: Ethernet address: 00:a0:cc:da:da:da
 dc0: [ITHREAD]
 dc1: &lt;82c169 PNIC 10/100BaseTX&gt; port 0x9800-0x98ff mem 0xd3000000-0xd30
 000ff irq 11 at device 12.0 on pci0
 miibus1: &lt;MII bus&gt; on dc1
 bmtphy1: &lt;BCM5201 10/100baseTX PHY&gt; PHY 1 on miibus1
 bmtphy1:  10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
 dc1: Ethernet address: 00:a0:cc:da:da:db
 dc1: [ITHREAD]</screen>
 
       <para>If the driver for the <acronym>NIC</acronym> is not
 	present in <filename>GENERIC</filename>, but a driver is
 	available, the driver will need to be loaded before the
 	<acronym>NIC</acronym> can be configured and used.  This may
 	be accomplished in one of two ways:</para>
 
       <itemizedlist>
 	<listitem>
 	  <para>The easiest way is to load a kernel module for the
 	    <acronym>NIC</acronym> using &man.kldload.8;.  To also
 	    automatically load the driver at boot time, add the
 	    appropriate line to
 	    <filename>/boot/loader.conf</filename>.  Not all
 	    <acronym>NIC</acronym> drivers are available as
 	    modules.</para>
 	</listitem>
 
 	<listitem>
 	  <para>Alternatively, statically compile support for the
 	    <acronym>NIC</acronym> into a custom kernel.  Refer to
 	    <filename>/usr/src/sys/conf/NOTES</filename>,
 	    <filename>/usr/src/sys/<replaceable>arch</replaceable>/conf/NOTES</filename>
 	    and the manual page of the driver to determine which line
 	    to add to the custom kernel configuration file.  For more
 	    information about recompiling the kernel, refer to <xref
 	      linkend="kernelconfig"/>.  If the <acronym>NIC</acronym>
 	    was detected at boot, the kernel does not need to be
 	    recompiled.</para>
 	</listitem>
       </itemizedlist>
 
       <sect3 xml:id="config-network-ndis">
 	<title>Using &windows; <acronym>NDIS</acronym> Drivers</title>
 
 	<indexterm>
 	  <primary><acronym>NDIS</acronym></primary>
 	</indexterm>
 	<indexterm>
 	  <primary>NDISulator</primary>
 	</indexterm>
 	<indexterm>
 	  <primary>&windows; drivers</primary>
 	</indexterm>
 	<indexterm>
 	  <primary>&microsoft.windows;</primary>
 	  <secondary>device drivers</secondary>
 	</indexterm>
 	<indexterm>
 	  <primary><acronym>KLD</acronym> (kernel loadable
 	    object)</primary>
 	</indexterm>
 <!-- We should probably omit the expanded name, and add a <see> entry
 for it.  Whatever is done must also be done to the same indexterm in
 linuxemu/chapter.xml -->
 
 	<para>Unfortunately, there are still many vendors that do not
 	  provide schematics for their drivers to the open source
 	  community because they regard such information as trade
 	  secrets.  Consequently, the developers of &os; and other
 	  operating systems are left with two choices: develop the
 	  drivers by a long and pain-staking process of reverse
 	  engineering or using the existing driver binaries available
 	  for &microsoft.windows; platforms.</para>
 
 	<para>&os; provides <quote>native</quote> support for the
 	  Network Driver Interface Specification
 	  (<acronym>NDIS</acronym>).  It includes &man.ndisgen.8;
 	  which can be used to convert a &windowsxp; driver into a
 	  format that can be used on &os;.  Because the &man.ndis.4;
 	  driver uses a &windowsxp; binary, it only runs on &i386;
 	  and amd64 systems.  <acronym>PCI</acronym>, CardBus,
 	  <acronym>PCMCIA</acronym>, and <acronym>USB</acronym>
 	  devices are supported.</para>
 
 	<para>To use &man.ndisgen.8;, three things are needed:</para>
 
 	<orderedlist>
 	  <listitem>
 	    <para>&os; kernel sources.</para>
 	  </listitem>
 
 	  <listitem>
 	    <para>A &windowsxp; driver binary with a
 	      <filename>.SYS</filename> extension.</para>
 	  </listitem>
 
 	  <listitem>
 	    <para>A &windowsxp; driver configuration file with a
 	      <filename>.INF</filename> extension.</para>
 	  </listitem>
 	</orderedlist>
 
 	<para>Download the <filename>.SYS</filename> and
 	  <filename>.INF</filename> files for the specific
 	  <acronym>NIC</acronym>.  Generally, these can be found on
 	  the driver CD or at the vendor's website.  The following
 	  examples use <filename>W32DRIVER.SYS</filename> and
 	  <filename>W32DRIVER.INF</filename>.</para>
 
 	<para>The driver bit width must match the version of &os;.
 	  For &os;/i386, use a &windows; 32-bit driver.  For
 	  &os;/amd64, a &windows; 64-bit driver is needed.</para>
 
 	<para>The next step is to compile the driver binary into a
 	  loadable kernel module.  As
 	  <systemitem class="username">root</systemitem>, use
 	  &man.ndisgen.8;:</para>
 
 	<screen>&prompt.root; <userinput>ndisgen <replaceable>/path/to/W32DRIVER.INF</replaceable> <replaceable>/path/to/W32DRIVER.SYS</replaceable></userinput></screen>
 
 	<para>This command is interactive and prompts for any extra
 	  information it requires.  A new kernel module will be
 	  generated in the current directory.  Use &man.kldload.8;
 	  to load the new module:</para>
 
 	<screen>&prompt.root; <userinput>kldload <replaceable>./W32DRIVER_SYS.ko</replaceable></userinput></screen>
 
 	<para>In addition to the generated kernel module, the
 	  <filename>ndis.ko</filename> and
 	  <filename>if_ndis.ko</filename> modules must be loaded.
 	  This should happen automatically when any module that
 	  depends on &man.ndis.4; is loaded.  If not, load them
 	  manually, using the following commands:</para>
 
 	<screen>&prompt.root; <userinput>kldload ndis</userinput>
 &prompt.root; <userinput>kldload if_ndis</userinput></screen>
 
 	<para>The first command loads the &man.ndis.4; miniport driver
 	  wrapper and the second loads the generated
 	  <acronym>NIC</acronym> driver.</para>
 
 	<para>Check &man.dmesg.8; to see if there were any load
 	  errors.  If all went well, the output should be similar to
 	  the following:</para>
 
 	<screen>ndis0: &lt;Wireless-G PCI Adapter&gt; mem 0xf4100000-0xf4101fff irq 3 at device 8.0 on pci1
 ndis0: NDIS API version: 5.0
 ndis0: Ethernet address: 0a:b1:2c:d3:4e:f5
 ndis0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
 ndis0: 11g rates: 6Mbps 9Mbps 12Mbps 18Mbps 36Mbps 48Mbps 54Mbps</screen>
 
 	<para>From here, <filename>ndis0</filename> can be
 	  configured like any other <acronym>NIC</acronym>.</para>
 
 	<para>To configure the system to load the &man.ndis.4; modules
 	  at boot time, copy the generated module,
 	  <filename>W32DRIVER_SYS.ko</filename>, to
 	  <filename>/boot/modules</filename>.  Then, add the following
 	  line to <filename>/boot/loader.conf</filename>:</para>
 
 	<programlisting>W32DRIVER_SYS_load="YES"</programlisting>
       </sect3>
     </sect2>
 
     <sect2>
       <title>Configuring the Network Card</title>
 
       <indexterm>
 	<primary>network cards</primary>
 	<secondary>configuration</secondary>
       </indexterm>
 
       <para>Once the right driver is loaded for the
 	<acronym>NIC</acronym>, the card needs to be configured.  It
 	may have been configured at installation time by
 	&man.bsdinstall.8;.</para>
 
       <para>To display the <acronym>NIC</acronym> configuration,
 	enter the following command:</para>
 
       <screen>&prompt.user; <userinput>ifconfig</userinput>
 dc0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
         options=80008&lt;VLAN_MTU,LINKSTATE&gt;
         ether 00:a0:cc:da:da:da
         inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255
         media: Ethernet autoselect (100baseTX &lt;full-duplex&gt;)
         status: active
 dc1: flags=8802&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
         options=80008&lt;VLAN_MTU,LINKSTATE&gt;
         ether 00:a0:cc:da:da:db
         inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
         media: Ethernet 10baseT/UTP
         status: no carrier
 lo0: flags=8049&lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; metric 0 mtu 16384
         options=3&lt;RXCSUM,TXCSUM&gt;
         inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
         inet6 ::1 prefixlen 128
         inet 127.0.0.1 netmask 0xff000000
         nd6 options=3&lt;PERFORMNUD,ACCEPT_RTADV&gt;</screen>
 
       <para>In this example, the following devices were
 	displayed:</para>
 
       <itemizedlist>
 	<listitem>
 	  <para><filename>dc0</filename>: The first Ethernet
 	    interface.</para>
 	</listitem>
 
 	<listitem>
 	  <para><filename>dc1</filename>: The second Ethernet
 	    interface.</para>
 	</listitem>
 
 	<listitem>
 	  <para><filename>lo0</filename>: The loopback
 	    device.</para>
 	</listitem>
       </itemizedlist>
 
       <para>&os; uses the driver name followed by the order in which
 	the card is detected at boot to name the
 	<acronym>NIC</acronym>.  For example,
 	<filename>sis2</filename> is the third
 	<acronym>NIC</acronym> on the system using the &man.sis.4;
 	driver.</para>
 
       <para>In this example, <filename>dc0</filename> is up and
 	running.  The key indicators are:</para>
 
       <orderedlist>
 	<listitem>
 	  <para><literal>UP</literal> means that the card is
 	    configured and ready.</para>
 	</listitem>
 
 	<listitem>
 	  <para>The card has an Internet (<literal>inet</literal>)
 	    address, <systemitem
 	      class="ipaddress">192.168.1.3</systemitem>.</para>
 	</listitem>
 
 	<listitem>
 	  <para>It has a valid subnet mask
 	    (<literal>netmask</literal>), where
 	    <systemitem class="netmask">0xffffff00</systemitem> is the
 	    same as <systemitem
 	      class="netmask">255.255.255.0</systemitem>.</para>
 	</listitem>
 
 	<listitem>
 	  <para>It has a valid broadcast address, <systemitem
 	      class="ipaddress">192.168.1.255</systemitem>.</para>
 	</listitem>
 
 	<listitem>
 	  <para>The <acronym>MAC</acronym> address of the card
 	    (<literal>ether</literal>) is <systemitem
 	      class="etheraddress">00:a0:cc:da:da:da</systemitem>.</para>
 	</listitem>
 
 	<listitem>
 	  <para>The physical media selection is on autoselection mode
 	    (<literal>media: Ethernet autoselect (100baseTX
 	      &lt;full-duplex&gt;)</literal>).  In this example,
 	    <filename>dc1</filename> is configured to run with
 	    <literal>10baseT/UTP</literal> media.  For more
 	    information on available media types for a driver, refer
 	    to its manual page.</para>
 	</listitem>
 
 	<listitem>
 	  <para>The status of the link (<literal>status</literal>) is
 	    <literal>active</literal>, indicating that the carrier
 	    signal is detected.  For <filename>dc1</filename>, the
 	    <literal>status: no carrier</literal> status is normal
 	    when an Ethernet cable is not plugged into the
 	    card.</para>
 	</listitem>
       </orderedlist>
 
       <para>If the &man.ifconfig.8; output had shown something similar
 	to:</para>
 
       <screen>dc0: flags=8843&lt;BROADCAST,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
 	options=80008&lt;VLAN_MTU,LINKSTATE&gt;
 	ether 00:a0:cc:da:da:da
 	media: Ethernet autoselect (100baseTX &lt;full-duplex&gt;)
 	status: active</screen>
 
       <para>it would indicate the card has not been configured.</para>
 
       <para>The card must be configured as
 	<systemitem class="username">root</systemitem>.  The
 	<acronym>NIC</acronym> configuration can be performed from the
 	command line with &man.ifconfig.8; but will not persist after
 	a reboot unless the configuration is also added to
 	<filename>/etc/rc.conf</filename>.  If a
 	<acronym>DHCP</acronym> server is present on the LAN,
 	just add this line:</para>
 
       <programlisting>ifconfig_dc0="DHCP"</programlisting>
 
       <para>Replace <replaceable>dc0</replaceable> with the correct
 	value for the system.</para>
 
       <para>The line added, then, follow the instructions given in
 	<xref linkend="config-network-testing"/>.</para>
 
       <note>
 	<para>If the network was configured during installation, some
 	  entries for the <acronym>NIC</acronym>(s) may be already
 	  present.  Double check <filename>/etc/rc.conf</filename>
 	  before adding any lines.</para>
       </note>
 
-      <para>In the case, there is no <acronym>DHCP</acronym> server,
-	the <acronym>NIC</acronym>(s) have to be configured manually.
+      <para>If there is no <acronym>DHCP</acronym> server,
+	the <acronym>NIC</acronym>(s) must be configured manually.
 	Add a line for each <acronym>NIC</acronym> present on the
 	system, as seen in this example:</para>
 
       <programlisting>ifconfig_dc0="inet 192.168.1.3 netmask 255.255.255.0"
 ifconfig_dc1="inet 10.0.0.1 netmask 255.255.255.0 media 10baseT/UTP"</programlisting>
 
       <para>Replace <filename>dc0</filename> and
 	<filename>dc1</filename> and the <acronym>IP</acronym>
 	address information with the correct values for the system.
 	Refer to the man page for the driver, &man.ifconfig.8;, and
 	&man.rc.conf.5; for more details about the allowed options and
 	the syntax of <filename>/etc/rc.conf</filename>.</para>
 
       <para>If the network is not using <acronym>DNS</acronym>, edit
 	<filename>/etc/hosts</filename> to add the names and
 	<acronym>IP</acronym> addresses of the hosts on the
 	<acronym>LAN</acronym>, if they are not already there.  For
 	more information, refer to &man.hosts.5; and to
 	<filename>/usr/share/examples/etc/hosts</filename>.</para>
 
       <note>
 	<para>If there is no <acronym>DHCP</acronym> server and
 	  access to the Internet is needed, manually configure the
 	  default gateway and the nameserver:</para>
 
 	<screen>&prompt.root; <userinput>echo 'defaultrouter="<replaceable>your_default_router</replaceable>"' &gt;&gt; /etc/rc.conf</userinput>
 &prompt.root; <userinput>echo 'nameserver <replaceable>your_DNS_server</replaceable>' &gt;&gt; /etc/resolv.conf</userinput></screen>
       </note>
     </sect2>
 
     <sect2 xml:id="config-network-testing">
       <title>Testing and Troubleshooting</title>
 
       <para>Once the necessary changes to
 	<filename>/etc/rc.conf</filename> are saved, a reboot can be
 	used to test the network configuration and to verify that the
 	system restarts without any configuration errors.
 	Alternatively, apply the settings to the networking system
 	with this command:</para>
 
       <screen>&prompt.root; <userinput>service netif restart</userinput></screen>
 
       <note>
 	<para>If a default gateway has been set in
 	  <filename>/etc/rc.conf</filename>, also issue this
 	  command:</para>
 
 	<screen>&prompt.root; <userinput>service routing restart</userinput></screen>
       </note>
 
       <para>Once the networking system has been relaunched, test the
 	<acronym>NIC</acronym>s.</para>
 
       <sect3>
 	<title>Testing the Ethernet Card</title>
 
 	<indexterm>
 	  <primary>network cards</primary>
 	  <secondary>testing</secondary>
 	</indexterm>
 
 	<para>To verify that an Ethernet card is configured correctly,
 	  &man.ping.8; the interface itself, and then &man.ping.8;
 	  another machine on the <acronym>LAN</acronym>:</para>
 
 	<screen>&prompt.user; <userinput>ping -c5 192.168.1.3</userinput>
 PING 192.168.1.3 (192.168.1.3): 56 data bytes
 64 bytes from 192.168.1.3: icmp_seq=0 ttl=64 time=0.082 ms
 64 bytes from 192.168.1.3: icmp_seq=1 ttl=64 time=0.074 ms
 64 bytes from 192.168.1.3: icmp_seq=2 ttl=64 time=0.076 ms
 64 bytes from 192.168.1.3: icmp_seq=3 ttl=64 time=0.108 ms
 64 bytes from 192.168.1.3: icmp_seq=4 ttl=64 time=0.076 ms
 
 --- 192.168.1.3 ping statistics ---
 5 packets transmitted, 5 packets received, 0% packet loss
 round-trip min/avg/max/stddev = 0.074/0.083/0.108/0.013 ms</screen>
 
 	<screen>&prompt.user; <userinput>ping -c5 192.168.1.2</userinput>
 PING 192.168.1.2 (192.168.1.2): 56 data bytes
 64 bytes from 192.168.1.2: icmp_seq=0 ttl=64 time=0.726 ms
 64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=0.766 ms
 64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=0.700 ms
 64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.747 ms
 64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=0.704 ms
 
 --- 192.168.1.2 ping statistics ---
 5 packets transmitted, 5 packets received, 0% packet loss
 round-trip min/avg/max/stddev = 0.700/0.729/0.766/0.025 ms</screen>
 
 	<para>To test network resolution, use the host name instead
 	  of the <acronym>IP</acronym> address.  If there is no
 	  <acronym>DNS</acronym> server on the network,
 	  <filename>/etc/hosts</filename> must first be
 	  configured.  To this purpose, edit
 	  <filename>/etc/hosts</filename> to add the names and
 	  <acronym>IP</acronym> addresses of the hosts on the
 	  <acronym>LAN</acronym>, if they are not already there.  For
 	  more information, refer to &man.hosts.5; and to
 	  <filename>/usr/share/examples/etc/hosts</filename>.</para>
       </sect3>
 
       <sect3>
 	<title>Troubleshooting</title>
 
 	<indexterm>
 	  <primary>network cards</primary>
 	  <secondary>troubleshooting</secondary>
 	</indexterm>
 
 	<para>When troubleshooting hardware and software
 	  configurations, check the simple things first.  Is the
 	  network cable plugged in?  Are the network services properly
 	  configured?  Is the firewall configured correctly?  Is the
 	  <acronym>NIC</acronym> supported by &os;?  Before sending
 	  a bug report, always check the Hardware Notes, update the
 	  version of &os; to the latest STABLE version, check the
 	  mailing list archives, and search the Internet.</para>
 
 	<para>If the card works, yet performance is poor, read
 	  through &man.tuning.7;.  Also, check the network
 	  configuration as incorrect network settings can cause slow
 	  connections.</para>
 
 	<para>Some users experience one or two
 	  <errorname>device timeout</errorname> messages, which is
 	  normal for some cards.  If they continue, or are bothersome,
 	  determine if the device is conflicting with another device.
 	  Double check the cable connections.  Consider trying another
 	  card.</para>
 
 	<para>To resolve <errorname>watchdog timeout</errorname>
 	  errors,  first check the network cable.  Many cards
 	  require a <acronym>PCI</acronym> slot which supports bus
 	  mastering.  On some old motherboards, only one
 	  <acronym>PCI</acronym> slot allows it, usually slot 0.
 	  Check the <acronym>NIC</acronym> and the motherboard
 	  documentation to determine if that may be the
 	  problem.</para>
 
 	<para><errorname>No route to host</errorname> messages occur
 	  if the system is unable to route a packet to the destination
 	  host.  This can happen if no default route is specified or
 	  if a cable is unplugged.  Check the output of
 	  <command>netstat -rn</command> and make sure there is a
 	  valid route to the host.  If there is not, read
 	  <xref linkend="network-routing"/>.</para>
 
 	<para><errorname>ping: sendto: Permission denied</errorname>
 	  error messages are often caused by a misconfigured firewall.
 	  If a firewall is enabled on &os; but no rules have been
 	  defined, the default policy is to deny all traffic, even
 	  &man.ping.8;.  Refer to
 	  <xref linkend="firewalls"/> for more information.</para>
 
 	<para>Sometimes performance of the card is poor or below
 	  average.  In these cases, try setting the media
 	  selection mode from <literal>autoselect</literal> to the
 	  correct media selection.  While this works for most
 	  hardware, it may or may not resolve the issue.  Again,
 	  check all the network settings, and refer to
 	  &man.tuning.7;.</para>
       </sect3>
     </sect2>
   </sect1>
 
   <sect1 xml:id="configtuning-virtual-hosts">
     <title>Virtual Hosts</title>
 
     <indexterm><primary>virtual hosts</primary></indexterm>
     <indexterm><primary><acronym>IP</acronym>
 	aliases</primary></indexterm>
 
     <para>A common use of &os; is virtual site hosting, where one
       server appears to the network as many servers.  This is achieved
       by assigning multiple network addresses to a single
       interface.</para>
 
     <para>A given network interface has one <quote>real</quote>
       address, and may have any number of <quote>alias</quote>
       addresses.  These aliases are normally added by placing alias
       entries in <filename>/etc/rc.conf</filename>, as seen in this
       example:</para>
 
     <programlisting>ifconfig_fxp0_alias0="inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"</programlisting>
 
     <para>Alias entries must start with
       <literal>alias<replaceable>0</replaceable></literal> using a
       sequential number such as
       <literal>alias0</literal>, <literal>alias1</literal>,
       and so on.  The configuration process will stop at the first
       missing number.</para>
 
     <para>The calculation of alias netmasks is important.  For a
       given interface, there must be one address which correctly
       represents the network's netmask.  Any other addresses which
       fall within this network must have a netmask of all
       <literal>1</literal>s, expressed as either
       <systemitem class="netmask">255.255.255.255</systemitem> or
       <systemitem class="netmask">0xffffffff</systemitem>.</para>
 
     <para>For example, consider the case where the
       <filename>fxp0</filename> interface is connected to two
       networks: <systemitem class="ipaddress">10.1.1.0</systemitem>
       with a netmask of
       <systemitem class="netmask">255.255.255.0</systemitem> and
       <systemitem class="ipaddress">202.0.75.16</systemitem> with a
       netmask of
       <systemitem class="netmask">255.255.255.240</systemitem>.  The
       system is to be configured to appear in the ranges
       <systemitem class="ipaddress">10.1.1.1</systemitem> through
       <systemitem class="ipaddress">10.1.1.5</systemitem> and
       <systemitem class="ipaddress">202.0.75.17</systemitem> through
       <systemitem class="ipaddress">202.0.75.20</systemitem>.  Only
       the first address in a given network range should have a real
       netmask.  All the rest
       (<systemitem class="ipaddress">10.1.1.2</systemitem> through
       <systemitem class="ipaddress">10.1.1.5</systemitem> and
       <systemitem class="ipaddress">202.0.75.18</systemitem> through
       <systemitem class="ipaddress">202.0.75.20</systemitem>) must be
       configured with a netmask of
       <systemitem class="netmask">255.255.255.255</systemitem>.</para>
 
     <para>The following <filename>/etc/rc.conf</filename> entries
       configure the adapter correctly for this scenario:</para>
 
     <programlisting>ifconfig_fxp0="inet 10.1.1.1 netmask 255.255.255.0"
 ifconfig_fxp0_alias0="inet 10.1.1.2 netmask 255.255.255.255"
 ifconfig_fxp0_alias1="inet 10.1.1.3 netmask 255.255.255.255"
 ifconfig_fxp0_alias2="inet 10.1.1.4 netmask 255.255.255.255"
 ifconfig_fxp0_alias3="inet 10.1.1.5 netmask 255.255.255.255"
 ifconfig_fxp0_alias4="inet 202.0.75.17 netmask 255.255.255.240"
 ifconfig_fxp0_alias5="inet 202.0.75.18 netmask 255.255.255.255"
 ifconfig_fxp0_alias6="inet 202.0.75.19 netmask 255.255.255.255"
 ifconfig_fxp0_alias7="inet 202.0.75.20 netmask 255.255.255.255"</programlisting>
 
     <para>A simpler way to express this is with a space-separated list
       of <acronym>IP</acronym> address ranges.  The first address
       will be given the
       indicated subnet mask and the additional addresses will have a
       subnet mask of <literal>255.255.255.255</literal>.</para>
 
     <programlisting>ifconfig_fxp0_aliases="inet 10.1.1.1-5/24 inet 202.0.75.17-20/28"</programlisting>
   </sect1>
 
   <sect1 xml:id="configtuning-syslog">
     <info>
       <title>Configuring System Logging</title>
 
       <authorgroup>
 	<author>
 	  <personname>
 	    <firstname>Niclas</firstname>
 	    <surname>Zeising</surname>
 	  </personname>
 	  <contrib>Contributed by </contrib>
 	</author>
       </authorgroup>
     </info>
 
     <indexterm>
       <primary>system logging</primary>
     </indexterm>
     <indexterm>
       <primary>syslog</primary>
     </indexterm>
     <indexterm>
       <primary>&man.syslogd.8;</primary>
     </indexterm>
 
     <para>Generating and reading system logs is an important aspect of
       system administration.  The information in system logs can be
       used to detect hardware and software issues as well as
       application and system configuration errors.  This information
       also plays an important role in security auditing and incident
       response.  Most system daemons and applications will generate
       log entries.</para>
 
     <para>&os; provides a system logger,
       <application>syslogd</application>, to manage logging.  By
       default, <application>syslogd</application> is started when the
       system boots.  This is controlled by the variable
       <literal>syslogd_enable</literal> in
       <filename>/etc/rc.conf</filename>.  There are numerous
       application arguments that can be set using
       <literal>syslogd_flags</literal> in
       <filename>/etc/rc.conf</filename>.  Refer to &man.syslogd.8; for
       more information on the available arguments.</para>
 
     <para>This section describes how to configure the &os; system
       logger for both local and remote logging and how to perform log
       rotation and log management.</para>
 
     <sect2>
       <title>Configuring Local Logging</title>
 
       <indexterm><primary>syslog.conf</primary></indexterm>
 
       <para>The configuration file,
 	<filename>/etc/syslog.conf</filename>, controls what
 	<application>syslogd</application> does with log entries as
 	they are received.  There are several parameters to control
 	the handling of incoming events.  The
 	<firstterm>facility</firstterm> describes which subsystem
 	generated the message, such as the kernel or a daemon, and the
 	<firstterm>level</firstterm> describes the severity of the
 	event that occurred.  This makes it possible to configure if
 	and where a log message is logged, depending on the facility
 	and level.  It is also possible to take action depending on
 	the application that sent the message, and in the case of
 	remote logging, the hostname of the machine generating the
 	logging event.</para>
 
       <para>This configuration file contains one line per action,
 	where the syntax for each line is a selector field followed by
 	an action field.  The syntax of the selector field is
 	<replaceable>facility.level</replaceable> which will match log
 	messages from <replaceable>facility</replaceable> at level
 	<replaceable>level</replaceable> or higher.  It is also
 	possible to add an optional comparison flag before the level
 	to specify more precisely what is logged.  Multiple selector
 	fields can be used for the same action, and are separated with
 	a semicolon (<literal>;</literal>).  Using
 	<literal>*</literal> will match everything.  The action field
 	denotes where to send the log message, such as to a file or
 	remote log host.  As an example, here is the default
 	<filename>syslog.conf</filename> from &os;:</para>
 
       <programlisting># <phrase its:translate="no">&dollar;&os;&dollar;</phrase>
 #
 #       Spaces ARE valid field separators in this file. However,
 #       other *nix-like systems still insist on using tabs as field
 #       separators. If you are sharing this file between systems, you
 #       may want to use only tabs as field separators here.
 #       Consult the syslog.conf(5) manpage.
 *.err;kern.warning;auth.notice;mail.crit                /dev/console
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages
 security.*                                      /var/log/security
 auth.info;authpriv.info                         /var/log/auth.log
 mail.info                                       /var/log/maillog
 lpr.info                                        /var/log/lpd-errs
 ftp.info                                        /var/log/xferlog
 cron.*                                          /var/log/cron
 !-devd
 *.=debug                                        /var/log/debug.log
 *.emerg                                         *
 # uncomment this to log all writes to /dev/console to /var/log/console.log
 #console.info                                   /var/log/console.log
 # uncomment this to enable logging of all log messages to /var/log/all.log
 # touch /var/log/all.log and chmod it to mode 600 before it will work
 #*.*                                            /var/log/all.log
 # uncomment this to enable logging to a remote loghost named loghost
 #*.*                                            @loghost
 # uncomment these if you're running inn
 # news.crit                                     /var/log/news/news.crit
 # news.err                                      /var/log/news/news.err
 # news.notice                                   /var/log/news/news.notice
 # Uncomment this if you wish to see messages produced by devd
 # !devd
 # *.>=info
 !ppp
 *.*                                             /var/log/ppp.log
 !*</programlisting>
 
       <para>In this example:</para>
 
       <itemizedlist>
 	<listitem>
 	  <para>Line 8 matches all messages with a level of
 	    <literal>err</literal> or higher, as well as
 	    <literal>kern.warning</literal>,
 	    <literal>auth.notice</literal> and
 	    <literal>mail.crit</literal>, and sends these log messages
 	    to the console
 	    (<filename>/dev/console</filename>).</para>
 	</listitem>
 
 	<listitem>
 	  <para>Line 12 matches all messages from the
 	    <literal>mail</literal> facility at level
 	    <literal>info</literal> or above and logs the messages to
 	    <filename>/var/log/maillog</filename>.</para>
 	</listitem>
 
 	<listitem>
 	  <para>Line 17 uses a comparison flag (<literal>=</literal>)
 	    to only match messages at level <literal>debug</literal>
 	    and logs them to
 	    <filename>/var/log/debug.log</filename>.</para>
 	</listitem>
 
 	<listitem>
 	  <para>Line 33 is an example usage of a program
 	    specification.  This makes the rules following it only
 	    valid for the specified program.  In this case, only the
 	    messages generated by <application>ppp</application> are
 	    logged to <filename>/var/log/ppp.log</filename>.</para>
 	</listitem>
       </itemizedlist>
 
       <para>The available levels, in order from most to least
 	critical are <literal>emerg</literal>,
 	<literal>alert</literal>, <literal>crit</literal>,
 	<literal>err</literal>, <literal>warning</literal>,
 	<literal>notice</literal>, <literal>info</literal>, and
 	<literal>debug</literal>.</para>
 
       <para>The facilities, in no particular order, are
 	<literal>auth</literal>, <literal>authpriv</literal>,
 	<literal>console</literal>, <literal>cron</literal>,
 	<literal>daemon</literal>, <literal>ftp</literal>,
 	<literal>kern</literal>, <literal>lpr</literal>,
 	<literal>mail</literal>, <literal>mark</literal>,
 	<literal>news</literal>, <literal>security</literal>,
 	<literal>syslog</literal>, <literal>user</literal>,
 	<literal>uucp</literal>, and <literal>local0</literal> through
 	<literal>local7</literal>.  Be aware that other operating
 	systems might have different facilities.</para>
 
       <para>To log everything of level <literal>notice</literal> and
 	higher to <filename>/var/log/daemon.log</filename>, add the
 	following entry:</para>
 
       <programlisting>daemon.notice                                        /var/log/daemon.log</programlisting>
 
       <para>For more information about the different levels and
 	facilities, refer to &man.syslog.3; and &man.syslogd.8;.
 	For more information about
 	<filename>/etc/syslog.conf</filename>, its syntax, and more
 	advanced usage examples, see &man.syslog.conf.5;.</para>
     </sect2>
 
     <sect2>
       <title>Log Management and Rotation</title>
 
       <indexterm><primary>newsyslog</primary></indexterm>
       <indexterm><primary>newsyslog.conf</primary></indexterm>
       <indexterm><primary>log rotation</primary></indexterm>
       <indexterm><primary>log management</primary></indexterm>
 
       <para>Log files can grow quickly, taking up disk space and
 	making it more difficult to locate useful information.  Log
 	management attempts to mitigate this.  In &os;,
 	<application>newsyslog</application> is used to manage log
 	files.  This built-in program periodically rotates and
 	compresses log files, and optionally creates missing log files
 	and signals programs when log files are moved.  The log files
 	may be generated by <application>syslogd</application> or by
 	any other program which generates log files.  While
 	<application>newsyslog</application> is normally run from
 	&man.cron.8;, it is not a system daemon.  In the default
 	configuration, it runs every hour.</para>
 
       <para>To know which actions to take,
 	<application>newsyslog</application> reads its configuration
 	file, <filename>/etc/newsyslog.conf</filename>.  This file
 	contains one line for each log file that
 	<application>newsyslog</application> manages.  Each line
 	states the file owner, permissions, when to rotate that file,
 	optional flags that affect log rotation, such as compression,
 	and programs to signal when the log is rotated.  Here is the
 	default configuration in &os;:</para>
 
       <programlisting># configuration file for newsyslog
 # <phrase its:translate="no">&dollar;FreeBSD&dollar;</phrase>
 #
 # Entries which do not specify the '/pid_file' field will cause the
 # syslogd process to be signalled when that log file is rotated.  This
 # action is only appropriate for log files which are written to by the
 # syslogd process (ie, files listed in /etc/syslog.conf).  If there
 # is no process which needs to be signalled when a given log file is
 # rotated, then the entry for that file should include the 'N' flag.
 #
 # The 'flags' field is one or more of the letters: BCDGJNUXZ or a '-'.
 #
 # Note: some sites will want to select more restrictive protections than the
 # defaults.  In particular, it may be desirable to switch many of the 644
 # entries to 640 or 600.  For example, some sites will consider the
 # contents of maillog, messages, and lpd-errs to be confidential.  In the
 # future, these defaults may change to more conservative ones.
 #
 # logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
 /var/log/all.log                        600  7     *    @T00  J
 /var/log/amd.log                        644  7     100  *     J
 /var/log/auth.log                       600  7     100  @0101T JC
 /var/log/console.log                    600  5     100  *     J
 /var/log/cron                           600  3     100  *     JC
 /var/log/daily.log                      640  7     *    @T00  JN
 /var/log/debug.log                      600  7     100  *     JC
 /var/log/kerberos.log                   600  7     100  *     J
 /var/log/lpd-errs                       644  7     100  *     JC
 /var/log/maillog                        640  7     *    @T00  JC
 /var/log/messages                       644  5     100  @0101T JC
 /var/log/monthly.log                    640  12    *    $M1D0 JN
 /var/log/pflog                          600  3     100  *     JB    /var/run/pflogd.pid
 /var/log/ppp.log        root:network    640  3     100  *     JC
 /var/log/devd.log                       644  3     100  *     JC
 /var/log/security                       600  10    100  *     JC
 /var/log/sendmail.st                    640  10    *    168   B
 /var/log/utx.log                        644  3     *    @01T05 B
 /var/log/weekly.log                     640  5     1    $W6D0 JN
 /var/log/xferlog                        600  7     100  *     JC</programlisting>
 
       <para>Each line starts with the name of the log to be rotated,
 	optionally followed by an owner and group for both rotated and
 	newly created files.  The <literal>mode</literal> field sets
 	the permissions on the log file and <literal>count</literal>
 	denotes how many rotated log files should be kept.  The
 	<literal>size</literal> and <literal>when</literal> fields
 	tell <application>newsyslog</application> when to rotate the
 	file.  A log file is rotated when either its size is larger
 	than the <literal>size</literal> field or when the time in the
 	<literal>when</literal> field has passed.  An asterisk
 	(<literal>*</literal>) means that this field is ignored.  The
 	<replaceable>flags</replaceable> field gives further
 	instructions, such as how to compress the rotated file or to
 	create the log file if it is missing.  The last two fields are
 	optional and specify the name of the Process ID
 	(<acronym>PID</acronym>) file of a process and a signal number
 	to send to that process when the file is rotated.</para>
 
       <para>For more information on all fields, valid flags, and how
 	to specify the rotation time, refer to &man.newsyslog.conf.5;.
 	Since <application>newsyslog</application> is run from
 	&man.cron.8;, it cannot rotate files more often than it is
 	scheduled to run from &man.cron.8;.</para>
     </sect2>
 
     <sect2 xml:id="network-syslogd">
       <info>
 	<title>Configuring Remote Logging</title>
 
 	<authorgroup>
 	  <author>
 	    <personname>
 	      <firstname>Tom</firstname>
 	      <surname>Rhodes</surname>
 	    </personname>
 	    <contrib>Contributed by </contrib>
 	  </author>
 	</authorgroup>
       </info>
 
       <para>Monitoring the log files of multiple hosts can become
 	unwieldy as the number of systems increases.  Configuring
 	centralized logging can reduce some of the administrative
 	burden of log file administration.</para>
 
       <para>In &os;, centralized log file aggregation, merging, and
 	rotation can be configured using
 	<application>syslogd</application> and
 	<application>newsyslog</application>.  This section
 	demonstrates an example configuration, where host
 	<systemitem>A</systemitem>, named <systemitem
 	  class="fqdomainname">logserv.example.com</systemitem>, will
 	collect logging information for the local network.  Host
 	<systemitem>B</systemitem>, named <systemitem
 	  class="fqdomainname">logclient.example.com</systemitem>,
 	will be configured to pass logging information to the logging
 	server.</para>
 
       <sect3>
 	<title>Log Server Configuration</title>
 
 	<para>A log server is a system that has been configured to
 	  accept logging information from other hosts.  Before
 	  configuring a log server, check the following:</para>
 
 	<itemizedlist>
 	  <listitem>
 	    <para>If there is a firewall between the logging server
 	      and any logging clients, ensure that the firewall
 	      ruleset allows <acronym>UDP</acronym> port 514 for both
 	      the clients and the server.</para>
 	  </listitem>
 
 	  <listitem>
 	    <para>The logging server and all client  machines must
 	      have forward and reverse entries in the local
 	      <acronym>DNS</acronym>.  If the network does not have a
 	      <acronym>DNS</acronym> server, create entries in each
 	      system's <filename>/etc/hosts</filename>.  Proper name
 	      resolution is required so that log entries are not
 	      rejected by the logging server.</para>
 	  </listitem>
 	</itemizedlist>
 
 	<para>On the log server, edit
 	  <filename>/etc/syslog.conf</filename> to specify the name of
 	  the client to receive log entries from, the logging facility
 	  to be used, and the name of the log to store the host's log
 	  entries.  This example adds the hostname of
 	  <systemitem>B</systemitem>, logs all facilities, and stores
 	  the log entries in
 	  <filename>/var/log/logclient.log</filename>.</para>
 
 	<example>
 	  <title>Sample Log Server Configuration</title>
 
 	  <programlisting>+logclient.example.com
 *.*     /var/log/logclient.log</programlisting>
 	</example>
 
 	<para>When adding multiple log clients, add a similar two-line
 	  entry for each client.  More information about the available
 	  facilities may be found in &man.syslog.conf.5;.</para>
 
 	<para>Next, configure
 	  <filename>/etc/rc.conf</filename>:</para>
 
 	<programlisting>syslogd_enable="YES"
 syslogd_flags="-a logclient.example.com -v -v"</programlisting>
 
 	<para>The first entry starts
 	  <application>syslogd</application> at system boot.  The
 	  second entry allows log entries from the specified client.
 	  The <option>-v -v</option> increases the verbosity of logged
 	  messages.  This is useful for tweaking facilities as
 	  administrators are able to see what type of messages are
 	  being logged under each facility.</para>
 
 	<para>Multiple <option>-a</option> options may be specified to
 	  allow logging from multiple clients.  <acronym>IP</acronym>
 	  addresses and whole netblocks may also be specified.  Refer
 	  to &man.syslogd.8; for a full list of possible
 	  options.</para>
 
 	<para>Finally, create the log file:</para>
 
 	<screen>&prompt.root; <userinput>touch /var/log/logclient.log</userinput></screen>
 
 	<para>At this point, <application>syslogd</application> should
 	  be restarted and verified:</para>
 
 	<screen>&prompt.root; <userinput>service syslogd restart</userinput>
 &prompt.root; <userinput>pgrep syslog</userinput></screen>
 
 	<para>If a <acronym>PID</acronym> is returned, the server
 	  restarted successfully, and client configuration can begin.
 	  If the server did not restart, consult
 	  <filename>/var/log/messages</filename> for the error.</para>
       </sect3>
 
       <sect3>
 	<title>Log Client Configuration</title>
 
 	<para>A logging client sends log entries to a logging server
 	  on the network.  The client also keeps a local copy of its
 	  own logs.</para>
 
 	<para>Once a logging server has been configured, edit
 	  <filename>/etc/rc.conf</filename> on the logging
 	  client:</para>
 
 	<programlisting>syslogd_enable="YES"
 syslogd_flags="-s -v -v"</programlisting>
 
 	<para>The first entry enables
 	  <application>syslogd</application> on boot up.  The second
 	  entry prevents logs from being accepted by this client from
 	  other hosts (<option>-s</option>) and increases the
 	  verbosity of logged messages.</para>
 
 	<para>Next, define the logging server in the client's
 	  <filename>/etc/syslog.conf</filename>.  In this example, all
 	  logged facilities are sent to a remote system, denoted by
 	  the <literal>@</literal> symbol, with the specified
 	  hostname:</para>
 
 	<programlisting>*.*		@logserv.example.com</programlisting>
 
 	<para>After saving the edit, restart
 	  <application>syslogd</application> for the changes to take
 	  effect:</para>
 
 	<screen>&prompt.root; <userinput>service syslogd restart</userinput></screen>
 
 	<para>To test that log messages are being sent across the
 	  network, use &man.logger.1; on the client to send a message
 	  to <application>syslogd</application>:</para>
 
 	<screen>&prompt.root; <userinput>logger "<replaceable>Test message from logclient</replaceable>"</userinput></screen>
 
 	<para>This message should now exist both in
 	  <filename>/var/log/messages</filename> on the client and
 	  <filename>/var/log/logclient.log</filename> on the log
 	  server.</para>
       </sect3>
 
       <sect3>
 	<title>Debugging Log Servers</title>
 
 	<para>If no messages are being received on the log server, the
 	  cause is most likely a network connectivity issue, a
 	  hostname resolution issue, or a typo in a configuration
 	  file.  To isolate the cause, ensure that both the logging
 	  server and the logging client are able to
 	  <command>ping</command> each other using the hostname
 	  specified in their <filename>/etc/rc.conf</filename>.  If
 	  this fails, check the network cabling, the firewall ruleset,
 	  and the hostname entries in the <acronym>DNS</acronym>
 	  server or <filename>/etc/hosts</filename> on both the
 	  logging server and clients.  Repeat until the
 	  <command>ping</command> is successful from both
 	  hosts.</para>
 
 	<para>If the <command>ping</command> succeeds on both hosts
 	  but log messages are still not being received, temporarily
 	  increase logging verbosity to narrow down the configuration
 	  issue.  In the following example,
 	  <filename>/var/log/logclient.log</filename> on the logging
 	  server is empty and <filename>/var/log/messages</filename>
 	  on the logging client does not indicate a reason for the
 	  failure.  To increase debugging output, edit the
 	  <literal>syslogd_flags</literal> entry on the logging server
 	  and issue a restart:</para>
 
 	<programlisting>syslogd_flags="-d -a logclient.example.com -v -v"</programlisting>
 
 	<screen>&prompt.root; <userinput>service syslogd restart</userinput></screen>
 
 	<para>Debugging data similar to the following will flash on
 	  the console immediately after the restart:</para>
 
 	<screen>logmsg: pri 56, flags 4, from logserv.example.com, msg syslogd: restart
 syslogd: restarted
 logmsg: pri 6, flags 4, from logserv.example.com, msg syslogd: kernel boot file is /boot/kernel/kernel
 Logging to FILE /var/log/messages
 syslogd: kernel boot file is /boot/kernel/kernel
 cvthname(192.168.1.10)
 validate: dgram from IP 192.168.1.10, port 514, name logclient.example.com;
 rejected in rule 0 due to name mismatch.</screen>
 
 	<para>In this example, the log messages are being rejected due
 	  to a typo which results in a hostname mismatch.  The
 	  client's hostname should be <literal>logclient</literal>,
 	  not <literal>logclien</literal>.  Fix the typo, issue a
 	  restart, and verify the results:</para>
 
 	<screen>&prompt.root; <userinput>service syslogd restart</userinput>
 logmsg: pri 56, flags 4, from logserv.example.com, msg syslogd: restart
 syslogd: restarted
 logmsg: pri 6, flags 4, from logserv.example.com, msg syslogd: kernel boot file is /boot/kernel/kernel
 syslogd: kernel boot file is /boot/kernel/kernel
 logmsg: pri 166, flags 17, from logserv.example.com,
 msg Dec 10 20:55:02 &lt;syslog.err&gt; logserv.example.com syslogd: exiting on signal 2
 cvthname(192.168.1.10)
 validate: dgram from IP 192.168.1.10, port 514, name logclient.example.com;
 accepted in rule 0.
 logmsg: pri 15, flags 0, from logclient.example.com, msg Dec 11 02:01:28 trhodes: Test message 2
 Logging to FILE /var/log/logclient.log
 Logging to FILE /var/log/messages</screen>
 
 	<para>At this point, the messages are being properly received
 	  and placed in the correct file.</para>
       </sect3>
 
       <sect3>
 	<title>Security Considerations</title>
 
 	<para>As with any network service, security requirements
 	  should be considered before implementing a logging server.
 	  Log files may contain sensitive data about services enabled
 	  on the local host, user accounts, and configuration data.
 	  Network data sent from the client to the server will not be
 	  encrypted or password protected.  If a need for encryption
 	  exists, consider using <package>security/stunnel</package>,
 	  which will transmit the logging data over an encrypted
 	  tunnel.</para>
 
 	<para>Local security is also an issue.  Log files are not
 	  encrypted during use or after log rotation.  Local users may
 	  access log files to gain additional insight into system
 	  configuration.  Setting proper permissions on log files is
 	  critical.  The built-in log rotator,
 	  <application>newsyslog</application>, supports setting
 	  permissions on newly created and rotated log files.  Setting
 	  log files to mode <literal>600</literal> should prevent
 	  unwanted access by local users.  Refer to
 	  &man.newsyslog.conf.5; for additional information.</para>
       </sect3>
     </sect2>
   </sect1>
 
   <sect1 xml:id="configtuning-configfiles">
     <title>Configuration Files</title>
 
     <sect2>
       <title><filename>/etc</filename>
 	Layout</title>
 
       <para>There are a number of directories in which configuration
 	information is kept.  These include:</para>
 
       <informaltable frame="none" pgwide="1">
 	<tgroup cols="2">
 	  <colspec colwidth="1*"/>
 	  <colspec colwidth="2*"/>
 
 	  <tbody>
 	    <row>
 	      <entry><filename>/etc</filename></entry>
 	      <entry>Generic system-specific configuration
 		information.</entry>
 	    </row>
 
 	    <row>
 	      <entry><filename>/etc/defaults</filename></entry>
 	      <entry>Default versions of system configuration
 		files.</entry>
 	    </row>
 
 	    <row>
 	      <entry><filename>/etc/mail</filename></entry>
 	      <entry>Extra &man.sendmail.8; configuration and other
 		<acronym>MTA</acronym> configuration files.</entry>
 	    </row>
 
 	    <row>
 	      <entry><filename>/etc/ppp</filename></entry>
 	      <entry>Configuration for both user- and kernel-ppp
 		programs.</entry>
 	    </row>
 
 	    <row>
 	      <entry><filename>/usr/local/etc</filename></entry>
 	      <entry>Configuration files for installed applications.
 		May contain per-application subdirectories.</entry>
 	    </row>
 
 	    <row>
 	      <entry><filename>/usr/local/etc/rc.d</filename></entry>
 	      <entry>&man.rc.8; scripts for installed
 		applications.</entry>
 	    </row>
 
 	    <row>
 	      <entry><filename>/var/db</filename></entry>
 	      <entry>Automatically generated system-specific database
 		files, such as the package database and the
 		&man.locate.1; database.</entry>
 	    </row>
 	  </tbody>
 	</tgroup>
       </informaltable>
     </sect2>
 
     <sect2>
       <title>Hostnames</title>
 
       <indexterm><primary>hostname</primary></indexterm>
       <indexterm><primary>DNS</primary></indexterm>
 
       <sect3>
 	<title><filename>/etc/resolv.conf</filename></title>
 
 	<indexterm>
 	  <primary><filename>resolv.conf</filename></primary>
 	</indexterm>
 
 	<para>How a &os; system accesses the Internet Domain Name
 	  System (<acronym>DNS</acronym>) is controlled by
 	  &man.resolv.conf.5;.</para>
 
 	<para>The most common entries to
 	  <filename>/etc/resolv.conf</filename> are:</para>
 
 	<informaltable frame="none" pgwide="1">
 	  <tgroup cols="2">
 	    <colspec colwidth="1*"/>
 	    <colspec colwidth="2*"/>
 
 	    <tbody>
 	      <row>
 		<entry><literal>nameserver</literal></entry>
 		<entry>The <acronym>IP</acronym> address of a name
 		  server the resolver should query.  The servers are
 		  queried in the order listed with a maximum of
 		  three.</entry>
 	      </row>
 
 	      <row>
 		<entry><literal>search</literal></entry>
 		<entry>Search list for hostname lookup.  This is
 		  normally determined by the domain of the local
 		  hostname.</entry>
 	      </row>
 
 	      <row>
 		<entry><literal>domain</literal></entry>
 		<entry>The local domain name.</entry>
 	      </row>
 	    </tbody>
 	  </tgroup>
 	</informaltable>
 
 	<para>A typical <filename>/etc/resolv.conf</filename> looks
 	  like this:</para>
 
 	<programlisting>search example.com
 nameserver 147.11.1.11
 nameserver 147.11.100.30</programlisting>
 
 	<note>
 	  <para>Only one of the <literal>search</literal> and
 	    <literal>domain</literal> options should be used.</para>
 	</note>
 
 	<para>When using <acronym>DHCP</acronym>, &man.dhclient.8;
 	  usually rewrites <filename>/etc/resolv.conf</filename>
 	  with information received from the <acronym>DHCP</acronym>
 	  server.</para>
       </sect3>
 
       <sect3>
 	<title><filename>/etc/hosts</filename></title>
 
 	<indexterm><primary>hosts</primary></indexterm>
 
 	<para><filename>/etc/hosts</filename> is a simple text
 	  database which works in conjunction with
 	  <acronym>DNS</acronym> and
 	  <acronym>NIS</acronym> to provide host name to
 	  <acronym>IP</acronym> address mappings.  Entries for local
 	  computers connected via a <acronym>LAN</acronym> can be
 	  added to this file for simplistic naming purposes instead
 	  of setting up a &man.named.8; server.  Additionally,
 	  <filename>/etc/hosts</filename> can be used to provide a
 	  local record of Internet names, reducing the need to query
 	  external <acronym>DNS</acronym> servers for commonly
 	  accessed names.</para>
 
 	<programlisting># <phrase its:translate="no">&dollar;&os;&dollar;</phrase>
 #
 #
 # Host Database
 #
 # This file should contain the addresses and aliases for local hosts that
 # share this file.  Replace 'my.domain' below with the domainname of your
 # machine.
 #
 # In the presence of the domain name service or NIS, this file may
 # not be consulted at all; see /etc/nsswitch.conf for the resolution order.
 #
 #
 ::1			localhost localhost.my.domain
 127.0.0.1		localhost localhost.my.domain
 #
 # Imaginary network.
 #10.0.0.2		myname.my.domain myname
 #10.0.0.3		myfriend.my.domain myfriend
 #
 # According to RFC 1918, you can use the following IP networks for
 # private nets which will never be connected to the Internet:
 #
 #	10.0.0.0	-   10.255.255.255
 #	172.16.0.0	-   172.31.255.255
 #	192.168.0.0	-   192.168.255.255
 #
 # In case you want to be able to connect to the Internet, you need
 # real official assigned numbers.  Do not try to invent your own network
 # numbers but instead get one from your network provider (if any) or
 # from your regional registry (ARIN, APNIC, LACNIC, RIPE NCC, or AfriNIC.)
 #</programlisting>
 
 	<para>The format of <filename>/etc/hosts</filename> is as
 	  follows:</para>
 
 	<programlisting>[Internet address] [official hostname] [alias1] [alias2] ...</programlisting>
 
 	<para>For example:</para>
 
 	<programlisting>10.0.0.1 myRealHostname.example.com myRealHostname foobar1 foobar2</programlisting>
 
 	<para>Consult &man.hosts.5; for more information.</para>
       </sect3>
     </sect2>
   </sect1>
 
   <sect1 xml:id="configtuning-sysctl">
     <title>Tuning with &man.sysctl.8;</title>
 
     <indexterm><primary>sysctl</primary></indexterm>
     <indexterm>
       <primary>tuning</primary>
       <secondary>with sysctl</secondary>
     </indexterm>
 
     <para>&man.sysctl.8; is used to make changes to a running &os;
       system.  This includes many advanced options of the
       <acronym>TCP/IP</acronym> stack and virtual memory system
       that can dramatically improve performance for an experienced
       system administrator.  Over five hundred system variables can
       be read and set using &man.sysctl.8;.</para>
 
     <para>At its core, &man.sysctl.8; serves two functions: to read
       and to modify system settings.</para>
 
     <para>To view all readable variables:</para>
 
     <screen>&prompt.user; <userinput>sysctl -a</userinput></screen>
 
     <para>To read a particular variable, specify its name:</para>
 
     <screen>&prompt.user; <userinput>sysctl kern.maxproc</userinput>
 kern.maxproc: 1044</screen>
 
     <para>To set a particular variable, use the
       <replaceable>variable</replaceable>=<replaceable>value</replaceable>
       syntax:</para>
 
     <screen>&prompt.root; <userinput>sysctl kern.maxfiles=5000</userinput>
 kern.maxfiles: 2088 -&gt; 5000</screen>
 
     <para>Settings of sysctl variables are usually either strings,
       numbers, or booleans, where a boolean is <literal>1</literal>
       for yes or <literal>0</literal> for no.</para>
 
     <para>To automatically set some variables each time the machine
       boots, add them to <filename>/etc/sysctl.conf</filename>.  For
       more information, refer to &man.sysctl.conf.5; and
       <xref linkend="configtuning-sysctlconf"/>.</para>
 
     <sect2 xml:id="configtuning-sysctlconf">
       <title><filename>sysctl.conf</filename></title>
 
       <indexterm><primary>sysctl.conf</primary></indexterm>
       <indexterm><primary>sysctl</primary></indexterm>
 
       <para>The configuration file for &man.sysctl.8;,
 	<filename>/etc/sysctl.conf</filename>, looks much like
 	<filename>/etc/rc.conf</filename>.  Values are set in a
 	<literal>variable=value</literal> form.  The specified values
 	are set after the system goes into multi-user mode.  Not all
 	variables are settable in this mode.</para>
 
       <para>For example, to turn off logging of fatal signal exits
 	and prevent users from seeing processes started by other
 	users, the following tunables can be set in
 	<filename>/etc/sysctl.conf</filename>:</para>
 
       <programlisting># Do not log fatal signal exits (e.g., sig 11)
 kern.logsigexit=0
 
 # Prevent users from seeing information about processes that
 # are being run under another UID.
 security.bsd.see_other_uids=0</programlisting>
     </sect2>
 
     <sect2 xml:id="sysctl-readonly">
       <info>
 	<title>&man.sysctl.8; Read-only</title>
 
 	<authorgroup>
 	  <author>
 	    <personname>
 	      <firstname>Tom</firstname>
 	      <surname>Rhodes</surname>
 	    </personname>
 	    <contrib>Contributed by </contrib>
 	  </author>
 	</authorgroup>
       </info>
 
       <para>In some cases it may be desirable to modify read-only
 	&man.sysctl.8; values, which will require a reboot of the
 	system.</para>
 
       <para>For instance, on some laptop models the &man.cardbus.4;
 	device will not probe memory ranges and will fail with errors
 	similar to:</para>
 
       <screen>cbb0: Could not map register memory
 device_probe_and_attach: cbb0 attach returned 12</screen>
 
       <para>The fix requires the modification of a read-only
 	&man.sysctl.8; setting.  Add
 	<option>hw.pci.allow_unsupported_io_range=1</option> to
 	<filename>/boot/loader.conf</filename> and reboot.  Now
 	&man.cardbus.4; should work properly.</para>
     </sect2>
   </sect1>
 
   <sect1 xml:id="configtuning-disk">
     <title>Tuning Disks</title>
 
     <para>The following section will discuss various tuning
       mechanisms and options which may be applied to disk
       devices.  In many cases, disks with mechanical parts,
       such as <acronym>SCSI</acronym> drives, will be the
       bottleneck driving down the overall system performance.  While
       a solution is to install a drive without mechanical parts,
       such as a solid state drive, mechanical drives are not
       going away anytime in the near future.  When tuning disks,
       it is advisable to utilize the features of the &man.iostat.8;
       command to test various changes to the system.  This
       command will allow the user to obtain valuable information
       on system <acronym>IO</acronym>.</para>
 
     <sect2>
       <title>Sysctl Variables</title>
 
       <sect3>
 	<title><varname>vfs.vmiodirenable</varname></title>
 
 	<indexterm>
 	  <primary><varname>vfs.vmiodirenable</varname></primary>
 	</indexterm>
 
 	<para>The <varname>vfs.vmiodirenable</varname> &man.sysctl.8;
 	  variable
 	  may be set to either <literal>0</literal> (off) or
 	  <literal>1</literal> (on).  It is set to
 	  <literal>1</literal> by default.  This variable controls
 	  how directories are cached by the system.  Most directories
 	  are small, using just a single fragment (typically 1&nbsp;K)
 	  in the file system and typically 512&nbsp;bytes in the
 	  buffer cache.  With this variable turned off, the buffer
 	  cache will only cache a fixed number of directories, even
 	  if the system has a huge amount of memory.  When turned on,
 	  this &man.sysctl.8; allows the buffer cache to use the
 	  <acronym>VM</acronym> page cache to cache the directories,
 	  making all the memory available for caching directories.
 	  However, the minimum in-core memory used to cache a
 	  directory is the physical page size (typically 4&nbsp;K)
 	  rather than 512&nbsp; bytes.  Keeping this option enabled
 	  is recommended if the system is running any services which
 	  manipulate large numbers of files.  Such services can
 	  include web caches, large mail systems, and news systems.
 	  Keeping this option on will generally not reduce
 	  performance, even with the wasted memory, but one should
 	  experiment to find out.</para>
       </sect3>
 
       <sect3>
 	<title><varname>vfs.write_behind</varname></title>
 
 	<indexterm>
 	  <primary><varname>vfs.write_behind</varname></primary>
 	</indexterm>
 
 	<para>The <varname>vfs.write_behind</varname> &man.sysctl.8;
 	  variable
 	  defaults to <literal>1</literal> (on).  This tells the file
 	  system to issue media writes as full clusters are collected,
 	  which typically occurs when writing large sequential files.
 	  This avoids saturating the buffer cache with dirty buffers
 	  when it would not benefit I/O performance.  However, this
 	  may stall processes and under certain circumstances should
 	  be turned off.</para>
       </sect3>
 
       <sect3>
 	<title><varname>vfs.hirunningspace</varname></title>
 
 	<indexterm>
 	  <primary><varname>vfs.hirunningspace</varname></primary>
 	</indexterm>
 
 	<para>The <varname>vfs.hirunningspace</varname> &man.sysctl.8;
 	  variable determines how much outstanding write I/O may be
 	  queued to disk controllers system-wide at any given
 	  instance.  The default is usually sufficient, but on
 	  machines with many disks, try bumping it up to four or five
 	  <emphasis>megabytes</emphasis>.  Setting too high a value
 	  which exceeds the buffer cache's write threshold can lead
 	  to bad clustering performance.  Do not set this value
 	  arbitrarily high as higher write values may add latency to
 	  reads occurring at the same time.</para>
 
 	<para>There are various other buffer cache and
 	  <acronym>VM</acronym> page cache related &man.sysctl.8;
 	  values.  Modifying these values is not recommended as the
 	  <acronym>VM</acronym> system does a good job of
 	  automatically tuning itself.</para>
       </sect3>
 
       <sect3>
 	<title><varname>vm.swap_idle_enabled</varname></title>
 
 	<indexterm>
 	  <primary><varname>vm.swap_idle_enabled</varname></primary>
 	</indexterm>
 
 	<para>The <varname>vm.swap_idle_enabled</varname>
 	  &man.sysctl.8; variable is useful in large multi-user
 	  systems with many active login users and lots of idle
 	  processes.  Such systems tend to generate continuous
 	  pressure on free memory reserves.  Turning this feature on
 	  and tweaking the swapout hysteresis (in idle seconds) via
 	  <varname>vm.swap_idle_threshold1</varname> and
 	  <varname>vm.swap_idle_threshold2</varname> depresses the
 	  priority of memory pages associated with idle processes more
 	  quickly then the normal pageout algorithm.  This gives a
 	  helping hand to the pageout daemon.  Only turn this option
 	  on if needed, because the tradeoff is essentially pre-page
 	  memory sooner rather than later which eats more swap and
 	  disk bandwidth.  In a small system this option will have a
 	  determinable effect, but in a large system that is already
 	  doing moderate paging, this option allows the
 	  <acronym>VM</acronym> system to stage whole processes into
 	  and out of memory easily.</para>
       </sect3>
 
       <sect3>
 	<title><varname>hw.ata.wc</varname></title>
 
 	<indexterm>
 	  <primary><varname>hw.ata.wc</varname></primary>
 	</indexterm>
 
 	<para>Turning off <acronym>IDE</acronym> write caching reduces
 	  write bandwidth to <acronym>IDE</acronym> disks, but may
 	  sometimes be necessary due to data consistency issues
 	  introduced by hard drive vendors.  The problem is that
 	  some <acronym>IDE</acronym> drives lie about when a write
 	  completes.  With <acronym>IDE</acronym> write caching
 	  turned on, <acronym>IDE</acronym> hard drives write data
 	  to disk out of order and will sometimes delay writing some
 	  blocks indefinitely when under heavy disk load.  A crash or
 	  power failure may cause serious file system corruption.
 	  Check the default on the system by observing the
 	  <varname>hw.ata.wc</varname> &man.sysctl.8; variable.  If
 	  <acronym>IDE</acronym> write caching is turned off, one can
 	  set this read-only variable to
 	  <literal>1</literal> in
 	  <filename>/boot/loader.conf</filename> in order to enable
 	  it at boot time.</para>
 
 	<para>For more information, refer to &man.ata.4;.</para>
       </sect3>
 
       <sect3>
 	<title><literal>SCSI_DELAY</literal>
 	  (<varname>kern.cam.scsi_delay</varname>)</title>
 
 	<indexterm>
 	  <primary><varname>kern.cam.scsi_delay</varname></primary>
 	</indexterm>
 
 	<indexterm>
 	  <primary>kernel options</primary>
 	  <secondary><literal>SCSI DELAY</literal></secondary>
 	</indexterm>
 
 	<para>The <literal>SCSI_DELAY</literal> kernel configuration
 	  option may be used to reduce system boot times.  The
 	  defaults are fairly high and can be responsible for
 	  <literal>15</literal> seconds of delay in the boot process.
 	  Reducing it to <literal>5</literal> seconds usually works
 	  with modern drives.  The
 	  <varname>kern.cam.scsi_delay</varname> boot time tunable
 	  should be used.  The tunable and kernel configuration
 	  option accept values in terms of
 	  <emphasis>milliseconds</emphasis> and
 	  <emphasis>not</emphasis>
 	  <emphasis>seconds</emphasis>.</para>
       </sect3>
     </sect2>
 
     <sect2 xml:id="soft-updates">
       <title>Soft Updates</title>
 
       <indexterm><primary>Soft Updates</primary></indexterm>
       <indexterm><primary>&man.tunefs.8;</primary></indexterm>
 
       <para>To fine-tune a file system, use &man.tunefs.8;.  This
 	program has many different options.  To toggle Soft Updates
 	on and off, use:</para>
 
       <screen>&prompt.root; <userinput>tunefs -n enable /filesystem</userinput>
 &prompt.root; <userinput>tunefs -n disable /filesystem</userinput></screen>
 
       <para>A file system cannot be modified with &man.tunefs.8; while
 	it is mounted.  A good time to enable Soft Updates is before
 	any partitions have been mounted, in single-user mode.</para>
 
       <para>Soft Updates is recommended for <acronym>UFS</acronym>
 	file systems as it drastically improves meta-data performance,
 	mainly file creation and deletion, through the use of a memory
 	cache.  There are two downsides to Soft Updates to be aware
 	of.  First, Soft Updates guarantee file system consistency
 	in the case of a crash, but could easily be several seconds
 	or even a minute behind updating the physical disk.  If the
 	system crashes, unwritten data may be lost.  Secondly, Soft
 	Updates delay the freeing of file system blocks.  If the
 	root file system is almost full, performing a major update,
 	such as <command>make installworld</command>, can cause the
 	file system to run out of space and the update to fail.</para>
 
       <sect3>
 	<title>More Details About Soft Updates</title>
 
 	<indexterm>
 	  <primary>Soft Updates</primary>
 	  <secondary>details</secondary>
 	</indexterm>
 
 	<para>Meta-data updates are updates to non-content data like
 	  inodes or directories.  There are two traditional approaches
 	  to writing a file system's meta-data back to disk.</para>
 
 	<para>Historically, the default behavior was to write out
 	  meta-data updates synchronously.  If a directory changed,
 	  the system waited until the change was actually written to
 	  disk.  The file data buffers (file contents) were passed
 	  through the buffer cache and backed up to disk later on
 	  asynchronously.  The advantage of this implementation is
 	  that it operates safely.  If there is a failure during an
 	  update, meta-data is always in a consistent state.  A
 	  file is either created completely or not at all.  If the
 	  data blocks of a file did not find their way out of the
 	  buffer cache onto the disk by the time of the crash,
 	  &man.fsck.8; recognizes this and repairs the file system
 	  by setting the file length to <literal>0</literal>.
 	  Additionally, the implementation is clear and simple.  The
 	  disadvantage is that meta-data changes are slow.  For
 	  example, <command>rm -r</command> touches all the files in a
 	  directory sequentially, but each directory change will be
 	  written synchronously to the disk.  This includes updates to
 	  the directory itself, to the inode table, and possibly to
 	  indirect blocks allocated by the file.  Similar
 	  considerations apply for unrolling large hierarchies using
 	  <command>tar -x</command>.</para>
 
 	<para>The second approach is to use asynchronous meta-data
 	  updates.  This is the default for a <acronym>UFS</acronym>
 	  file system mounted with <command>mount -o async</command>.
 	  Since all meta-data updates are also passed through the
 	  buffer cache, they will be intermixed with the updates of
 	  the file content data.  The advantage of this
 	  implementation is there is no need to wait until each
 	  meta-data update has been written to disk, so all operations
 	  which cause huge amounts of meta-data updates work much
 	  faster than in the synchronous case.  This implementation
 	  is still clear and simple, so there is a low risk for bugs
 	  creeping into the code.  The disadvantage is that there is
 	  no guarantee for a consistent state of the file system.
 	  If there is a failure during an operation that updated
 	  large amounts of meta-data, like a power failure or someone
 	  pressing the reset button, the file system will be left
 	  in an unpredictable state.  There is no opportunity to
 	  examine the state of the file system when the system comes
 	  up again as the data blocks of a file could already have
 	  been written to the disk while the updates of the inode
 	  table or the associated directory were not.  It is
 	  impossible to implement a &man.fsck.8; which is able to
 	  clean up the resulting chaos because the necessary
 	  information is not available on the disk.  If the file
 	  system has been damaged beyond repair, the only choice
 	  is to reformat it and restore from backup.</para>
 
 	<para>The usual solution for this problem is to implement
 	  <emphasis>dirty region logging</emphasis>, which is also
 	  referred to as <emphasis>journaling</emphasis>.
 	  Meta-data updates are still written synchronously, but only
 	  into a small region of the disk.  Later on, they are moved
 	  to their proper location.  Because the logging area is a
 	  small, contiguous region on the disk, there are no long
 	  distances for the disk heads to move, even during heavy
 	  operations, so these operations are quicker than synchronous
 	  updates.  Additionally, the complexity of the implementation
 	  is limited, so the risk of bugs being present is low.  A
 	  disadvantage is that all meta-data is written twice, once
 	  into the logging region and once to the proper location, so
 	  performance <quote>pessimization</quote> might result.  On
 	  the other hand, in case of a crash, all pending meta-data
 	  operations can be either quickly rolled back or completed
 	  from the logging area after the system comes up again,
 	  resulting in a fast file system startup.</para>
 
 	<para>Kirk McKusick, the developer of Berkeley
 	  <acronym>FFS</acronym>, solved this problem with Soft
 	  Updates.  All pending meta-data updates are kept in memory
 	  and written out to disk in a sorted sequence
 	  (<quote>ordered meta-data updates</quote>).  This has the
 	  effect that, in case of heavy meta-data operations, later
 	  updates to an item <quote>catch</quote> the earlier ones
 	  which are still in memory and have not already been written
 	  to disk.  All operations are generally performed in memory
 	  before the update is written to disk and the data blocks are
 	  sorted according to their position so that they will not be
 	  on the disk ahead of their meta-data.  If the system
 	  crashes, an implicit <quote>log rewind</quote> causes all
 	  operations which were not written to the disk appear as if
 	  they never happened.  A consistent file system state is
 	  maintained that appears to be the one of 30 to 60 seconds
 	  earlier.  The algorithm used guarantees that all resources
 	  in use are marked as such in their blocks and inodes.
 	  After a crash, the only resource allocation error that
 	  occurs is that resources are marked as <quote>used</quote>
 	  which are actually <quote>free</quote>.  &man.fsck.8;
 	  recognizes this situation, and frees the resources that
 	  are no longer used.  It is safe to ignore the dirty state
 	  of the file system after a crash by forcibly mounting it
 	  with <command>mount -f</command>.  In order to free
 	  resources that may be unused, &man.fsck.8; needs to be run
 	  at a later time.  This is the idea behind the
 	  <emphasis>background &man.fsck.8;</emphasis>: at system
 	  startup time, only a <emphasis>snapshot</emphasis> of the
 	  file system is recorded and &man.fsck.8; is run afterwards.
 	  All file systems can then be mounted
 	  <quote>dirty</quote>, so the system startup proceeds in
 	  multi-user mode.  Then, background &man.fsck.8; is
 	  scheduled for all file systems where this is required, to
 	  free resources that may be unused.  File systems that do
 	  not use Soft Updates still need the usual foreground
 	  &man.fsck.8;.</para>
 
 	<para>The advantage is that meta-data operations are nearly
 	  as fast as asynchronous updates and are faster than
 	  <emphasis>logging</emphasis>, which has to write the
 	  meta-data twice.  The disadvantages are the complexity of
 	  the code, a higher memory consumption, and some
 	  idiosyncrasies.  After a crash, the state of the file
 	  system appears to be somewhat <quote>older</quote>.  In
 	  situations where the standard synchronous approach would
 	  have caused some zero-length files to remain after the
 	  &man.fsck.8;, these files do not exist at all with Soft
 	  Updates because neither the meta-data nor the file contents
 	  have been written to disk.  Disk space is not released until
 	  the updates have been written to disk, which may take place
 	  some time after running &man.rm.1;.  This may cause problems
 	  when installing large amounts of data on a file system
 	  that does not have enough free space to hold all the files
 	  twice.</para>
       </sect3>
     </sect2>
   </sect1>
 
   <sect1 xml:id="configtuning-kernel-limits">
     <title>Tuning Kernel Limits</title>
 
     <indexterm>
       <primary>tuning</primary>
       <secondary>kernel limits</secondary>
     </indexterm>
 
     <sect2 xml:id="file-process-limits">
       <title>File/Process Limits</title>
 
       <sect3 xml:id="kern-maxfiles">
 	<title><varname>kern.maxfiles</varname></title>
 
 	<indexterm>
 	  <primary><varname>kern.maxfiles</varname></primary>
 	</indexterm>
 
 	<para>The <varname>kern.maxfiles</varname> &man.sysctl.8;
 	  variable can be raised or lowered based upon system
 	  requirements.  This variable indicates the maximum number
 	  of file descriptors on the system.  When the file descriptor
 	  table is full, <errorname>file: table is full</errorname>
 	  will show up repeatedly in the system message buffer, which
 	  can be viewed using &man.dmesg.8;.</para>
 
 	<para>Each open file, socket, or fifo uses one file
 	  descriptor.  A large-scale production server may easily
 	  require many thousands of file descriptors, depending on the
 	  kind and number of services running concurrently.</para>
 
 	<para>In older &os; releases, the default value of
 	  <varname>kern.maxfiles</varname> is derived from
 	  <option>maxusers</option> in the kernel configuration file.
 	  <varname>kern.maxfiles</varname> grows proportionally to the
 	  value of <option>maxusers</option>.  When compiling a custom
 	  kernel, consider setting this kernel configuration option
 	  according to the use of the system.  From this number, the
 	  kernel is given most of its pre-defined limits.  Even though
 	  a production machine may not have 256 concurrent users, the
 	  resources needed may be similar to a high-scale web
 	  server.</para>
 
 	<para>The read-only &man.sysctl.8; variable
 	  <varname>kern.maxusers</varname> is automatically sized at
 	  boot based on the amount of memory available in the system,
 	  and may be determined at run-time by inspecting the value
 	  of <varname>kern.maxusers</varname>.  Some systems require
 	  larger or smaller values of
 	  <varname>kern.maxusers</varname> and values of
 	  <literal>64</literal>, <literal>128</literal>, and
 	  <literal>256</literal> are not uncommon.  Going above
 	  <literal>256</literal> is not recommended  unless a huge
 	  number of file descriptors is needed.  Many of the tunable
 	  values set to their defaults by
 	  <varname>kern.maxusers</varname> may be individually
 	  overridden at boot-time or run-time in
 	  <filename>/boot/loader.conf</filename>.  Refer to
 	  &man.loader.conf.5; and
 	  <filename>/boot/defaults/loader.conf</filename> for more
 	  details and some hints.</para>
 
 	<para>In older releases, the system will auto-tune
 	  <literal>maxusers</literal> if it is set to
 	  <literal>0</literal>.
 	  <footnote><para>The auto-tuning algorithm sets
 	      <literal>maxusers</literal> equal to the amount of
 	      memory in the system, with a minimum of
 	      <literal>32</literal>, and a maximum of
 	      <literal>384</literal>.</para></footnote>.  When
 	  setting this option, set <literal>maxusers</literal> to
 	  at least <literal>4</literal>, especially if the system
 	  runs <application>&xorg;</application> or is used to
 	  compile software.  The most important table set by
 	  <literal>maxusers</literal> is the maximum number of
 	  processes, which is set to
 	  <literal>20 + 16 * maxusers</literal>.  If
 	  <literal>maxusers</literal> is set to <literal>1</literal>,
 	  there can only be
 	  <literal>36</literal> simultaneous processes, including
 	  the <literal>18</literal> or so that the system starts up
 	  at boot time and the <literal>15</literal> or so used by
 	  <application>&xorg;</application>.  Even a simple task like
 	  reading a manual page will start up nine processes to
 	  filter, decompress, and view it.  Setting
 	  <literal>maxusers</literal> to <literal>64</literal> allows
 	  up to <literal>1044</literal> simultaneous processes, which
 	  should be enough for nearly all uses.  If, however, the
 	  <errortype>proc table full</errortype> error is displayed
 	  when trying to start another program, or a server is
 	  running with a large number of simultaneous users, increase
 	  the number and rebuild.</para>
 
 	<note>
 	  <para><literal>maxusers</literal> does
 	    <emphasis>not</emphasis> limit the number of users which
 	    can log into the machine.  It instead sets various table
 	    sizes to reasonable values considering the maximum number
 	    of users on the system and how many processes each user
 	    will be running.</para>
 	</note>
       </sect3>
 
       <sect3>
 	<title><varname>kern.ipc.soacceptqueue</varname></title>
 
 	<indexterm>
 	  <primary><varname>kern.ipc.soacceptqueue</varname></primary>
 	</indexterm>
 
 	<para>The <varname>kern.ipc.soacceptqueue</varname>
 	  &man.sysctl.8; variable limits the size of the listen queue
 	  for accepting new <literal>TCP</literal> connections.  The
 	  default value of <literal>128</literal> is typically too low
 	  for robust handling of new connections on a heavily loaded
 	  web server.  For such environments, it is recommended to
 	  increase this value to <literal>1024</literal> or higher.  A
 	  service such as &man.sendmail.8;, or
 	  <application>Apache</application> may itself limit the
 	  listen queue size, but will often have a directive in its
 	  configuration file to adjust the queue size.  Large listen
 	  queues do a better job of avoiding Denial of Service
 	  (<acronym>DoS</acronym>) attacks.</para>
       </sect3>
     </sect2>
 
     <sect2 xml:id="nmbclusters">
       <title>Network Limits</title>
 
       <para>The <literal>NMBCLUSTERS</literal> kernel configuration
 	option dictates the amount of network Mbufs available to the
 	system.  A heavily-trafficked server with a low number of
 	Mbufs will hinder performance.  Each cluster represents
 	approximately 2&nbsp;K of memory, so a value of
 	<literal>1024</literal> represents <literal>2</literal>
 	megabytes of kernel memory reserved for network buffers.  A
 	simple calculation can be done to figure out how many are
 	needed.  A web server which maxes out at
 	<literal>1000</literal> simultaneous connections where each
 	connection uses a 6&nbsp;K receive and 16&nbsp;K send buffer,
 	requires approximately 32&nbsp;MB worth of network buffers
 	to cover the web server.  A good rule of thumb is to multiply
 	by <literal>2</literal>, so
 	2x32&nbsp;MB&nbsp;/&nbsp;2&nbsp;KB&nbsp;=
 	64&nbsp;MB&nbsp;/&nbsp;2&nbsp;kB&nbsp;=
 	<literal>32768</literal>.  Values between
 	<literal>4096</literal> and <literal>32768</literal> are
 	recommended for machines with greater amounts of memory.
 	Never specify an arbitrarily high value for this parameter
 	as it could lead to a boot time crash.  To observe network
 	cluster usage, use <option>-m</option> with
 	&man.netstat.1;.</para>
 
       <para>The <varname>kern.ipc.nmbclusters</varname> loader tunable
 	should be used to tune this at boot time.  Only older versions
 	of &os; will require the use of the
 	<literal>NMBCLUSTERS</literal> kernel &man.config.8;
 	option.</para>
 
       <para>For busy servers that make extensive use of the
 	&man.sendfile.2; system call, it may be necessary to increase
 	the number of &man.sendfile.2; buffers via the
 	<literal>NSFBUFS</literal> kernel configuration option or by
 	setting its value in <filename>/boot/loader.conf</filename>
 	(see &man.loader.8; for details).  A common indicator that
 	this parameter needs to be adjusted is when processes are seen
 	in the <literal>sfbufa</literal> state.  The &man.sysctl.8;
 	variable <varname>kern.ipc.nsfbufs</varname> is read-only.
 	This parameter nominally scales with
 	<varname>kern.maxusers</varname>, however it may be necessary
 	to tune accordingly.</para>
 
       <important>
 	<para>Even though a socket has been marked as non-blocking,
 	  calling &man.sendfile.2; on the non-blocking socket may
 	  result in the &man.sendfile.2; call blocking until enough
 	  <literal>struct sf_buf</literal>'s are made
 	  available.</para>
       </important>
 
       <sect3>
 	<title><varname>net.inet.ip.portrange.*</varname></title>
 
 	<indexterm>
 	  <primary>net.inet.ip.portrange.*</primary>
 	</indexterm>
 
 	<para>The <varname>net.inet.ip.portrange.*</varname>
 	  &man.sysctl.8; variables control the port number ranges
 	  automatically bound to <literal>TCP</literal> and
 	  <literal>UDP</literal> sockets.  There are three ranges: a
 	  low range, a default range, and a high range.  Most network
 	  programs use the default range which is controlled by
 	  <varname>net.inet.ip.portrange.first</varname> and
 	  <varname>net.inet.ip.portrange.last</varname>, which default
 	  to <literal>1024</literal> and <literal>5000</literal>,
 	  respectively.  Bound port ranges are used for outgoing
 	  connections and it is possible to run the system out of
 	  ports under certain circumstances.  This most commonly
 	  occurs when running a heavily loaded web proxy.  The port
 	  range is not an issue when running a server which handles
 	  mainly incoming connections, such as a web server, or has
 	  a limited number of outgoing connections, such as a mail
 	  relay.  For situations where there is a shortage of ports,
 	  it is recommended to increase
 	  <varname>net.inet.ip.portrange.last</varname> modestly.  A
 	  value of <literal>10000</literal>, <literal>20000</literal>
 	  or <literal>30000</literal> may be reasonable.  Consider
 	  firewall effects when changing the port range.  Some
 	  firewalls may block large ranges of ports, usually
 	  low-numbered ports, and expect systems to use higher ranges
 	  of ports for outgoing connections.  For this reason, it
 	  is not recommended that the value of
 	  <varname>net.inet.ip.portrange.first</varname> be
 	  lowered.</para>
       </sect3>
 
       <sect3>
 	<title><literal>TCP</literal> Bandwidth Delay Product</title>
 
 	<indexterm>
 	  <primary><literal>TCP</literal> Bandwidth Delay Product
 	      Limiting</primary>
 	  <secondary><varname>net.inet.tcp.inflight.enable</varname></secondary>
 	</indexterm>
 
 	<para><literal>TCP</literal> bandwidth delay product limiting
 	  can be enabled by setting the
 	  <varname>net.inet.tcp.inflight.enable</varname>
 	  &man.sysctl.8; variable to <literal>1</literal>.  This
 	  instructs the system to attempt to calculate the bandwidth
 	  delay product for each connection and limit the amount of
 	  data queued to the network to just the amount required to
 	  maintain optimum throughput.</para>
 
 	<para>This feature is useful when serving data over modems,
 	  Gigabit Ethernet, high speed <literal>WAN</literal> links,
 	  or any other link with a high bandwidth delay product,
 	  especially when also using window scaling or when a large
 	  send window has been configured.  When enabling this option,
 	  also set <varname>net.inet.tcp.inflight.debug</varname> to
 	  <literal>0</literal> to disable debugging.  For production
 	  use, setting <varname>net.inet.tcp.inflight.min</varname>
 	  to at least <literal>6144</literal> may be beneficial.
 	  Setting high minimums may effectively disable bandwidth
 	  limiting, depending on the link.  The limiting feature
 	  reduces the amount of data built up in intermediate route
 	  and switch packet queues and reduces the amount of data
 	  built up in the local host's interface queue.  With fewer
 	  queued packets, interactive connections, especially over
 	  slow modems, will operate with lower
 	  <emphasis>Round Trip Times</emphasis>.  This feature only
 	  effects server side data transmission such as uploading.
 	  It has no effect on data reception or downloading.</para>
 
 	<para>Adjusting <varname>net.inet.tcp.inflight.stab</varname>
 	  is <emphasis>not</emphasis> recommended.  This parameter
 	  defaults to <literal>20</literal>, representing 2 maximal
 	  packets added to the bandwidth delay product window
 	  calculation.  The additional window is required to stabilize
 	  the algorithm and improve responsiveness to changing
 	  conditions, but it can also result in higher &man.ping.8;
 	  times over slow links, though still much lower than without
 	  the inflight algorithm.  In such cases, try reducing this
 	  parameter to <literal>15</literal>, <literal>10</literal>,
 	  or <literal>5</literal> and reducing
 	  <varname>net.inet.tcp.inflight.min</varname> to a value such
 	  as <literal>3500</literal> to get the desired effect.
 	  Reducing these parameters should be done as a last resort
 	  only.</para>
       </sect3>
     </sect2>
 
     <sect2>
       <title>Virtual Memory</title>
 
       <sect3>
 	<title><varname>kern.maxvnodes</varname></title>
 
 	<para>A vnode is the internal representation of a file or
 	  directory.  Increasing the number of vnodes available to
 	  the operating system reduces disk I/O.  Normally, this is
 	  handled by the operating system and does not need to be
 	  changed.  In some cases where disk I/O is a bottleneck and
 	  the system is running out of vnodes, this setting needs
 	  to be increased.  The amount of inactive and free
 	  <acronym>RAM</acronym> will need to be taken into
 	  account.</para>
 
 	<para>To see the current number of vnodes in use:</para>
 
 	<screen>&prompt.root; <userinput>sysctl vfs.numvnodes</userinput>
 vfs.numvnodes: 91349</screen>
 
 	<para>To see the maximum vnodes:</para>
 
 	<screen>&prompt.root; <userinput>sysctl kern.maxvnodes</userinput>
 kern.maxvnodes: 100000</screen>
 
 	<para>If the current vnode usage is near the maximum, try
 	  increasing <varname>kern.maxvnodes</varname> by a value of
 	  <literal>1000</literal>.  Keep an eye on the number of
 	  <varname>vfs.numvnodes</varname>.  If it climbs up to the
 	  maximum again, <varname>kern.maxvnodes</varname> will need
 	  to be increased further.  Otherwise, a shift in memory
 	  usage as reported by &man.top.1; should be visible and
 	  more memory should be active.</para>
       </sect3>
     </sect2>
   </sect1>
 
   <sect1 xml:id="adding-swap-space">
     <title>Adding Swap Space</title>
 
     <para>Sometimes a system requires more swap space.  This section
       describes two methods to increase swap space: adding swap to an
       existing partition or new hard drive, and creating a swap file
       on an existing partition.</para>
 
     <para>For information on how to encrypt swap space, which options
       exist, and why it should be done, refer to <xref
 	linkend="swap-encrypting"/>.</para>
 
     <sect2 xml:id="new-drive-swap">
       <title>Swap on a New Hard Drive or Existing Partition</title>
 
       <para>Adding a new hard drive for swap gives better performance
 	than using a partition on an existing drive.  Setting up
 	partitions and hard drives is explained in <xref
 	  linkend="disks-adding"/> while <xref
 	  linkend="configtuning-initial"/> discusses partition layouts
 	and swap partition size considerations.</para>
 
       <para>Use <command>swapon</command> to add a swap partition to
 	the system.  For example:</para>
 
       <screen>&prompt.root; <userinput>swapon <replaceable>/dev/ada1s1b</replaceable></userinput></screen>
 
       <warning>
 	<para>It is possible to use any partition not currently
 	  mounted, even if it already contains data.  Using
 	  <command>swapon</command> on a partition that contains data
 	  will overwrite and destroy that data.  Make sure that the
 	  partition to be added as swap is really the intended
 	  partition before running <command>swapon</command>.</para>
       </warning>
 
       <para>To automatically add this swap partition on boot, add an
 	entry to <filename>/etc/fstab</filename>:</para>
 
       <programlisting><replaceable>/dev/ada1s1b</replaceable>	none	swap	sw	0	0</programlisting>
 
       <para>See &man.fstab.5; for an explanation of the entries in
 	<filename>/etc/fstab</filename>.  More information about
 	<command>swapon</command> can be found in
 	&man.swapon.8;.</para>
     </sect2>
 
     <sect2 xml:id="create-swapfile">
       <title>Creating a Swap File</title>
 
       <para>These examples create a 64M swap file called
 	<filename>/usr/swap0</filename> instead of using a
 	partition.</para>
 
       <para>Using swap files requires that the module needed by
 	&man.md.4; has either been built into the kernel or has been
 	loaded before swap is enabled.  See
 	<xref linkend="kernelconfig"/> for information about building
 	a custom kernel.</para>
 
       <example xml:id="swapfile-10-and-later">
 	<title>Creating a Swap File on
 	  &os;&nbsp;10.<replaceable>X</replaceable> and Later</title>
 
 	<procedure>
 	  <step>
 	    <para>Create the swap file:</para>
 
 	    <screen>&prompt.root; <userinput>dd if=/dev/zero of=<replaceable>/usr/swap0</replaceable> bs=1m count=<replaceable>64</replaceable></userinput></screen>
 	  </step>
 
 	  <step>
 	    <para>Set the proper permissions on the new file:</para>
 
 	    <screen>&prompt.root; <userinput>chmod 0600 <replaceable>/usr/swap0</replaceable></userinput></screen>
 	  </step>
 
 	  <step>
 	    <para>Inform the system about the swap file by adding a
 	      line to <filename>/etc/fstab</filename>:</para>
 
 	    <programlisting>md99	none	swap	sw,file=/usr/swap0,late	0	0</programlisting>
 
 	    <para>The &man.md.4; device <filename>md99</filename> is
 	      used, leaving lower device numbers available for
 	      interactive use.</para>
 	  </step>
 
 	  <step>
 	    <para>Swap space will be added on system startup.  To add
 	      swap space immediately, use &man.swapon.8;:</para>
 
 	    <screen>&prompt.root; <userinput>swapon -aL</userinput></screen>
 	  </step>
 	</procedure>
       </example>
 
       <example xml:id="swapfile-9-and-earlier">
 	<title>Creating a Swap File on
 	  &os;&nbsp;9.<replaceable>X</replaceable> and Earlier</title>
 
 	<procedure>
 	  <step>
 	    <para>Create the swap file,
 	      <filename>/usr/swap0</filename>:</para>
 
 	    <screen>&prompt.root; <userinput>dd if=/dev/zero of=<replaceable>/usr/swap0</replaceable> bs=1m count=<replaceable>64</replaceable></userinput></screen>
 	  </step>
 
 	  <step>
 	    <para>Set the proper permissions on
 	      <filename>/usr/swap0</filename>:</para>
 
 	    <screen>&prompt.root; <userinput>chmod 0600 <replaceable>/usr/swap0</replaceable></userinput></screen>
 	  </step>
 
 	  <step>
 	    <para>Enable the swap file in
 	      <filename>/etc/rc.conf</filename>:</para>
 
 	    <programlisting>swapfile="<replaceable>/usr/swap0</replaceable>"   # Set to name of swap file</programlisting>
 	  </step>
 
 	  <step>
 	    <para>Swap space will be added on system startup.  To
 	      enable the swap file immediately, specify a free memory
 	      device.  Refer to <xref linkend="disks-virtual"/> for
 	      more information about memory devices.</para>
 
 	    <screen>&prompt.root; <userinput>mdconfig -a -t vnode -f <replaceable>/usr/swap0</replaceable> -u <replaceable>0</replaceable> &amp;&amp; swapon /dev/md<replaceable>0</replaceable></userinput></screen>
 	  </step>
 	</procedure>
       </example>
     </sect2>
   </sect1>
 
   <sect1 xml:id="acpi-overview">
     <info>
       <title>Power and Resource Management</title>
 
       <authorgroup>
 	<author>
 	  <personname>
 	    <firstname>Hiten</firstname>
 	    <surname>Pandya</surname>
 	  </personname>
 	  <contrib>Written by </contrib>
 	</author>
 
 	<author>
 	  <personname>
 	    <firstname>Tom</firstname>
 	    <surname>Rhodes</surname>
 	  </personname>
 	</author>
       </authorgroup>
     </info>
 
     <para>It is important to utilize hardware resources in an
       efficient manner.  Power and resource management allows the
       operating system to monitor system limits and to possibly
       provide an alert if the system temperature increases
       unexpectedly.  An early specification for providing power
       management was the Advanced Power Management
       (<acronym>APM</acronym>) facility.  <acronym>APM</acronym>
       controls the power usage of a system based on its activity.
       However, it was difficult and inflexible for operating systems
       to manage the power usage and thermal properties of a system.
       The hardware was managed by the <acronym>BIOS</acronym> and the
       user had limited configurability and visibility into the power
       management settings.  The <acronym>APM</acronym>
       <acronym>BIOS</acronym> is supplied by the vendor and is
       specific to the hardware platform.  An <acronym>APM</acronym>
       driver in the operating system mediates access to the
       <acronym>APM</acronym> Software Interface, which allows
       management of power levels.</para>
 
     <para>There are four major problems in <acronym>APM</acronym>.
       First, power management is done by the vendor-specific
       <acronym>BIOS</acronym>, separate from the operating system.
       For example, the user can set idle-time values for a hard drive
       in the <acronym>APM</acronym> <acronym>BIOS</acronym> so that,
       when exceeded, the <acronym>BIOS</acronym> spins down the hard
       drive without the consent of the operating system.  Second, the
       <acronym>APM</acronym> logic is embedded in the
       <acronym>BIOS</acronym>, and it operates outside the scope of
       the operating system.  This means that users can only fix
       problems in the <acronym>APM</acronym>
       <acronym>BIOS</acronym> by flashing a new one into the
       <acronym>ROM</acronym>, which is a dangerous procedure with the
       potential to leave the system in an unrecoverable state if it
       fails.  Third, <acronym>APM</acronym> is a vendor-specific
       technology, meaning that there is a lot of duplication of
       efforts and bugs found in one vendor's <acronym>BIOS</acronym>
       may not be solved in others.  Lastly, the <acronym>APM</acronym>
       <acronym>BIOS</acronym> did not have enough room to implement a
       sophisticated power policy or one that can adapt well to the
       purpose of the machine.</para>
 
     <para>The Plug and Play <acronym>BIOS</acronym>
       (<acronym>PNPBIOS</acronym>) was unreliable in many situations.
       <acronym>PNPBIOS</acronym> is 16-bit technology, so the
       operating system has to use 16-bit emulation in order to
       interface with <acronym>PNPBIOS</acronym> methods.  &os;
       provides an <acronym>APM</acronym> driver as
       <acronym>APM</acronym> should still be used for systems
       manufactured at or before the year 2000.  The driver is
       documented in &man.apm.4;.</para>
 
     <indexterm>
       <primary>ACPI</primary>
     </indexterm>
 
     <indexterm>
       <primary>APM</primary>
     </indexterm>
 
     <para>The successor to <acronym>APM</acronym> is the Advanced
       Configuration and Power Interface (<acronym>ACPI</acronym>).
       <acronym>ACPI</acronym> is a standard written by an alliance of
       vendors to provide an interface for hardware resources and power
       management.  It is a key element in <emphasis>Operating
 	System-directed configuration and Power Management</emphasis>
       as it provides more control and flexibility to the operating
       system.</para>
 
     <para>This chapter demonstrates how to configure
       <acronym>ACPI</acronym> on &os;.  It then offers some tips on
       how to debug <acronym>ACPI</acronym> and how to submit a problem
       report containing debugging information so that developers can
       diagnosis and fix <acronym>ACPI</acronym> issues.</para>
 
     <sect2 xml:id="acpi-config">
       <title>Configuring <acronym>ACPI</acronym></title>
 
       <para>In &os; the &man.acpi.4; driver is loaded by default at
 	system boot and should <emphasis>not</emphasis> be compiled
 	into the kernel.  This driver cannot be unloaded after boot
 	because the system bus uses it for various hardware
 	interactions.  However, if the system is experiencing
 	problems, <acronym>ACPI</acronym> can be disabled altogether
 	by rebooting after setting
 	<literal>hint.acpi.0.disabled="1"</literal> in
 	<filename>/boot/loader.conf</filename> or by setting this
 	variable at the loader prompt, as described in <xref
 	  linkend="boot-loader"/>.</para>
 
       <note>
 	<para><acronym>ACPI</acronym> and <acronym>APM</acronym>
 	  cannot coexist and should be used separately.  The last one
 	  to load will terminate if the driver notices the other is
 	  running.</para>
       </note>
 
       <para><acronym>ACPI</acronym> can be used to put the system into
 	a sleep mode with <command>acpiconf</command>, the
 	<option>-s</option> flag, and a number from
 	<literal>1</literal> to <literal>5</literal>.  Most users only
 	need <literal>1</literal> (quick suspend to
 	<acronym>RAM</acronym>) or <literal>3</literal> (suspend to
 	<acronym>RAM</acronym>).  Option <literal>5</literal> performs
 	a soft-off which is the same as running
 	<command>halt -p</command>.</para>
 
       <para>Other options are available using
 	<command>sysctl</command>.  Refer to &man.acpi.4; and
 	&man.acpiconf.8; for more information.</para>
     </sect2>
 
     <sect2 xml:id="ACPI-comprob">
       <title>Common Problems</title>
 
       <indexterm>
 	<primary><acronym>ACPI</acronym></primary>
       </indexterm>
 
       <para><acronym>ACPI</acronym> is present in all modern computers
 	that conform to the ia32 (x86) and amd64
 	(<acronym>AMD</acronym>) architectures.  The full standard has
 	many features including <acronym>CPU</acronym> performance
 	management, power planes control, thermal zones, various
 	battery systems, embedded controllers, and bus enumeration.
 	Most systems implement less than the full standard.  For
 	instance, a desktop system usually only implements bus
 	enumeration while a laptop might have cooling and battery
 	management support as well.  Laptops also have suspend and
 	resume, with their own associated complexity.</para>
 
       <para>An <acronym>ACPI</acronym>-compliant system has various
 	components.  The <acronym>BIOS</acronym> and chipset vendors
 	provide various fixed tables, such as <acronym>FADT</acronym>,
 	in memory that specify things like the <acronym>APIC</acronym>
 	map (used for <acronym>SMP</acronym>), config registers, and
 	simple configuration values.  Additionally, a bytecode table,
 	the Differentiated System Description Table
 	<acronym>DSDT</acronym>, specifies a tree-like name space of
 	devices and methods.</para>
 
       <para>The <acronym>ACPI</acronym> driver must parse the fixed
 	tables, implement an interpreter for the bytecode, and modify
 	device drivers and the kernel to accept information from the
 	<acronym>ACPI</acronym> subsystem.  For &os;, &intel; has
 	provided an interpreter (<acronym>ACPI-CA</acronym>) that is
 	shared with &linux; and NetBSD.  The path to the
 	<acronym>ACPI-CA</acronym> source code is
 	<filename>src/sys/contrib/dev/acpica</filename>.  The glue
 	code that allows <acronym>ACPI-CA</acronym> to work on &os; is
 	in <filename>src/sys/dev/acpica/Osd</filename>.  Finally,
 	drivers that implement various <acronym>ACPI</acronym> devices
 	are found in <filename>src/sys/dev/acpica</filename>.</para>
 
       <indexterm>
 	<primary>ACPI</primary>
 	<secondary>problems</secondary>
       </indexterm>
 
       <para>For <acronym>ACPI</acronym> to work correctly, all the
 	parts have to work correctly.  Here are some common problems,
 	in order of frequency of appearance, and some possible
 	workarounds or fixes.  If a fix does not resolve the issue,
 	refer to <xref linkend="ACPI-submitdebug"/> for instructions
 	on how to submit a bug report.</para>
 
       <sect3>
 	<title>Mouse Issues</title>
 
 	<para>In some cases, resuming from a suspend operation will
 	  cause the mouse to fail.  A known work around is to add
 	  <literal>hint.psm.0.flags="0x3000"</literal> to
 	  <filename>/boot/loader.conf</filename>.</para>
       </sect3>
 
       <sect3>
 	<title>Suspend/Resume</title>
 
 	<para><acronym>ACPI</acronym> has three suspend to
 	  <acronym>RAM</acronym> (<acronym>STR</acronym>) states,
 	  <literal>S1</literal>-<literal>S3</literal>, and one suspend
 	  to disk state (<acronym>STD</acronym>), called
 	  <literal>S4</literal>.  <acronym>STD</acronym> can be
 	  implemented in two separate ways.  The
 	  <literal>S4</literal><acronym>BIOS</acronym> is a
 	  <acronym>BIOS</acronym>-assisted suspend to disk and
 	  <literal>S4</literal><acronym>OS</acronym> is implemented
 	  entirely by the operating system.  The normal state the
 	  system is in when plugged in but not powered up is
 	  <quote>soft off</quote> (<literal>S5</literal>).</para>
 
 	<para>Use <command>sysctl hw.acpi</command> to check for the
 	  suspend-related items.  These example results are from a
 	  Thinkpad:</para>
 
 	<screen>hw.acpi.supported_sleep_state: S3 S4 S5
 hw.acpi.s4bios: 0</screen>
 
 	<para>Use <command>acpiconf -s</command> to test
 	  <literal>S3</literal>, <literal>S4</literal>, and
 	  <literal>S5</literal>.  An <option>s4bios</option> of one
 	  (<literal>1</literal>) indicates
 	  <literal>S4</literal><acronym>BIOS</acronym> support instead
 	  of <literal>S4</literal> operating system support.</para>
 
 	<para>When testing suspend/resume, start with
 	  <literal>S1</literal>, if supported.  This state is most
 	  likely to work since it does not require much driver
 	  support.  No one has implemented <literal>S2</literal>,
 	  which is similar to <literal>S1</literal>.  Next, try
 	  <literal>S3</literal>.  This is the deepest
 	  <acronym>STR</acronym> state and requires a lot of driver
 	  support to properly reinitialize the hardware.</para>
 
 	<para>A common problem with suspend/resume is that many device
 	  drivers do not save, restore, or reinitialize their
 	  firmware, registers, or device memory properly.  As a first
 	  attempt at debugging the problem, try:</para>
 
 	<screen>&prompt.root; <userinput>sysctl debug.bootverbose=1</userinput>
 &prompt.root; <userinput>sysctl debug.acpi.suspend_bounce=1</userinput>
 &prompt.root; <userinput>acpiconf -s 3</userinput></screen>
 
 	<para>This test emulates the suspend/resume cycle of all
 	  device drivers without actually going into
 	  <literal>S3</literal> state.  In some cases, problems such
 	  as losing firmware state, device watchdog time out, and
 	  retrying forever, can be captured with this method.  Note
 	  that the system will not really enter <literal>S3</literal>
 	  state, which means devices may not lose power, and many
 	  will work fine even if suspend/resume methods are totally
 	  missing, unlike real <literal>S3</literal> state.</para>
 
 	<para>Harder cases require additional hardware, such as a
 	  serial port and cable for debugging through a serial
 	  console, a Firewire port and cable for using &man.dcons.4;,
 	  and kernel debugging skills.</para>
 
 	<para>To help isolate the problem, unload as many drivers as
 	  possible.  If it works, narrow down which driver is the
 	  problem by loading drivers until it fails again.  Typically,
 	  binary drivers like <filename>nvidia.ko</filename>, display
 	  drivers, and <acronym>USB</acronym> will have the most
 	  problems while Ethernet interfaces usually work fine.  If
 	  drivers can be properly loaded and unloaded, automate this
 	  by putting the appropriate commands in
 	  <filename>/etc/rc.suspend</filename> and
 	  <filename>/etc/rc.resume</filename>.  Try setting
 	  <option>hw.acpi.reset_video</option> to <literal>1</literal>
 	  if the display is messed up after resume.  Try setting
 	  longer or shorter values for
 	  <option>hw.acpi.sleep_delay</option> to see if that
 	  helps.</para>
 
 	<para>Try loading a recent &linux; distribution to see if
 	  suspend/resume works on the same hardware.  If it works on
 	  &linux;, it is likely a &os; driver problem.  Narrowing down
 	  which driver causes the problem will assist developers in
 	  fixing the problem.  Since the <acronym>ACPI</acronym>
 	  maintainers rarely maintain other drivers, such as sound
 	  or <acronym>ATA</acronym>, any driver problems should also
 	  be posted to the &a.current.name; list and mailed to the
 	  driver maintainer.  Advanced users can include debugging
 	  &man.printf.3;s in a problematic driver to track down where
 	  in its resume function it hangs.</para>
 
 	<para>Finally, try disabling <acronym>ACPI</acronym> and
 	  enabling <acronym>APM</acronym> instead.  If suspend/resume
 	  works with <acronym>APM</acronym>, stick with
 	  <acronym>APM</acronym>, especially on older hardware
 	  (pre-2000).  It took vendors a while to get
 	  <acronym>ACPI</acronym> support correct and older hardware
 	  is more likely to have <acronym>BIOS</acronym> problems with
 	  <acronym>ACPI</acronym>.</para>
       </sect3>
 
       <sect3>
 	<title>System Hangs</title>
 
 	<para>Most system hangs are a result of lost interrupts or an
 	  interrupt storm.  Chipsets may have problems based on boot,
 	  how the <acronym>BIOS</acronym> configures interrupts before
 	  correctness of the <acronym>APIC</acronym>
 	  (<acronym>MADT</acronym>) table, and routing of the System
 	  Control Interrupt (<acronym>SCI</acronym>).</para>
 
 	<indexterm>
 	  <primary>interrupt storms</primary>
 	</indexterm>
 
 	<para>Interrupt storms can be distinguished from lost
 	  interrupts by checking the output of
 	  <command>vmstat -i</command> and looking at the line that
 	  has <literal>acpi0</literal>.  If the counter is increasing
 	  at more than a couple per second, there is an interrupt
 	  storm.  If the system appears hung, try breaking to
 	  <acronym>DDB</acronym> (<keycombo action="simul">
 	    <keycap>CTRL</keycap>
 	    <keycap>ALT</keycap>
 	    <keycap>ESC</keycap>
 	  </keycombo> on console) and type
 	  <literal>show interrupts</literal>.</para>
 
 	<indexterm>
 	  <primary>APIC</primary>
 	  <secondary>disabling</secondary>
 	</indexterm>
 
 	<para>When dealing with interrupt problems, try disabling
 	  <acronym>APIC</acronym> support with
 	  <literal>hint.apic.0.disabled="1"</literal> in
 	  <filename>/boot/loader.conf</filename>.</para>
       </sect3>
 
       <sect3>
 	<title>Panics</title>
 
 	<para>Panics are relatively rare for <acronym>ACPI</acronym>
 	  and are the top priority to be fixed.  The first step is to
 	  isolate the steps to reproduce the panic, if possible, and
 	  get a backtrace.  Follow the advice for enabling
 	  <literal>options DDB</literal> and setting up a serial
 	  console in <xref linkend="serialconsole-ddb"/> or setting
 	  up a dump partition.  To get a backtrace in
 	  <acronym>DDB</acronym>, use <literal>tr</literal>.  When
 	  handwriting the backtrace, get at least the last five and
 	  the top five lines in the trace.</para>
 
 	<para>Then, try to isolate the problem by booting with
 	  <acronym>ACPI</acronym> disabled.  If that works, isolate
 	  the <acronym>ACPI</acronym> subsystem by using various
 	  values of <option>debug.acpi.disable</option>.  See
 	  &man.acpi.4; for some examples.</para>
       </sect3>
 
       <sect3>
 	<title>System Powers Up After Suspend or Shutdown</title>
 
 	<para>First, try setting
 	  <literal>hw.acpi.disable_on_poweroff="0"</literal> in
 	  <filename>/boot/loader.conf</filename>.  This keeps
 	  <acronym>ACPI</acronym> from disabling various events during
 	  the shutdown process.  Some systems need this value set to
 	  <literal>1</literal> (the default) for the same reason.
 	  This usually fixes the problem of a system powering up
 	  spontaneously after a suspend or poweroff.</para>
       </sect3>
 
       <sect3 xml:id="ACPI-aslanddump">
 	<title>BIOS Contains Buggy Bytecode</title>
 
 	<indexterm>
 	  <primary><acronym>ACPI</acronym></primary>
 	  <secondary><acronym>ASL</acronym></secondary>
 	</indexterm>
 
 	<para>Some <acronym>BIOS</acronym> vendors provide incorrect
 	  or buggy bytecode.  This is usually manifested by kernel
 	  console messages like this:</para>
 
 	<screen>ACPI-1287: *** Error: Method execution failed [\\_SB_.PCI0.LPC0.FIGD._STA] \\
 (Node 0xc3f6d160), AE_NOT_FOUND</screen>
 
 	<para>Often, these problems may be resolved by updating the
 	  <acronym>BIOS</acronym> to the latest revision.  Most
 	  console messages are harmless, but if there are other
 	  problems, like the battery status is not working, these
 	  messages are a good place to start looking for
 	  problems.</para>
       </sect3>
     </sect2>
 
     <sect2>
       <title>Overriding the Default <acronym>AML</acronym></title>
 
       <para>The <acronym>BIOS</acronym> bytecode, known as
 	<acronym>ACPI</acronym> Machine Language
 	(<acronym>AML</acronym>), is compiled from a source language
 	called <acronym>ACPI</acronym> Source Language
 	(<acronym>ASL</acronym>).  The <acronym>AML</acronym> is
 	found in the table known as the Differentiated System
 	Description Table (<acronym>DSDT</acronym>).</para>
       <indexterm>
 	<primary><acronym>ACPI</acronym></primary>
 	<secondary><acronym>ASL</acronym></secondary>
       </indexterm>
 
       <para>The goal of &os; is for everyone to have working
 	<acronym>ACPI</acronym> without any user intervention.
 	Workarounds are still being developed for common mistakes made
 	by <acronym>BIOS</acronym>  vendors.  The &microsoft;
 	interpreter (<filename>acpi.sys</filename> and
 	<filename>acpiec.sys</filename>) does not strictly check for
 	adherence to the standard, and thus many
 	<acronym>BIOS</acronym> vendors who only test
 	<acronym>ACPI</acronym> under &windows; never fix their
 	<acronym>ASL</acronym>.  &os; developers continue to identify
 	and document which non-standard behavior is allowed by
 	&microsoft;'s interpreter and replicate it so that &os; can
 	work without forcing users to fix the
 	<acronym>ASL</acronym>.</para>
 
       <para>To help identify buggy behavior and possibly fix it
 	manually, a copy can be made of the system's
 	<acronym>ASL</acronym>.  To copy the system's
 	<acronym>ASL</acronym> to a specified file name, use
 	<command>acpidump</command> with <option>-t</option>, to show
 	the contents of the fixed tables, and <option>-d</option>, to
 	disassemble the <acronym>AML</acronym>:</para>
 
       <screen>&prompt.root; <userinput>acpidump -td > <replaceable>my.asl</replaceable></userinput></screen>
 
       <para>Some <acronym>AML</acronym> versions assume the user is
 	running &windows;.  To override this, set
 	<literal>hw.acpi.osname=<replaceable>"Windows
 	  2009"</replaceable></literal> in
 	<filename>/boot/loader.conf</filename>, using the most recent
 	&windows; version listed in the <acronym>ASL</acronym>.</para>
 
       <para>Other workarounds may require <filename>my.asl</filename>
 	to be customized.  If this file is edited, compile the new
 	<acronym>ASL</acronym> using the following command.  Warnings
 	can usually be ignored, but errors are bugs that will usually
 	prevent <acronym>ACPI</acronym> from working correctly.</para>
 
       <screen>&prompt.root; <userinput>iasl -f <replaceable>my.asl</replaceable></userinput></screen>
 
       <para>Including <option>-f</option> forces creation of the
 	<acronym>AML</acronym>, even if there are errors during
 	compilation.  Some errors, such as missing return statements,
 	are automatically worked around by the &os;
 	interpreter.</para>
 
       <para>The default output filename for <command>iasl</command> is
 	<filename>DSDT.aml</filename>.  Load this file instead of the
 	<acronym>BIOS</acronym>'s buggy copy, which is still present
 	in flash memory, by editing
 	<filename>/boot/loader.conf</filename> as follows:</para>
 
       <programlisting>acpi_dsdt_load="YES"
 acpi_dsdt_name="/boot/DSDT.aml"</programlisting>
 
       <para>Be sure to copy <filename>DSDT.aml</filename> to
 	<filename>/boot</filename>, then reboot the system.  If this
 	fixes the problem, send a &man.diff.1; of the old and new
 	<acronym>ASL</acronym> to &a.acpi.name; so that developers can
 	work around the buggy behavior in
 	<filename>acpica</filename>.</para>
     </sect2>
 
     <sect2 xml:id="ACPI-submitdebug">
       <info>
 	<title>Getting and Submitting Debugging Info</title>
 
 	<authorgroup>
 	  <author>
 	    <personname>
 	      <firstname>Nate</firstname>
 	      <surname>Lawson</surname>
 	    </personname>
 	    <contrib>Written by </contrib>
 	  </author>
 	</authorgroup>
 
 	<authorgroup>
 	  <author>
 	    <personname>
 	      <firstname>Peter</firstname>
 	      <surname>Schultz</surname>
 	    </personname>
 	    <contrib>With contributions from </contrib>
 	  </author>
 
 	  <author>
 	    <personname>
 	      <firstname>Tom</firstname>
 	      <surname>Rhodes</surname>
 	    </personname>
 	  </author>
 	</authorgroup>
       </info>
 
       <indexterm>
 	<primary>ACPI</primary>
 	<secondary>problems</secondary>
       </indexterm>
 
       <indexterm>
 	<primary>ACPI</primary>
 	<secondary>debugging</secondary>
       </indexterm>
 
       <para>The <acronym>ACPI</acronym> driver has a flexible
 	debugging facility.  A set of subsystems and the level of
 	verbosity can be specified.  The subsystems to debug are
 	specified as layers and are broken down into components
 	(<literal>ACPI_ALL_COMPONENTS</literal>) and
 	<acronym>ACPI</acronym> hardware support
 	(<literal>ACPI_ALL_DRIVERS</literal>).  The verbosity of
 	debugging output is specified as the level and ranges from
 	just report errors (<literal>ACPI_LV_ERROR</literal>) to
 	everything (<literal>ACPI_LV_VERBOSE</literal>).  The level is
 	a bitmask so multiple options can be set at once, separated by
 	spaces.  In practice, a serial console should be used to log
 	the output so it is not lost as the console message buffer
 	flushes.  A full list of the individual layers and levels is
 	found in &man.acpi.4;.</para>
 
       <para>Debugging output is not enabled by default.  To enable it,
 	add <literal>options ACPI_DEBUG</literal> to the custom kernel
 	configuration file if <acronym>ACPI</acronym> is compiled into
 	the kernel.  Add <literal>ACPI_DEBUG=1</literal> to
 	<filename>/etc/make.conf</filename> to enable it globally.  If
 	a module is used instead of a custom kernel, recompile just
 	the <filename>acpi.ko</filename> module as follows:</para>
 
       <screen>&prompt.root; <userinput>cd /sys/modules/acpi/acpi &amp;&amp; make clean &amp;&amp; make ACPI_DEBUG=1</userinput></screen>
 
       <para>Copy the compiled <filename>acpi.ko</filename> to
 	<filename>/boot/kernel</filename> and add the desired level
 	and layer to <filename>/boot/loader.conf</filename>.  The
 	entries in this example enable debug messages for all
 	<acronym>ACPI</acronym> components and hardware drivers and
 	output error messages at the least verbose level:</para>
 
       <programlisting>debug.acpi.layer="ACPI_ALL_COMPONENTS ACPI_ALL_DRIVERS"
 debug.acpi.level="ACPI_LV_ERROR"</programlisting>
 
       <para>If the required information is triggered by a specific
 	event, such as a suspend and then resume, do not modify
 	<filename>/boot/loader.conf</filename>.  Instead, use
 	<command>sysctl</command> to specify the layer and level after
 	booting and preparing the system for the specific event.  The
 	variables which can be set using <command>sysctl</command> are
 	named the same as the tunables in
 	<filename>/boot/loader.conf</filename>.</para>
 
       <indexterm>
 	<primary>ACPI</primary>
 	<secondary>problems</secondary>
       </indexterm>
 
       <para>Once the debugging information is gathered, it can be sent
 	to &a.acpi.name; so that it can be used by the &os;
 	<acronym>ACPI</acronym> maintainers to identify the root cause
 	of the problem and to develop a solution.</para>
 
       <note>
 	<para>Before submitting debugging information to this mailing
 	  list, ensure the latest <acronym>BIOS</acronym> version is
 	  installed and, if available, the embedded controller
 	  firmware version.</para>
       </note>
 
       <para>When submitting a problem report, include the following
 	information:</para>
 
       <itemizedlist>
 	<listitem>
 	  <para>Description of the buggy behavior, including system
 	    type, model, and anything that causes the bug to appear.
 	    Note as accurately as possible when the bug began
 	    occurring if it is new.</para>
 	</listitem>
 
 	<listitem>
 	  <para>The output of <command>dmesg</command> after running
 	    <command>boot -v</command>, including any error messages
 	    generated by the bug.</para>
 	</listitem>
 
 	<listitem>
 	  <para>The <command>dmesg</command> output from <command>boot
 	      -v</command> with <acronym>ACPI</acronym> disabled,
 	    if disabling <acronym>ACPI</acronym> helps to fix the
 	    problem.</para>
 	</listitem>
 
 	<listitem>
 	  <para>Output from <command>sysctl hw.acpi</command>.  This
 	    lists which features the system offers.</para>
 	</listitem>
 
 	<listitem>
 	  <para>The <acronym>URL</acronym> to a pasted version of the
 	    system's <acronym>ASL</acronym>.  Do
 	    <emphasis>not</emphasis> send the <acronym>ASL</acronym>
 	    directly to the list as it can be very large.  Generate a
 	    copy of the <acronym>ASL</acronym> by running this
 	    command:</para>
 
 	  <screen>&prompt.root; <userinput>acpidump -dt &gt; <replaceable>name</replaceable>-<replaceable>system</replaceable>.asl</userinput></screen>
 
 	  <para>Substitute the login name for
 	    <replaceable>name</replaceable> and manufacturer/model for
 	    <replaceable>system</replaceable>.  For example, use
 	    <filename>njl-FooCo6000.asl</filename>.</para>
 	</listitem>
       </itemizedlist>
 
       <para>Most &os; developers watch the &a.current;, but one should
 	submit problems to &a.acpi.name; to be sure it is seen.  Be
 	patient when waiting for a response.  If the bug is not
 	immediately apparent, submit a bug report.
 	When entering a <acronym>PR</acronym>,
 	include the same information as requested above.  This helps
 	developers to track the problem and resolve it.  Do not send a
 	<acronym>PR</acronym> without emailing &a.acpi.name; first as
 	it is likely that the problem has been reported before.</para>
     </sect2>
 
     <sect2 xml:id="ACPI-References">
       <title>References</title>
 
       <para>More information about <acronym>ACPI</acronym> may be
 	found in the following locations:</para>
 
       <itemizedlist>
 	<listitem>
 	  <para>The &os; <acronym>ACPI</acronym> Mailing List Archives
 	    (<uri
 	      xlink:href="https://lists.freebsd.org/pipermail/freebsd-acpi/">https://lists.freebsd.org/pipermail/freebsd-acpi/</uri>)</para>
 	</listitem>
 
 	<listitem>
 	  <para>The <acronym>ACPI</acronym> 2.0 Specification (<uri
 	      xlink:href="http://acpi.info/spec.htm">http://acpi.info/spec.htm</uri>)</para>
 	</listitem>
 
 	<listitem>
 	  <para>&man.acpi.4;, &man.acpi.thermal.4;, &man.acpidump.8;,
 	    &man.iasl.8;, and &man.acpidb.8;</para>
 	</listitem>
       </itemizedlist>
     </sect2>
   </sect1>
 </chapter>