19ea5492b62aa06bc75073a5afbeecf2be4fb374
[ikiwiki.git] / docs / newhandbook / UnixBasics / index.mdwn
1 # UNIX Basics 
2
3 ***Rewritten by Chris Shumway. ***
4 [[!toc  levels=3]]
5
6 ## Synopsis 
7
8 The following chapter will cover the basic commands and functionality of the DragonFly operating system. Much of this material is relevant for any UNIX®-like operating system. Feel free to skim over this chapter if you are familiar with the material. If you are new to DragonFly, then you will definitely want to read through this chapter carefully.
9
10 After reading this chapter, you will know:
11
12 * How to use the ***virtual consoles*** of DragonFly.
13
14 * How UNIX file permissions work along with understanding file flags in DragonFly.
15
16 * The default DragonFly file system layout.
17
18 * The DragonFly disk organization.
19
20 * How to mount and unmount file systems.
21
22 * What processes, daemons, and signals are.
23
24 * What a shell is, and how to change your default login environment.
25
26 * How to use basic text editors.
27
28 * What devices and device nodes are.
29
30 * What binary format is used under DragonFly.
31
32 * How to read manual pages for more information.
33
34 ## Virtual Consoles and Terminals 
35
36 DragonFly can be used in various ways. One of them is typing commands to a text terminal. A lot of the flexibility and power of a UNIX® operating system is readily available at your hands when using DragonFly this way. This section describes what ***terminals*** and ***consoles*** are, and how you can use them in !DragonFly.
37
38 <!-- XXX: also mention vesa.ko and other modes for the vt, but maybe somewhere else -->
39
40 ### The Console 
41
42 If you have not configured DragonFly to automatically start a graphical environment during startup, the system will present you with a login prompt after it boots, right after the startup scripts finish running. You will see something similar to:
43
44     Additional ABI support:.
45     Starting cron.
46     Local package initialization:.
47     Additional TCP options:.
48     
49     Wed Feb 18 17:53:48 GMT 2009
50     
51     DragonFly/i386 (Amnesiac) (ttyv0)
52
53     login: 
54
55 The messages might be a bit different on your system, but you will see something similar. The last two lines are what we are interested in right now. The second last line reads:
56
57     DragonFly/i386 (Amnesiac) (ttyv0)
58
59 This line contains some bits of information about the system you have just booted. You are looking at a ***DragonFlyBSD*** console, running on an Intel or compatible processor of the x86 architecture[(1)](#FTN.AEN1036). The name of this machine (every UNIX machine has a name) is `Amnesiac`, and you are now looking at its system console--the `ttyv0` terminal. Finally, the last line is always:
60
61     login:
62
63 This is the part where you are supposed to type in your <i>username</i> to log into DragonFly. The next section describes how you can do this.
64
65 ### Logging into DragonFly 
66
67 DragonFly is a multiuser, multiprocessing system. This is the formal description that is usually given to a system that can be used by many different people, who simultaneously run a lot of programs on a single machine. Every multiuser system needs some way to distinguish one <i>user</i>from the rest. In !DragonFly (and all the UNIX-like operating systems), this is accomplished by requiring that every user must ***log into*** the system before being able to run programs. Every user has a unique name (the <i>username</i> and a personal, secret key (the <i>password</i>). DragonFly will ask for these two before allowing a user to run any programs.
68
69 Right after DragonFly boots and finishes running its startup scripts[(2)](#FTN.AEN1060), it will present you with a prompt and ask for a valid username: 
70
71     login:
72
73 For the sake of this example, let us assume that your username is `john`. Type `john` at this prompt and press  **Enter** . You should then be presented with a prompt to enter a <i>password</i>:
74     
75
76     login: john
77     Password:
78
79 Type in `john`'s password now, and press  **Enter** . The password is <i>not echoed!</i> You need not worry about this right now. Suffice it to say that it is done for security reasons. If you have typed your password correctly, you should by now be logged into DragonFly and ready to try out all the available commands. You should see the MOTD or message of the day followed by a command prompt (a `#`, `$`, or `%` character). This indicates you have successfully logged into DragonFly.
80
81 ### Multiple Consoles 
82
83 Running UNIX commands in one console is fine, but DragonFly can run many programs at once. Having one console where commands can be typed would be a bit of a waste when an operating system like DragonFly can run dozens of programs at the same time. This is where <i>virtual consoles</i> can be very helpful. DragonFly can be configured to present you with many different virtual consoles. You can switch from one of them to any other virtual console by pressing a couple of keys on your keyboard. Each console has its own different output channel, and DragonFly takes care of properly redirecting keyboard input and monitor output as you switch from one virtual console to the next.
84
85 Special key combinations have been reserved by DragonFly for switching consoles[(3)](#FTN.AEN1087). You can use  **Alt** - **F1** ,  **Alt** - **F2** , through  **Alt** - **F8**  to switch to a different virtual console in DragonFly. As you are switching from one console to the next, DragonFly takes care of saving and restoring the screen output. The result is an <i>illusion</i> of having multiple <i>virtual</i> screens and keyboards that you can use to type commands for DragonFly to run. The programs that you launch on one virtual console do not stop running when that console is not visible. They continue running when you have switched to a different virtual console.
86
87 ### The /etc/ttys File 
88
89 The default configuration of DragonFly will start up with eight virtual consoles. This is not a hardwired setting though, and you can easily customize your installation to boot with more or fewer virtual consoles. The number and settings of the virtual consoles are configured in the `/etc/ttys` file.
90
91 You can use the `/etc/ttys` file to configure the virtual consoles of DragonFly. Each uncommented line in this file (lines that do not start with a `#` character) contains settings for a single terminal or virtual console. The default version of this file that ships with DragonFly configures nine virtual consoles, and enables eight of them. They are the lines that start with `ttyv`:
92     
93
94     # name  getty                           type    status          comments
95     #
96     ttyv0   "/usr/libexec/getty Pc"         cons25  on  secure
97     # Virtual terminals
98     ttyv1   "/usr/libexec/getty Pc"         cons25  on  secure
99     ttyv2   "/usr/libexec/getty Pc"         cons25  on  secure
100     ttyv3   "/usr/libexec/getty Pc"         cons25  on  secure
101     ttyv4   "/usr/libexec/getty Pc"         cons25  on  secure
102     ttyv5   "/usr/libexec/getty Pc"         cons25  on  secure
103     ttyv6   "/usr/libexec/getty Pc"         cons25  on  secure
104     ttyv7   "/usr/libexec/getty Pc"         cons25  on  secure
105     ttyv8   "/usr/pkg/xorg/bin/xdm -nodaemon"  xterm   off secure
106
107 For a detailed description of every column in this file and all the options you can use to set things up for the virtual consoles, consult the [ttys(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#ttys&section5) manual page.
108
109 ### Single User Mode Console 
110
111 A detailed description of what <i>single user mode</i> is can be found in [boot-init.html#BOOT-SINGLEUSER Section 7.5.2]. It is worth noting that there is only one console when you are running DragonFly in single user mode. There are no virtual consoles available. The settings of the single user mode console can also be found in the `/etc/ttys` file. Look for the line that starts with `console`:
112
113     
114
115     # name  getty                           type    status          comments
116     #
117     # If console is marked "insecure", then init will ask for the root password
118     # when going to single-user mode.
119     console none                            unknown off secure
120
121  **Note:** As the comments above the `console` line indicate, you can edit this line and change `secure` to `insecure`. If you do that, when DragonFly boots into single user mode, it will still ask for the `root` password. ***Be careful when changing this to insecure***. If you ever forget the `root` password, booting into single user mode is a bit involved. It is still possible, but it might be a bit hard for someone who is not very comfortable with the DragonFly booting process and the programs involved.
122
123 #### Notes 
124
125 [[!table  data="""
126 <tablestyle="width:100%">[ (1)](consoles.html#AEN1036) | This is what `i386` means. Note that even if you are not running DragonFly on an Intel 386 CPU, this is going to be `i386`. It is not the type of your processor, but the processor ***architecture*** that is shown here. 
127  [ (2)](consoles.html#AEN1060) | Startup scripts are programs that are run automatically by DragonFly when booting. Their main function is to set things up for everything else to run, and start any services that you have configured to run in the background doing useful things. 
128  [ (3)](consoles.html#AEN1087) | A fairly technical and accurate description of all the details of the DragonFly console and keyboard drivers can be found in the manual pages of [syscons(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=syscons&section4), [atkbd(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=atkbd&section=4), [vidcontrol(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=vidcontrol&section=1) and [kbdcontrol(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kbdcontrol&section=1). We will not expand on the details here, but the interested reader can always consult the manual pages for a more detailed and thorough explanation of how things work. |
129
130 """]]
131
132 ## Permissions 
133
134 DragonFly, being a direct descendant of BSD UNIX®, is based on several key UNIX concepts. The first and most pronounced is that DragonFly is a multi-user operating system. The system can handle several users all working simultaneously on completely unrelated tasks. The system is responsible for properly sharing and managing requests for hardware devices, peripherals, memory, and CPU time fairly to each user.
135
136 Because the system is capable of supporting multiple users, everything the system manages has a set of permissions governing who can read, write, and execute the resource. These permissions are stored as three octets broken into three pieces, one for the owner of the file, one for the group that the file belongs to, and one for everyone else. This numerical representation works like this:
137
138 [[!table  data="""
139 |<tablestyle="width:100%"> Value | Permission | Directory Listing 
140 <tablestyle="width:100%"> 0 | No read, no write, no execute | `---` 
141  1 | No read, no write, execute | `--x` 
142  2 | No read, write, no execute | `-w-` 
143  3 | No read, write, execute | `-wx` 
144  4 | Read, no write, no execute | `r--` 
145  5 | Read, no write, execute | `r-x` 
146  6 | Read, write, no execute | `rw-` 
147  7 | Read, write, execute | `rwx` |
148
149 """]]
150
151 You can use the `-l` command line argument to [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ls&section1) to view a long directory listing that includes a column with information about a file's permissions for the owner, group, and everyone else. For example, a `ls -l` in an arbitrary directory may show:
152
153     % ls -l
154     total 530
155     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 myfile
156     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 otherfile
157     -rw-r--r--  1 root  wheel    7680 Sep  5 12:31 email.txt
158     ...
159
160 Here is how the first column of `ls -l` is broken up:    
161
162     -rw-r--r--
163
164 <!-- XXX: Check all these http:// links to see if they are broken -->
165
166 The first (leftmost) character tells if this file is a regular file, a directory, a special character device, a socket, or any other special pseudo-file device. In this case, the `-` indicates a regular file. The next three characters, `rw-` in this example, give the permissions for the owner of the file. The next three characters, `r--`, give the permissions for the group that the file belongs to. The final three characters, `r--`, give the permissions for the rest of the world. A dash means that the permission is turned off. In the case of this file, the permissions are set so the owner can read and write to the file, the group can read the file, and the rest of the world can only read the file. According to the table above, the permissions for this file would be `644`, where each digit represents the three parts of the file's permission.
167
168 This is all well and good, but how does the system control permissions on devices? DragonFly actually treats most hardware devices as a file that programs can open, read, and write data to just like any other file. These special device files are stored on the `/dev` directory.
169
170 Directories are also treated as files. They have read, write, and execute permissions. The executable bit for a directory has a slightly different meaning than that of files. When a directory is marked executable, it means it can be traversed into, that is, it is possible to ***cd*** (change directory) into it. This also means that within the directory it is possible to access files whose names are known (subject, of course, to the permissions on the files themselves).
171
172 In particular, in order to perform a directory listing, read permission must be set on the directory, whilst to delete a file that one knows the name of, it is necessary to have write ***and*** execute permissions to the directory containing the file. There are more permission bits, but they are primarily used in special circumstances such as setuid binaries and sticky directories. If you want more information on file permissions and how to set them, be sure to look at the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section1) manual page.
173
174 ### Symbolic Permissions 
175
176 ***Contributed by Tom Rhodes.***
177
178 Symbolic permissions, sometimes referred to as symbolic expressions, use characters in place of octal values to assign permissions to files or directories. Symbolic expressions use the syntax of (who) (action) (permissions), where the following values are available:
179
180 [[!table  data="""
181 <tablestyle="width:100%"> Option | Letter | Represents 
182 <tablestyle="width:100%"> (who) | u | User 
183  (who) | g | Group owner 
184  (who) | o | Other 
185  (who) | a | All (***world***) 
186  (action) | + | Adding permissions 
187  (action) | - | Removing permissions 
188  (action) | = | Explicitly set permissions 
189  (permissions) | r | Read 
190  (permissions) | w | Write 
191  (permissions) | x | Execute 
192  (permissions) | t | Sticky bit 
193  (permissions) | s | Set UID or GID |
194
195 """]]
196
197 These values are used with the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&amp;section1) command just like before, but with letters. For an example, you could use the following command to block other users from accessing `FILE`:
198
199     
200
201     % chmod go=FILE
202
203 A comma separated list can be provided when more than one set of changes to a file must be made. For example the following command will remove the groups and ***world*** write permission on `FILE`, then it adds the execute permissions for everyone:
204
205     
206
207     % chmod go-w,a+x FILE
208
209 ### DragonFly File Flags 
210
211 ***Contributed by Tom Rhodes.***
212
213 In addition to file permissions discussed previously, DragonFly supports the use of ***file flags.*** These flags add an additional level of security and control over files, but not directories. These file flags add an additional level of control over files, helping to ensure that in some cases not even the `root` can remove or alter files.  File flags are altered by using the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&amp;section1) utility, using a simple interface. For example, to enable the system undeletable flag on the file `file1`, issue the following command:
214
215     
216
217     # chflags sunlink file1
218
219 And to disable the system undeletable flag, simply issue the previous command with ***no*** in front of the `sunlink`. Observe:
220
221     
222
223     # chflags nosunlink file1
224
225 To view the flags of this file, use the [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ls&amp;section1) with the `-lo` flags:
226
227     
228
229     # ls -lo file1
230
231 The output should look like the following:
232
233     
234
235     -rw-r--r--  1 trhodes  trhodes  sunlnk 0 Mar  1 05:54 file1
236
237 Several flags may only added or removed to files by the `root` user. In other cases, the file owner may set these flags. It is recommended an administrator read over the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&section1) and [chflags(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&section=2) manual pages for more information.
238
239 ## Directory Structure 
240
241 The DragonFly directory hierarchy is fundamental to obtaining an overall understanding of the system. The most important concept to grasp is that of the root directory, ***/***. This directory is the first one mounted at boot time and it contains the base system necessary to prepare the operating system for multi-user operation. The root directory also contains mount points for every other file system that you may want to mount.
242
243 A mount point is a directory where additional file systems can be grafted onto the root file system. This is further described in [ this Section](disk-organization.html). Standard mount points include `/usr`, `/var`, `/tmp`, `/mnt`, and `/cdrom`. These directories are usually referenced to entries in the file `/etc/fstab`. `/etc/fstab` is a table of various file systems and mount points for reference by the system. Most of the file systems in `/etc/fstab` are mounted automatically at boot time from the script [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc&section8) unless they contain the `noauto` option. Details can be found in [ this section](mount-unmount.html#DISKS-FSTAB).
244
245 A complete description of the file system hierarchy is available in [hier(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=hier&section7). For now, a brief overview of the most common directories will suffice.
246
247 [[!table  data="""
248 <tablestyle="width:100%">Directory | Description 
249 <tablestyle="width:100%">  `/` | Root directory of the file system. 
250  `/bin/` | User utilities fundamental to both single-user and multi-user environments. 
251  `/boot/` | Programs and configuration files used during operating system bootstrap. 
252  `/boot/defaults/` | Default bootstrapping configuration files; see [loader.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=loader.conf&section5). 
253  `/dev/` | Device nodes; see [intro(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=intro&section4). 
254  `/etc/` | System configuration files and scripts. 
255  `/etc/defaults/` | Default system configuration files; see [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc&section8). 
256  `/etc/mail/` | Configuration files for mail transport agents such as [sendmail(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendmail&section8). 
257  `/etc/namedb/` | `named` configuration files; see [named(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=named&section8). 
258  `/etc/periodic/` | Scripts that are run daily, weekly, and monthly, via [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section8); see [periodic(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=periodic&section=8). 
259  `/etc/ppp/` | `ppp` configuration files; see [ppp(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=ppp&section8). 
260  `/mnt/` | Empty directory commonly used by system administrators as a temporary mount point. 
261  `/proc/` | Process file system; see [procfs(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=procfs&section5), [mount_procfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount_procfs&section=8). 
262  `/root/` | Home directory for the `root` account. 
263  `/sbin/` | System programs and administration utilities fundamental to both single-user and multi-user environments. 
264  `/tmp/` | Temporary files. The contents of `/tmp` are usually NOT preserved across a system reboot. A memory-based file system is often mounted at `/tmp`. This can be automated with an entry in `/etc/fstab`; see [mfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mfs&section8). 
265  `/usr/` | The majority of user utilities and applications. 
266  `/usr/bin/` | Common utilities, programming tools, and applications. 
267  `/usr/include/` | Standard C include files. 
268  `/usr/lib/` | Archive libraries. 
269  `/usr/libdata/` | Miscellaneous utility data files. 
270  `/usr/libexec/` | System daemons &amp; system utilities (executed by other programs). 
271  `/usr/local/` | Local executables, libraries, etc. Within `/usr/local`, the general layout sketched out by [hier(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=hier&section7) for `/usr` should be used. An exceptions is the man directory, which is directly under `/usr/local` rather than under `/usr/local/share`. 
272  `/usr/obj/` | Architecture-specific target tree produced by building the `/usr/src` tree. 
273  `/usr/pkg` | Used as the default destination for the files installed via the pkgsrc® tree or pkgsrc packages (optional). The configuration directory is tunable, but the default location is `/usr/pkg/etc`. 
274  `/usr/pkg/xorg/` | Xorg distribution executables, libraries, etc (optional). 
275  `/usr/pkgsrc` | The pkgsrc tree for installing packages (optional). 
276  `/usr/sbin/` | System daemons &amp; system utilities (executed by users). 
277  `/usr/share/` | Architecture-independent files. 
278  `/usr/src/` | BSD and/or local source files. 
279  `/var/` | Multi-purpose log, temporary, transient, and spool files. A memory-based file system is sometimes mounted at `/var`. This can be automated with an entry in `/etc/fstab`; see [mfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mfs&section8). 
280  `/var/log/` | Miscellaneous system log files. 
281  `/var/mail/` | User mailbox files. 
282  `/var/spool/` | Miscellaneous printer and mail system spooling directories. 
283  `/var/tmp/` | Temporary files. The files are usually preserved across a system reboot, unless `/var` is a memory-based file system. 
284  `/var/yp` | NIS maps. |
285
286 """]]
287
288 ## Disk Organization 
289
290 The smallest unit of organization that DragonFly uses to find files is the filename. Filenames are case-sensitive, which means that `readme.txt` and `README.TXT` are two separate files. DragonFly does not use the extension (`.txt`) of a file to determine whether the file is a program, or a document, or some other form of data.
291
292 Files are stored in directories.  A directory may contain no files, or it may contain many hundreds of files.  A directory can also contain other directories, allowing you to build up a hierarchy of directories within one another.  This makes it much easier to organize your data.
293
294 Files and directories are referenced by giving the file or directory name, followed by a forward slash, `/`, followed by any other directory names that are necessary.  If you have directory `foo`, which contains directory `bar`, which contains the file `readme.txt`, then the full name, or ***path*** to the file is `foo/bar/readme.txt`.
295
296 Directories and files are stored in a file system. Each file system contains exactly one directory at the very top level, called the ***root directory*** for that file system.  This root directory can then contain other directories.
297
298 So far this is probably similar to any other operating system you may have used.  There are a few differences; for example, MS-DOS® and Windows® use `\`.
299
300 DragonFly does not use drive letters, or other drive names in the path. You would not write `c:/foo/bar/readme.txt` on DragonFly.
301
302 Instead, one file system is designated the ***root file system***.  The root file system's root directory is referred to as `/`.  Every other file system is then ***mounted*** under the root file system. No matter how many disks you have on your DragonFly system, every directory appears to be part of the same disk.
303
304 Suppose you have three file systems, called `A`, `B`, and `C`. Each file system has one root directory, which contains two other directories, called `A1`, `A2` (and likewise `B1`, `B2` and `C1`, `C2`).
305
306 Call `A` the root file system. If you used the `ls` command to view the contents of this directory you would see two subdirectories, `A1` and `A2`.  The directory tree looks like this:
307
308 <!-- XXX: image -->
309
310 A file system must be mounted on to a directory in another file system. So now suppose that you mount file system `B` on to the directory `A1`.  The root directory of `B` replaces `A1`, and the directories in `B` appear accordingly:
311
312 <!-- XXX: image -->
313
314 Any files that are in the `B1` or `B2` directories can be reached with the path `/A1/B1` or `/A1/B2` as necessary. Any files that were in `/A1` have been temporarily hidden.  They will reappear if `B` is ***unmounted*** from A.
315
316 If `B` had been mounted on `A2` then the diagram would look like this:
317
318 <!-- XXX: image -->
319
320 and the paths would be `/A2/B1` and `/A2/B2` respectively.
321
322 File systems can be mounted on top of one another.  Continuing the last example, the `C` file system could be mounted on top of the `B1` directory in the `B` file system, leading to this arrangement:
323
324 <!-- XXX: image -->
325
326 Or `C` could be mounted directly on to the `A` file system, under the `A1` directory:
327
328 <!-- XXX: image -->
329
330 If you are familiar with MS-DOS, this is similar, although not identical, to the `join` command.
331
332 ## Choosing File System Layout 
333
334 This is not normally something you need to concern yourself with. Typically you create file systems when installing DragonFly and decide where to mount them, and then never change them unless you add a new disk.
335
336 It is entirely possible to have one large root file system, and not need to create any others. There are some drawbacks to this approach, and one advantage.
337
338  **Benefits of Multiple File Systems** 
339
340 * Different file systems can have different ***mount options***.  For example, with careful planning, the root file system can be mounted read-only, making it impossible for you to inadvertently delete or edit a critical file.  Separating user-writable file systems, such as `/home`, from other file systems also allows them to be mounted ***nosuid***; this option prevents the ***suid***/***guid*** bits on executables stored on the file system from taking effect, possibly improving security.
341
342 * The UFS file system automatically optimizes the layout of files, depending on how the file system is being used. So a file system that contains many small files that are written frequently will have a different optimization to one that contains fewer, larger files.  By having one big file system this optimization breaks down.
343
344 * DragonFly's file systems are very robust should you lose power.  However, a power loss at a critical point could still damage the structure of the file system.  By splitting your data over multiple file systems it is more likely that the system will still come up, making it easier for you to restore from backup as necessary. This a major reason to make the root file system of limited size, and with low write activity.
345
346  **Benefit of a Single File System** 
347
348 * File systems are a fixed size. If you create a file system when you install DragonFly and give it a specific size, you may later discover that you need to make the partition bigger.  The [growfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=growfs&amp;section8) command makes it possible to increase the size of a UFS file system on the fly.
349 <!-- XXX: what about hammer? -->
350
351 ## Disk Slices, Partitions and local UNIX file systems 
352
353 Here we describe how disks are subdivided.
354
355 <!-- XXX: mention serno stuff -->
356
357 ### Slices 
358
359 A disk can be subdivided in slices.
360
361 Slices are named `s0`, `s1` and so on.
362
363 For example the disk `ad6` can contain the slice `ad6s3`.
364
365 DragonFly support two schemes for slices, MBR and GPT, either of them will manage all slices on a disk:
366
367 * MBR: set up using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&amp;section8), can be up to 2 TB in size.  MBR slices are numbered from 1; but if disk is ***dangerously dedicated*** it has slice number 0.
368
369 * GPT: set up using [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section8), can be extremely large: size up to 8 billion TB.  DragonFly doesn't support booting from a GPT slice in DragonFly  2.0.  Note that GPT slices are numbered from 0. ***Dangerously dedicated*** is not supported nor needed for GPT.  DragonFly 2.1 does have some support for booting from a GPT slice, this is described in [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8).
370
371 ### Partitions 
372
373 Partitions are contained in slices.
374
375 Partitions are named `a`, `b` and so on.
376
377 DragonFly support 16 partitions per slice, that is `a` through `p`.
378
379 For example the partition `ad6s3a` is contained in the slice `ad6s3`.
380
381 Partition layout is defined in a label on the slice where the partition reside. DragonFly support two types of disk labels, disklabel32 and disklabel64 (the default):
382
383 * [disklabel32(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8): 32 bit disk label which can use slices with size up to 2 TB.
384
385 * [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section8): 64 bit disk label which can use very large slices: size up to 16 million TB.
386
387 ### Local UNIX file systems 
388
389 File systems are contained in partitions.  Each partition can contain only one file system, which means that file systems often are described by either their typical mount point in the file system hierarchy, or the letter of the partition they are contained in.  ***Partition*** does not have the same meaning as the common usage of the term partition (for example, MS-DOS partition), because of DragonFly's UNIX® heritage.
390
391 DragonFly support two local UNIX file systems, UFS and HAMMER:
392
393 * UFS: The classical BSD UNIX file system, see [ffs(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#ffs&amp;section5), it supports size up to 2 TB.
394
395 * [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&amp;section5): A new file system, as of DragonFly 2.0, with many advanced features.  HAMMER file system support size up to 1 million TB.
396
397 ### Typical disk layout 
398
399 From the above we see the following typical disk layout scenarios:
400
401 * For booting DragonFly from a local file system UFS is recommended.  A BOOT+HAMMER setup is recommended for HAMMER use, this consists of a small UFS file system for booting, typically 512MB, and a HAMMER root file system.  The BOOT file system is mounted as /boot after boot.
402
403 * For moderate storage requirements UFS can be used; it can be setup on any partition, e.g. on the same disk slice as the boot partition.  HAMMER is an alternative, with extra features supported, like history retention.  You should evaluate if HAMMER is suitable, see note below.
404
405 * If really big storage capacity is needed UFS can't fit the need.  You should evaluate if HAMMER is suitable, see note below.  For this use HAMMER needs to be used on a GPT slice with  a [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section8) label.  In DragonFly 2.0 it has to be set up on a disk separate from the boot disk.  In  DragonFly 2.1 one disk can be used for both booting and HAMMER file system on GPT slice, as some support for booting from GPT is present, as described in [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8).
406
407 ### HAMMER Note 
408
409 [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&amp;section5)
410
411 is a rather new file system, under active development.
412
413 As of DragonFly 2.2.1 release HAMMER is considered production ready.  At 2.0 release it was considered to be in an early Beta state .
414
415 All major features except the mirroring are quite well tested as-of the 2.2.1 release.
416
417 You should evaluate if HAMMER is suitable for your needs.
418 <!-- XXX: mention disk and memory requirements for efficient hammer use -->
419
420 Examples of ongoing development includes:
421
422 * Making HAMMER more self managing; e.g. ability to setup policy for which history to save for how long: e.g. make snapshot every hour and prune and reblock the file system regularly.  When snapshot gets older than 1 month only keep them for every 6 hours; when older than 3 months only keep snapshot for every 24 hours, when older than 3 years only keep snapshot per month.  For now you need to set up [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&amp;section8) jobs for this yourself, see [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8).
423
424 * Multi master mirroring. For now only one mirror master is supported, but multiple mirror targets, called slaves, are already supported.
425
426 * Support for shrinking existing HAMMER file systems.  The HAMMER design is prepared for this, utility just have to be written to support it.
427 <!-- XXX: is this still accurate? Do we really want to mention it here? -->
428
429 ### HAMMER Features 
430
431 [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&amp;section5) has several advanced features not found in UFS:
432
433 * Large file systems:  Up to 1 million TB, also called 1 Exabyte is supported.
434
435 * Multiple volumes:  A HAMMER file system can span up to 256 disks, each partition part of a HAMMER file system is called a volume.  Each volume can be up to 4096 TB in size.
436
437 * Support for growing and shrinking existing HAMMER file systems: adding and removing volumes from the file system.  As of 2.4 release an existing HAMMER file system can be expanded by adding extra space, see the `expand` directive to [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8).  The HAMMER design is also prepared for removing volumes, utilities just have to be written to support it.
438
439 * Instant crash recovery:  If a crash should occur, then HAMMER file systems will be ready a few seconds after boot, no lenghty fsck have to be run.
440
441 * Full history retention:  All file system changes are saved every ~30 seconds.  Changes are written at least when sync() is called, see [syncer(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=syncer&amp;section4).  Every time data for files are written to disk a transaction is completed, this is assigned an ID and the file updated can after this be accessed with the contents from this moment.  To access the file with the state of this moment, the transaction ID, TID for brevity, just needs to be added to the file name, like: 'file@@<TID>'.  The TID can be saved from the 'snapshot', 'cleanup', or 'synctid' [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8) command or looked up with the 'hammer history file' command.  This history will typically grow over time, so any disk will fill up over time.  Two things are done so disks doesn't fill up: first: big disks are used, at least 50GB is typical for HAMMER file systems, and second: unused history information is deleted regularly. Here we need to define what unused means: a TID is used if a snapshot have been taken on it. Data assigned to unused history can be reclaimed using the `prune` and `reblock` [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8) commands, this will also defragment the file system and can be done while the file system is in normal operation.  Generally after file system is pruned only TIDs for the snapshots or newer than newest shapshot should be used, see explanation [here](http://leaf.dragonflybsd.org/mailarchive/bugs/2008-07/msg00213.html) (more info on HAMMER design [here](http://leaf.dragonflybsd.org/mailarchive/kernel/2008-07/msg00114.html)).  See also [hammer(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=5). 
442
443 * Mirroring:  A master file system can be mirrored online to a number of slave file systems.  Mirror targets are read-only, but does have history available.  History retension policy can even be different on slaves and master.  Mirroring can be over network and unreliable connections are handled gracefully.
444
445 * Data integrity:  HAMMER has high focus in data integrity and implements a CRC checksum on all data, this means that if disk fails with bit errors it will be detected.
446
447 More info on HAMMER can be found [here](http://www.dragonflybsd.org/hammer/index.html).
448
449 DragonFly also uses disk space for ***swap space***.  Swap space provides DragonFly with ***virtual memory***.  This allows your computer to behave as though it has much more memory than it actually does.  When DragonFly runs low on memory it moves some of the data that is not currently being used to the swap space, and moves it back in (moving something else out) when it needs it.
450
451 <!-- XXX: mention swapcache, and also how to configure and use it (somewhere else, probably) -->
452
453 ### Adding a Disk 
454
455 Adding a disk is done by installing it physically, and to connect it to a disk controller that DragonFly supports.  If you are in doubt if controller is supported, manual pages for disk controllers can be consulted ('man -k disk' or 'man -k scsi' can be of help).  The easiest thing is normally to boot DargonFly with the controller installed and note if boot message contains the controller.
456
457 Assuming that disk `ad6` is installed, we could set it up using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&amp;section8) and  disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8) or  [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section8) and 
458 [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section8).
459
460 In this example we choose [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8) & [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section=8).
461
462 <!-- XXX: mention that disklabel64 is default now -->
463     
464
465     # gpt -v create ad6
466
467     ...
468
469     # gpt add -s1 ad6
470
471     ad6s0
472
473     # gpt add ad6
474
475     ad6s1
476
477     # gpt show ad6
478
479     ...
480
481 Here we first create the GPT and then add two slices.  In this example the first slice added is `ad6s0`, which is made a dummy slice of size 1 sector, this is just for not having to make further reference to it, as many users remembers that `s0` has special meaning, which really isn't true for GPT slices.  The second slice is `ad6s1` which will cover the rest of the disk.
482
483     
484
485     # disklabel64 -rw ad6s1 auto
486
487     # disklabel64 -e ad6s1          # edit label to add partitions as needed
488
489 ### disklabel 
490 <!-- XXX: what is all this fuzz about dangerously dedicated? -->
491
492 For [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8) labels some partitions have certain conventions associated with them.
493
494 [[!table  data="""
495 <tablestyle="width:100%"> Partition | Convention 
496 <tablestyle="width:100%"> `a` | Normally contains the root file system 
497  `b` | Normally contains swap space 
498  `c` | Normally the same size as the enclosing slice.  This allows utilities that need to work on the entire slice (for example, a bad block scanner) to work on the `c` partition. You would not normally create a file system on this partition. This is not necessarily true; it is possible to use the 'c' partition as a normal partition.
499  `d` | Partition `d` used to have a special meaning associated with it, although that is now gone.  To this day, some tools may operate oddly if told to work on partition `d`. |
500
501 """]]
502
503 Each partition-that-contains-a-file-system is stored in what DragonFly calls a ***slice***.  Slice is DragonFly's term for what the common call partitions, and again, this is because of DragonFly's UNIX background.  Slices are numbered, starting at 1.
504
505 Slice numbers follow the device name, prefixed with an `s`, starting at 1. So ***da0s1*** is the first slice on the first SCSI drive. There can only be four physical slices on a disk, but you can have logical slices inside physical slices of the appropriate type.  These extended slices are numbered starting at 5, so ***ad0s5*** is the first extended slice on the first IDE disk. These devices are used by file systems that expect to occupy a slice.
506
507 <!-- XXX: gpt allows for way more than 4 partitions... let's remove this stuff above -->
508
509 ***Dangerously dedicated*** physical drives are accessed as slice 0.
510
511 Slices, ***dangerously dedicated*** physical drives, and other drives contain ***partitions***, which are represented as letters from `a` to `p`.  This letter is appended to the device name, so ***da0s0a*** is the a partition on the first da drive, which is ***dangerously dedicated***. ***ad1s3e*** is the fifth partition in the third slice of the second IDE disk drive.
512
513 Finally, each disk on the system is identified.  A disk name starts with a code that indicates the type of disk, and then a number, indicating which disk it is.  Disk numbering starts at 0. Common codes that you will see are listed in [Table 3-1](disk-organization.html#BASICS-DEV-CODES).
514
515 <!-- XXX: here would probably be the right place to talk about serno -->
516
517 When referring to a partition DragonFly requires that you also name the slice and disk that contains the partition, and when referring to a slice you should also refer to the disk name. Do this by listing the disk name, `s`, the slice number, and then the partition letter.  Examples are shown in [Example 3-1](disk-organization.html#BASICS-DISK-SLICE-PART).
518
519 <!-- XXX: later talk also about devfs, definitely not here though. also, devfs rules -->
520
521 [Example 3-2](disk-organization.html#BASICS-CONCEPT-DISK-MODEL) shows a conceptual model of the disk layout that should help make things clearer.
522
523 In order to install DragonFly you must first configure the disk slices, then create partitions within the slice you will use for DragonFly, and then create a file system (or swap space) in each partition, and decide where that file system will be mounted.
524
525 ***'Table 3-1. Disk Device Codes***'
526
527 [[!table  data="""
528 <tablestyle="width:100%"> Code | Meaning 
529 <tablestyle="width:100%"> `ad` | ATAPI (IDE) disk 
530  `da` | SCSI direct access disk 
531  `acd` | ATAPI (IDE) CDROM 
532  `cd` | SCSI CDROM 
533  `vn` | Virtual disk
534  `fd` | Floppy disk |
535
536 """]]
537
538 ***'Example 3-1. Sample Disk, Slice, and Partition Names***'
539
540 [[!table  data="""
541 <tablestyle="width:100%"> Name | Meaning 
542 <tablestyle="width:100%"> `ad0s1a` | The first partition (`a`) on the first slice (`s1`) on the first IDE disk (`ad0`). 
543  `da1s2e` | The fifth partition (`e`) on the second slice (`s2`) on the second SCSI disk (`da1`). |
544
545 """]]
546
547 ***'Example 3-2. Conceptual Model of a Disk***'
548
549 This diagram shows DragonFly's view of the first IDE disk attached to the system. Assume that the disk is 4 GB in size, and contains two 2 GB slices (MS-DOS partitions).  The first slice contains a MS-DOS disk, `C:`, and the second slice contains a DragonFly installation. This example DragonFly installation has three partitions, and a swap partition.
550
551 The three partitions will each hold a file system. Partition `a` will be used for the root file system, `e` for the `/var` directory hierarchy, and `f` for the `/usr` directory hierarchy.
552
553 <!-- XXX: image -->
554
555 ## Mounting and Unmounting File Systems 
556
557 The file system is best visualized as a tree, rooted at `/`.
558
559 The directories, e.g. `/dev` and `/usr`, in the root directory are branches,
560
561 which may have their own branches, such as `/usr/local`, and so on.
562
563 There are various reasons to house some of these directories on separate file systems. `/var` contains the directories `log/` and `spool/`, and various types of temporary files, and as such, may get filled up. Filling up the root file system is not a good idea, so splitting `/var` from `/` is often favorable.
564
565 Another common reason to contain certain directory trees on other file systems is if they are to be housed on separate physical disks, e.g. CD-ROM, or are used as separate virtual disks, such as [Network File System](network-nfs.html) exports.
566
567 ### The fstab File 
568
569 During the [boot process](boot.html), file systems listed in `/etc/fstab` are automatically mounted (unless they are listed with the `noauto` option).
570
571 The `/etc/fstab` file contains a list of lines of the following format:
572   
573
574     device       mount-point   fstype     options      dumpfreq     passno
575
576 These parameters have the following meaning:
577
578 * `device`: A device name (which should exist), as explained [here](disks-naming.html).
579
580 * `mount-point`: A directory (which should exist), on which to mount the file system.
581
582 * `fstype`: The file system type to pass to [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8). The default DragonFly file system is `ufs`.
583
584 * `options`: Either `rw` for read-write file systems, or `ro` for read-only file systems, followed by any other options that may be needed. A common option is `noauto` for file systems not normally mounted during the boot sequence. Other options are listed in the [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) manual page.
585
586 * `dumpfreq`: This is used by [dump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dump&section8) to determine which file systems require dumping. If the field is missing, a value of zero is assumed.
587
588 * `passno`: This determines the order in which file systems should be checked. File systems that should be skipped should have their `passno` set to zero. The root file system (which needs to be checked before everything else) should have its `passno` set to one, and other file systems' `passno` should be set to values greater than one. If more than one file systems have the same `passno` then [fsck(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fsck&section8) will attempt to check file systems in parallel if possible.
589
590 Consult the [fstab(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=fstab&section5) manual page for more information on the format of the `/etc/fstab` file and the options it contains.
591
592 ### The mount Command 
593
594 The [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) command is what is ultimately used to mount file systems.
595
596 In its most basic form, you use:
597
598     
599
600     # mount device mountpoint
601
602 Or, if `mountpoint` is specified in `/etc/fstab`, just:
603
604     
605
606     # mount mountpoint
607
608 There are plenty of options, as mentioned in the [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) manual page, but the most common are:
609
610  **Mount Options** 
611
612 * `-a`: Mount all the file systems listed in `/etc/fstab`. Except those marked as `noauto`, excluded by the `-t` flag, or those that are already mounted.
613
614 * `-d`: Do everything except for the actual mount system call. This option is useful in conjunction with the `-v` flag to determine what [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) is actually trying to do.
615
616 * `-f`: Force the mount of an unclean file system (dangerous), or forces the revocation of write access when downgrading a file system's mount status from read-write to read-only.
617
618 * `-r`: Mount the file system read-only. This is identical to using the `rdonly` argument to the `-o` option.
619
620 * `-t` ***fstype***: Mount the given file system as the given file system type, or, if used with `-a` option, mount only file systems of the given type. `ufs` is the default file system type.
621
622 * `-u`: Update mount options on the file system.
623
624 * `-v`: Be verbose.
625
626 * `-w`: Mount the file system read-write.
627
628 The `-o` option takes a comma-separated list of the options, including the following:
629
630 * `nodev:` Do not interpret special devices on the file system. This is a useful security option.
631
632 * `noexec`: Do not allow execution of binaries on this file system. This is also a useful security option.
633
634 * `nosuid`: Do not interpret setuid or setgid flags on the file system. This is also a useful security option.
635
636 ### The umount Command 
637
638 The [umount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=umount&section8) command takes, as a parameter, one of a mountpoint, a device name, or the `-a` or `-A` option.
639
640 All forms take `-f` to force unmounting, and `-v` for verbosity. Be warned that `-f` is not generally a good idea. Forcibly unmounting file systems might crash the computer or damage data on the file system.
641
642 `-a` and `-A` are used to unmount all mounted file systems, possibly modified by the file system types listed after `-t`. `-A`, however, does not attempt to unmount the root file system.
643
644 ## Processes 
645
646 DragonFly is a multi-tasking operating system. This means that it seems as though more than one program is running at once. Each program running at any one time is called a ***process***. Every command you run will start at least one new process, and there are a number of system processes that run all the time, keeping the system functional.
647
648 <!-- XXX: talk about LWPs and threads? -->
649
650 Each process is uniquely identified by a number called a ***process ID***, or ***PID***, and, like files, each process also has one owner and group. The owner and group information is used to determine what files and devices the process can open, using the file permissions discussed earlier. Most processes also have a parent process. The parent process is the process that started them. For example, if you are typing commands to the shell then the shell is a process, and any commands you run are also processes. Each process you run in this way will have your shell as its parent process. The exception to this is a special process called [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init&section8). `init` is always the first process, so its PID is always 1. `init` is started automatically by the kernel when DragonFly starts.
651
652 Two commands are particularly useful to see the processes on the system, [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section1) and [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1). The `ps` command is used to show a static list of the currently running processes, and can show their PID, how much memory they are using, the command line they were started with, and so on. The `top` command displays all the running processes, and updates the display every few seconds, so that you can interactively see what your computer is doing.
653
654 By default, `ps` only shows you the commands that are running and are owned by you. For example:
655
656     
657
658     % ps
659
660       PID  TT  STAT      TIME COMMAND
661       298  p0  Ss     0:01.10 tcsh
662      7078  p0  S      2:40.88 xemacs mdoc.xsl (xemacs-21.1.14)
663     37393  p0  I      0:03.11 xemacs freebsd.dsl (xemacs-21.1.14)
664     48630  p0  S      2:50.89 /usr/local/lib/netscape-linux/navigator-linux-4.77.bi
665     48730  p0  IW     0:00.00 (dns helper) (navigator-linux-)
666     72210  p0  R+     0:00.00 ps
667       390  p1  Is     0:01.14 tcsh
668      7059  p2  Is+    1:36.18 /usr/local/bin/mutt -y
669      6688  p3  IWs    0:00.00 tcsh
670     10735  p4  IWs    0:00.00 tcsh
671     20256  p5  IWs    0:00.00 tcsh
672       262  v0  IWs    0:00.00 -tcsh (tcsh)
673       270  v0  IW+    0:00.00 /bin/sh /usr/X11R6/bin/startx -- -bpp 16
674       280  v0  IW+    0:00.00 xinit /home/nik/.xinitrc -- -bpp 16
675       284  v0  IW     0:00.00 /bin/sh /home/nik/.xinitrc
676       285  v0  S      0:38.45 /usr/X11R6/bin/sawfish
677
678 As you can see in this example, the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section1) is organized into a number of columns. `PID` is the process ID discussed earlier. PIDs are assigned starting from 1, go up to 99999, and wrap around back to the beginning when you run out. The `TT` column shows the tty the program is running on, and can safely be ignored for the moment. `STAT` shows the program's state, and again, can be safely ignored. `TIME` is the amount of time the program has been running on the CPU--this is usually not the elapsed time since you started the program, as most programs spend a lot of time waiting for things to happen before they need to spend time on the CPU. Finally, `COMMAND` is the command line that was used to run the program.
679
680 [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section1) supports a number of different options to change the information that is displayed. One of the most useful sets is `auxww`. `a` displays information about all the running processes, not just your own. `u` displays the username of the process' owner, as well as memory usage. `x` displays information about daemon processes, and `ww` causes [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) to display the full command line, rather than truncating it once it gets too long to fit on the screen.
681
682 The output from [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section1) is similar. A sample session looks like this:
683
684     
685
686     % top
687     last pid: 72257;  load averages:  0.13,  0.09,  0.03    up 0+13:38:33  22:39:10
688     47 processes:  1 running, 46 sleeping
689     CPU states: 12.6% user,  0.0% nice,  7.8% system,  0.0% interrupt, 79.7% idle
690     Mem: 36M Active, 5256K Inact, 13M Wired, 6312K Cache, 15M Buf, 408K Free
691     Swap: 256M Total, 38M Used, 217M Free, 15% Inuse
692     
693
694       PID USERNAME PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND
695     72257 nik       28   0  1960K  1044K RUN      0:00 14.86%  1.42% top
696      7078 nik        2   0 15280K 10960K select   2:54  0.88%  0.88% xemacs-21.1.14
697       281 nik        2   0 18636K  7112K select   5:36  0.73%  0.73% XF86_SVGA
698       296 nik        2   0  3240K  1644K select   0:12  0.05%  0.05% xterm
699     48630 nik        2   0 29816K  9148K select   3:18  0.00%  0.00% navigator-linu
700       175 root       2   0   924K   252K select   1:41  0.00%  0.00% syslogd
701      7059 nik        2   0  7260K  4644K poll     1:38  0.00%  0.00% mutt
702     ...
703
704 The output is split into two sections. The header (the first five lines) shows the PID of the last process to run, the system load averages (which are a measure of how busy the system is), the system uptime (time since the last reboot) and the current time. The other figures in the header relate to how many processes are running (47 in this case), how much memory and swap space has been taken up, and how much time the system is spending in different CPU states.
705
706 Below that are a series of columns containing similar information to the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section1). As before you can see the PID, the username, the amount of CPU time taken, and the command that was run. [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1) also defaults to showing you the amount of memory space taken by the process. This is split into two columns, one for total size, and one for resident size--total size is how much memory the application has needed, and the resident size is how much it is actually using at the moment. In this example you can see that  **Netscape®**  has required almost 30 MB of RAM, but is currently only using 9 MB.
707
708 [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section1) automatically updates this display every two seconds; this can be changed with the `s` option.
709
710 ## Daemons, Signals, and Killing Processes 
711
712 When you run an editor it is easy to control the editor, tell it to load files, and so on. You can do this because the editor provides facilities to do so, and because the editor is attached to a ***terminal***. Some programs are not designed to be run with continuous user input, and so they disconnect from the terminal at the first opportunity. For example, a web server spends all day responding to web requests, it normally does not need any input from you. Programs that transport email from site to site are another example of this class of application.
713
714 We call these programs ***daemons***. Daemons were characters in Greek mythology; neither good or evil, they were little attendant spirits that, by and large, did useful things for mankind. Much like the web servers and mail servers of today do useful things. This is why the mascot for a number of BSD-based operating systems has, for a long time, been a cheerful looking daemon with sneakers and a pitchfork.
715
716 There is a convention to name programs that normally run as daemons with a trailing ***d***.  **BIND**  is the Berkeley Internet Name Daemon (and the actual program that executes is called `named`), the  **Apache**  web server program is called `httpd`, the line printer spooling daemon is `lpd` and so on. This is a convention, not a hard and fast rule; for example, the main mail daemon for the  **Sendmail**  application is called `sendmail`, and not `maild`, as you might imagine.
717
718 Sometimes you will need to communicate with a daemon process. These communications are called ***signals***, and you can communicate with a daemon (or with any other running process) by sending it a signal. There are a number of different signals that you can send--some of them have a specific meaning, others are interpreted by the application, and the application's documentation will tell you how that application interprets signals. You can only send a signal to a process that you own. If you send a signal to someone else's process with [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) or [kill(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=2) permission will be denied. The exception to this is the `root` user, who can send signals to everyone's processes.
719
720 DragonFly will also send applications signals in some cases. If an application is badly written, and tries to access memory that it is not supposed to, DragonFly sends the process the ***Segmentation Violation*** signal (`SIGSEGV`). If an application has used the [alarm(3)](http://leaf.dragonflybsd.org/cgi/web-man?command=alarm&section=3) system call to be alerted after a period of time has elapsed then it will be sent the Alarm signal (`SIGALRM`), and so on.
721
722 Two signals can be used to stop a process, `SIGTERM` and `SIGKILL`. `SIGTERM` is the polite way to kill a process; the process can ***catch*** the signal, realize that you want it to shut down, close any log files it may have open, and generally finish whatever it is doing at the time before shutting down. In some cases a process may even ignore `SIGTERM` if it is in the middle of some task that can not be interrupted.
723
724 `SIGKILL` can not be ignored by a process. This is the ***I do not care what you are doing, stop right now*** signal. If you send `SIGKILL` to a process then DragonFly will stop that process there and then[(1)](#FTN.AEN2181).
725
726 The other signals you might want to use are `SIGHUP`, `SIGUSR1`, and `SIGUSR2`. These are general purpose signals, and different applications will do different things when they are sent.
727
728 Suppose that you have changed your web server's configuration file--you would like to tell the web server to re-read its configuration. You could stop and restart `httpd`, but this would result in a brief outage period on your web server, which may be undesirable. Most daemons are written to respond to the `SIGHUP` signal by re-reading their configuration file. So instead of killing and restarting `httpd` you would send it the `SIGHUP` signal. Because there is no standard way to respond to these signals, different daemons will have different behavior, so be sure and read the documentation for the daemon in question.
729
730 Signals are sent using the [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) command, as this example shows.
731
732  **Sending a Signal to a Process** 
733
734 This example shows how to send a signal to [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8). The `inetd` configuration file is `/etc/inetd.conf`, and `inetd` will re-read this configuration file when it is sent `SIGHUP`.
735
736   1. Find the process ID of the process you want to send the signal to. Do this using [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section=1) and [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep&section=1). The [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep&section=1) command is used to search through output, looking for the string you specify. This command is run as a normal user, and [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) is run as `root`, so the `ax` options must be given to [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1).
737
738       
739
740         % ps -ax | grep inetd
741
742         198  ??  IWs    0:00.00 inetd -wW
743
744   
745
746   So the [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#inetd&section8) PID is 198. In some cases the `grep inetd` command might also occur in this output. This is because of the way [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) has to find the list of running processes.
747
748   2. Use [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) to send the signal. Because [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) is being run by `root` you must use [su(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=su&section=1) to become `root` first.
749
750       
751
752         % su
753
754         Password:
755
756         # /bin/kill -s HUP 198
757
758   
759
760   In common with most UNIX® commands, [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) will not print any output if it is successful. If you send a signal to a process that you do not own then you will see `kill: PID: Operation not permitted`. If you mistype the PID you will either send the signal to the wrong process, which could be bad, or, if you are lucky, you will have sent the signal to a PID that is not currently in use, and you will see `kill: PID: No such process`.
761
762 **Why Use `/bin/kill`?** Many shells provide the `kill` command as a built in command; that is, the shell will send the signal directly, rather than running `/bin/kill`. This can be very useful, but different shells have a different syntax for specifying the name of the signal to send. Rather than try to learn all of them, it can be simpler just to use the `/bin/kill ...` command directly.
763
764 Sending other signals is very similar, just substitute `TERM` or `KILL` in the command line as necessary.
765
766  **Important:** Killing random process on the system can be a bad idea. In particular, [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init&section=8), process ID 1, is very special. Running `/bin/kill -s KILL 1` is a quick way to shutdown your system. ***Always*** double check the arguments you run [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) with ***before*** you press  **Return** .
767
768  
769  
770  
771  
772  
773 ## Shells 
774
775 In DragonFly, a lot of everyday work is done in a command line interface called a shell. A shell's main job is to take commands from the input channel and execute them. A lot of shells also have built in functions to help everyday tasks such as file management, file globbing, command line editing, command macros, and environment variables. DragonFly comes with a set of shells, such as `sh`, the Bourne Shell, and `tcsh`, the improved C-shell. Many other shells are available from pkgsrc®, such as `zsh` and `bash`.
776
777 Which shell do you use? It is really a matter of taste. If you are a C programmer you might feel more comfortable with a C-like shell such as `tcsh`. If you have come from Linux or are new to a UNIX® command line interface you might try `bash`. The point is that each shell has unique properties that may or may not work with your preferred working environment, and that you have a choice of what shell to use.
778
779 One common feature in a shell is filename completion. Given the typing of the first few letters of a command or filename, you can usually have the shell automatically complete the rest of the command or filename by hitting the  **Tab**  key on the keyboard. Here is an example. Suppose you have two files called `foobar` and `foo.bar`. You want to delete `foo.bar`. So what you would type on the keyboard is: `rm fo[ **Tab** ].[ **Tab** ]`.
780
781 The shell would print out `rm foo[BEEP].bar`.
782
783 The [BEEP] is the console bell, which is the shell telling me it was unable to totally complete the filename because there is more than one match. Both `foobar` and `foo.bar` start with `fo`, but it was able to complete to `foo`. If you type in `.`, then hit  **Tab**  again, the shell would be able to fill in the rest of the filename for you.
784
785 Another feature of the shell is the use of environment variables. Environment variables are a variable key pair stored in the shell's environment space. This space can be read by any program invoked by the shell, and thus contains a lot of program configuration. Here is a list of common environment variables and what they mean:
786
787 [[!table  data="""
788 <tablestyle="width:100%"> Variable | Description 
789 <tablestyle="width:100%"> `USER` | Current logged in user's name. 
790  `PATH` | Colon separated list of directories to search for binaries. 
791  `DISPLAY` | Network name of the X11 display to connect to, if available. 
792  `SHELL` | The current shell. 
793  `TERM` | The name of the user's terminal. Used to determine the capabilities of the terminal. 
794  `TERMCAP` | Database entry of the terminal escape codes to perform various terminal functions. 
795  `OSTYPE` | Type of operating system. e.g., DragonFly. 
796  `MACHTYPE` | The CPU architecture that the system is running on. 
797  `EDITOR` | The user's preferred text editor. 
798  `PAGER` | The user's preferred text pager. 
799  `MANPATH` | Colon separated list of directories to search for manual pages. |
800
801 """]]
802
803 Setting an environment variable differs somewhat from shell to shell. For example, in the C-Style shells such as `tcsh` and `csh`, you would use `setenv` to set environment variables. Under Bourne shells such as `sh` and `bash`, you would use `export` to set your current environment variables. For example, to set or modify the `EDITOR` environment variable, under `csh` or `tcsh` a command like this would set `EDITOR` to `/usr/pkg/bin/emacs`:
804     
805
806     % setenv EDITOR /usr/pkg/bin/emacs
807
808 Under Bourne shells:
809    
810
811     % export EDITOR="/usr/pkg/bin/emacs"
812
813 You can also make most shells expand the environment variable by placing a `$` character in front of it on the command line. For example, `echo $TERM` would print out whatever `$TERM` is set to, because the shell expands `$TERM` and passes it on to `echo`.
814
815 Shells treat a lot of special characters, called meta-characters as special representations of data. The most common one is the `*` character, which represents any number of characters in a filename. These special meta-characters can be used to do filename globbing. For example, typing in `echo *` is almost the same as typing in `ls` because the shell takes all the files that match `*` and puts them on the command line for `echo` to see.
816
817 To prevent the shell from interpreting these special characters, they can be escaped from the shell by putting a backslash (`\`) character in front of them. `echo $TERM` prints whatever your terminal is set to. `echo \$TERM` prints `$TERM` as is.
818
819 ### Changing Your Shell 
820
821 <!-- XXX: does chsh still exist? chpass will do, too -->
822
823 The easiest way to change your shell is to use the `chsh` command. Running `chsh` will place you into the editor that is in your `EDITOR` environment variable; if it is not set, you will be placed in `vi`. Change the ***Shell:*** line accordingly.
824
825 You can also give `chsh` the `-s` option; this will set your shell for you, without requiring you to enter an editor. For example, if you wanted to change your shell to `bash`, the following should do the trick:
826
827     
828
829     % chsh -s /usr/pkg/bin/bash
830
831  **Note:** The shell that you wish to use ***must*** be present in the `/etc/shells` file. If you have installed a shell from the [ pkgsrc tree ](pkgsrc.html), then this should have been done for you already. If you installed the shell by hand, you must do this.
832
833 For example, if you installed `bash` by hand and placed it into `/usr/local/bin`, you would want to:
834
835     
836
837     # echo "/usr/local/bin/bash" >> /etc/shells
838
839 Then rerun `chsh`.
840
841 ## Text Editors 
842
843 A lot of configuration in DragonFly is done by editing text files. Because of this, it would be a good idea to become familiar with a text editor. DragonFly comes with a few as part of the base system, and many more are available in the pkgsrc® tree.
844
845 The easiest and simplest editor to learn is an editor called  **ee** , which stands for easy editor. To start  **ee** , one would type at the command line `ee filename` where `filename` is the name of the file to be edited. For example, to edit `/etc/rc.conf`, type in `ee /etc/rc.conf`. Once inside of `ee`, all of the commands for manipulating the editor's functions are listed at the top of the display. The caret `^` character represents the  **Ctrl**  key on the keyboard, so `^e` expands to the key combination  **Ctrl** + **e** . To leave  **ee** , hit the  **Esc**  key, then choose leave editor. The editor will prompt you to save any changes if the file has been modified.
846
847 DragonFly also comes with more powerful text editors such as  **vi**  as part of the base system, while other editors, like  **emacs**  and  **vim** , are part of the pkgsrc tree. These editors offer much more functionality and power at the expense of being a little more complicated to learn. However if you plan on doing a lot of text editing, learning a more powerful editor such as  **vim**  or  **emacs**  will save you much more time in the long run.
848
849 ## Devices and Device Nodes 
850
851 A device is a term used mostly for hardware-related activities in a system, including disks, printers, graphics cards, and keyboards. When DragonFly boots, the majority of what DragonFly displays are devices being detected. You can look through the boot messages again by viewing `/var/run/dmesg.boot`.
852
853 For example, `acd0` is the first IDE CDROM drive, while `kbd0` represents the keyboard.
854
855 Most of these devices in a UNIX® operating system must be accessed through special files called device nodes, which are located in the `/dev` directory.
856
857 The device nodes in the `/dev` directory are created and destroyed automatically on DragonFly >= 2.4, by means of the device file system (devfs).
858
859 ## Binary Formats 
860
861 To understand why DragonFly uses the [elf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=elf&amp;section=5) format, you must first know a little about the three currently ***dominant*** executable formats for UNIX®:
862
863 * [a.out(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=a.out&amp;section=5)
864
865   The oldest and ***classic*** UNIX object format. It uses a short and compact header with a magic number at the beginning that is often used to characterize the format (see [a.out(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=a.out&amp;section=5) for more details). It contains three loaded segments: .text, .data, and .bss plus a symbol table and a string table.
866
867 * <u>COFF</u>
868
869   The SVR3 object format. The header now comprises a section table, so you can have more than just .text, .data, and .bss sections.
870
871 * [elf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=elf&amp;section=5)
872
873   The successor to COFF, featuring multiple sections and 32-bit or 64-bit possible values. One major drawback: ELF was also designed with the assumption that there would be only one ABI per system architecture. That assumption is actually quite incorrect, and not even in the commercial SYSV world (which has at least three ABIs: SVR4, Solaris, SCO) does it hold true. DragonFly tries to work around this problem somewhat by providing a utility for ***branding*** a known ELF executable with information about the ABI it is compliant with. See the manual page for [brandelf(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=brandelf&amp;section=1) for more information. DragonFly runs ELF.
874
875 So, why are there so many different formats? Back in the dim, dark past, there was simple hardware. This simple hardware supported a simple, small system. `a.out` was completely adequate for the job of representing binaries on this simple system (a PDP-11). As people ported UNIX from this simple system, they retained the `a.out` format because it was sufficient for the early ports of UNIX to architectures like the Motorola 68k, VAXen, etc.
876
877 Then some bright hardware engineer decided that if he could force software to do some sleazy tricks, then he would be able to shave a few gates off the design and allow his CPU core to run faster. While it was made to work with this new kind of hardware (known these days as RISC), `a.out` was ill-suited for this hardware, so many formats were developed to get to a better performance from this hardware than the limited, simple `a.out` format could offer. Things like COFF, ECOFF, and a few obscure others were invented and their limitations explored before things seemed to settle on ELF.
878
879 In addition, program sizes were getting huge and disks (and physical memory) were still relatively small so the concept of a shared library was born. The VM system also became more sophisticated. While each one of these advancements was done using the `a.out` format, its usefulness was stretched more and more with each new feature. In addition, people wanted to dynamically load things at run time, or to junk parts of their program after the init code had run to save in core memory and swap space. Languages became more sophisticated and people wanted code called before main automatically. Lots of hacks were done to the `a.out` format to allow all of these things to happen, and they basically worked for a time. In time, `a.out` was not up to handling all these problems without an ever increasing overhead in code and complexity. While ELF solved many of these problems, it would be painful to switch from the system that basically worked. So ELF had to wait until it was more painful to remain with `a.out` than it was to migrate to ELF.
880
881 ELF is more expressive than `a.out` and allows more extensibility in the base system. The ELF tools are better maintained, and offer cross compilation support, which is important to many people. ELF may be a little slower than `a.out`, but trying to measure it can be difficult. There are also numerous details that are different between the two in how they map pages, handle init code, etc. None of these are very important, but they are differences.
882
883 <!-- XXX: do we really need all this bullshit about file formats? -->
884
885 ## For More Information 
886
887 ### Manual Pages 
888
889 The most comprehensive documentation on DragonFly is in the form of manual pages. Nearly every program on the system comes with a short reference manual explaining the basic operation and various arguments. These manuals can be viewed with the `man` command. Use of the `man` command is simple:
890
891     % man command
892
893 `command` is the name of the command you wish to learn about. For example, to learn more about `ls` command type:
894
895     % man ls
896
897 The online manual is divided up into numbered sections:
898
899   1. User commands.
900   1. System calls and error numbers.
901   1. Functions in the C libraries.
902   1. Device drivers.
903   1. File formats.
904   1. Games and other diversions.
905   1. Miscellaneous information.
906   1. System maintenance and operation commands.
907   1. Kernel internals.
908
909 In some cases, the same topic may appear in more than one section of the online manual. For example, there is a `chmod` user command and a `chmod()` system call. In this case, you can tell the `man` command which one you want by specifying the section:
910     
911
912     % man 1 chmod
913
914 This will display the manual page for the user command `chmod`. References to a particular section of the online manual are traditionally placed in parenthesis in written documentation, so [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section=1) refers to the `chmod` user command and [chmod(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section=2) refers to the system call.
915
916 This is fine if you know the name of the command and simply wish to know how to use it, but what if you cannot recall the command name? You can use `man` to search for keywords in the command descriptions by using the `-k` switch:
917
918    
919
920     % man -k mail
921
922 With this command you will be presented with a list of commands that have the keyword ***mail*** in their descriptions. This is actually functionally equivalent to using the `apropos` command.
923
924 So, you are looking at all those fancy commands in `/usr/bin` but do not have the faintest idea what most of them actually do? Simply do:    
925
926     % cd /usr/bin
927     % man -f *
928
929 or
930    
931
932     % cd /usr/bin
933     % whatis *
934
935 which does the same thing.
936
937 ### GNU Info Files 
938
939 DragonFly includes many applications and utilities produced by the Free Software Foundation (FSF). In addition to manual pages, these programs come with more extensive hypertext documents called `info` files which can be viewed with the `info` command or, if you installed  **emacs** , the info mode of  **emacs** . To use the [info(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=info&section=1) command, simply type:
940
941     % info
942
943 For a brief introduction, type `h`. For a quick command reference, type `?`.
944
945 # UNIX Basics 
946
947 ***Rewritten by Chris Shumway. ***
948 [[!toc  levels=3]]
949
950 ## Synopsis 
951
952 The following chapter will cover the basic commands and functionality of the DragonFly operating system. Much of this material is relevant for any UNIX®-like operating system. Feel free to skim over this chapter if you are familiar with the material. If you are new to DragonFly, then you will definitely want to read through this chapter carefully.
953
954 After reading this chapter, you will know:
955
956 * How to use the ***virtual consoles*** of DragonFly.
957
958 * How UNIX file permissions work along with understanding file flags in DragonFly.
959
960 * The default DragonFly file system layout.
961
962 * The DragonFly disk organization.
963
964 * How to mount and unmount file systems.
965
966 * What processes, daemons, and signals are.
967
968 * What a shell is, and how to change your default login environment.
969
970 * How to use basic text editors.
971
972 * What devices and device nodes are.
973
974 * What binary format is used under DragonFly.
975
976 * How to read manual pages for more information.
977
978 ## Virtual Consoles and Terminals 
979
980 DragonFly can be used in various ways. One of them is typing commands to a text terminal. A lot of the flexibility and power of a UNIX® operating system is readily available at your hands when using DragonFly this way. This section describes what ***terminals*** and ***consoles*** are, and how you can use them in !DragonFly.
981
982 <!-- XXX: also mention vesa.ko and other modes for the vt, but maybe somewhere else -->
983
984 ### The Console 
985
986 If you have not configured DragonFly to automatically start a graphical environment during startup, the system will present you with a login prompt after it boots, right after the startup scripts finish running. You will see something similar to:
987
988     Additional ABI support:.
989     Starting cron.
990     Local package initialization:.
991     Additional TCP options:.
992     
993     Wed Feb 18 17:53:48 GMT 2009
994     
995     DragonFly/i386 (Amnesiac) (ttyv0)
996
997     login: 
998
999 The messages might be a bit different on your system, but you will see something similar. The last two lines are what we are interested in right now. The second last line reads:
1000
1001     DragonFly/i386 (Amnesiac) (ttyv0)
1002
1003 This line contains some bits of information about the system you have just booted. You are looking at a ***DragonFlyBSD*** console, running on an Intel or compatible processor of the x86 architecture[(1)](#FTN.AEN1036). The name of this machine (every UNIX machine has a name) is `Amnesiac`, and you are now looking at its system console--the `ttyv0` terminal. Finally, the last line is always:
1004
1005     login:
1006
1007 This is the part where you are supposed to type in your <i>username</i> to log into DragonFly. The next section describes how you can do this.
1008
1009 ### Logging into DragonFly 
1010
1011 DragonFly is a multiuser, multiprocessing system. This is the formal description that is usually given to a system that can be used by many different people, who simultaneously run a lot of programs on a single machine. Every multiuser system needs some way to distinguish one <i>user</i>from the rest. In !DragonFly (and all the UNIX-like operating systems), this is accomplished by requiring that every user must ***log into*** the system before being able to run programs. Every user has a unique name (the <i>username</i> and a personal, secret key (the <i>password</i>). DragonFly will ask for these two before allowing a user to run any programs.
1012
1013 Right after DragonFly boots and finishes running its startup scripts[(2)](#FTN.AEN1060), it will present you with a prompt and ask for a valid username: 
1014
1015     login:
1016
1017 For the sake of this example, let us assume that your username is `john`. Type `john` at this prompt and press  **Enter** . You should then be presented with a prompt to enter a <i>password</i>:
1018     
1019
1020     login: john
1021     Password:
1022
1023 Type in `john`'s password now, and press  **Enter** . The password is <i>not echoed!</i> You need not worry about this right now. Suffice it to say that it is done for security reasons. If you have typed your password correctly, you should by now be logged into DragonFly and ready to try out all the available commands. You should see the MOTD or message of the day followed by a command prompt (a `#`, `$`, or `%` character). This indicates you have successfully logged into DragonFly.
1024
1025 ### Multiple Consoles 
1026
1027 Running UNIX commands in one console is fine, but DragonFly can run many programs at once. Having one console where commands can be typed would be a bit of a waste when an operating system like DragonFly can run dozens of programs at the same time. This is where <i>virtual consoles</i> can be very helpful. DragonFly can be configured to present you with many different virtual consoles. You can switch from one of them to any other virtual console by pressing a couple of keys on your keyboard. Each console has its own different output channel, and DragonFly takes care of properly redirecting keyboard input and monitor output as you switch from one virtual console to the next.
1028
1029 Special key combinations have been reserved by DragonFly for switching consoles[(3)](#FTN.AEN1087). You can use  **Alt** - **F1** ,  **Alt** - **F2** , through  **Alt** - **F8**  to switch to a different virtual console in DragonFly. As you are switching from one console to the next, DragonFly takes care of saving and restoring the screen output. The result is an <i>illusion</i> of having multiple <i>virtual</i> screens and keyboards that you can use to type commands for DragonFly to run. The programs that you launch on one virtual console do not stop running when that console is not visible. They continue running when you have switched to a different virtual console.
1030
1031 ### The /etc/ttys File 
1032
1033 The default configuration of DragonFly will start up with eight virtual consoles. This is not a hardwired setting though, and you can easily customize your installation to boot with more or fewer virtual consoles. The number and settings of the virtual consoles are configured in the `/etc/ttys` file.
1034
1035 You can use the `/etc/ttys` file to configure the virtual consoles of DragonFly. Each uncommented line in this file (lines that do not start with a `#` character) contains settings for a single terminal or virtual console. The default version of this file that ships with DragonFly configures nine virtual consoles, and enables eight of them. They are the lines that start with `ttyv`:
1036     
1037
1038     # name  getty                           type    status          comments
1039     #
1040     ttyv0   "/usr/libexec/getty Pc"         cons25  on  secure
1041     # Virtual terminals
1042     ttyv1   "/usr/libexec/getty Pc"         cons25  on  secure
1043     ttyv2   "/usr/libexec/getty Pc"         cons25  on  secure
1044     ttyv3   "/usr/libexec/getty Pc"         cons25  on  secure
1045     ttyv4   "/usr/libexec/getty Pc"         cons25  on  secure
1046     ttyv5   "/usr/libexec/getty Pc"         cons25  on  secure
1047     ttyv6   "/usr/libexec/getty Pc"         cons25  on  secure
1048     ttyv7   "/usr/libexec/getty Pc"         cons25  on  secure
1049     ttyv8   "/usr/pkg/xorg/bin/xdm -nodaemon"  xterm   off secure
1050
1051 For a detailed description of every column in this file and all the options you can use to set things up for the virtual consoles, consult the [ttys(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#ttys&section5) manual page.
1052
1053 ### Single User Mode Console 
1054
1055 A detailed description of what <i>single user mode</i> is can be found in [boot-init.html#BOOT-SINGLEUSER Section 7.5.2]. It is worth noting that there is only one console when you are running DragonFly in single user mode. There are no virtual consoles available. The settings of the single user mode console can also be found in the `/etc/ttys` file. Look for the line that starts with `console`:
1056
1057     
1058
1059     # name  getty                           type    status          comments
1060     #
1061     # If console is marked "insecure", then init will ask for the root password
1062     # when going to single-user mode.
1063     console none                            unknown off secure
1064
1065  **Note:** As the comments above the `console` line indicate, you can edit this line and change `secure` to `insecure`. If you do that, when DragonFly boots into single user mode, it will still ask for the `root` password. ***Be careful when changing this to insecure***. If you ever forget the `root` password, booting into single user mode is a bit involved. It is still possible, but it might be a bit hard for someone who is not very comfortable with the DragonFly booting process and the programs involved.
1066
1067 #### Notes 
1068
1069 [[!table  data="""
1070 <tablestyle="width:100%">[ (1)](consoles.html#AEN1036) | This is what `i386` means. Note that even if you are not running DragonFly on an Intel 386 CPU, this is going to be `i386`. It is not the type of your processor, but the processor ***architecture*** that is shown here. 
1071  [ (2)](consoles.html#AEN1060) | Startup scripts are programs that are run automatically by DragonFly when booting. Their main function is to set things up for everything else to run, and start any services that you have configured to run in the background doing useful things. 
1072  [ (3)](consoles.html#AEN1087) | A fairly technical and accurate description of all the details of the DragonFly console and keyboard drivers can be found in the manual pages of [syscons(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=syscons&section4), [atkbd(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=atkbd&section=4), [vidcontrol(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=vidcontrol&section=1) and [kbdcontrol(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kbdcontrol&section=1). We will not expand on the details here, but the interested reader can always consult the manual pages for a more detailed and thorough explanation of how things work. |
1073
1074 """]]
1075
1076 ## Permissions 
1077
1078 DragonFly, being a direct descendant of BSD UNIX®, is based on several key UNIX concepts. The first and most pronounced is that DragonFly is a multi-user operating system. The system can handle several users all working simultaneously on completely unrelated tasks. The system is responsible for properly sharing and managing requests for hardware devices, peripherals, memory, and CPU time fairly to each user.
1079
1080 Because the system is capable of supporting multiple users, everything the system manages has a set of permissions governing who can read, write, and execute the resource. These permissions are stored as three octets broken into three pieces, one for the owner of the file, one for the group that the file belongs to, and one for everyone else. This numerical representation works like this:
1081
1082 [[!table  data="""
1083 |<tablestyle="width:100%"> Value | Permission | Directory Listing 
1084 <tablestyle="width:100%"> 0 | No read, no write, no execute | `---` 
1085  1 | No read, no write, execute | `--x` 
1086  2 | No read, write, no execute | `-w-` 
1087  3 | No read, write, execute | `-wx` 
1088  4 | Read, no write, no execute | `r--` 
1089  5 | Read, no write, execute | `r-x` 
1090  6 | Read, write, no execute | `rw-` 
1091  7 | Read, write, execute | `rwx` |
1092
1093 """]]
1094
1095 You can use the `-l` command line argument to [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ls&section1) to view a long directory listing that includes a column with information about a file's permissions for the owner, group, and everyone else. For example, a `ls -l` in an arbitrary directory may show:
1096
1097     % ls -l
1098     total 530
1099     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 myfile
1100     -rw-r--r--  1 root  wheel     512 Sep  5 12:31 otherfile
1101     -rw-r--r--  1 root  wheel    7680 Sep  5 12:31 email.txt
1102     ...
1103
1104 Here is how the first column of `ls -l` is broken up:    
1105
1106     -rw-r--r--
1107
1108 <!-- XXX: Check all these http:// links to see if they are broken -->
1109
1110 The first (leftmost) character tells if this file is a regular file, a directory, a special character device, a socket, or any other special pseudo-file device. In this case, the `-` indicates a regular file. The next three characters, `rw-` in this example, give the permissions for the owner of the file. The next three characters, `r--`, give the permissions for the group that the file belongs to. The final three characters, `r--`, give the permissions for the rest of the world. A dash means that the permission is turned off. In the case of this file, the permissions are set so the owner can read and write to the file, the group can read the file, and the rest of the world can only read the file. According to the table above, the permissions for this file would be `644`, where each digit represents the three parts of the file's permission.
1111
1112 This is all well and good, but how does the system control permissions on devices? DragonFly actually treats most hardware devices as a file that programs can open, read, and write data to just like any other file. These special device files are stored on the `/dev` directory.
1113
1114 Directories are also treated as files. They have read, write, and execute permissions. The executable bit for a directory has a slightly different meaning than that of files. When a directory is marked executable, it means it can be traversed into, that is, it is possible to ***cd*** (change directory) into it. This also means that within the directory it is possible to access files whose names are known (subject, of course, to the permissions on the files themselves).
1115
1116 In particular, in order to perform a directory listing, read permission must be set on the directory, whilst to delete a file that one knows the name of, it is necessary to have write ***and*** execute permissions to the directory containing the file. There are more permission bits, but they are primarily used in special circumstances such as setuid binaries and sticky directories. If you want more information on file permissions and how to set them, be sure to look at the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section1) manual page.
1117
1118 ### Symbolic Permissions 
1119
1120 ***Contributed by Tom Rhodes.***
1121
1122 Symbolic permissions, sometimes referred to as symbolic expressions, use characters in place of octal values to assign permissions to files or directories. Symbolic expressions use the syntax of (who) (action) (permissions), where the following values are available:
1123
1124 [[!table  data="""
1125 <tablestyle="width:100%"> Option | Letter | Represents 
1126 <tablestyle="width:100%"> (who) | u | User 
1127  (who) | g | Group owner 
1128  (who) | o | Other 
1129  (who) | a | All (***world***) 
1130  (action) | + | Adding permissions 
1131  (action) | - | Removing permissions 
1132  (action) | = | Explicitly set permissions 
1133  (permissions) | r | Read 
1134  (permissions) | w | Write 
1135  (permissions) | x | Execute 
1136  (permissions) | t | Sticky bit 
1137  (permissions) | s | Set UID or GID |
1138
1139 """]]
1140
1141 These values are used with the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&amp;section1) command just like before, but with letters. For an example, you could use the following command to block other users from accessing `FILE`:
1142
1143     
1144
1145     % chmod go=FILE
1146
1147 A comma separated list can be provided when more than one set of changes to a file must be made. For example the following command will remove the groups and ***world*** write permission on `FILE`, then it adds the execute permissions for everyone:
1148
1149     
1150
1151     % chmod go-w,a+x FILE
1152
1153 ### DragonFly File Flags 
1154
1155 ***Contributed by Tom Rhodes.***
1156
1157 In addition to file permissions discussed previously, DragonFly supports the use of ***file flags.*** These flags add an additional level of security and control over files, but not directories. These file flags add an additional level of control over files, helping to ensure that in some cases not even the `root` can remove or alter files.  File flags are altered by using the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&amp;section1) utility, using a simple interface. For example, to enable the system undeletable flag on the file `file1`, issue the following command:
1158
1159     
1160
1161     # chflags sunlink file1
1162
1163 And to disable the system undeletable flag, simply issue the previous command with ***no*** in front of the `sunlink`. Observe:
1164
1165     
1166
1167     # chflags nosunlink file1
1168
1169 To view the flags of this file, use the [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ls&amp;section1) with the `-lo` flags:
1170
1171     
1172
1173     # ls -lo file1
1174
1175 The output should look like the following:
1176
1177     
1178
1179     -rw-r--r--  1 trhodes  trhodes  sunlnk 0 Mar  1 05:54 file1
1180
1181 Several flags may only added or removed to files by the `root` user. In other cases, the file owner may set these flags. It is recommended an administrator read over the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&section1) and [chflags(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&section=2) manual pages for more information.
1182
1183 ## Directory Structure 
1184
1185 The DragonFly directory hierarchy is fundamental to obtaining an overall understanding of the system. The most important concept to grasp is that of the root directory, ***/***. This directory is the first one mounted at boot time and it contains the base system necessary to prepare the operating system for multi-user operation. The root directory also contains mount points for every other file system that you may want to mount.
1186
1187 A mount point is a directory where additional file systems can be grafted onto the root file system. This is further described in [ this Section](disk-organization.html). Standard mount points include `/usr`, `/var`, `/tmp`, `/mnt`, and `/cdrom`. These directories are usually referenced to entries in the file `/etc/fstab`. `/etc/fstab` is a table of various file systems and mount points for reference by the system. Most of the file systems in `/etc/fstab` are mounted automatically at boot time from the script [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc&section8) unless they contain the `noauto` option. Details can be found in [ this section](mount-unmount.html#DISKS-FSTAB).
1188
1189 A complete description of the file system hierarchy is available in [hier(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=hier&section7). For now, a brief overview of the most common directories will suffice.
1190
1191 [[!table  data="""
1192 <tablestyle="width:100%">Directory | Description 
1193 <tablestyle="width:100%">  `/` | Root directory of the file system. 
1194  `/bin/` | User utilities fundamental to both single-user and multi-user environments. 
1195  `/boot/` | Programs and configuration files used during operating system bootstrap. 
1196  `/boot/defaults/` | Default bootstrapping configuration files; see [loader.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=loader.conf&section5). 
1197  `/dev/` | Device nodes; see [intro(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=intro&section4). 
1198  `/etc/` | System configuration files and scripts. 
1199  `/etc/defaults/` | Default system configuration files; see [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc&section8). 
1200  `/etc/mail/` | Configuration files for mail transport agents such as [sendmail(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendmail&section8). 
1201  `/etc/namedb/` | `named` configuration files; see [named(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=named&section8). 
1202  `/etc/periodic/` | Scripts that are run daily, weekly, and monthly, via [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section8); see [periodic(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=periodic&section=8). 
1203  `/etc/ppp/` | `ppp` configuration files; see [ppp(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=ppp&section8). 
1204  `/mnt/` | Empty directory commonly used by system administrators as a temporary mount point. 
1205  `/proc/` | Process file system; see [procfs(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=procfs&section5), [mount_procfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount_procfs&section=8). 
1206  `/root/` | Home directory for the `root` account. 
1207  `/sbin/` | System programs and administration utilities fundamental to both single-user and multi-user environments. 
1208  `/tmp/` | Temporary files. The contents of `/tmp` are usually NOT preserved across a system reboot. A memory-based file system is often mounted at `/tmp`. This can be automated with an entry in `/etc/fstab`; see [mfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mfs&section8). 
1209  `/usr/` | The majority of user utilities and applications. 
1210  `/usr/bin/` | Common utilities, programming tools, and applications. 
1211  `/usr/include/` | Standard C include files. 
1212  `/usr/lib/` | Archive libraries. 
1213  `/usr/libdata/` | Miscellaneous utility data files. 
1214  `/usr/libexec/` | System daemons &amp; system utilities (executed by other programs). 
1215  `/usr/local/` | Local executables, libraries, etc. Within `/usr/local`, the general layout sketched out by [hier(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=hier&section7) for `/usr` should be used. An exceptions is the man directory, which is directly under `/usr/local` rather than under `/usr/local/share`. 
1216  `/usr/obj/` | Architecture-specific target tree produced by building the `/usr/src` tree. 
1217  `/usr/pkg` | Used as the default destination for the files installed via the pkgsrc® tree or pkgsrc packages (optional). The configuration directory is tunable, but the default location is `/usr/pkg/etc`. 
1218  `/usr/pkg/xorg/` | Xorg distribution executables, libraries, etc (optional). 
1219  `/usr/pkgsrc` | The pkgsrc tree for installing packages (optional). 
1220  `/usr/sbin/` | System daemons &amp; system utilities (executed by users). 
1221  `/usr/share/` | Architecture-independent files. 
1222  `/usr/src/` | BSD and/or local source files. 
1223  `/var/` | Multi-purpose log, temporary, transient, and spool files. A memory-based file system is sometimes mounted at `/var`. This can be automated with an entry in `/etc/fstab`; see [mfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mfs&section8). 
1224  `/var/log/` | Miscellaneous system log files. 
1225  `/var/mail/` | User mailbox files. 
1226  `/var/spool/` | Miscellaneous printer and mail system spooling directories. 
1227  `/var/tmp/` | Temporary files. The files are usually preserved across a system reboot, unless `/var` is a memory-based file system. 
1228  `/var/yp` | NIS maps. |
1229
1230 """]]
1231
1232 ## Disk Organization 
1233
1234 The smallest unit of organization that DragonFly uses to find files is the filename. Filenames are case-sensitive, which means that `readme.txt` and `README.TXT` are two separate files. DragonFly does not use the extension (`.txt`) of a file to determine whether the file is a program, or a document, or some other form of data.
1235
1236 Files are stored in directories.  A directory may contain no files, or it may contain many hundreds of files.  A directory can also contain other directories, allowing you to build up a hierarchy of directories within one another.  This makes it much easier to organize your data.
1237
1238 Files and directories are referenced by giving the file or directory name, followed by a forward slash, `/`, followed by any other directory names that are necessary.  If you have directory `foo`, which contains directory `bar`, which contains the file `readme.txt`, then the full name, or ***path*** to the file is `foo/bar/readme.txt`.
1239
1240 Directories and files are stored in a file system. Each file system contains exactly one directory at the very top level, called the ***root directory*** for that file system.  This root directory can then contain other directories.
1241
1242 So far this is probably similar to any other operating system you may have used.  There are a few differences; for example, MS-DOS® and Windows® use `\`.
1243
1244 DragonFly does not use drive letters, or other drive names in the path. You would not write `c:/foo/bar/readme.txt` on DragonFly.
1245
1246 Instead, one file system is designated the ***root file system***.  The root file system's root directory is referred to as `/`.  Every other file system is then ***mounted*** under the root file system. No matter how many disks you have on your DragonFly system, every directory appears to be part of the same disk.
1247
1248 Suppose you have three file systems, called `A`, `B`, and `C`. Each file system has one root directory, which contains two other directories, called `A1`, `A2` (and likewise `B1`, `B2` and `C1`, `C2`).
1249
1250 Call `A` the root file system. If you used the `ls` command to view the contents of this directory you would see two subdirectories, `A1` and `A2`.  The directory tree looks like this:
1251
1252 <!-- XXX: image -->
1253
1254 A file system must be mounted on to a directory in another file system. So now suppose that you mount file system `B` on to the directory `A1`.  The root directory of `B` replaces `A1`, and the directories in `B` appear accordingly:
1255
1256 <!-- XXX: image -->
1257
1258 Any files that are in the `B1` or `B2` directories can be reached with the path `/A1/B1` or `/A1/B2` as necessary. Any files that were in `/A1` have been temporarily hidden.  They will reappear if `B` is ***unmounted*** from A.
1259
1260 If `B` had been mounted on `A2` then the diagram would look like this:
1261
1262 <!-- XXX: image -->
1263
1264 and the paths would be `/A2/B1` and `/A2/B2` respectively.
1265
1266 File systems can be mounted on top of one another.  Continuing the last example, the `C` file system could be mounted on top of the `B1` directory in the `B` file system, leading to this arrangement:
1267
1268 <!-- XXX: image -->
1269
1270 Or `C` could be mounted directly on to the `A` file system, under the `A1` directory:
1271
1272 <!-- XXX: image -->
1273
1274 If you are familiar with MS-DOS, this is similar, although not identical, to the `join` command.
1275
1276 ## Choosing File System Layout 
1277
1278 This is not normally something you need to concern yourself with. Typically you create file systems when installing DragonFly and decide where to mount them, and then never change them unless you add a new disk.
1279
1280 It is entirely possible to have one large root file system, and not need to create any others. There are some drawbacks to this approach, and one advantage.
1281
1282  **Benefits of Multiple File Systems** 
1283
1284 * Different file systems can have different ***mount options***.  For example, with careful planning, the root file system can be mounted read-only, making it impossible for you to inadvertently delete or edit a critical file.  Separating user-writable file systems, such as `/home`, from other file systems also allows them to be mounted ***nosuid***; this option prevents the ***suid***/***guid*** bits on executables stored on the file system from taking effect, possibly improving security.
1285
1286 * The UFS file system automatically optimizes the layout of files, depending on how the file system is being used. So a file system that contains many small files that are written frequently will have a different optimization to one that contains fewer, larger files.  By having one big file system this optimization breaks down.
1287
1288 * DragonFly's file systems are very robust should you lose power.  However, a power loss at a critical point could still damage the structure of the file system.  By splitting your data over multiple file systems it is more likely that the system will still come up, making it easier for you to restore from backup as necessary. This a major reason to make the root file system of limited size, and with low write activity.
1289
1290  **Benefit of a Single File System** 
1291
1292 * File systems are a fixed size. If you create a file system when you install DragonFly and give it a specific size, you may later discover that you need to make the partition bigger.  The [growfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=growfs&amp;section8) command makes it possible to increase the size of a UFS file system on the fly.
1293 <!-- XXX: what about hammer? -->
1294
1295 ## Disk Slices, Partitions and local UNIX file systems 
1296
1297 Here we describe how disks are subdivided.
1298
1299 <!-- XXX: mention serno stuff -->
1300
1301 ### Slices 
1302
1303 A disk can be subdivided in slices.
1304
1305 Slices are named `s0`, `s1` and so on.
1306
1307 For example the disk `ad6` can contain the slice `ad6s3`.
1308
1309 DragonFly support two schemes for slices, MBR and GPT, either of them will manage all slices on a disk:
1310
1311 * MBR: set up using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&amp;section8), can be up to 2 TB in size.  MBR slices are numbered from 1; but if disk is ***dangerously dedicated*** it has slice number 0.
1312
1313 * GPT: set up using [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section8), can be extremely large: size up to 8 billion TB.  DragonFly doesn't support booting from a GPT slice in DragonFly  2.0.  Note that GPT slices are numbered from 0. ***Dangerously dedicated*** is not supported nor needed for GPT.  DragonFly 2.1 does have some support for booting from a GPT slice, this is described in [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8).
1314
1315 ### Partitions 
1316
1317 Partitions are contained in slices.
1318
1319 Partitions are named `a`, `b` and so on.
1320
1321 DragonFly support 16 partitions per slice, that is `a` through `p`.
1322
1323 For example the partition `ad6s3a` is contained in the slice `ad6s3`.
1324
1325 Partition layout is defined in a label on the slice where the partition reside. DragonFly support two types of disk labels, disklabel32 and disklabel64 (the default):
1326
1327 * [disklabel32(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8): 32 bit disk label which can use slices with size up to 2 TB.
1328
1329 * [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section8): 64 bit disk label which can use very large slices: size up to 16 million TB.
1330
1331 ### Local UNIX file systems 
1332
1333 File systems are contained in partitions.  Each partition can contain only one file system, which means that file systems often are described by either their typical mount point in the file system hierarchy, or the letter of the partition they are contained in.  ***Partition*** does not have the same meaning as the common usage of the term partition (for example, MS-DOS partition), because of DragonFly's UNIX® heritage.
1334
1335 DragonFly support two local UNIX file systems, UFS and HAMMER:
1336
1337 * UFS: The classical BSD UNIX file system, see [ffs(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#ffs&amp;section5), it supports size up to 2 TB.
1338
1339 * [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&amp;section5): A new file system, as of DragonFly 2.0, with many advanced features.  HAMMER file system support size up to 1 million TB.
1340
1341 ### Typical disk layout 
1342
1343 From the above we see the following typical disk layout scenarios:
1344
1345 * For booting DragonFly from a local file system UFS is recommended.  A BOOT+HAMMER setup is recommended for HAMMER use, this consists of a small UFS file system for booting, typically 512MB, and a HAMMER root file system.  The BOOT file system is mounted as /boot after boot.
1346
1347 * For moderate storage requirements UFS can be used; it can be setup on any partition, e.g. on the same disk slice as the boot partition.  HAMMER is an alternative, with extra features supported, like history retention.  You should evaluate if HAMMER is suitable, see note below.
1348
1349 * If really big storage capacity is needed UFS can't fit the need.  You should evaluate if HAMMER is suitable, see note below.  For this use HAMMER needs to be used on a GPT slice with  a [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section8) label.  In DragonFly 2.0 it has to be set up on a disk separate from the boot disk.  In  DragonFly 2.1 one disk can be used for both booting and HAMMER file system on GPT slice, as some support for booting from GPT is present, as described in [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8).
1350
1351 ### HAMMER Note 
1352
1353 [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&amp;section5)
1354
1355 is a rather new file system, under active development.
1356
1357 As of DragonFly 2.2.1 release HAMMER is considered production ready.  At 2.0 release it was considered to be in an early Beta state .
1358
1359 All major features except the mirroring are quite well tested as-of the 2.2.1 release.
1360
1361 You should evaluate if HAMMER is suitable for your needs.
1362 <!-- XXX: mention disk and memory requirements for efficient hammer use -->
1363
1364 Examples of ongoing development includes:
1365
1366 * Making HAMMER more self managing; e.g. ability to setup policy for which history to save for how long: e.g. make snapshot every hour and prune and reblock the file system regularly.  When snapshot gets older than 1 month only keep them for every 6 hours; when older than 3 months only keep snapshot for every 24 hours, when older than 3 years only keep snapshot per month.  For now you need to set up [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&amp;section8) jobs for this yourself, see [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8).
1367
1368 * Multi master mirroring. For now only one mirror master is supported, but multiple mirror targets, called slaves, are already supported.
1369
1370 * Support for shrinking existing HAMMER file systems.  The HAMMER design is prepared for this, utility just have to be written to support it.
1371 <!-- XXX: is this still accurate? Do we really want to mention it here? -->
1372
1373 ### HAMMER Features 
1374
1375 [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&amp;section5) has several advanced features not found in UFS:
1376
1377 * Large file systems:  Up to 1 million TB, also called 1 Exabyte is supported.
1378
1379 * Multiple volumes:  A HAMMER file system can span up to 256 disks, each partition part of a HAMMER file system is called a volume.  Each volume can be up to 4096 TB in size.
1380
1381 * Support for growing and shrinking existing HAMMER file systems: adding and removing volumes from the file system.  As of 2.4 release an existing HAMMER file system can be expanded by adding extra space, see the `expand` directive to [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8).  The HAMMER design is also prepared for removing volumes, utilities just have to be written to support it.
1382
1383 * Instant crash recovery:  If a crash should occur, then HAMMER file systems will be ready a few seconds after boot, no lenghty fsck have to be run.
1384
1385 * Full history retention:  All file system changes are saved every ~30 seconds.  Changes are written at least when sync() is called, see [syncer(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=syncer&amp;section4).  Every time data for files are written to disk a transaction is completed, this is assigned an ID and the file updated can after this be accessed with the contents from this moment.  To access the file with the state of this moment, the transaction ID, TID for brevity, just needs to be added to the file name, like: 'file@@<TID>'.  The TID can be saved from the 'snapshot', 'cleanup', or 'synctid' [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8) command or looked up with the 'hammer history file' command.  This history will typically grow over time, so any disk will fill up over time.  Two things are done so disks doesn't fill up: first: big disks are used, at least 50GB is typical for HAMMER file systems, and second: unused history information is deleted regularly. Here we need to define what unused means: a TID is used if a snapshot have been taken on it. Data assigned to unused history can be reclaimed using the `prune` and `reblock` [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=8) commands, this will also defragment the file system and can be done while the file system is in normal operation.  Generally after file system is pruned only TIDs for the snapshots or newer than newest shapshot should be used, see explanation [here](http://leaf.dragonflybsd.org/mailarchive/bugs/2008-07/msg00213.html) (more info on HAMMER design [here](http://leaf.dragonflybsd.org/mailarchive/kernel/2008-07/msg00114.html)).  See also [hammer(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&amp;section=5). 
1386
1387 * Mirroring:  A master file system can be mirrored online to a number of slave file systems.  Mirror targets are read-only, but does have history available.  History retension policy can even be different on slaves and master.  Mirroring can be over network and unreliable connections are handled gracefully.
1388
1389 * Data integrity:  HAMMER has high focus in data integrity and implements a CRC checksum on all data, this means that if disk fails with bit errors it will be detected.
1390
1391 More info on HAMMER can be found [here](http://www.dragonflybsd.org/hammer/index.html).
1392
1393 DragonFly also uses disk space for ***swap space***.  Swap space provides DragonFly with ***virtual memory***.  This allows your computer to behave as though it has much more memory than it actually does.  When DragonFly runs low on memory it moves some of the data that is not currently being used to the swap space, and moves it back in (moving something else out) when it needs it.
1394
1395 <!-- XXX: mention swapcache, and also how to configure and use it (somewhere else, probably) -->
1396
1397 ### Adding a Disk 
1398
1399 Adding a disk is done by installing it physically, and to connect it to a disk controller that DragonFly supports.  If you are in doubt if controller is supported, manual pages for disk controllers can be consulted ('man -k disk' or 'man -k scsi' can be of help).  The easiest thing is normally to boot DargonFly with the controller installed and note if boot message contains the controller.
1400
1401 Assuming that disk `ad6` is installed, we could set it up using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&amp;section8) and  disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8) or  [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section8) and 
1402 [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section8).
1403
1404 In this example we choose [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&amp;section=8) & [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&amp;section=8).
1405
1406 <!-- XXX: mention that disklabel64 is default now -->
1407     
1408
1409     # gpt -v create ad6
1410
1411     ...
1412
1413     # gpt add -s1 ad6
1414
1415     ad6s0
1416
1417     # gpt add ad6
1418
1419     ad6s1
1420
1421     # gpt show ad6
1422
1423     ...
1424
1425 Here we first create the GPT and then add two slices.  In this example the first slice added is `ad6s0`, which is made a dummy slice of size 1 sector, this is just for not having to make further reference to it, as many users remembers that `s0` has special meaning, which really isn't true for GPT slices.  The second slice is `ad6s1` which will cover the rest of the disk.
1426
1427     
1428
1429     # disklabel64 -rw ad6s1 auto
1430
1431     # disklabel64 -e ad6s1          # edit label to add partitions as needed
1432
1433 ### disklabel 
1434 <!-- XXX: what is all this fuzz about dangerously dedicated? -->
1435
1436 For [disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&amp;section8) labels some partitions have certain conventions associated with them.
1437
1438 [[!table  data="""
1439 <tablestyle="width:100%"> Partition | Convention 
1440 <tablestyle="width:100%"> `a` | Normally contains the root file system 
1441  `b` | Normally contains swap space 
1442  `c` | Normally the same size as the enclosing slice.  This allows utilities that need to work on the entire slice (for example, a bad block scanner) to work on the `c` partition. You would not normally create a file system on this partition. This is not necessarily true; it is possible to use the 'c' partition as a normal partition.
1443  `d` | Partition `d` used to have a special meaning associated with it, although that is now gone.  To this day, some tools may operate oddly if told to work on partition `d`. |
1444
1445 """]]
1446
1447 Each partition-that-contains-a-file-system is stored in what DragonFly calls a ***slice***.  Slice is DragonFly's term for what the common call partitions, and again, this is because of DragonFly's UNIX background.  Slices are numbered, starting at 1.
1448
1449 Slice numbers follow the device name, prefixed with an `s`, starting at 1. So ***da0s1*** is the first slice on the first SCSI drive. There can only be four physical slices on a disk, but you can have logical slices inside physical slices of the appropriate type.  These extended slices are numbered starting at 5, so ***ad0s5*** is the first extended slice on the first IDE disk. These devices are used by file systems that expect to occupy a slice.
1450
1451 <!-- XXX: gpt allows for way more than 4 partitions... let's remove this stuff above -->
1452
1453 ***Dangerously dedicated*** physical drives are accessed as slice 0.
1454
1455 Slices, ***dangerously dedicated*** physical drives, and other drives contain ***partitions***, which are represented as letters from `a` to `p`.  This letter is appended to the device name, so ***da0s0a*** is the a partition on the first da drive, which is ***dangerously dedicated***. ***ad1s3e*** is the fifth partition in the third slice of the second IDE disk drive.
1456
1457 Finally, each disk on the system is identified.  A disk name starts with a code that indicates the type of disk, and then a number, indicating which disk it is.  Disk numbering starts at 0. Common codes that you will see are listed in [Table 3-1](disk-organization.html#BASICS-DEV-CODES).
1458
1459 <!-- XXX: here would probably be the right place to talk about serno -->
1460
1461 When referring to a partition DragonFly requires that you also name the slice and disk that contains the partition, and when referring to a slice you should also refer to the disk name. Do this by listing the disk name, `s`, the slice number, and then the partition letter.  Examples are shown in [Example 3-1](disk-organization.html#BASICS-DISK-SLICE-PART).
1462
1463 <!-- XXX: later talk also about devfs, definitely not here though. also, devfs rules -->
1464
1465 [Example 3-2](disk-organization.html#BASICS-CONCEPT-DISK-MODEL) shows a conceptual model of the disk layout that should help make things clearer.
1466
1467 In order to install DragonFly you must first configure the disk slices, then create partitions within the slice you will use for DragonFly, and then create a file system (or swap space) in each partition, and decide where that file system will be mounted.
1468
1469 ***'Table 3-1. Disk Device Codes***'
1470
1471 [[!table  data="""
1472 <tablestyle="width:100%"> Code | Meaning 
1473 <tablestyle="width:100%"> `ad` | ATAPI (IDE) disk 
1474  `da` | SCSI direct access disk 
1475  `acd` | ATAPI (IDE) CDROM 
1476  `cd` | SCSI CDROM 
1477  `vn` | Virtual disk
1478  `fd` | Floppy disk |
1479
1480 """]]
1481
1482 ***'Example 3-1. Sample Disk, Slice, and Partition Names***'
1483
1484 [[!table  data="""
1485 <tablestyle="width:100%"> Name | Meaning 
1486 <tablestyle="width:100%"> `ad0s1a` | The first partition (`a`) on the first slice (`s1`) on the first IDE disk (`ad0`). 
1487  `da1s2e` | The fifth partition (`e`) on the second slice (`s2`) on the second SCSI disk (`da1`). |
1488
1489 """]]
1490
1491 ***'Example 3-2. Conceptual Model of a Disk***'
1492
1493 This diagram shows DragonFly's view of the first IDE disk attached to the system. Assume that the disk is 4 GB in size, and contains two 2 GB slices (MS-DOS partitions).  The first slice contains a MS-DOS disk, `C:`, and the second slice contains a DragonFly installation. This example DragonFly installation has three partitions, and a swap partition.
1494
1495 The three partitions will each hold a file system. Partition `a` will be used for the root file system, `e` for the `/var` directory hierarchy, and `f` for the `/usr` directory hierarchy.
1496
1497 <!-- XXX: image -->
1498
1499 ## Mounting and Unmounting File Systems 
1500
1501 The file system is best visualized as a tree, rooted at `/`.
1502
1503 The directories, e.g. `/dev` and `/usr`, in the root directory are branches,
1504
1505 which may have their own branches, such as `/usr/local`, and so on.
1506
1507 There are various reasons to house some of these directories on separate file systems. `/var` contains the directories `log/` and `spool/`, and various types of temporary files, and as such, may get filled up. Filling up the root file system is not a good idea, so splitting `/var` from `/` is often favorable.
1508
1509 Another common reason to contain certain directory trees on other file systems is if they are to be housed on separate physical disks, e.g. CD-ROM, or are used as separate virtual disks, such as [Network File System](network-nfs.html) exports.
1510
1511 ### The fstab File 
1512
1513 During the [boot process](boot.html), file systems listed in `/etc/fstab` are automatically mounted (unless they are listed with the `noauto` option).
1514
1515 The `/etc/fstab` file contains a list of lines of the following format:
1516   
1517
1518     device       mount-point   fstype     options      dumpfreq     passno
1519
1520 These parameters have the following meaning:
1521
1522 * `device`: A device name (which should exist), as explained [here](disks-naming.html).
1523
1524 * `mount-point`: A directory (which should exist), on which to mount the file system.
1525
1526 * `fstype`: The file system type to pass to [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8). The default DragonFly file system is `ufs`.
1527
1528 * `options`: Either `rw` for read-write file systems, or `ro` for read-only file systems, followed by any other options that may be needed. A common option is `noauto` for file systems not normally mounted during the boot sequence. Other options are listed in the [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) manual page.
1529
1530 * `dumpfreq`: This is used by [dump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dump&section8) to determine which file systems require dumping. If the field is missing, a value of zero is assumed.
1531
1532 * `passno`: This determines the order in which file systems should be checked. File systems that should be skipped should have their `passno` set to zero. The root file system (which needs to be checked before everything else) should have its `passno` set to one, and other file systems' `passno` should be set to values greater than one. If more than one file systems have the same `passno` then [fsck(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fsck&section8) will attempt to check file systems in parallel if possible.
1533
1534 Consult the [fstab(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=fstab&section5) manual page for more information on the format of the `/etc/fstab` file and the options it contains.
1535
1536 ### The mount Command 
1537
1538 The [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) command is what is ultimately used to mount file systems.
1539
1540 In its most basic form, you use:
1541
1542     
1543
1544     # mount device mountpoint
1545
1546 Or, if `mountpoint` is specified in `/etc/fstab`, just:
1547
1548     
1549
1550     # mount mountpoint
1551
1552 There are plenty of options, as mentioned in the [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) manual page, but the most common are:
1553
1554  **Mount Options** 
1555
1556 * `-a`: Mount all the file systems listed in `/etc/fstab`. Except those marked as `noauto`, excluded by the `-t` flag, or those that are already mounted.
1557
1558 * `-d`: Do everything except for the actual mount system call. This option is useful in conjunction with the `-v` flag to determine what [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount&section8) is actually trying to do.
1559
1560 * `-f`: Force the mount of an unclean file system (dangerous), or forces the revocation of write access when downgrading a file system's mount status from read-write to read-only.
1561
1562 * `-r`: Mount the file system read-only. This is identical to using the `rdonly` argument to the `-o` option.
1563
1564 * `-t` ***fstype***: Mount the given file system as the given file system type, or, if used with `-a` option, mount only file systems of the given type. `ufs` is the default file system type.
1565
1566 * `-u`: Update mount options on the file system.
1567
1568 * `-v`: Be verbose.
1569
1570 * `-w`: Mount the file system read-write.
1571
1572 The `-o` option takes a comma-separated list of the options, including the following:
1573
1574 * `nodev:` Do not interpret special devices on the file system. This is a useful security option.
1575
1576 * `noexec`: Do not allow execution of binaries on this file system. This is also a useful security option.
1577
1578 * `nosuid`: Do not interpret setuid or setgid flags on the file system. This is also a useful security option.
1579
1580 ### The umount Command 
1581
1582 The [umount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=umount&section8) command takes, as a parameter, one of a mountpoint, a device name, or the `-a` or `-A` option.
1583
1584 All forms take `-f` to force unmounting, and `-v` for verbosity. Be warned that `-f` is not generally a good idea. Forcibly unmounting file systems might crash the computer or damage data on the file system.
1585
1586 `-a` and `-A` are used to unmount all mounted file systems, possibly modified by the file system types listed after `-t`. `-A`, however, does not attempt to unmount the root file system.
1587
1588 ## Processes 
1589
1590 DragonFly is a multi-tasking operating system. This means that it seems as though more than one program is running at once. Each program running at any one time is called a ***process***. Every command you run will start at least one new process, and there are a number of system processes that run all the time, keeping the system functional.
1591
1592 <!-- XXX: talk about LWPs and threads? -->
1593
1594 Each process is uniquely identified by a number called a ***process ID***, or ***PID***, and, like files, each process also has one owner and group. The owner and group information is used to determine what files and devices the process can open, using the file permissions discussed earlier. Most processes also have a parent process. The parent process is the process that started them. For example, if you are typing commands to the shell then the shell is a process, and any commands you run are also processes. Each process you run in this way will have your shell as its parent process. The exception to this is a special process called [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init&section8). `init` is always the first process, so its PID is always 1. `init` is started automatically by the kernel when DragonFly starts.
1595
1596 Two commands are particularly useful to see the processes on the system, [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section1) and [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1). The `ps` command is used to show a static list of the currently running processes, and can show their PID, how much memory they are using, the command line they were started with, and so on. The `top` command displays all the running processes, and updates the display every few seconds, so that you can interactively see what your computer is doing.
1597
1598 By default, `ps` only shows you the commands that are running and are owned by you. For example:
1599
1600     
1601
1602     % ps
1603
1604       PID  TT  STAT      TIME COMMAND
1605       298  p0  Ss     0:01.10 tcsh
1606      7078  p0  S      2:40.88 xemacs mdoc.xsl (xemacs-21.1.14)
1607     37393  p0  I      0:03.11 xemacs freebsd.dsl (xemacs-21.1.14)
1608     48630  p0  S      2:50.89 /usr/local/lib/netscape-linux/navigator-linux-4.77.bi
1609     48730  p0  IW     0:00.00 (dns helper) (navigator-linux-)
1610     72210  p0  R+     0:00.00 ps
1611       390  p1  Is     0:01.14 tcsh
1612      7059  p2  Is+    1:36.18 /usr/local/bin/mutt -y
1613      6688  p3  IWs    0:00.00 tcsh
1614     10735  p4  IWs    0:00.00 tcsh
1615     20256  p5  IWs    0:00.00 tcsh
1616       262  v0  IWs    0:00.00 -tcsh (tcsh)
1617       270  v0  IW+    0:00.00 /bin/sh /usr/X11R6/bin/startx -- -bpp 16
1618       280  v0  IW+    0:00.00 xinit /home/nik/.xinitrc -- -bpp 16
1619       284  v0  IW     0:00.00 /bin/sh /home/nik/.xinitrc
1620       285  v0  S      0:38.45 /usr/X11R6/bin/sawfish
1621
1622 As you can see in this example, the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section1) is organized into a number of columns. `PID` is the process ID discussed earlier. PIDs are assigned starting from 1, go up to 99999, and wrap around back to the beginning when you run out. The `TT` column shows the tty the program is running on, and can safely be ignored for the moment. `STAT` shows the program's state, and again, can be safely ignored. `TIME` is the amount of time the program has been running on the CPU--this is usually not the elapsed time since you started the program, as most programs spend a lot of time waiting for things to happen before they need to spend time on the CPU. Finally, `COMMAND` is the command line that was used to run the program.
1623
1624 [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section1) supports a number of different options to change the information that is displayed. One of the most useful sets is `auxww`. `a` displays information about all the running processes, not just your own. `u` displays the username of the process' owner, as well as memory usage. `x` displays information about daemon processes, and `ww` causes [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) to display the full command line, rather than truncating it once it gets too long to fit on the screen.
1625
1626 The output from [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section1) is similar. A sample session looks like this:
1627
1628     
1629
1630     % top
1631     last pid: 72257;  load averages:  0.13,  0.09,  0.03    up 0+13:38:33  22:39:10
1632     47 processes:  1 running, 46 sleeping
1633     CPU states: 12.6% user,  0.0% nice,  7.8% system,  0.0% interrupt, 79.7% idle
1634     Mem: 36M Active, 5256K Inact, 13M Wired, 6312K Cache, 15M Buf, 408K Free
1635     Swap: 256M Total, 38M Used, 217M Free, 15% Inuse
1636     
1637
1638       PID USERNAME PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND
1639     72257 nik       28   0  1960K  1044K RUN      0:00 14.86%  1.42% top
1640      7078 nik        2   0 15280K 10960K select   2:54  0.88%  0.88% xemacs-21.1.14
1641       281 nik        2   0 18636K  7112K select   5:36  0.73%  0.73% XF86_SVGA
1642       296 nik        2   0  3240K  1644K select   0:12  0.05%  0.05% xterm
1643     48630 nik        2   0 29816K  9148K select   3:18  0.00%  0.00% navigator-linu
1644       175 root       2   0   924K   252K select   1:41  0.00%  0.00% syslogd
1645      7059 nik        2   0  7260K  4644K poll     1:38  0.00%  0.00% mutt
1646     ...
1647
1648 The output is split into two sections. The header (the first five lines) shows the PID of the last process to run, the system load averages (which are a measure of how busy the system is), the system uptime (time since the last reboot) and the current time. The other figures in the header relate to how many processes are running (47 in this case), how much memory and swap space has been taken up, and how much time the system is spending in different CPU states.
1649
1650 Below that are a series of columns containing similar information to the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section1). As before you can see the PID, the username, the amount of CPU time taken, and the command that was run. [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section=1) also defaults to showing you the amount of memory space taken by the process. This is split into two columns, one for total size, and one for resident size--total size is how much memory the application has needed, and the resident size is how much it is actually using at the moment. In this example you can see that  **Netscape®**  has required almost 30 MB of RAM, but is currently only using 9 MB.
1651
1652 [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top&section1) automatically updates this display every two seconds; this can be changed with the `s` option.
1653
1654 ## Daemons, Signals, and Killing Processes 
1655
1656 When you run an editor it is easy to control the editor, tell it to load files, and so on. You can do this because the editor provides facilities to do so, and because the editor is attached to a ***terminal***. Some programs are not designed to be run with continuous user input, and so they disconnect from the terminal at the first opportunity. For example, a web server spends all day responding to web requests, it normally does not need any input from you. Programs that transport email from site to site are another example of this class of application.
1657
1658 We call these programs ***daemons***. Daemons were characters in Greek mythology; neither good or evil, they were little attendant spirits that, by and large, did useful things for mankind. Much like the web servers and mail servers of today do useful things. This is why the mascot for a number of BSD-based operating systems has, for a long time, been a cheerful looking daemon with sneakers and a pitchfork.
1659
1660 There is a convention to name programs that normally run as daemons with a trailing ***d***.  **BIND**  is the Berkeley Internet Name Daemon (and the actual program that executes is called `named`), the  **Apache**  web server program is called `httpd`, the line printer spooling daemon is `lpd` and so on. This is a convention, not a hard and fast rule; for example, the main mail daemon for the  **Sendmail**  application is called `sendmail`, and not `maild`, as you might imagine.
1661
1662 Sometimes you will need to communicate with a daemon process. These communications are called ***signals***, and you can communicate with a daemon (or with any other running process) by sending it a signal. There are a number of different signals that you can send--some of them have a specific meaning, others are interpreted by the application, and the application's documentation will tell you how that application interprets signals. You can only send a signal to a process that you own. If you send a signal to someone else's process with [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) or [kill(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=2) permission will be denied. The exception to this is the `root` user, who can send signals to everyone's processes.
1663
1664 DragonFly will also send applications signals in some cases. If an application is badly written, and tries to access memory that it is not supposed to, DragonFly sends the process the ***Segmentation Violation*** signal (`SIGSEGV`). If an application has used the [alarm(3)](http://leaf.dragonflybsd.org/cgi/web-man?command=alarm&section=3) system call to be alerted after a period of time has elapsed then it will be sent the Alarm signal (`SIGALRM`), and so on.
1665
1666 Two signals can be used to stop a process, `SIGTERM` and `SIGKILL`. `SIGTERM` is the polite way to kill a process; the process can ***catch*** the signal, realize that you want it to shut down, close any log files it may have open, and generally finish whatever it is doing at the time before shutting down. In some cases a process may even ignore `SIGTERM` if it is in the middle of some task that can not be interrupted.
1667
1668 `SIGKILL` can not be ignored by a process. This is the ***I do not care what you are doing, stop right now*** signal. If you send `SIGKILL` to a process then DragonFly will stop that process there and then[(1)](#FTN.AEN2181).
1669
1670 The other signals you might want to use are `SIGHUP`, `SIGUSR1`, and `SIGUSR2`. These are general purpose signals, and different applications will do different things when they are sent.
1671
1672 Suppose that you have changed your web server's configuration file--you would like to tell the web server to re-read its configuration. You could stop and restart `httpd`, but this would result in a brief outage period on your web server, which may be undesirable. Most daemons are written to respond to the `SIGHUP` signal by re-reading their configuration file. So instead of killing and restarting `httpd` you would send it the `SIGHUP` signal. Because there is no standard way to respond to these signals, different daemons will have different behavior, so be sure and read the documentation for the daemon in question.
1673
1674 Signals are sent using the [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) command, as this example shows.
1675
1676  **Sending a Signal to a Process** 
1677
1678 This example shows how to send a signal to [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8). The `inetd` configuration file is `/etc/inetd.conf`, and `inetd` will re-read this configuration file when it is sent `SIGHUP`.
1679
1680   1. Find the process ID of the process you want to send the signal to. Do this using [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps&section=1) and [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep&section=1). The [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep&section=1) command is used to search through output, looking for the string you specify. This command is run as a normal user, and [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) is run as `root`, so the `ax` options must be given to [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1).
1681
1682       
1683
1684         % ps -ax | grep inetd
1685
1686         198  ??  IWs    0:00.00 inetd -wW
1687
1688   
1689
1690   So the [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#inetd&section8) PID is 198. In some cases the `grep inetd` command might also occur in this output. This is because of the way [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps&section=1) has to find the list of running processes.
1691
1692   2. Use [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) to send the signal. Because [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd&section=8) is being run by `root` you must use [su(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=su&section=1) to become `root` first.
1693
1694       
1695
1696         % su
1697
1698         Password:
1699
1700         # /bin/kill -s HUP 198
1701
1702   
1703
1704   In common with most UNIX® commands, [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) will not print any output if it is successful. If you send a signal to a process that you do not own then you will see `kill: PID: Operation not permitted`. If you mistype the PID you will either send the signal to the wrong process, which could be bad, or, if you are lucky, you will have sent the signal to a PID that is not currently in use, and you will see `kill: PID: No such process`.
1705
1706 **Why Use `/bin/kill`?** Many shells provide the `kill` command as a built in command; that is, the shell will send the signal directly, rather than running `/bin/kill`. This can be very useful, but different shells have a different syntax for specifying the name of the signal to send. Rather than try to learn all of them, it can be simpler just to use the `/bin/kill ...` command directly.
1707
1708 Sending other signals is very similar, just substitute `TERM` or `KILL` in the command line as necessary.
1709
1710  **Important:** Killing random process on the system can be a bad idea. In particular, [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init&section=8), process ID 1, is very special. Running `/bin/kill -s KILL 1` is a quick way to shutdown your system. ***Always*** double check the arguments you run [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill&section=1) with ***before*** you press  **Return** .
1711
1712  
1713  
1714  
1715  
1716  
1717 ## Shells 
1718
1719 In DragonFly, a lot of everyday work is done in a command line interface called a shell. A shell's main job is to take commands from the input channel and execute them. A lot of shells also have built in functions to help everyday tasks such as file management, file globbing, command line editing, command macros, and environment variables. DragonFly comes with a set of shells, such as `sh`, the Bourne Shell, and `tcsh`, the improved C-shell. Many other shells are available from pkgsrc®, such as `zsh` and `bash`.
1720
1721 Which shell do you use? It is really a matter of taste. If you are a C programmer you might feel more comfortable with a C-like shell such as `tcsh`. If you have come from Linux or are new to a UNIX® command line interface you might try `bash`. The point is that each shell has unique properties that may or may not work with your preferred working environment, and that you have a choice of what shell to use.
1722
1723 One common feature in a shell is filename completion. Given the typing of the first few letters of a command or filename, you can usually have the shell automatically complete the rest of the command or filename by hitting the  **Tab**  key on the keyboard. Here is an example. Suppose you have two files called `foobar` and `foo.bar`. You want to delete `foo.bar`. So what you would type on the keyboard is: `rm fo[ **Tab** ].[ **Tab** ]`.
1724
1725 The shell would print out `rm foo[BEEP].bar`.
1726
1727 The [BEEP] is the console bell, which is the shell telling me it was unable to totally complete the filename because there is more than one match. Both `foobar` and `foo.bar` start with `fo`, but it was able to complete to `foo`. If you type in `.`, then hit  **Tab**  again, the shell would be able to fill in the rest of the filename for you.
1728
1729 Another feature of the shell is the use of environment variables. Environment variables are a variable key pair stored in the shell's environment space. This space can be read by any program invoked by the shell, and thus contains a lot of program configuration. Here is a list of common environment variables and what they mean:
1730
1731 [[!table  data="""
1732 <tablestyle="width:100%"> Variable | Description 
1733 <tablestyle="width:100%"> `USER` | Current logged in user's name. 
1734  `PATH` | Colon separated list of directories to search for binaries. 
1735  `DISPLAY` | Network name of the X11 display to connect to, if available. 
1736  `SHELL` | The current shell. 
1737  `TERM` | The name of the user's terminal. Used to determine the capabilities of the terminal. 
1738  `TERMCAP` | Database entry of the terminal escape codes to perform various terminal functions. 
1739  `OSTYPE` | Type of operating system. e.g., DragonFly. 
1740  `MACHTYPE` | The CPU architecture that the system is running on. 
1741  `EDITOR` | The user's preferred text editor. 
1742  `PAGER` | The user's preferred text pager. 
1743  `MANPATH` | Colon separated list of directories to search for manual pages. |
1744
1745 """]]
1746
1747 Setting an environment variable differs somewhat from shell to shell. For example, in the C-Style shells such as `tcsh` and `csh`, you would use `setenv` to set environment variables. Under Bourne shells such as `sh` and `bash`, you would use `export` to set your current environment variables. For example, to set or modify the `EDITOR` environment variable, under `csh` or `tcsh` a command like this would set `EDITOR` to `/usr/pkg/bin/emacs`:
1748     
1749
1750     % setenv EDITOR /usr/pkg/bin/emacs
1751
1752 Under Bourne shells:
1753    
1754
1755     % export EDITOR="/usr/pkg/bin/emacs"
1756
1757 You can also make most shells expand the environment variable by placing a `$` character in front of it on the command line. For example, `echo $TERM` would print out whatever `$TERM` is set to, because the shell expands `$TERM` and passes it on to `echo`.
1758
1759 Shells treat a lot of special characters, called meta-characters as special representations of data. The most common one is the `*` character, which represents any number of characters in a filename. These special meta-characters can be used to do filename globbing. For example, typing in `echo *` is almost the same as typing in `ls` because the shell takes all the files that match `*` and puts them on the command line for `echo` to see.
1760
1761 To prevent the shell from interpreting these special characters, they can be escaped from the shell by putting a backslash (`\`) character in front of them. `echo $TERM` prints whatever your terminal is set to. `echo \$TERM` prints `$TERM` as is.
1762
1763 ### Changing Your Shell 
1764
1765 <!-- XXX: does chsh still exist? chpass will do, too -->
1766
1767 The easiest way to change your shell is to use the `chsh` command. Running `chsh` will place you into the editor that is in your `EDITOR` environment variable; if it is not set, you will be placed in `vi`. Change the ***Shell:*** line accordingly.
1768
1769 You can also give `chsh` the `-s` option; this will set your shell for you, without requiring you to enter an editor. For example, if you wanted to change your shell to `bash`, the following should do the trick:
1770
1771     
1772
1773     % chsh -s /usr/pkg/bin/bash
1774
1775  **Note:** The shell that you wish to use ***must*** be present in the `/etc/shells` file. If you have installed a shell from the [ pkgsrc tree ](pkgsrc.html), then this should have been done for you already. If you installed the shell by hand, you must do this.
1776
1777 For example, if you installed `bash` by hand and placed it into `/usr/local/bin`, you would want to:
1778
1779     
1780
1781     # echo "/usr/local/bin/bash" >> /etc/shells
1782
1783 Then rerun `chsh`.
1784
1785 ## Text Editors 
1786
1787 A lot of configuration in DragonFly is done by editing text files. Because of this, it would be a good idea to become familiar with a text editor. DragonFly comes with a few as part of the base system, and many more are available in the pkgsrc® tree.
1788
1789 The easiest and simplest editor to learn is an editor called  **ee** , which stands for easy editor. To start  **ee** , one would type at the command line `ee filename` where `filename` is the name of the file to be edited. For example, to edit `/etc/rc.conf`, type in `ee /etc/rc.conf`. Once inside of `ee`, all of the commands for manipulating the editor's functions are listed at the top of the display. The caret `^` character represents the  **Ctrl**  key on the keyboard, so `^e` expands to the key combination  **Ctrl** + **e** . To leave  **ee** , hit the  **Esc**  key, then choose leave editor. The editor will prompt you to save any changes if the file has been modified.
1790
1791 DragonFly also comes with more powerful text editors such as  **vi**  as part of the base system, while other editors, like  **emacs**  and  **vim** , are part of the pkgsrc tree. These editors offer much more functionality and power at the expense of being a little more complicated to learn. However if you plan on doing a lot of text editing, learning a more powerful editor such as  **vim**  or  **emacs**  will save you much more time in the long run.
1792
1793 ## Devices and Device Nodes 
1794
1795 A device is a term used mostly for hardware-related activities in a system, including disks, printers, graphics cards, and keyboards. When DragonFly boots, the majority of what DragonFly displays are devices being detected. You can look through the boot messages again by viewing `/var/run/dmesg.boot`.
1796
1797 For example, `acd0` is the first IDE CDROM drive, while `kbd0` represents the keyboard.
1798
1799 Most of these devices in a UNIX® operating system must be accessed through special files called device nodes, which are located in the `/dev` directory.
1800
1801 The device nodes in the `/dev` directory are created and destroyed automatically on DragonFly >= 2.4, by means of the device file system (devfs).
1802
1803 ## Binary Formats 
1804
1805 To understand why DragonFly uses the [elf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=elf&amp;section=5) format, you must first know a little about the three currently ***dominant*** executable formats for UNIX®:
1806
1807 * [a.out(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=a.out&amp;section=5)
1808
1809   The oldest and ***classic*** UNIX object format. It uses a short and compact header with a magic number at the beginning that is often used to characterize the format (see [a.out(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=a.out&amp;section=5) for more details). It contains three loaded segments: .text, .data, and .bss plus a symbol table and a string table.
1810
1811 * <u>COFF</u>
1812
1813   The SVR3 object format. The header now comprises a section table, so you can have more than just .text, .data, and .bss sections.
1814
1815 * [elf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=elf&amp;section=5)
1816
1817   The successor to COFF, featuring multiple sections and 32-bit or 64-bit possible values. One major drawback: ELF was also designed with the assumption that there would be only one ABI per system architecture. That assumption is actually quite incorrect, and not even in the commercial SYSV world (which has at least three ABIs: SVR4, Solaris, SCO) does it hold true. DragonFly tries to work around this problem somewhat by providing a utility for ***branding*** a known ELF executable with information about the ABI it is compliant with. See the manual page for [brandelf(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=brandelf&amp;section=1) for more information. DragonFly runs ELF.
1818
1819 So, why are there so many different formats? Back in the dim, dark past, there was simple hardware. This simple hardware supported a simple, small system. `a.out` was completely adequate for the job of representing binaries on this simple system (a PDP-11). As people ported UNIX from this simple system, they retained the `a.out` format because it was sufficient for the early ports of UNIX to architectures like the Motorola 68k, VAXen, etc.
1820
1821 Then some bright hardware engineer decided that if he could force software to do some sleazy tricks, then he would be able to shave a few gates off the design and allow his CPU core to run faster. While it was made to work with this new kind of hardware (known these days as RISC), `a.out` was ill-suited for this hardware, so many formats were developed to get to a better performance from this hardware than the limited, simple `a.out` format could offer. Things like COFF, ECOFF, and a few obscure others were invented and their limitations explored before things seemed to settle on ELF.
1822
1823 In addition, program sizes were getting huge and disks (and physical memory) were still relatively small so the concept of a shared library was born. The VM system also became more sophisticated. While each one of these advancements was done using the `a.out` format, its usefulness was stretched more and more with each new feature. In addition, people wanted to dynamically load things at run time, or to junk parts of their program after the init code had run to save in core memory and swap space. Languages became more sophisticated and people wanted code called before main automatically. Lots of hacks were done to the `a.out` format to allow all of these things to happen, and they basically worked for a time. In time, `a.out` was not up to handling all these problems without an ever increasing overhead in code and complexity. While ELF solved many of these problems, it would be painful to switch from the system that basically worked. So ELF had to wait until it was more painful to remain with `a.out` than it was to migrate to ELF.
1824
1825 ELF is more expressive than `a.out` and allows more extensibility in the base system. The ELF tools are better maintained, and offer cross compilation support, which is important to many people. ELF may be a little slower than `a.out`, but trying to measure it can be difficult. There are also numerous details that are different between the two in how they map pages, handle init code, etc. None of these are very important, but they are differences.
1826
1827 <!-- XXX: do we really need all this bullshit about file formats? -->
1828
1829 ## For More Information 
1830
1831 ### Manual Pages 
1832
1833 The most comprehensive documentation on DragonFly is in the form of manual pages. Nearly every program on the system comes with a short reference manual explaining the basic operation and various arguments. These manuals can be viewed with the `man` command. Use of the `man` command is simple:
1834
1835     % man command
1836
1837 `command` is the name of the command you wish to learn about. For example, to learn more about `ls` command type:
1838
1839     % man ls
1840
1841 The online manual is divided up into numbered sections:
1842
1843   1. User commands.
1844   1. System calls and error numbers.
1845   1. Functions in the C libraries.
1846   1. Device drivers.
1847   1. File formats.
1848   1. Games and other diversions.
1849   1. Miscellaneous information.
1850   1. System maintenance and operation commands.
1851   1. Kernel internals.
1852
1853 In some cases, the same topic may appear in more than one section of the online manual. For example, there is a `chmod` user command and a `chmod()` system call. In this case, you can tell the `man` command which one you want by specifying the section:
1854     
1855
1856     % man 1 chmod
1857
1858 This will display the manual page for the user command `chmod`. References to a particular section of the online manual are traditionally placed in parenthesis in written documentation, so [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section=1) refers to the `chmod` user command and [chmod(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section=2) refers to the system call.
1859
1860 This is fine if you know the name of the command and simply wish to know how to use it, but what if you cannot recall the command name? You can use `man` to search for keywords in the command descriptions by using the `-k` switch:
1861
1862    
1863
1864     % man -k mail
1865
1866 With this command you will be presented with a list of commands that have the keyword ***mail*** in their descriptions. This is actually functionally equivalent to using the `apropos` command.
1867
1868 So, you are looking at all those fancy commands in `/usr/bin` but do not have the faintest idea what most of them actually do? Simply do:    
1869
1870     % cd /usr/bin
1871     % man -f *
1872
1873 or
1874    
1875
1876     % cd /usr/bin
1877     % whatis *
1878
1879 which does the same thing.
1880
1881 ### GNU Info Files 
1882
1883 DragonFly includes many applications and utilities produced by the Free Software Foundation (FSF). In addition to manual pages, these programs come with more extensive hypertext documents called `info` files which can be viewed with the `info` command or, if you installed  **emacs** , the info mode of  **emacs** . To use the [info(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=info&section=1) command, simply type:
1884
1885     % info
1886
1887 For a brief introduction, type `h`. For a quick command reference, type `?`.
1888