Put in remaining pages and wiki contents.
[ikiwiki.git] / docs / handbook / handbook-kernelconfig-building.mdwn
1 ## Building and Installing a Custom Kernel \r
2 First, let us take a quick tour of the kernel build directory. All directories mentioned will be relative to the main `/usr/src/sys` directory, which is also accessible through `/sys`. There are a number of subdirectories here representing different parts of the kernel, but the most important, for our purposes, is `config`, where you will edit your custom kernel configuration, and `compile`, which is the staging area where your kernel will be built.  Notice the logical organization of the directory structure, with each supported device, file system, and option in its own subdirectory.\r
3 \r
4  **Installing the Source**  **** \r
5 \r
6 If there is ***not*** a `/usr/src/sys` directory on your system, then the kernel source has not been installed. One method to do this is via cvsup.  An alternative is to install the kernel source tree from the archive distributed on the DragonFly CD named `src-sys.tar.bz2`.  This is especially useful when you do not have ready access to the internet.  See [Building Kernel From Live CD](BuildingKernelFromLiveCD) for notes on how to access and extract this archive.  When installing kernel source only, use the alternate build procedure below.\r
7 \r
8  **Your Custom Config File** \r
9 \r
10 Next, move to the `config` directory and copy the `GENERIC` configuration file to the name you want to give your kernel. For example:\r
11 \r
12     \r
13     # cd /usr/src/sys/config\r
14     # cp GENERIC MYKERNEL\r
15 \r
16 Traditionally, this name is in all capital letters and, if you are maintaining multiple DragonFly machines with different hardware, it is a good idea to name it after your machine's hostname. We will call it `MYKERNEL` for the purpose of this example.\r
17 \r
18  **Tip:** Storing your kernel config file directly under `/usr/src` can be a bad idea. If you are experiencing problems it can be tempting to just delete `/usr/src` and start again. Five seconds after you do that you realize that you have deleted your custom kernel config file. Do not edit `GENERIC` directly, as it may get overwritten the next time you [update your source tree](updating.html#UPDATING-SETUP), and your kernel modifications will be lost.\r
19 \r
20 You might want to keep your kernel config file elsewhere, and then create a symbolic link to the file in the `config` directory.\r
21 \r
22 For example:\r
23 \r
24     \r
25     # cd /usr/src/sys/config\r
26     # mkdir /root/kernels\r
27     # cp GENERIC /root/kernels/MYKERNEL\r
28     # ln -s /root/kernels/MYKERNEL\r
29 \r
30  **Note:** You must execute these and all of the following commands under the `root` account or you will get permission denied errors.\r
31 \r
32 Now, edit `MYKERNEL` with your favorite text editor. If you are just starting out, the only editor available will probably be ***vi***, which is too complex to explain here, but is covered well in many books in the [bibliography](bibliography.html). However, DragonFly does offer an easier editor called ***ee*** which, if you are a beginner, should be your editor of choice. Feel free to change the comment lines at the top to reflect your configuration or the changes you have made to differentiate it from `GENERIC`.\r
33 \r
34 If you have built a kernel under SunOS™ or some other BSD operating system, much of this file will be very familiar to you. If you are coming from some other operating system such as DOS, on the other hand, the `GENERIC` configuration file might seem overwhelming to you, so follow the descriptions in the [Configuration File](kernelconfig-config.html) section slowly and carefully.\r
35 \r
36  **Building a Kernel - Full Source Tree** \r
37 \r
38  ****  **Note:** Be sure to always check the file `/usr/src/UPDATING`, before you perform any update steps, in the case you [sync your source tree](updating.html#UPDATING-SETUP) with the latest sources of the DragonFly project. In this file all important issues with updating DragonFly are typed out. `/usr/src/UPDATING` always fits your version of the DragonFly source, and is therefore more accurate for new information than the handbook.\r
39 \r
40  1. Change to the `/usr/src` directory.\r
41      \r
42       # cd /usr/src\r
43     \r
44 \r
45  1. Compile the kernel.\r
46      \r
47       # make buildkernel KERNCONF=MYKERNEL\r
48     \r
49 \r
50  1. Install the new kernel.\r
51      \r
52       # make installkernel KERNCONF=MYKERNEL\r
53     \r
54 \r
55 \r
56 If you have ***not*** upgraded your source tree in any way since the last time you successfully completed a `buildworld`-`installworld` cycle (you have not run  **CVSup** ), then it is safe to use the `quickworld` and `quickkernel`, `buildworld`, `buildkernel` sequence.\r
57 \r
58  **Building a Kernel - Kernel Source Only** \r
59 \r
60 When only the kernel source is installed, you need to change step 2, above, to this:\r
61 \r
62      \r
63      # make nativekernel KERNCONF=MYKERNEL\r
64 \r
65 \r
66 The other steps are the same.\r
67 \r
68  **Running Your New Kernel** \r
69 \r
70 The new kernel will have been copied to the boot directory as `kernel` and the old kernel will be moved to `/boot/kernel.old`, the same applies to the modules (`/boot/modules` -> `/boot/modules.old`). Now, shutdown the system and reboot to use your new kernel. In case something goes wrong, there are some [troubleshooting](kernelconfig-trouble.html) instructions at the end of this chapter. Be sure to read the section which explains how to recover in case your new kernel [does not boot](kernelconfig-trouble.html#KERNELCONFIG-NOBOOT).\r
71 \r
72  **Note:** If you have added any new devices (such as sound cards), you may have to add some device nodes to your `/dev` directory before you can use them. For more information, take a look at [Making Device Nodes](kernelconfig-nodes.html) section later on in this chapter.\r
73 \r
74 \r