Remove MAKEDEV reference
[ikiwiki.git] / docs / newhandbook / Configuration / index.mdwn
CommitLineData
c470a82e 1# Configuration and Tuning
2
3
4***Written by Chern Lee. Based on a tutorial written by Mike Smith. Also based on [tuning(7)](http://leaf.dragonflybsd.org/cgi/web-man?command#tuning&section7) written by Matt Dillon.***
5
ca31adac 6[[!toc levels=3]]
c470a82e 7
8
9##Synopsis
10
11
12
13One of the important aspects of DragonFly is system configuration. Correct system configuration will help prevent headaches during future upgrades. This chapter will explain much of the DragonFly configuration process, including some of the parameters which can be set to tune a DragonFly system.
14
15
16After reading this chapter, you will know:
17
18* How to efficiently work with file systems and swap partitions.
19
20* The basics of `rc.conf` configuration and `rc.d` startup systems.
21
22* How to configure and test a network card.
23
24* How to configure virtual hosts on your network devices.
25
26* How to use the various configuration files in `/etc`.
27
28* How to tune DragonFly using `sysctl` variables.
29
30* How to tune disk performance and modify kernel limitations.
31
32
33Before reading this chapter, you should:
34
35* Understand UNIX® and DragonFly basics ([Chapter 3](basics.html)).
36
37* Be familiar with the basics of kernel configuration/compilation ([Chapter 9](kernelconfig.html)).
38
39
40
41
42
43
44
45
46
47
48
49## Initial Configuration
50
51
52### Partition Layout
53
54
55#### Base Partitions
56
57When laying out file systems with [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&section=8) remember that hard drives transfer data faster from the outer tracks to the inner. Thus smaller and heavier-accessed file systems should be closer to the outside of the drive, while larger partitions like `/usr` should be placed toward the inner. It is a good idea to create partitions in a similar order to: root, swap, `/var`, `/usr`.
58<!-- XXX: on the advent of SSDs, do we really need to talk about this stuff? Who knows where on the platter the partitions land, considering that a hard disk has multiple platters? -->
59
60
61
62The size of `/var` reflects the intended machine usage. `/var` is used to hold mailboxes, log files, and printer spools. Mailboxes and log files can grow to unexpected sizes depending on how many users exist and how long log files are kept. Most users would never require a gigabyte, but remember that `/var/tmp` must be large enough to contain packages.
63
64
65
66The `/usr` partition holds much of the files required to support the system, the pkgsrc® collection (recommended) and the source code (optional). At least 2 gigabytes would be recommended for this partition.
67
68
69
70When selecting partition sizes, keep the space requirements in mind. Running out of space in one partition while barely using another can be a hassle.
71
72
73
74#### Swap Partition
75
76
77
78As a rule of thumb, the swap partition should be about double the size of system memory (RAM). For example, if the machine has 128 megabytes of memory, the swap file should be 256 megabytes. Systems with less memory may perform better with more swap. Less than 256 megabytes of swap is not recommended and memory expansion should be considered. The kernel's VM paging algorithms are tuned to perform best when the swap partition is at least two times the size of main memory. Configuring too little swap can lead to inefficiencies in the VM page scanning code and might create issues later if more memory is added.
79<!-- XXX: do we really recommend double the RAM for swap? IMHO the amount of RAM should be more than enough -->
80
81
82On larger systems with multiple SCSI disks (or multiple IDE disks operating on different controllers), it is recommend that a swap is configured on each drive (up to four drives). The swap partitions should be approximately the same size. The kernel can handle arbitrary sizes but internal data structures scale to 4 times the largest swap partition. Keeping the swap partitions near the same size will allow the kernel to optimally stripe swap space across disks. Large swap sizes are fine, even if swap is not used much. It might be easier to recover from a runaway program before being forced to reboot.
83
84
85
86#### Why Partition?
87
88
89
90Several users think a single large partition will be fine, but there are several reasons why this is a bad idea. First, each partition has different operational characteristics and separating them allows the file system to tune accordingly. For example, the root and `/usr` partitions are read-mostly, without much writing. While a lot of reading and writing could occur in `/var` and `/var/tmp`.
91
92By properly partitioning a system, fragmentation introduced in the smaller write heavy partitions will not bleed over into the mostly-read partitions. Keeping the write-loaded partitions closer to the disk's edge, will increase I/O performance in the partitions where it occurs the most. Now while I/O performance in the larger partitions may be needed, shifting them more toward the edge of the disk will not lead to a significant performance improvement over moving `/var` to the edge. Finally, there are safety concerns. A smaller, neater root partition which is mostly read-only has a greater chance of surviving a bad crash.
93<!-- XXX: again, same story about the edges of disks... -->
94
95
96
97CategoryHandbook
98
99CategoryHandbook-configuration
100
101
102
103
104
105## Core Configuration
106
107
108
109The principal location for system configuration information is within `/etc/rc.conf`. This file contains a wide range of configuration information, principally used at system startup to configure the system. Its name directly implies this; it is configuration information for the `rc*` files.
110
111
112
113An administrator should make entries in the `rc.conf` file to override the default settings from `/etc/defaults/rc.conf`. The defaults file should not be copied verbatim to `/etc` - it contains default values, not examples. All system-specific changes should be made in the `rc.conf` file itself.
114
115
116
117A number of strategies may be applied in clustered applications to separate site-wide configuration from system-specific configuration in order to keep administration overhead down. The recommended approach is to place site-wide configuration into another file, such as `/etc/rc.conf.site`, and then include this file into `/etc/rc.conf`, which will contain only system-specific information.
118
119
120
121As `rc.conf` is read by [sh(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=sh&section=1) it is trivial to achieve this. For example:
122
123* rc.conf:
124
125 hostname="node15.example.com"
126
127 network_interfaces="fxp0 lo0"
128
129 ifconfig_fxp0="inet 10.1.1.1"
130
131
132
133
134* rc.conf.site:
135
136 defaultrouter="10.1.1.254"
137
138 saver="daemon"
139
140 blanktime="100"
141
142
143
144
145
146The `rc.conf.site` file can then be distributed to every system using `rsync` or a similar program, while the `rc.conf` file remains unique.
147
148
149
150Upgrading the system using `make world` will not overwrite the `rc.conf` file, so system configuration information will not be lost.
151
152
153CategoryHandbook
154
155CategoryHandbook-configuration
156
157
158
159
160## Application Configuration
161
162
163
164Typically, installed applications have their own configuration files, with their own syntax, etc. It is important that these files be kept separate from the base system, so that they may be easily located and managed by the package management tools.
165
166
167
168Typically, these files are installed in `/usr/pkg/etc`. In the case where an application has a large number of configuration files, a subdirectory will be created to hold them.
169
170
171
172Normally, when a port or package is installed, sample configuration files are also installed. These are usually identified with a `.default` suffix. If there are no existing configuration files for the application, they will be created by copying the `.default` files.
173
174
175
176For example, consider the contents of the directory `/usr/pkg/etc/httpd`:
177
178
179
180
181
182 total 90
183
184 -rw-r--r-- 1 root wheel - 34K Jan 11 12:04 httpd.conf
185
186 -rw-r--r-- 1 root wheel - 13K Jan 11 12:02 magic
187
188 -rw-r--r-- 1 root wheel - 28K Jan 11 12:02 mime.types
189
190 -rw-r--r-- 1 root wheel - 11K Jan 11 12:02 ssl.conf
191
192
193
194
195
196
197
198
199
200
201## Starting Services
202
203
204
205It is common for a system to host a number of services. These may be started in several different fashions, each having different advantages.
206
207
208
209Software installed from a port or the packages collection will often place a script in `/usr/pkg/share/examples/rc.d` which is invoked at system startup with a `start` argument, and at system shutdown with a `stop` argument. This is the recommended way for starting system-wide services that are to be run as `root`, or that expect to be started as `root`. These scripts are registered as part of the installation of the package, and will be removed when the package is removed.
210
211
212A generic startup script in `/usr/pkg/share/examples/rc.d` looks like:
213
214
215
216
217
218 #!/bin/sh
219
220 echo -n ' FooBar'
221
222
223
224 case "$1" in
225
226 start)
227
228 /usr/pkg/bin/foobar
229
230 ;;
231
232 stop)
233
234 kill -9 `cat /var/run/foobar.pid`
235
236 ;;
237
238
239*)
240
241 echo "Usage: `basename $0` {start|stop}" >&2
242
243 exit 64
244
245 ;;
246
247 esac
248
249
250
251 exit 0
252
253
254
255
256
257
258<!-- XXX: I don't think we actually look in /usr/pkg/share/examples/rc.d -->
259
260The startup scripts of DragonFly will look in `/usr/pkg/share/examples/rc.d` for scripts that have an `.sh` extension and are executable by `root`. Those scripts that are found are called with an option `start` at startup, and `stop` at shutdown to allow them to carry out their purpose. So if you wanted the above sample script to be picked up and run at the proper time during system startup, you should save it to a file called `FooBar.sh` in `/usr/local/etc/rc.d` and make sure it is executable. You can make a shell script executable with [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section=1) as shown below:
261
262
263
264
265
266 # chmod 755 "FooBar.sh"
267
268
269
270
271
272Some services expect to be invoked by [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) when a connection is received on a suitable port. This is common for mail reader servers (POP and IMAP, etc.). These services are enabled by editing the file `/etc/inetd.conf`. See [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) for details on editing this file.
273
274
275
276Some additional system services may not be covered by the toggles in `/etc/rc.conf`. These are traditionally enabled by placing the command(s) to invoke them in `/etc/rc.local` (which does not exist by default). Note that `rc.local` is generally regarded as the location of last resort; if there is a better place to start a service, do it there.
277
278
279
280 **Note:** Do ***not*** place any commands in `/etc/rc.conf`. To start daemons, or run any commands at boot time, place a script in `/usr/pkg/share/examples/rc.d` instead.
281
282
283
284It is also possible to use the [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section=8) daemon to start system services. This approach has a number of advantages, not least being that because [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section=8) runs these processes as the owner of the `crontab`, services may be started and maintained by non-`root` users.
285
286
287
288This takes advantage of a feature of [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section=8): the time specification may be replaced by `@reboot`, which will cause the job to be run when [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section=8) is started shortly after system boot.
289
290
291
292
293
294
295
296CategoryHandbook
297
298CategoryHandbook-configuration
299
300
301
302
303
304
305
306## Configuring the cron Utility
307
308<!-- XXX: can't really comment on this. someone please revise it -->
309
310
311***Contributed by Tom Rhodes. ***
312
313
314
315One of the most useful utilities in DragonFly is [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section=8). The `cron` utility runs in the background and constantly checks the `/etc/crontab` file. The `cron` utility also checks the `/var/cron/tabs` directory, in search of new `crontab` files. These `crontab` files store information about specific functions which `cron` is supposed to perform at certain times.
316
317
318
319The `cron` utility uses two different types of configuration files, the system crontab and user crontabs. The only difference between these two formats is the sixth field. In the system crontab, the sixth field is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user. In a user crontab, the sixth field is the command to run, and all commands run as the user who created the crontab; this is an important security feature.
320
321
322
323 **Note:** User crontabs allow individual users to schedule tasks without the need for root privileges. Commands in a user's crontab run with the permissions of the user who owns the crontab.
324
325
326
327The `root` user can have a user crontab just like any other user. This one is different from `/etc/crontab` (the system crontab). Because of the system crontab, there's usually no need to create a user crontab for `root`.
328
329
330
331Let us take a look at the `/etc/crontab` file (the system crontab):
332
333
334
335
336
337 # /etc/crontab - root's crontab for DragonFly
338
339 #
340
341 # (1)
342
343 #
344
345 SHELL=/bin/sh
346
347 PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin (2)
348
349 HOME=/var/log
350
351 #
352
353 #
354
355 #minute hour mday month wday who command (3)
356
357 #
358
359 #
360
361
362 */5 * * * * root /usr/libexec/atrun (4)
363
364
365
366
367
368 1. Like most DragonFly configuration files, the `#` character represents a comment. 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.
369
370
371
372 1. First, the environment must be defined. The equals (`=`) character is used to define any environment settings, as with this example where it is used for the `SHELL`, `PATH`, and `HOME` options. If the shell line is omitted, `cron` will use the default, which is `sh`. If the `PATH` variable is omitted, no default will be used and file locations will need to be absolute. If `HOME` is omitted, `cron` will use the invoking users home directory.
373
374
375
376 1. This line defines a total of seven fields. Listed here are the values `minute`, `hour`, `mday`, `month`, `wday`, `who`, and `command`. These are almost all self explanatory. `minute` is the time in minutes the command will be run. `hour` is similar to the `minute` option, just in hours. `mday` stands for day of the month. `month` is similar to `hour` and `minute`, as it designates the month. The `wday` option stands for day of the week. All these fields must be numeric values, and follow the twenty-four hour clock. The `who` field is special, and only exists in the `/etc/crontab` file. This field specifies which user the command should be run as. When a user installs his or her `crontab` file, they will not have this option. Finally, the `command` option is listed. This is the last field, so naturally it should designate the command to be executed.
377
378
379
380 1. This last line will define the values discussed above. Notice here we have a `*/5` listing, followed by several more `*` characters. These `*` characters mean ***first-last***, and can be interpreted as ***every*** time. So, judging by this line, it is apparent that the `atrun` command is to be invoked by `root` every five minutes regardless of what day or month it is. For more information on the `atrun` command, see the [atrun(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=atrun&section=8) manual page.Commands can have any number of flags passed to them; however, commands which extend to multiple lines need to be broken with the backslash ***\*** continuation character.
381
382
383
384This is the basic set up for every `crontab` file, although there is one thing different about this one. Field number six, where we specified the username, only exists in the system `/etc/crontab` file. This field should be omitted for individual user `crontab` files.
385
386
387
388### Installing a Crontab
389
390
391
392 **Important:** You must not use the procedure described here to edit/install the system crontab. Simply use your favorite editor: the `cron` utility will notice that the file has changed and immediately begin using the updated version. If you use `crontab` to load the `/etc/crontab` file you may get an error like `root: not found` because of the system crontab's additional user field.
393
394
395
396To install a freshly written user `crontab`, first use your favorite editor to create a file in the proper format, and then use the `crontab` utility. The most common usage is:
397
398
399
400
401
402 % crontab crontab-file
403
404
405
406
407
408In this example, `crontab-file` is the filename of a `crontab` that was previously created.
409
410
411
412There is also an option to list installed `crontab` files: just pass the `-l` option to `crontab` and look over the output.
413
414
415
416For users who wish to begin their own crontab file from scratch, without the use of a template, the `crontab -e` option is available. This will invoke the selected editor with an empty file. When the file is saved, it will be automatically installed by the `crontab` command.
417
418
419
420If you later want to remove your user `crontab` completely, use `crontab` with the `-r` option.
421
422
423
424
425
426
427
428
429## Using rc under DragonFly
430
431
432
433***Contributed by Tom Rhodes. ***
434
435
436
437DragonFly uses the NetBSD® `rc.d` system for system initialization. Users should notice the files listed in the `/etc/rc.d` directory. Many of these files are for basic services which can be controlled with the `start`, `stop`, and `restart` options. For instance, [sshd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sshd&section=8&manpath=OpenBSD+3.3) can be restarted with the following command:
438
439
440
441
442
443 # /etc/rc.d/sshd restart
444
445
446
447
448
449This procedure is similar for other services. Of course, services are usually started automatically as specified in [rc.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc.conf&section=5). For example, enabling the Network Address Translation daemon at startup is as simple as adding the following line to `/etc/rc.conf`:
450
451
452 natd_enable="YES"
453
454
455
456If a `natd_enable="NO"` line is already present, then simply change the `NO` to `YES`. The rc scripts will automatically load any other dependent services during the next reboot, as described below.
457
458
459Another way to add services to the automatic startup/shutdown is to type, for example for `natd`,
460
461 # rcenable natd
462
463
464Since the `rc.d` system is primarily intended to start/stop services at system startup/shutdown time, the standard `start`, `stop` and `restart` options will only perform their action if the appropriate `/etc/rc.conf` variables are set. For instance the above `sshd restart` command will only work if `sshd_enable` is set to `YES` in `/etc/rc.conf`. To `start`, `stop` or `restart` a service regardless of the settings in `/etc/rc.conf`, the commands should be prefixed with ***force***. For instance to restart `sshd` regardless of the current `/etc/rc.conf` setting, execute the following command:
465
466
467
468
469
470 # /etc/rc.d/sshd forcerestart
471
472
473
474
475
476It is easy to check if a service is enabled in `/etc/rc.conf` by running the appropriate `rc.d` script with the option `rcvar`. Thus, an administrator can check that `sshd` is in fact enabled in `/etc/rc.conf` by running:
477
478
479
480
481
482 # /etc/rc.d/sshd rcvar
483
484 # sshd
485
486 $sshd_enable=YES
487
488
489
490
491
492 **Note:** The second line (`# sshd`) is the output from the `rc.d` script, not a `root` prompt.
493
494
495
496To determine if a service is running, a `status` option is available. For instance to verify that `sshd` is actually started:
497
498
499
500
501
502 # /etc/rc.d/sshd status
503
504 sshd is running as pid 433.
505
506
507
508
509
510It is also possible to `reload` a service. This will attempt 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 `SIGHUP` signal.
511
512
513
514The **rcNG** structure is used both for network services and system initialization. Some services are run only at boot; and the RCNG system is what triggers them.
515
516
517
518Many system services depend on other services to function properly. For example, NIS and other RPC-based services may fail to start until after the `rpcbind` (portmapper) 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 [rcorder(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rcorder&section=8) program is then used to parse these comments during system initialization to determine the order in which system services should be invoked to satisfy the dependencies. The following words may be included at the top of each startup file:
519
520
521
522
523* `PROVIDE`: Specifies the services this file provides.
524
525
526* `REQUIRE`: Lists services which are required for this service. This file will run ***after*** the specified services.
527
528
529* `BEFORE`: Lists services which depend on this service. This file will run ***before*** the specified services.
530
531
532* KEYWORD: When [rcorder(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rcorder&section=8) uses the `-k` option, then only the rc.d files matching this keyword are used. [(1)](#FTN.AEN4751) For example, when using `-k shutdown`, only the `rc.d` scripts defining the `shutdown` keyword are used.
533
534 With the `-s` option, [rcorder(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rcorder&section=8) will skip any `rc.d` script defining the corresponding keyword to skip. For example, scripts defining the `nostart` keyword are skipped at boot time.
535
536
537
538By using this method, an administrator can easily control system services without the hassle of ***runlevels*** like some other UNIX® operating systems.
539
540
541
542Additional information about the DragonFly `rc.d` system can be found in the [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc&section=8), [rc.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc.conf&section=5), and [rc.subr(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc.subr&section=8) manual pages.
543
544### Using DragonFly's rcrun(8)
545
546Besides the methods described above DragonFly supports [rcrun(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rcrun&section=8) to control rc(8) scripts. [rcrun(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rcrun&section=8) provides a number of command for controlling rc(8)
547
548scripts. The ***start***, ***forcestart***, ***faststart***, ***stop***, ***restart***, and ***rcvar*** commands are just passed to the scripts. See rc(8) for more information on these commands.
549
550
551
552The remaining commands are:
553
554
555
556[[!table data="""
557 **disable** | Sets the corresponding `_enable` variable in rc.conf(5) to ***NO*** and runs the stop command.
558 **enable** | Sets the corresponding `_enable` variable in rc.conf(5) to ***YES*** and runs the start command.
559 **list** | Shows the status of the specified scripts. If no argument is specified, the status of all scripts is shown. |
560
561"""]]
562
563
564To enable the [dntpd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dntpd&section=8) service, you can use:
565
566 # rcenable dntpd
567
568
569
570To check if [dntpd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dntpd&section=8) is running you can use the following command:
571
572
573
574 # rclist dntpd
575
576 rcng_dntpd=stopped
577
578
579
580To start [dntpd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dntpd&section=8):
581
582
583
584
585
586 # rcstart dntpd
587
588 Running /etc/rc.d/dntpd start
589
590 Starting dntpd.
591
592
593
594Restart and stop works the same way:
595
596
597
598 # rcrestart dntpd
599
600 Stopping dntpd.
601
602 Starting dntpd.
603
604
605
606 # rcstop dntpd
607
608 Stopping dntpd.
609
610
611
612
613
614If a service is not enabled in `/etc/rc.conf`, but you want it start anyway, execute the following:
615
616
617
618 # rcforce dntpd
619
620 Running /etc/rc.d/dntpd forcestart
621
622 Starting dntpd.
623
624
625
626#### Notes
627
628
629
630[[!table data="""
631<tablestyle="width:100%"> [(1)](configtuning-rcng.html#AEN4751) | Previously this was used to define *BSD dependent features.
632| |
633
634"""]]
635
636
637
638
639
640
641
642## Setting Up Network Interface Cards
643
644
645
646***Contributed by Marc Fonvieille. ***
647
648
649
650Nowadays we can not think about a computer without thinking about a network connection. Adding and configuring a network card is a common task for any DragonFly administrator.
651
652
653
654### Locating the Correct Driver
655
656
657
658Before you begin, you should know the model of the card you have, the chip it uses, and whether it is a PCI or ISA card. DragonFly supports a wide variety of both PCI and ISA cards. Check the Hardware Compatibility List for your release to see if your card is supported.
659
660
661
662Once you are sure your card is supported, you need to determine the proper driver for the card. The file `/usr/src/sys/i386/conf/LINT` will give you the list of network interfaces drivers with some information about the supported chipsets/cards. If you have doubts about which driver is the correct one, read the manual page of the driver. The manual page will give you more information about the supported hardware and even the possible problems that could occur.
663
664
665
666If you own a common card, most of the time you will not have to look very hard for a driver. Drivers for common network cards are present in the `GENERIC` kernel, so your card should show up during boot, like so:
667
668
669
670
671
672 dc0: <82c169 PNIC 10/100BaseTX> port 0xa000-0xa0ff mem 0xd3800000-0xd38
673
674 000ff irq 15 at device 11.0 on pci0
675
676 dc0: Ethernet address: 00:a0:cc:da:da:da
677
678 miibus0: <MII bus> on dc0
679
680 ukphy0: <Generic IEEE 802.3u media interface> on miibus0
681
682 ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
683
684 dc1: <82c169 PNIC 10/100BaseTX> port 0x9800-0x98ff mem 0xd3000000-0xd30
685
686 000ff irq 11 at device 12.0 on pci0
687
688 dc1: Ethernet address: 00:a0:cc:da:da:db
689
690 miibus1: <MII bus> on dc1
691
692 ukphy1: <Generic IEEE 802.3u media interface> on miibus1
693
694 ukphy1: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
695
696
697
698
699
700In this example, we see that two cards using the [dc(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=dc&section=4) driver are present on the system.
701
702
703
704To use your network card, you will need to load the proper driver. This may be accomplished in one of two ways. The easiest way is to simply load a kernel module for your network card with [kldload(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=kldload&section=8). A module is not available for all network card drivers (ISA cards and cards using the [ed(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=ed&section=4) driver, for example). Alternatively, you may statically compile the support for your card into your kernel. Check `/usr/src/sys/i386/conf/LINT` and the manual page of the driver to know what to add in your kernel configuration file. For more information about recompiling your kernel, please see [kernelconfig.html Chapter 9]. If your card was detected at boot by your kernel (`GENERIC`) you do not have to build a new kernel.
705
706
707
708### Configuring the Network Card
709
710
711
712Once the right driver is loaded for the network card, the card needs to be configured. As with many other things, the network card may have been configured at installation time.
713
714
715
716To display the configuration for the network interfaces on your system, enter the following command:
717
718
719
720
721
722 % ifconfig
723
724 dc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
725
726 inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255
727
728 ether 00:a0:cc:da:da:da
729
730 media: Ethernet autoselect (100baseTX <full-duplex>)
731
732 status: active
733
734 dc1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
735
736 inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
737
738 ether 00:a0:cc:da:da:db
739
740 media: Ethernet 10baseT/UTP
741
742 status: no carrier
743
744 lp0: flags=8810<POINTOPOINT,SIMPLEX,MULTICAST> mtu 1500
745
746 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
747
748 inet 127.0.0.1 netmask 0xff000000
749
750 tun0: flags=8010<POINTOPOINT,MULTICAST> mtu 1500
751
752
753
754
755
756 **Note:** Note that entries concerning IPv6 (`inet6` etc.) were omitted in this example.
757
758
759
760In this example, the following devices were displayed:
761
762
763
764
765* `dc0`: The first Ethernet interface
766
767
768* `dc1`: The second Ethernet interface
769
770
771* `lp0`: The parallel port interface
772
773
774* `lo0`: The loopback device
775
776
777* `tun0`: The tunnel device used by **ppp**
778
779
780
781DragonFly uses the driver name followed by the order in which one the card is detected at the kernel boot to name the network card, starting the count at zero. For example, `sis2` would be the third network card on the system using the [sis(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=sis&section=4) driver.
782
783
784
785In this example, the `dc0` device is up and running. The key indicators are:
786
787
788
789 1. `UP` means that the card is configured and ready.
790
791 1. The card has an Internet (`inet`) address (in this case `192.168.1.3`).
792
793 1. It has a valid subnet mask (`netmask`; `0xffffff00` is the same as `255.255.255.0`).
794
795 1. It has a valid broadcast address (in this case, `192.168.1.255`).
796
797 1. The MAC address of the card (`ether`) is `00:a0:cc:da:da:da`
798
799 1. The physical media selection is on autoselection mode (`media: Ethernet autoselect (100baseTX <full-duplex>)`). We see that `dc1` was configured to run with `10baseT/UTP` media. For more information on available media types for a driver, please refer to its manual page.
800
801 1. The status of the link (`status`) is `active`, i.e. the carrier is detected. For `dc1`, we see `status: no carrier`. This is normal when an Ethernet cable is not plugged into the card.
802
803
804
805If the [ifconfig(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=ifconfig&section=8) output had shown something similar to:
806
807
808
809
810
811 dc0: flags=8843<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
812
813 ether 00:a0:cc:da:da:da
814
815
816
817
818
819it would indicate the card has not been configured.
820
821
822
823To configure your card, you need `root` privileges. The network card configuration can be done from the command line with [ifconfig(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=ifconfig&section=8) as root.
824
825
826
827
828
829 # ifconfig dc0 inet 192.168.1.3 netmask 255.255.255.0
830
831
832
833
834
835Manually configuring the care has the disadvantage that you would have to do it after each reboot of the system. The file `/etc/rc.conf` is where to add the network card's configuration.
836
837
838
839Open `/etc/rc.conf` in your favorite editor. You need to add a line for each network card present on the system, for example in our case, we added these lines:
840
841
842
843
844
845 ifconfig_dc0="inet 192.168.1.3 netmask 255.255.255.0"
846
847 ifconfig_dc1="inet 10.0.0.1 netmask 255.255.255.0 media 10baseT/UTP"
848
849
850
851
852
853You have to replace `dc0`, `dc1`, and so on, with the correct device for your cards, and the addresses with the proper ones. You should read the card driver and [ifconfig(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#ifconfig&section8) manual pages for more details about the allowed options and also [rc.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc.conf&section=5) manual page for more information on the syntax of `/etc/rc.conf`.
854
855
856
857If you configured the network during installation, some lines about the network card(s) may be already present. Double check `/etc/rc.conf` before adding any lines.
858
859
860
861You will also have to edit the file `/etc/hosts` to add the names and the IP addresses of various machines of the LAN, if they are not already there. For more information please refer to [hosts(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=hosts&section=5) and to `/usr/share/examples/etc/hosts`.
862
863
864
865### Testing and Troubleshooting
866
867
868
869Once you have made the necessary changes in `/etc/rc.conf`, you should reboot your system. This will allow the change(s) to the interface(s) to be applied, and verify that the system restarts without any configuration errors.
870
871
872
873Once the system has been rebooted, you should test the network interfaces.
874
875
876
877#### Testing the Ethernet Card
878
879
880
881To verify that an Ethernet card is configured correctly, you have to try two things. First, ping the interface itself, and then ping another machine on the LAN.
882
883
884
885First test the local interface:
886
887
888
889
890
891 % ping -c5 192.168.1.3
892
893 PING 192.168.1.3 (192.168.1.3): 56 data bytes
894
895 64 bytes from 192.168.1.3: icmp_seq#0 ttl64 time=0.082 ms
896
897 64 bytes from 192.168.1.3: icmp_seq#1 ttl64 time=0.074 ms
898
899 64 bytes from 192.168.1.3: icmp_seq#2 ttl64 time=0.076 ms
900
901 64 bytes from 192.168.1.3: icmp_seq#3 ttl64 time=0.108 ms
902
903 64 bytes from 192.168.1.3: icmp_seq#4 ttl64 time=0.076 ms
904
905
906
907 --- 192.168.1.3 ping statistics ---
908
909 5 packets transmitted, 5 packets received, 0% packet loss
910
911 round-trip min/avg/max/stddev = 0.074/0.083/0.108/0.013 ms
912
913
914
915
916
917Now we have to ping another machine on the LAN:
918
919
920
921
922
923 % ping -c5 192.168.1.2
924
925 PING 192.168.1.2 (192.168.1.2): 56 data bytes
926
927 64 bytes from 192.168.1.2: icmp_seq#0 ttl64 time=0.726 ms
928
929 64 bytes from 192.168.1.2: icmp_seq#1 ttl64 time=0.766 ms
930
931 64 bytes from 192.168.1.2: icmp_seq#2 ttl64 time=0.700 ms
932
933 64 bytes from 192.168.1.2: icmp_seq#3 ttl64 time=0.747 ms
934
935 64 bytes from 192.168.1.2: icmp_seq#4 ttl64 time=0.704 ms
936
937
938
939 --- 192.168.1.2 ping statistics ---
940
941 5 packets transmitted, 5 packets received, 0% packet loss
942
943 round-trip min/avg/max/stddev = 0.700/0.729/0.766/0.025 ms
944
945
946
947
948
949You could also use the machine name instead of `192.168.1.2` if you have set up the `/etc/hosts` file.
950
951
952
953#### Troubleshooting
954
955
956
957Troubleshooting hardware and software configurations is always a pain, and a pain which can be alleviated by checking the simple things first. Is your network cable plugged in? Have you properly configured the network services? Did you configure the firewall correctly? Is the card you are using supported by DragonFly? Always check the hardware notes before sending off a bug report. Update your version of DragonFly to the latest PREVIEW version. Check the mailing list archives, or perhaps search the Internet.
958
959
960
961If the card works, yet performance is poor, it would be worthwhile to read over the [tuning(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=tuning&section=7) manual page. You can also check the network configuration as incorrect network settings can cause slow connections.
962
963
964
965Some users experience one or two ***device timeouts***, which is normal for some cards. If they continue, or are bothersome, you may wish to be sure the device is not conflicting with another device. Double check the cable connections. Perhaps you may just need to get another card.
966
967
968
969At times, users see a few ***`watchdog timeout`*** errors. The first thing to do here is to check your network cable. Many cards require a PCI slot which supports Bus Mastering. On some old motherboards, only one PCI slot allows it (usually slot 0). Check the network card and the motherboard documentation to determine if that may be the problem.
970
971
972
973***`No route to host`*** 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 `netstat -rn` and make sure there is a valid route to the host you are trying to reach. If there is not, read on to [advanced-networking.html Chapter 19].
974
975
976
977***`ping: sendto: Permission denied`*** error messages are often caused by a misconfigured firewall. If `ipfw` is enabled in the kernel but no rules have been defined, then the default policy is to deny all traffic, even ping requests! Read on to [firewalls.html Section 10.7] for more information.
978
979
980
981Sometimes performance of the card is poor, or below average. In these cases it is best to set the media selection mode from `autoselect` to the correct media selection. While this usually works for most hardware, it may not resolve this issue for everyone. Again, check all the network settings, and read over the [tuning(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=tuning&section=7) manual page.
982
983
984
985
986
987
988
989
990
991## Virtual Hosts
992
993
994
995A very common use of DragonFly 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.
996
997
998
999A given network interface has one ***real*** address, and may have any number of ***alias*** addresses. These aliases are normally added by placing alias entries in `/etc/rc.conf`.
1000
1001
1002
1003An alias entry for the interface `fxp0` looks like:
1004
1005
1006
1007
1008
1009 ifconfig_fxp0_alias0="inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"
1010
1011
1012
1013
1014
1015Note that alias entries must start with `alias0` and proceed upwards in order, (for example, `_alias1`, `_alias2`, and so on). The configuration process will stop at the first missing number.
1016
1017
1018
1019The calculation of alias netmasks is important, but fortunately quite simple. 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 `1`s (expressed as either `255.255.255.255` or `0xffffffff`).
1020
1021
1022
1023For example, consider the case where the `fxp0` interface is connected to two networks, the `10.1.1.0` network with a netmask of `255.255.255.0` and the `202.0.75.16` network with a netmask of `255.255.255.240`. We want the system to appear at `10.1.1.1` through `10.1.1.5` and at `202.0.75.17` through `202.0.75.20`. As noted above, only the first address in a given network range (in this case, `10.0.1.1` and `202.0.75.17`) should have a real netmask; all the rest (`10.1.1.2` through `10.1.1.5` and `202.0.75.18` through `202.0.75.20`) must be configured with a netmask of `255.255.255.255`.
1024
1025
1026
1027The following entries configure the adapter correctly for this arrangement:
1028
1029
1030
1031
1032
1033 ifconfig_fxp0="inet 10.1.1.1 netmask 255.255.255.0"
1034
1035 ifconfig_fxp0_alias0="inet 10.1.1.2 netmask 255.255.255.255"
1036
1037 ifconfig_fxp0_alias1="inet 10.1.1.3 netmask 255.255.255.255"
1038
1039 ifconfig_fxp0_alias2="inet 10.1.1.4 netmask 255.255.255.255"
1040
1041 ifconfig_fxp0_alias3="inet 10.1.1.5 netmask 255.255.255.255"
1042
1043 ifconfig_fxp0_alias4="inet 202.0.75.17 netmask 255.255.255.240"
1044
1045 ifconfig_fxp0_alias5="inet 202.0.75.18 netmask 255.255.255.255"
1046
1047 ifconfig_fxp0_alias6="inet 202.0.75.19 netmask 255.255.255.255"
1048
1049 ifconfig_fxp0_alias7="inet 202.0.75.20 netmask 255.255.255.255"
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059CategoryHandbook
1060
1061CategoryHandbook-configuration
1062
1063
1064
1065
1066
1067
1068## Configuration Files
1069
1070### /etc Layout
1071
1072There are a number of directories in which configuration information is kept. These include:
1073
1074[[!table data="""
1075 `/etc` | Generic system configuration information; data here is system-specific.
1076 `/etc/defaults` | Default versions of system configuration files.
1077 `/etc/mail` | Extra [sendmail(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendmail&section=8) configuration, other MTA configuration files.
1078 `/etc/ppp` | Configuration for both user- and kernel-ppp programs.
1079 `/etc/namedb` | Default location for [named(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=named&section=8) data. Normally `named.conf` and zone files are stored here.
1080 `/usr/local/etc` | Configuration files for installed applications. May contain per-application subdirectories.
1081 `/usr/local/etc/rc.d` | Start/stop scripts for installed applications.
1082 `/var/db` | Automatically generated system-specific database files, such as the package database, the locate database, and so on |
1083
1084"""]]
1085
1086
1087
1088### Hostnames
1089
1090#### /etc/resolv.conf
1091
1092`/etc/resolv.conf` dictates how DragonFly's resolver accesses the Internet Domain Name System (DNS).
1093
1094
1095
1096The most common entries to `resolv.conf` are:
1097
1098[[!table data="""
1099 `nameserver` | The IP address of a name server the resolver should query. The servers are queried in the order listed with a maximum of three.
1100 `search` | Search list for hostname lookup. This is normally determined by the domain of the local hostname.
1101 `domain` | The local domain name. |
1102
1103"""]]
1104
1105
1106
1107A typical `resolv.conf`:
1108
1109
1110
1111
1112
1113 search example.com
1114
1115 nameserver 147.11.1.11
1116
1117 nameserver 147.11.100.30
1118
1119
1120
1121 **Note:** Only one of the `search` and `domain` options should be used.
1122
1123
1124
1125If you are using DHCP, [dhclient(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dhclient&section=8) usually rewrites `resolv.conf` with information received from the DHCP server.
1126
1127
1128
1129#### /etc/hosts
1130
1131`/etc/hosts` is a simple text database reminiscent of the old Internet. It works in conjunction with DNS and NIS providing name to IP address mappings. Local computers connected via a LAN can be placed in here for simplistic naming purposes instead of setting up a [named(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=named&section=8) server. Additionally, `/etc/hosts` can be used to provide a local record of Internet names, reducing the need to query externally for commonly accessed names.
1132
1133
1134
1135
1136
1137 #
1138
1139 #
1140
1141 # Host Database
1142
1143 # This file should contain the addresses and aliases
1144
1145 # for local hosts that share this file.
1146
1147 # In the presence of the domain name service or NIS, this file may
1148
1149 # not be consulted at all; see /etc/nsswitch.conf for the resolution order.
1150
1151 #
1152
1153 #
1154
1155 ::1 localhost localhost.my.domain myname.my.domain
1156
1157 127.0.0.1 localhost localhost.my.domain myname.my.domain
1158
1159 #
1160
1161 # Imaginary network.
1162
1163 #10.0.0.2 myname.my.domain myname
1164
1165 #10.0.0.3 myfriend.my.domain myfriend
1166
1167 #
1168
1169 # According to RFC 1918, you can use the following IP networks for
1170
1171 # private nets which will never be connected to the Internet:
1172
1173 #
1174
1175 # 10.0.0.0 - 10.255.255.255
1176
1177 # 172.16.0.0 - 172.31.255.255
1178
1179 # 192.168.0.0 - 192.168.255.255
1180
1181 #
1182
1183 # In case you want to be able to connect to the Internet, you need
1184
1185 # real official assigned numbers. PLEASE PLEASE PLEASE do not try
1186
1187 # to invent your own network numbers but instead get one from your
1188
1189 # network provider (if any) or from the Internet Registry (ftp to
1190
1191 # rs.internic.net, directory `/templates').
1192
1193 #
1194
1195
1196
1197`/etc/hosts` takes on the simple format of:
1198
1199
1200
1201
1202
1203 [Internet address] [official hostname] [alias1] [alias2] ...
1204
1205
1206
1207For example:
1208
1209
1210
1211
1212
1213 10.0.0.1 myRealHostname.example.com myRealHostname foobar1 foobar2
1214
1215
1216
1217Consult [hosts(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=hosts&section=5) for more information.
1218
1219
1220
1221### Log File Configuration
1222
1223#### syslog.conf
1224
1225`syslog.conf` is the configuration file for the [syslogd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=syslogd&section=8) program. It indicates which types of `syslog` messages are logged to particular log files.
1226
1227
1228
1229
1230
1231 #
1232
1233 #
1234
1235 # Spaces ARE valid field separators in this file. However,
1236
1237 # other *nix-like systems still insist on using tabs as field
1238
1239 # separators. If you are sharing this file between systems, you
1240
1241 # may want to use only tabs as field separators here.
1242
1243 # Consult the syslog.conf(5) manual page.
1244
1245
1246*.err;kern.debug;auth.notice;mail.crit /dev/console
1247
1248 *.notice;kern.debug;lpr.info;mail.crit;news.err /var/log/messages
1249
1250
1251 security.* /var/log/security
1252
1253 mail.info /var/log/maillog
1254
1255 lpr.info /var/log/lpd-errs
1256
1257 cron.* /var/log/cron
1258
1259
1260*.err root
1261
1262 *.notice;news.err root
1263
1264 *.alert root
1265
1266 *.emerg *
1267
1268
1269 # uncomment this to log all writes to /dev/console to /var/log/console.log
1270
1271 #console.info /var/log/console.log
1272
1273 # uncomment this to enable logging of all log messages to /var/log/all.log
1274
1275 #*.* /var/log/all.log
1276
1277 # uncomment this to enable logging to a remote log host named loghost
1278
1279 #*.* @loghost
1280
1281 # uncomment these if you're running inn
1282
1283 # news.crit /var/log/news/news.crit
1284
1285 # news.err /var/log/news/news.err
1286
1287 # news.notice /var/log/news/news.notice
1288
1289 !startslip
1290
1291
1292*.* /var/log/slip.log
1293
1294 !ppp
1295
1296
1297*.* /var/log/ppp.log
1298
1299
1300
1301Consult the [syslog.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=syslog.conf&section=5) manual page for more information.
1302
1303
1304
1305#### newsyslog.conf
1306
1307`newsyslog.conf` is the configuration file for [newsyslog(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=newsyslog&section=8), a program that is normally scheduled to run by [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section=8). [newsyslog(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=newsyslog&section=8) determines when log files require archiving or rearranging. `logfile` is moved to `logfile.0`, `logfile.0` is moved to `logfile.1`, and so on. Alternatively, the log files may be archived in [gzip(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=gzip&section=1) format causing them to be named: `logfile.0.gz`, `logfile.1.gz`, and so on.
1308
1309
1310
1311`newsyslog.conf` indicates which log files are to be managed, how many are to be kept, and when they are to be touched. Log files can be rearranged and/or archived when they have either reached a certain size, or at a certain periodic time/date.
1312
1313
1314
1315
1316
1317 # configuration file for newsyslog
1318
1319 #
1320
1321 #
1322
1323 # filename [owner:group] mode count size when [ZB] [/pid_file] [sig_num]
1324
1325 /var/log/cron 600 3 100 * Z
1326
1327 /var/log/amd.log 644 7 100 * Z
1328
1329 /var/log/kerberos.log 644 7 100 * Z
1330
1331 /var/log/lpd-errs 644 7 100 * Z
1332
1333 /var/log/maillog 644 7 * @T00 Z
1334
1335 /var/log/sendmail.st 644 10 * 168 B
1336
1337 /var/log/messages 644 5 100 * Z
1338
1339 /var/log/all.log 600 7 * @T00 Z
1340
1341 /var/log/slip.log 600 3 100 * Z
1342
1343 /var/log/ppp.log 600 3 100 * Z
1344
1345 /var/log/security 600 10 100 * Z
1346
1347 /var/log/wtmp 644 3 * @01T05 B
1348
1349 /var/log/daily.log 640 7 * @T00 Z
1350
1351 /var/log/weekly.log 640 5 1 $W6D0 Z
1352
1353 /var/log/monthly.log 640 12 * $M1D0 Z
1354
1355 /var/log/console.log 640 5 100 * Z
1356
1357
1358
1359Consult the [newsyslog(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=newsyslog&section=8) manual page for more information.
1360
1361
1362
1363### sysctl.conf
1364
1365`sysctl.conf` looks much like `rc.conf`. Values are set in a `variable=value` form. The specified values are set after the system goes into multi-user mode. Not all variables are settable in this mode.
1366
1367
1368
1369A sample `sysctl.conf` turning off logging of fatal signal exits and letting Linux programs know they are really running under DragonFly:
1370
1371
1372
1373
1374
1375 kern.logsigexit=0 # Do not log fatal signal exits (e.g. sig 11)
1376
1377 compat.linux.osname=DragonFly
1378
1379 compat.linux.osrelease=4.3-STABLE
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389## Tuning with sysctl
1390
1391
1392
1393[sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8) is an interface that allows you to make changes to a running DragonFly system. This includes many advanced options of the TCP/IP 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 [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8).
1394
1395
1396
1397At its core, [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8) serves two functions: to read and to modify system settings.
1398
1399
1400
1401To view all readable variables:
1402
1403
1404
1405
1406
1407 % sysctl -a
1408
1409
1410
1411
1412
1413To read a particular variable, for example, `kern.maxproc`:
1414
1415
1416
1417
1418
1419 % sysctl kern.maxproc
1420
1421 kern.maxproc: 1044
1422
1423
1424
1425
1426
1427To set a particular variable, use the intuitive `***variable***`=`***value***` syntax:
1428
1429
1430
1431
1432
1433 # sysctl kern.maxfiles=5000
1434
1435 kern.maxfiles: 2088 -< 5000
1436
1437
1438
1439
1440
1441Settings of sysctl variables are usually either strings, numbers, or booleans (a boolean being `1` for yes or a `0` for no).
1442
1443
1444
1445If you want to set automatically some variables each time the machine boots, add them to the `/etc/sysctl.conf` file. For more information see the [sysctl.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl.conf&section=5) manual page and the [configtuning-configfiles.html#CONFIGTUNING-SYSCTLCONF Section 6.10.4].
1446
1447
1448
1449### sysctl(8) Read-only
1450
1451
1452
1453***Contributed by Tom Rhodes. ***
1454
1455
1456
1457In some cases it may be desirable to modify read-only [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8) values. While this is not recommended, it is also sometimes unavoidable.
1458
1459
1460
1461For instance on some laptop models the [cardbus(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=cardbus&section=4) device will not probe memory ranges, and fail with errors which look similar to:
1462
1463
1464
1465
1466
1467 cbb0: Could not map register memory
1468
1469 device_probe_and_attach: cbb0 attach returned 12
1470
1471
1472
1473
1474
1475Cases like the one above usually require the modification of some default [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8) settings which are set read only. To overcome these situations a user can put [sysctl(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sysctl&section=8) ***OIDs*** in their local `/boot/loader.conf`. Default settings are located in the `/boot/defaults/loader.conf` file.
1476
1477
1478
1479Fixing the problem mentioned above would require a user to set `hw.pci.allow_unsupported_io_range=1` in the aforementioned file. Now [cardbus(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=cardbus&section=4) will work properly.
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489## Tuning Disks
1490
1491
1492
1493### Sysctl Variables
1494
1495
1496
1497#### `vfs.vmiodirenable`
1498
1499
1500
1501The `vfs.vmiodirenable` sysctl variable may be set to either 0 (off) or 1 (on); it is 1 by default. This variable controls how directories are cached by the system. Most directories are small, using just a single fragment (typically 1 K) in the file system and less (typically 512 bytes) in the buffer cache. With this variable turned off (to 0), the buffer cache will only cache a fixed number of directories even if ou have a huge amount of memory. When turned on (to 1), this sysctl allows the buffer cache to use the VM 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 K) rather than 512  bytes. We recommend keeping this option on if you are 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 you should experiment to find out.
1502
1503
1504
1505#### `vfs.write_behind`
1506
1507
1508
1509The `vfs.write_behind` sysctl variable defaults to `1` (on). This tells the file system to issue media writes as full clusters are collected, which typically occurs when writing large sequential files. The idea is to avoid saturating the buffer cache with dirty buffers when it would not benefit I/O performance. However, this may stall processes and under certain circumstances you may wish to turn it off.
1510
1511
1512
1513#### `vfs.hirunningspace`
1514
1515
1516
1517The `vfs.hirunningspace` sysctl 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 lots of disks you may want to bump it up to four or five ***megabytes***. Note that setting too high a value (exceeding the buffer cache's write threshold) can lead to extremely bad clustering performance. Do not set this value arbitrarily high! Higher write values may add latency to reads occurring at the same time.
1518
1519
1520
1521There are various other buffer-cache and VM page cache related sysctls. We do not recommend modifying these values. The VM system does an extremely good job of automatically tuning itself.
1522
1523
1524
1525#### `vm.swap_idle_enabled`
1526
1527
1528
1529The `vm.swap_idle_enabled` sysctl variable is useful in large multi-user systems where you have lots of users entering and leaving the system and lots of idle processes. Such systems tend to generate a great deal of continuous pressure on free memory reserves. Turning this feature on and tweaking the swapout hysteresis (in idle seconds) via `vm.swap_idle_threshold1` and `vm.swap_idle_threshold2` allows you to depress 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. Do not turn this option on unless you need it, because the tradeoff you are making is essentially pre-page memory sooner rather than later; thus eating 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 VM system to stage whole processes into and out of memory easily.
1530
1531
1532
1533#### `hw.ata.wc`
1534
1535
1536
1537IDE drives lie about when a write completes. With IDE write caching turned on, IDE hard drives not only write data to disk out of order, but will sometimes delay writing some blocks indefinitely when under heavy disk loads. A crash or power failure may cause serious file system corruption. Turning off write caching will remove the danger of this data loss, but will also cause disk operations to proceed ***very slowly.*** Change this only if prepared to suffer with the disk slowdown.
1538
1539
1540
1541Changing this variable must be done from the boot loader at boot time. Attempting to do it after the kernel boots will have no effect.
1542
1543
1544
1545For more information, please see [ata(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=ata&section=4) manual page.
1546
1547<!-- XXX: add some more sysctls, e.g. relating to AHCI, nata, ... -->
1548
1549
1550
1551### Soft Updates
1552
1553**Note** that soft updates are only available on UFS.
1554
1555The [tunefs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=tunefs&section=8) program can be used to fine-tune a UFS file system. This program has many different options, but for now we are only concerned with toggling Soft Updates on and off, which is done by:
1556
1557
1558
1559
1560
1561 # tunefs -n enable /filesystem
1562
1563 # tunefs -n disable /filesystem
1564
1565
1566
1567
1568
1569A filesystem cannot be modified with [tunefs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=tunefs&section=8) while it is mounted. A good time to enable Soft Updates is before any partitions have been mounted, in single-user mode.
1570
1571
1572
1573 **Note:** It is possible to enable Soft Updates at filesystem creation time, through use of the `-U` option to [newfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=newfs&section=8).
1574
1575
1576
1577Soft Updates drastically improves meta-data performance, mainly file creation and deletion, through the use of a memory cache. We recommend to use Soft Updates on all of your file systems. There are two downsides to Soft Updates that you should be aware of: First, Soft Updates guarantees filesystem consistency in the case of a crash but could very easily be several seconds (even a minute!) behind updating the physical disk. If your system crashes you may lose more work than otherwise. Secondly, Soft Updates delays the freeing of filesystem blocks. If you have a filesystem (such as the root filesystem) which is almost full, performing a major update, such as `make installworld`, can cause the filesystem to run out of space and the update to fail.
1578
1579
1580
1581#### More Details about Soft Updates
1582<!-- XXX: consider axing this section -->
1583
1584
1585There are two traditional approaches to writing a file systems meta-data back to disk. (Meta-data updates are updates to non-content data like inodes or directories.)
1586
1587
1588
1589Historically, the default behavior was to write out meta-data updates synchronously. If a directory had been 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, the meta-data are 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, [fsck(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#fsck&section8) is able to recognize this and repair the filesystem by setting the file length to 0. Additionally, the implementation is clear and simple. The disadvantage is that meta-data changes are slow. An `rm -r`, for instance, touches all the files in a directory sequentially, but each directory change (deletion of a file) 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 (`tar -x`).
1590
1591
1592
1593The second case is asynchronous meta-data updates. This is the default for Linux/ext2fs and `mount -o async` for *BSD ufs. All meta-data updates are simply being passed through the buffer cache too, that is, 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. Also, the 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 at all for a consistent state of the filesystem. 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 filesystem will be left in an unpredictable state. There is no opportunity to examine the state of the filesystem when the system comes up again; 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 actually impossible to implement a `fsck` which is able to clean up the resulting chaos (because the necessary information is not available on the disk). If the filesystem has been damaged beyond repair, the only choice is to use [newfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#newfs&section8) on it and restore it from backup.
1594
1595
1596
1597The usual solution for this problem was to implement ***dirty region logging***, which is also referred to as ***journaling***, although that term is not used consistently and is occasionally applied to other forms of transaction logging as well. Meta-data updates are still written synchronously, but only into a small region of the disk. Later on they will be 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 fairly limited, so the risk of bugs being present is low. A disadvantage is that all meta-data are written twice (once into the logging region and once to the proper location) so for normal work, a performance ***pessimization*** might result. On the other hand, in case of a crash, all pending meta-data operations can be quickly either rolled-back or completed from the logging area after the system comes up again, resulting in a fast filesystem startup.
1598
1599
1600
1601Kirk McKusick, the developer of Berkeley FFS, solved this problem with Soft Updates: all pending meta-data updates are kept in memory and written out to disk in a sorted sequence (***ordered meta-data updates***). This has the effect that, in case of heavy meta-data operations, later updates to an item ***catch*** the earlier ones if the earlier ones are still in memory and have not already been written to disk. So all operations on, say, a directory are generally performed in memory before the update is written to disk (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, this causes an implicit ***log rewind***: all operations which did not find their way to the disk appear as if they had never happened. A consistent filesystem 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 appropriate bitmaps: blocks and inodes. After a crash, the only resource allocation error that occurs is that resources are marked as ***used*** which are actually ***free***. [fsck(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#fsck&section8) recognizes this situation, and frees the resources that are no longer used. It is safe to ignore the dirty state of the filesystem after a crash by forcibly mounting it with `mount -f`. In order to free resources that may be unused, [fsck(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fsck&section=8) needs to be run at a later time.
1602
1603
1604
1605The advantage is that meta-data operations are nearly as fast as asynchronous updates (i.e. faster than with ***logging***, which has to write the meta-data twice). The disadvantages are the complexity of the code (implying a higher risk for bugs in an area that is highly sensitive regarding loss of user data), and a higher memory consumption. Additionally there are some idiosyncrasies one has to get used to. After a crash, the state of the filesystem appears to be somewhat ***older***. In situations where the standard synchronous approach would have caused some zero-length files to remain after the `fsck`, these files do not exist at all with a Soft Updates filesystem because neither the meta-data nor the file contents have ever 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 `rm`. This may cause problems when installing large amounts of data on a filesystem that does not have enough free space to hold all the files twice.
1606
1607
1608
1609
1610
1611
1612
1613## Tuning Kernel Limits
1614
1615
1616
1617### File/Process Limits
1618
1619
1620
1621#### `kern.maxfiles`
1622
1623<!-- XXX: revise this section; someone who knows about it -->
1624
1625`kern.maxfiles` can be raised or lowered based upon your system requirements. This variable indicates the maximum number of file descriptors on your system. When the file descriptor table is full, ***`file: table is full`*** will show up repeatedly in the system message buffer, which can be viewed with the `dmesg` command.
1626
1627
1628
1629Each 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.
1630
1631
1632
1633`kern.maxfile`'s default value is dictated by the `MAXUSERS` option in your kernel configuration file. `kern.maxfiles` grows proportionally to the value of `MAXUSERS`. When compiling a custom kernel, it is a good idea to set this kernel configuration option according to the uses of your system. From this number, the kernel is given most of its pre-defined limits. Even though a production machine may not actually have 256 users connected at once, the resources needed may be similar to a high-scale web server.
1634
1635
1636
1637 **Note:** Setting `MAXUSERS` to `0` in your kernel configuration file will choose a reasonable default value based on the amount of RAM present in your system. It is set to 0 in the default GENERIC kernel.
1638
1639
1640
1641#### `kern.ipc.somaxconn`
1642
1643
1644
1645The `kern.ipc.somaxconn` sysctl variable limits the size of the listen queue for accepting new TCP connections. The default value of `128` is typically too low for robust handling of new connections in a heavily loaded web server environment. For such environments, it is recommended to increase this value to `1024` or higher. The service daemon may itself limit the listen queue size (e.g. [sendmail(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendmail&section=8), or **Apache** ) but will often have a directive in its configuration file to adjust the queue size. Large listen queues also do a better job of avoiding Denial of Service (DoS) attacks.
1646
1647
1648
1649### Network Limits
1650
1651
1652The `NMBCLUSTERS` 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 DragonFly's ability. Each cluster represents approximately 2 K of memory, so a value of 1024 represents 2 megabytes of kernel memory reserved for network buffers. A simple calculation can be done to figure out how many are needed. If you have a web server which maxes out at 1000 simultaneous connections, and each connection eats a 16 K receive and 16 K send buffer, you need approximately 32 MB worth of network buffers to cover the web server. A good rule of thumb is to multiply by 2, so 2x32 MB / 2 KB # 64 MB / 2 kB  32768. We recommend values between 4096 and 32768 for machines with greater amounts of memory. Under no circumstances should you specify an arbitrarily high value for this parameter as it could lead to a boot time crash. The `-m` option to [netstat(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=netstat&section=1) may be used to observe network cluster use. `kern.ipc.nmbclusters` loader tunable should be used to tune this at boot time.
1653
1654<!-- XXX: mention kern.ipc.mbufs sysctl -->
1655
1656
1657For busy servers that make extensive use of the [sendfile(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendfile&section=2) system call, it may be necessary to increase the number of [sendfile(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendfile&section=2) buffers via the `NSFBUFS` kernel configuration option or by setting its value in `/boot/loader.conf` (see [loader(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=loader&section=8) for details). A common indicator that this parameter needs to be adjusted is when processes are seen in the `sfbufa` state. The sysctl variable `kern.ipc.nsfbufs` is a read-only glimpse at the kernel configured variable. This parameter nominally scales with `kern.maxusers`, however it may be necessary to tune accordingly.
1658
1659
1660
1661 **Important:** Even though a socket has been marked as non-blocking, calling [sendfile(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendfile&section=2) on the non-blocking socket may result in the [sendfile(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendfile&section=2) call blocking until enough `struct sf_buf`'s are made available.
1662
1663
1664
1665#### `net.inet.ip.portrange.*`
1666
1667
1668
1669The `net.inet.ip.portrange.*` sysctl variables control the port number ranges automatically bound to TCP and UDP 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 the `net.inet.ip.portrange.first` and `net.inet.ip.portrange.last`, which default to 1024 and 5000, 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 you are running a heavily loaded web proxy. The port range is not an issue when running servers which handle mainly incoming connections, such as a normal web server, or has a limited number of outgoing connections, such as a mail relay. For situations where you may run yourself out of ports, it is recommended to increase `net.inet.ip.portrange.last` modestly. A value of `10000`, `20000` or `30000` may be reasonable. You should also 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 recommended that `net.inet.ip.portrange.first` be lowered.
1670
1671
1672
1673#### TCP Bandwidth Delay Product
1674<!-- XXX: Revise this stuff, I'm not familiar with it -->
1675
1676
1677The TCP Bandwidth Delay Product Limiting is similar to TCP/Vegas in NetBSD. It can be enabled by setting `net.inet.tcp.inflight_enable` sysctl variable to `1`. The system will 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.
1678
1679
1680
1681This feature is useful if you are serving data over modems, Gigabit Ethernet, or even high speed WAN links (or any other link with a high bandwidth delay product), especially if you are also using window scaling or have configured a large send window. If you enable this option, you should also be sure to set `net.inet.tcp.inflight_debug` to `0` (disable debugging), and for production use setting `net.inet.tcp.inflight_min` to at least `6144` may be beneficial. However, note that 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 as well as reduces the amount of data built up in the local host's interface queue. With fewer packets queued up, interactive connections, especially over slow modems, will also be able to operate with lower ***Round Trip Times***. However, note that this feature only effects data transmission (uploading / server side). It has no effect on data reception (downloading).
1682
1683
1684
1685Adjusting `net.inet.tcp.inflight_stab` is ***not*** recommended. This parameter defaults to 20, 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 ping times over slow links (though still much lower than you would get without the inflight algorithm). In such cases, you may wish to try reducing this parameter to 15, 10, or 5; and may also have to reduce `net.inet.tcp.inflight_min` (for example, to 3500) to get the desired effect. Reducing these parameters should be done as a last resort only.
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697## Adding Swap Space
1698<!-- XXX: swapcache -->
1699
1700
1701No matter how well you plan, sometimes a system does not run as you expect. If you find you need more swap space, it is simple enough to add. You have three ways to increase swap space: adding a new hard drive, enabling swap over NFS, and creating a swap file on an existing partition.
1702
1703
1704
1705### Swap on a New Hard Drive
1706
1707
1708
1709The best way to add swap, of course, is to use this as an excuse to add another hard drive. You can always use another hard drive, after all. If you can do this, go reread the discussion about swap space in [configtuning-initial.html Section 6.2] for some suggestions on how to best arrange your swap.
1710
1711
1712
1713### Swapping over NFS
1714
1715
1716
1717Swapping over NFS is only recommended if you do not have a local hard disk to swap to. Even though DragonFly has an excellent NFS implementation, NFS swapping will be limited by the available network bandwidth and puts an additional burden on the NFS server.
1718
1719
1720
1721### Swapfiles
1722
1723
1724
1725You can create a file of a specified size to use as a swap file. In our example here we will use a 64MB file called `/usr/swap0`. You can use any name you want, of course.
1726
1727
1728
1729 **Example 6-1. Creating a Swapfile**
1730
1731
1732
1733 1. Be certain that your kernel configuration includes the vnode driver. It is ***not*** in recent versions of `GENERIC`.
1734
1735
1736
1737 pseudo-device vn 1 #Vnode driver (turns a file into a device)
1738
1739
1740
c470a82e 1741 1. Create a swapfile (`/usr/swap0`):
1742
1743
1744
1745 # dd if=/dev/zero of=/usr/swap0 bs=1024k count=64
1746
1747
1748
1749 1. Set proper permissions on (`/usr/swap0`):
1750
1751
1752
1753 # chmod 0600 /usr/swap0
1754
1755
1756
1757 1. Enable the swap file in `/etc/rc.conf`:
1758
1759
1760
1761 swapfile="/usr/swap0" # Set to name of swapfile if aux swapfile desired.
1762
1763
1764
1765 1. Reboot the machine or to enable the swap file immediately, type:
1766
1767
1768
1769 # vnconfig -e /dev/vn0b /usr/swap0 swap
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784## Power and Resource Management
1785
1786
1787
1788***Written by Hiten Pandya and Tom Rhodes. ***
1789
1790
1791
1792It is very important to utilize hardware resources in an efficient manner. Before ACPI was introduced, it was very difficult and inflexible for operating systems to manage the power usage and thermal properties of a system. The hardware was controlled by some sort of BIOS embedded interface, such as ***Plug and Play BIOS (PNPBIOS)***, or ***Advanced Power Management (APM)*** and so on. Power and Resource Management is one of the key components of a modern operating system. For example, you may want an operating system to monitor system limits (and possibly alert you) in case your system temperature increased unexpectedly.
1793
1794
1795
1796In this section, we will provide comprehensive information about ACPI. References will be provided for further reading at the end. Please be aware that ACPI is available on DragonFly systems as a default kernel module.
1797
1798
1799
1800### What Is ACPI?
1801
1802
1803
1804Advanced Configuration and Power Interface (ACPI) is a standard written by an alliance of vendors to provide a standard interface for hardware resources and power management (hence the name). It is a key element in ***Operating System-directed configuration and Power Management***, i.e.: it provides more control and flexibility to the operating system (OS). Modern systems ***stretched*** the limits of the current Plug and Play interfaces (such as APM), prior to the introduction of ACPI. ACPI is the direct successor to APM (Advanced Power Management).
1805
1806
1807
1808### Shortcomings of Advanced Power Management (APM)
1809
1810
1811
1812The ***Advanced Power Management (APM)*** facility control's the power usage of a system based on its activity. The APM BIOS is supplied by the (system) vendor and it is specific to the hardware platform. An APM driver in the OS mediates access to the ***APM Software Interface***, which allows management of power levels.
1813
1814
1815There are four major problems in APM. Firstly, power management is done by the (vendor-specific) BIOS, and the OS does not have any knowledge of it. One example of this, is when the user sets idle-time values for a hard drive in the APM BIOS, that when exceeded, it (BIOS) would spin down the hard drive, without the consent of the OS. Secondly, the APM logic is embedded in the BIOS, and it operates outside the scope of the OS. This means users can only fix problems in their APM BIOS by flashing a new one into the ROM; which, is a very dangerous procedure, and if it fails, it could leave the system in an unrecoverable state. Thirdly, APM is a vendor-specific technology, which, means that there is a lot or parity (duplication of efforts) and bugs found in one vendor's BIOS, may not be solved in others. Last but not the least, the APM BIOS did not have enough room to implement a sophisticated power policy, or one that can adapt very well to the purpose of the machine.
1816
1817
1818***Plug and Play BIOS (PNPBIOS)*** was unreliable in many situations. PNPBIOS is 16-bit technology, so the OS has to use 16-bit emulation in order to ***interface*** with PNPBIOS methods.
1819
1820
1821
1822The DragonFly APM driver is documented in the [apm(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=apm&section=4) manual page.
1823
1824
1825
1826### Configuring ACPI
1827
1828
1829
1830The `acpi.ko` driver is loaded by default at start up by the [loader(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=loader&section=8) and should ***not*** be compiled into the kernel. The reasoning behind this is that modules are easier to work with, say if switching to another `acpi.ko` without doing a kernel rebuild. This has the advantage of making testing easier. Another reason is that starting ACPI after a system has been brought up is not too useful, and in some cases can be fatal. In doubt, just disable ACPI all together. This driver should not and can not be unloaded because the system bus uses it for various hardware interactions. ACPI can be disabled with the [acpiconf(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpiconf&section=8) utility. In fact most of the interaction with ACPI can be done via [acpiconf(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpiconf&section=8). Basically this means, if anything about ACPI is in the [dmesg(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dmesg&section=8) output, then most likely it is already running.
1831
1832
1833
1834 **Note:** ACPI and APM cannot coexist and should be used separately. The last one to load will terminate if the driver notices the other running.
1835
1836
1837
1838In the simplest form, ACPI can be used to put the system into a sleep mode with [acpiconf(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpiconf&section=8), the `-s` flag, and a `1-5` option. Most users will only need `1`. Option `5` will do a soft-off which is the same action as:
1839
1840
1841
1842 # halt -p
1843
1844
1845The other options are available. Check out the [acpiconf(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpiconf&section=8) manual page for more information.
1846
1847
1848## Using and Debugging DragonFly ACPI
1849
1850
1851
1852***Written by Nate Lawson. With contributions from Peter Schultz and Tom Rhodes. ***
1853
1854
1855ACPI is a fundamentally new way of discovering devices, managing power usage, and providing standardized access to various hardware previously managed by the BIOS. Progress is being made toward ACPI working on all systems, but bugs in some motherboards ***ACPI Machine Language*** (AML) bytecode, incompleteness in DragonFly's kernel subsystems, and bugs in the Intel ACPI-CA interpreter continue to appear.
1856
1857
1858This document is intended to help you assist the DragonFly ACPI maintainers in identifying the root cause of problems you observe and debugging and developing a solution. Thanks for reading this and we hope we can solve your system's problems.
1859
1860
1861### Submitting Debugging Information
1862
1863 **Note:** Before submitting a problem, be sure you are running the latest BIOS version and, if available, embedded controller firmware version.
1864
1865For those of you that want to submit a problem right away, please send the following information to [bugs](http://leaf.dragonflybsd.org/mailarchive/)
1866
1867
1868* Description of the buggy behavior, including system type and model and anything that causes the bug to appear. Also, please note as accurately as possible when the bug began occurring if it is new for you.
1869
1870* The dmesg output after ***boot `-v`***, including any error messages generated by you exercising the bug.
1871
1872* dmesg output from ***boot `-v`*** with ACPI disabled, if disabling it helps fix the problem.
1873
1874* Output from ***sysctl hw.acpi***. This is also a good way of figuring out what features your system offers.
1875
1876* URL where your ***ACPI Source Language*** (ASL) can be found. Do ***not*** send the ASL directly to the list as it can be very large. Generate a copy of your ASL by running this command:
1877
1878
1879 # acpidump -t -d > name-system.asl
1880
1881
1882
1883 (Substitute your login name for `name` and manufacturer/model for `system`. Example: `njl-FooCo6000.asl`)
1884
1885
1886
1887### Background
1888
1889
1890
1891ACPI is present in all modern computers that conform to the ia32 (x86), ia64 (Itanium), and amd64 (AMD) architectures. The full standard has many features including CPU 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 the bus enumeration parts while a laptop might have cooling and battery management support as well. Laptops also have suspend and resume, with their own associated complexity.
1892
1893
1894
1895An ACPI-compliant system has various components. The BIOS and chipset vendors provide various fixed tables (e.g., FADT) in memory that specify things like the APIC map (used for SMP), config registers, and simple configuration values. Additionally, a table of bytecode (the ***Differentiated System Description Table*** DSDT) is provided that specifies a tree-like name space of devices and methods.
1896
1897
1898
1899The ACPI driver must parse the fixed tables, implement an interpreter for the bytecode, and modify device drivers and the kernel to accept information from the ACPI subsystem. For DragonFly, Intel has provided an interpreter (ACPI-CA) that is shared with Linux and NetBSD®. The path to the ACPI-CA source code is `src/sys/dev/acpica5`. Finally, drivers that implement various ACPI devices are found in `src/sys/dev/acpica5`.
1900
1901
1902
1903### Common Problems
1904
1905
1906
1907For ACPI 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.
1908
1909
1910
1911#### Suspend/Resume
1912
1913
1914
1915ACPI has three suspend to RAM (STR) states, `S1`-`S3`, and one suspend to disk state (`STD`), called `S4`. `S5` is ***soft off*** and is the normal state your system is in when plugged in but not powered up. `S4` can actually be implemented two separate ways. `S4`BIOS is a BIOS-assisted suspend to disk. `S4`OS is implemented entirely by the operating system.
1916
1917
1918
1919Start by checking `sysctl` `hw.acpi` for the suspend-related items. Here are the results for my Thinkpad:
1920
1921 hw.acpi.supported_sleep_state: S3 S4 S5
1922
1923 hw.acpi.s4bios: 0
1924
1925
1926This means that I can use `acpiconf -s` to test `S3`, `S4`OS, and `S5`. If `s4bios` was one (`1`), I would have `S4`BIOS support instead of `S4` OS.
1927
1928
1929
1930When testing suspend/resume, start with `S1`, if supported. This state is most likely to work since it doesn't require much driver support. No one has implemented `S2` but if you have it, it's similar to `S1`. The next thing to try is `S3`. This is the deepest STR state and requires a lot of driver support to properly reinitialize your hardware. If you have problems resuming, feel free to email the [bugs](http://leaf.dragonflybsd.org/mailarchive/) list but do not expect the problem to be resolved since there are a lot of drivers/hardware that need more testing and work.
1931
1932
1933
1934To help isolate the problem, remove as many drivers from your kernel as possible. If it works, you can narrow down which driver is the problem by loading drivers until it fails again. Typically binary drivers like `nvidia.ko`, **X11** display drivers, and USB will have the most problems while Ethernet interfaces usually work fine. If you can load/unload the drivers ok, you can automate this by putting the appropriate commands in `/etc/rc.suspend` and `/etc/rc.resume`. There is a commented-out example for unloading and loading a driver. Try setting `hw.acpi.reset_video` to zero (0) if your display is messed up after resume. Try setting longer or shorter values for `hw.acpi.sleep_delay` to see if that helps.
1935
1936
1937
1938Another thing to try is load a recent Linux distribution with ACPI support and test their suspend/resume support on the same hardware. If it works on Linux, it's likely a DragonFly driver problem and narrowing down which driver causes the problems will help us fix the problem. Note that the ACPI maintainers do not usually maintain other drivers (e.g sound, ATA, etc.) so any work done on tracking down a driver problem should probably eventually be posted to the [bugs](http://leaf.dragonflybsd.org/mailarchive/) list and mailed to the driver maintainer. If you are feeling adventurous, go ahead and start putting some debugging [printf(3)](http://leaf.dragonflybsd.org/cgi/web-man?command#printf&section3)s in a problematic driver to track down where in its resume function it hangs.
1939
1940Finally, try disabling ACPI and enabling APM instead. If suspend/resume works with APM, you may be better off sticking with APM, especially on older hardware (pre-2000). It took vendors a while to get ACPI support correct and older hardware is more likely to have BIOS problems with ACPI.
1941
1942<-- XXX: mention sensors somewhere; but not in this section -->
1943
1944
1945#### System Hangs (temporary or permanent)
1946
1947Most system hangs are a result of lost interrupts or an interrupt storm. Chipsets have a lot of problems based on how the BIOS configures interrupts before boot, correctness of the APIC (MADT) table, and routing of the ***System Control Interrupt*** (SCI).
1948
1949Interrupt storms can be distinguished from lost interrupts by checking the output of `vmstat -i` and looking at the line that has `acpi0`. If the counter is increasing at more than a couple per second, you have an interrupt storm. If the system appears hung, try breaking to DDB ( **CTRL** + **ALT** + **ESC** on console) and type `show interrupts`.
1950
1951Your best hope when dealing with interrupt problems is to try disabling APIC support with `hint.apic.0.disabled="1"` in `loader.conf`.
1952
1953
1954
1955#### Panics
1956
1957Panics are relatively rare for ACPI 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 `options DDB` and setting up a serial console (see [ this section](serialconsole-setup.html#SERIALCONSOLE-DDB)) or setting up a [dump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dump&section=8) partition. You can get a backtrace in DDB with `tr`. If you have to handwrite the backtrace, be sure to at least get the lowest five (5) and top five (5) lines in the trace.
1958
1959Then, try to isolate the problem by booting with ACPI disabled. If that works, you can isolate the ACPI subsystem by using various values of `debug.acpi.disable`. See the [acpi(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpi&section=4) manual page for some examples.
1960
1961
1962
1963#### System Powers Up After Suspend or Shutdown
1964
1965
1966
1967First, try setting `hw.acpi.disable_on_poweroff#0` in [loader.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=loader.conf&section=5). This keeps ACPI from disabling various events during the shutdown process. Some systems need this value set to ***1*** (the default) for the same reason. This usually fixes the problem of a system powering up spontaneously after a suspend or poweroff.
1968
1969
1970
1971#### Other Problems
1972
1973
1974
1975If you have other problems with ACPI (working with a docking station, devices not detected, etc.), please email a description to the mailing list as well; however, some of these issues may be related to unfinished parts of the ACPI subsystem so they might take a while to be implemented. Please be patient and prepared to test patches we may send you.
1976
1977
1978
1979### ASL, acpidump, and IASL
1980<!-- XXX: IMHO all this crap about fixing your DSDT etc should be axed -->
1981
1982
1983The most common problem is the BIOS vendors providing incorrect (or outright buggy!) bytecode. This is usually manifested by kernel console messages like this:
1984
1985
1986
1987
1988
1989 ACPI-1287: *** Error: Method execution failed [\\_SB_.PCI0.LPC0.FIGD._STA] \\
1990
1991 (Node 0xc3f6d160), AE_NOT_FOUND
1992
1993
1994
1995
1996
1997Often, you can resolve these problems by updating your BIOS to the latest revision. Most console messages are harmless but if you have other problems like battery status not working, they're a good place to start looking for problems in the AML. The bytecode, known as AML, is compiled from a source language called ASL. The AML is found in the table known as the DSDT. To get a copy of your ASL, use [acpidump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpidump&section=8). You should use both the `-t` (show contents of the fixed tables) and `-d` (disassemble AML to ASL) options. See the [submitting Debugging Information](acpi-debug.html#ACPI-SUBMITDEBUG) section for an example syntax.
1998
1999
2000
2001The simplest first check you can do is to recompile your ASL to check for errors. Warnings can usually be ignored but errors are bugs that will usually prevent ACPI from working correctly. To recompile your ASL, issue the following command:
2002
2003
2004
2005
2006
2007 # iasl your.asl
2008
2009
2010
2011
2012
2013### Fixing Your ASL
2014
2015
2016In the long run, our goal is for almost everyone to have ACPI work without any user intervention. At this point, however, we are still developing workarounds for common mistakes made by the BIOS vendors. The Microsoft interpreter (`acpi.sys` and `acpiec.sys`) does not strictly check for adherence to the standard, and thus many BIOS vendors who only test ACPI under Windows never fix their ASL. We hope to continue to identify and document exactly what non-standard behavior is allowed by Microsoft's interpreter and replicate it so DragonFly can work without forcing users to fix the ASL. As a workaround and to help us identify behavior, you can fix the ASL manually. If this works for you, please send a [diff(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=diff&section=1) of the old and new ASL so we can possibly work around the buggy behavior in ACPI-CA and thus make your fix unnecessary.
2017
2018
2019Here is a list of common error messages, their cause, and how to fix them:
2020
2021
2022#### OS dependencies
2023
2024
2025Some AML assumes the world consists of various Windows versions. You can tell DragonFly to claim it is any OS to see if this fixes problems you may have. An easy way to override this is to set `hw.acpi.osname=Windows 2001` in `/boot/loader.conf` or other similar strings you find in the ASL.
2026
2027
2028
2029#### Missing Return statements
2030
2031
2032
2033Some methods do not explicitly return a value as the standard requires. While ACPI-CA does not handle this, DragonFly has a workaround that allows it to return the value implicitly. You can also add explicit Return statements where required if you know what value should be returned. To force `iasl` to compile the ASL, use the `-f` flag.
2034
2035
2036
2037#### Overriding the Default AML
2038
2039
2040
2041After you customize `your.asl`, you will want to compile it, run:
2042
2043
2044 # iasl your.asl
2045
2046
2047
2048
2049
2050You can add the `-f` flag to force creation of the AML, even if there are errors during compilation. Remember that some errors (e.g., missing Return statements) are automatically worked around by the interpreter.
2051
2052
2053
2054`DSDT.aml` is the default output filename for `iasl`. You can load this instead of your BIOS's buggy copy (which is still present in flash memory) by editing `/boot/loader.conf` as follows:
2055
2056
2057
2058
2059
2060 acpi_dsdt_load="YES"
2061
2062 acpi_dsdt_name="/boot/DSDT.aml"
2063
2064
2065
2066
2067Be sure to copy your `DSDT.aml` to the `/boot` directory.
2068
2069
2070
2071### Getting Debugging Output From ACPI
2072
2073
2074
2075The ACPI driver has a very flexible debugging facility. It allows you to specify a set of subsystems as well as the level of verbosity. The subsystems you wish to debug are specified as ***layers*** and are broken down into ACPI-CA components (ACPI_ALL_COMPONENTS) and ACPI hardware support (ACPI_ALL_DRIVERS). The verbosity of debugging output is specified as the ***level*** and ranges from ACPI_LV_ERROR (just report errors) to ACPI_LV_VERBOSE (everything). The ***level*** is a bitmask so multiple options can be set at once, separated by spaces. In practice, you will want to use a serial console to log the output if it is so long it flushes the console message buffer.
2076
2077
2078
2079Debugging output is not enabled by default. To enable it, add `options ACPI_DEBUG` to your kernel config if ACPI is compiled into the kernel. You can add `ACPI_DEBUG=1` to your `/etc/make.conf` to enable it globally. If it is a module, you can recompile just your `acpi.ko` module as follows:
2080
2081
2082
2083
2084
2085 # cd /sys/dev/acpica5 && make clean && make ACPI_DEBUG=1
2086
2087
2088
2089
2090
2091Install `acpi.ko` in `/boot/kernel` and add your desired level and layer to `loader.conf`. This example enables debug messages for all ACPI-CA components and all ACPI hardware drivers (CPU, LID, etc.) It will only output error messages, the least verbose level.
2092
2093
2094
2095
2096
2097 debug.acpi.layer="ACPI_ALL_COMPONENTS ACPI_ALL_DRIVERS"
2098
2099 debug.acpi.level="ACPI_LV_ERROR"
2100
2101
2102
2103
2104
2105If the information you want is triggered by a specific event (say, a suspend and then resume), you can leave out changes to `loader.conf` and instead use `sysctl` to specify the layer and level after booting and preparing your system for the specific event. The `sysctl`s are named the same as the tunables in `loader.conf`.
2106
2107
2108
2109### References
2110
2111
2112
2113More information about ACPI may be found in the following locations:
2114
2115
2116
2117
2118* The [FreeBSD ACPI mailing list](http://lists.FreeBSD.org/mailman/listinfo/freebsd-acpi) (This is FreeBSD-specific; posting DragonFly questions here may not generate much of an answer.)
2119
2120
2121* The ACPI Mailing List Archives (FreeBSD) http://lists.freebsd.org/pipermail/freebsd-acpi/
2122
2123
2124* The old ACPI Mailing List Archives (FreeBSD) http://home.jp.FreeBSD.org/mail-list/acpi-jp/
2125
2126
2127* The ACPI 2.0 Specification http://acpi.info/spec.htm
2128
2129
2130* DragonFly Manual pages: [acpidump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpidump&section8), [acpiconf(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpiconf&section=8), [acpidb(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=acpidb&section=8)
2131
2132
2133* [DSDT debugging resource](http://www.cpqlinux.com/acpi-howto.html#fix_broken_dsdt). (Uses Compaq as an example but generally useful.)
2134
2135
2136