initrd: Detach from the world and build on the fly
[dragonfly.git] / share / man / man7 / build.7
1 .\" Copyright (c) 2000
2 .\"     Mike W. Meyer
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD: src/share/man/man7/build.7,v 1.19.2.1 2002/03/18 08:33:02 murray Exp $
26 .\"
27 .Dd June 2, 2018
28 .Dt BUILD 7
29 .Os
30 .Sh NAME
31 .Nm build
32 .Nd information on how to build the system
33 .Sh DESCRIPTION
34 The source for the
35 .Dx
36 system and applications is located in
37 .Pa /usr/src .
38 This directory contains the
39 .Dq "base system"
40 sources, which is loosely defined as the things required to rebuild
41 the system to a useful state.
42 It also contains the source for the system documentation, including
43 manual pages.
44 Refer to
45 .Xr development 7
46 for more information on how to obtain the
47 .Dx
48 sources.
49 .Pp
50 Third party applications have to be built using the
51 .Xr dports 7
52 system.
53 The file
54 .Pa /usr/Makefile
55 has targets for obtaining the dports tree.
56 Typing
57 .Li make
58 in
59 .Pa /usr
60 gives specifics on how to obtain the tree for building packages.
61 .Pp
62 The
63 .Xr make 1
64 command is used in
65 .Pa /usr/src
66 to build and install the things in that directory.
67 Issuing the
68 .Xr make 1
69 command in any directory or
70 subdirectory of those directories has the same effect as issuing the
71 same command in all subdirectories of that directory.
72 With no target specified, the things in that directory are just built.
73 The following list provides the names and actions for other targets:
74 .Bl -tag -width ".Cm install"
75 .It Cm clean
76 Removes any files created during the build process.
77 .It Cm install
78 Installs the results of the build for this directory.
79 .El
80 .Pp
81 The other
82 .Pa /usr/src
83 make targets are:
84 .Bl -tag -width ".Cm installworld-force"
85 .It Cm buildworld
86 Rebuild everything but the kernel.
87 .It Cm quickworld
88 Same as
89 .Cm buildworld ,
90 but skip bootstrap, build and cross-build tool steps.
91 This target can be used for incremental upgrades once a full build of the
92 world has been done with
93 .Cm buildworld .
94 .It Cm realquickworld
95 Same as
96 .Cm quickworld ,
97 but also skip the depend step.
98 .It Cm crossworld
99 Just do the bootstrap, build and cross-build steps.
100 .It Cm installworld
101 Install everything built by
102 .Cm buildworld .
103 .It Cm installworld-force
104 Force an
105 .Cm installworld .
106 This will install to a temporary directory, then copy the main binaries
107 and libraries with a static
108 .Xr cpdup 1
109 to
110 .Ev DESTDIR
111 and finally will issue a normal
112 .Cm installworld
113 and
114 .Cm upgrade .
115 It is a special case to be used on older systems as a last resort when
116 the normal
117 .Cm installworld
118 doesn't work.
119 .It Cm world
120 .Cm buildworld +
121 .Cm installworld .
122 .It Cm buildkernel
123 Rebuild the kernel and the kernel-modules.
124 .It Cm nativekernel
125 Rebuild the kernel and the kernel-modules using native tools.
126 .It Cm quickkernel
127 Same as
128 .Cm buildkernel ,
129 but do not clean out the obj modules.
130 This target can be used for incremental upgrades once a full
131 build of the kernel has been done with
132 .Cm buildkernel .
133 .It Cm realquickkernel
134 Same as
135 .Cm quickkernel ,
136 but also skip the depend step.
137 .It Cm installkernel
138 Install the kernel and the kernel-modules.
139 .It Cm reinstallkernel
140 Reinstall the kernel and the kernel-modules.
141 .It Cm kernel
142 .Cm buildkernel +
143 .Cm installkernel .
144 .It Cm preupgrade
145 Perform certain upgrades that have to be done before
146 .Cm installworld ,
147 such as adding new users and groups.
148 .Cm installworld
149 will complain if they have not been done.
150 .It Cm upgrade
151 Upgrade the files in /etc and also setup the rest of the system for
152 the version of
153 .Dx
154 just installed.
155 .It Cm rescue
156 Build and install the statically linked rescue tools.
157 .It Cm initrd
158 Create the initial ramdisk based on the above rescue tools and install.
159 .It Cm most
160 Build user commands, no libraries or include files.
161 .It Cm installmost
162 Install user commands, no libraries or include files.
163 .It Cm backupworld
164 Manually archive binaries from installed world to location specified by
165 .Ev WORLD_BACKUP .
166 .It Cm backup-clean
167 Delete archive created by
168 .Cm backupworld .
169 .It Cm backup-auto-clean
170 Delete archive created automatically during
171 .Cm installworld .
172 .It Cm restoreworld
173 Restore binaries from archive created by
174 .Cm backupworld .
175 .It Cm restoreworld-auto
176 Restore binaries from archive created automatically during
177 .Cm installworld .
178 The archive location is specified by
179 .Ev AUTO_BACKUP .
180 .El
181 .Sh ENVIRONMENT
182 .Bl -tag -width ".Ev MAKEOBJDIRPREFIX"
183 .It Ev TARGET_ARCH , TARGET_PLATFORM
184 The target machine processor architecture and hardware platform.
185 These have to be set for cross-building.
186 .Ev TARGET_ARCH
187 is analogous to the
188 .Dq Nm uname Fl p
189 output.
190 For the 64 bit
191 .Tn AMD
192 architecture known as AMD64, x86-64 or Intel 64, use:
193 .Bd -literal -offset indent
194 TARGET_ARCH=x86_64
195 TARGET_PLATFORM=pc64
196 .Ed
197 .It Ev DESTDIR
198 An existing directory to be the root of
199 the hierarchy where the resulting binaries will be
200 installed (the default is
201 .Pa / ) .
202 .It Ev MAKEOBJDIRPREFIX
203 The directory hierarchy where the object files will be built (the default is
204 .Pa /usr/obj ) .
205 .It Ev __MAKE_CONF
206 Used to override the path of
207 .Xr make.conf 5
208 (the default is
209 .Pa /etc/make.conf ) .
210 .It Ev KERNCONF
211 The name of one or more kernel configurations from which kernels should
212 be built (the default is
213 .Li X86_64_GENERIC ) .
214 .It Ev KERNCONFDIR
215 The directory where the kernel configuration files are kept (the default is
216 .Pa /usr/src/sys/config ) .
217 .It Ev DESTLABEL
218 Common suffix added to kernel and modules directory names, prefixed by
219 a single dot.  For example,
220 .Bd -literal -offset indent
221 make DESTLABEL=test installkernel
222 .Ed
223 .Pp
224 installs them as
225 .Pa /boot/kernel.test/kernel
226 and
227 .Pa /boot/kernel.test ,
228 respectively.
229 .It Ev DESTKERNDIR
230 Where to install the kernel and the modules (the default is
231 .Pa /boot ) ,
232 in the directory hierarchy specified by the environment variable
233 .Ev DESTDIR .
234 .It Ev DESTKERNNAME
235 The name of the installed kernel file (the default is
236 .Pa kernel ) ,
237 under the directory specified by
238 .Ev DESTKERNDIR .
239 This overrides the effect of
240 .Ev DESTLABEL .
241 .It Ev DESTMODULESNAME
242 The name of the directory to install the kernel modules (the default is
243 .Pa modules ) ,
244 under the directory specified by
245 .Ev DESTKERNDIR .
246 This overrides the effect of
247 .Ev DESTLABEL .
248 .It Ev WORLD_BACKUP
249 Directory for manual backup of binaries of installed world (default:
250 .Pa /var/backups/world_backup ) .
251 .It Ev AUTO_BACKUP
252 Directory for automatic backup of binaries of installed world (default:
253 .Ev MAKEOBJDIRPREFIX Ns /world_binaries/ Ns Ev DESTDIR ) .
254 .It Ev NO_BACKUP
255 When defined, the automatic backup feature of
256 .Cm installworld
257 is inhibited.
258 .It Ev COPTFLAGS
259 Overrides the default optimization flags for kernel and module compiles.
260 .It Ev KCFLAGS
261 Allows you to add additional compiler flags for kernel and module compiles.
262 But use
263 .Ev COPTFLAGS
264 to specify any optimization overrides, as some modules may have to override
265 it to enforce a lower optimization level.
266 .El
267 .Sh OTHER
268 There are two other mechanisms that users should be aware of.  First,
269 when you issue a
270 .Cm installkernel
271 .Dx
272 will make a backup of the current kernel in
273 .Pa /boot/kernel.old .
274 Because people often do multiple installkernel operations, this backup
275 kernel can also get lost in the noise.
276 It is usually prudent to make a backup of the old kernel manually
277 every once in a while when you know that it is a good kernel.  you can
278 do this after issuing the
279 .Cm installkernel
280 by running the command:
281 .Bd -literal -offset indent
282 cpdup /boot/kernel.old /boot/kernel.bak
283 .Ed
284 .Pp
285 The advantage of this is that no installation mechanism will overwrite
286 your
287 .Pa /boot/kernel.bak ,
288 and in addition to that the loader's boot menu will check for its
289 existence and present a menu option 'b' to allow you to boot from it.
290 .Pp
291 The second mechanism is related to the two-stage root mount.
292 When using an encrypted root, the system will actually boot from a
293 small initial ramdisk (a.k.a. initrd) image stored as
294 .Pa /boot/kernel/initrd.img.gz .
295 This image will handle the encrypted configuration, mount, and chroot
296 to the real root.
297 This image is also used as the rescue ramdisk boot menu option.
298 This image is NOT updated automatically by
299 .Cm installworld
300 or
301 .Cm installkernel .
302 Instead, updating this image has to be done by running the manual command:
303 .Bd -literal -offset indent
304 make initrd
305 .Ed
306 .Pp
307 It is usually a good idea to run this command after rebooting into the new
308 world that you installed (so you know the world you installed is good).
309 This command will update the initrd image in
310 .Pa /boot/kernel .
311 .Sh FILES
312 .Bl -tag -width ".Pa /usr/src/Makefile_upgrade.inc" -compact
313 .It Pa /etc/make.conf
314 .It Pa /etc/defaults/make.conf
315 .It Pa /usr/src/share/doc/Makefile
316 .It Pa /usr/src/Makefile
317 .It Pa /usr/src/Makefile.inc1
318 .It Pa /usr/src/Makefile_upgrade.inc
319 .El
320 .Sh EXAMPLES
321 The
322 .Dq approved
323 method of updating your system from the latest sources is:
324 .Bd -literal -offset indent
325 make buildworld
326 make buildkernel KERNCONF=FOO
327 make installkernel KERNCONF=FOO
328 make installworld
329 make upgrade
330 .Ed
331 .Pp
332 After running these commands a system reboot is required,
333 otherwise many programs which have been rebuilt (such as
334 .Xr ps 1 ,
335 .Xr top 1 ,
336 etc.) may not work with the old kernel which is still running.
337 .Sh CAVEATS
338 The build and install order in the
339 .Sx EXAMPLES
340 section enforces that the new kernel is installed before the new
341 world.
342 Sometimes it might be necessary to reboot the system between those two
343 steps.
344 In this case
345 .Dq Nm make Cm installworld
346 will tell you to do so.
347 .Sh SEE ALSO
348 .Xr cc 1 ,
349 .Xr install 1 ,
350 .Xr make 1 ,
351 .Xr wmake 1 ,
352 .Xr make.conf 5 ,
353 .Xr development 7 ,
354 .Xr dports 7 ,
355 .Xr release 7 ,
356 .Xr config 8 ,
357 .Xr reboot 8 ,
358 .Xr shutdown 8
359 .Sh AUTHORS
360 .An -nosplit
361 .An Mike W. Meyer Aq Mt mwm@mired.org
362 and
363 .An Sascha Wildner Aq Mt swildner@gmail.com .