Initial import from FreeBSD RELENG_4:
[dragonfly.git] / share / man / man7 / development.7
1 .\" Copyright (c) 1998, Matthew Dillon.  Terms and conditions are those of
2 .\" the BSD Copyright as specified in the file "/usr/src/COPYRIGHT" in
3 .\" the FreeBSD source tree.
4 .\"
5 .\" $FreeBSD: src/share/man/man7/development.7,v 1.4.2.2 2003/05/23 07:48:35 brueffer Exp $
6 .\"
7 .Dd December 21, 2002
8 .Dt DEVELOPMENT 7
9 .Os
10 .Sh NAME
11 .Nm development
12 .Nd introduction to development with the FreeBSD codebase
13 .Sh DESCRIPTION
14 This manual page describes how an ordinary sysop,
15 .Ux admin, or developer
16 can, without any special permission, obtain, maintain, and modify the
17 .Fx
18 codebase as well as how to maintaining a master build which can
19 then be exported to other machines in your network.
20 This manual page
21 is targeted to system operators, programmers, and developers.
22 .Pp
23 Please note that what is being described here is based on a complete
24 FreeBSD environment, not just the FreeBSD kernel.
25 The methods described
26 here are as applicable to production installations as it is to development
27 environments.
28 You need a good 12-17GB of disk space on one machine to make this work
29 conveniently.
30 .Sh SETTING UP THE ENVIRONMENT ON THE MASTER SERVER
31 Your master server should always run a stable, production version of the
32 .Fx
33 operating system.   This does not prevent you from doing -CURRENT
34 builds or development.  The last thing you want to do is to run an
35 unstable environment on your master server which could lead to a situation
36 where you lose the environment and/or cannot recover from a mistake.
37 .Pp
38 Create a huge partition called /FreeBSD.
39 8-12GB is recommended.
40 This partition will contain nearly all the development environment,
41 including the CVS tree, broken-out source, and possibly even object files.
42 You are going to export this partition to your other machines via a 
43 READ-ONLY NFS export so do not mix it with other more security-sensitive
44 partitions.
45 .Pp
46 You have to make a choice in regards to
47 .Pa /usr/obj .
48 You can put
49 .Pa /usr/obj
50 in
51 .Pa /FreeBSD
52 or you can make
53 .Pa /usr/obj
54 its own partition.
55 I recommend making it a separate partition for several reasons.  First,
56 as a safety measure since this partition is written to a great deal.
57 Second, because you typically do not have to back it up.
58 Third, because it makes it far easier to mix and match the development
59 environments which are described later in this document.
60 I recommend a
61 .Pa /usr/obj
62 partition of at least 5GB.
63 .Pp
64 On the master server, use cvsup to automatically pull down and maintain
65 the
66 .Fx
67 CVS archive once a day.  The first pull will take a long time,
68 it is several gigabytes, but once you have it the daily syncs will be quite
69 small.
70 .Bd -literal -offset 4n
71 mkdir /FreeBSD/FreeBSD-CVS
72 rm -rf /home/ncvs
73 ln -s /FreeBSD/FreeBSD-CVS /home/ncvs
74 .Ed
75 .Pp
76 The cron job should look something like this (please randomize the time of
77 day!).
78 Note that you can use the cvsup file example directly from
79 /usr/share/examples without modification by supplying appropriate arguments
80 to cvsup.
81 .Bd -literal -offset 4n
82 33 6 * * *      /usr/local/bin/cvsup -g -r 20 -L 2 -h cvsup.freebsd.org /usr/share/examples/cvsup/cvs-supfile
83 .Ed
84 .Pp
85 Run the cvsup manually the first time to pull down the archive.  It could take
86 all day depending on how fast your connection is!
87 You will run all cvsup and cvs operations as root and you need to set
88 up a ~/.cvsrc (/root/.cvsrc) file, as shown below, for proper cvs operation.
89 Using ~/.cvsrc to specify cvs defaults is an excellent way
90 to "file and forget", but you should never forget that you put them in there.
91 .Bd -literal -offset 4n
92 # cvs -q
93 diff -u
94 update -Pd
95 checkout -P
96 .Ed
97 .Pp
98 Now use cvs to checkout a -STABLE source tree and a -CURRENT source tree,
99 as well as ports and docs, to create your initial source environment. 
100 Keeping the broken-out source and ports in /FreeBSD allows you to export
101 it to other machines via read-only NFS.
102 This also means you only need to edit/maintain files in one place and all
103 your clients automatically pick up the changes.
104 .Bd -literal -offset 4n
105 mkdir /FreeBSD/FreeBSD-4.x
106 mkdir /FreeBSD/FreeBSD-current
107
108 cd /FreeBSD/FreeBSD-4.x
109 cvs -d /home/ncvs checkout -rRELENG_4 src
110
111 cd /FreeBSD/FreeBSD-current
112 cvs -d /home/ncvs checkout src
113 cvs -d /home/ncvs checkout ports
114 cvs -d /home/ncvs checkout doc
115 .Ed
116 .Pp
117 Now create a softlink for /usr/src and /usr/src2.
118 On the main server I always point /usr/src at -STABLE and /usr/src2 at
119 -CURRENT.  On client machines I usually do not have a /usr/src2 and I make
120 /usr/src point at whatever version of FreeBSD the client box is intended to
121 run.
122 .Bd -literal -offset 4n
123 cd /usr
124 rm -rf src src2
125 ln -s /FreeBSD/FreeBSD-4.x/src src      (could be -CURRENT on a client)
126 ln -s /FreeBSD/FreeBSD-current/src src2 (MASTER SERVER ONLY)
127 .Ed
128 .Pp
129 Now you have to make a choice for /usr/obj.
130 Well, hopefully you made it already and chose the partition method.  If you
131 chose poorly you probably intend to put it in /FreeBSD and, if so, this is
132 what you want to do:
133 .Bd -literal -offset 4n
134 (ONLY IF YOU MADE A POOR CHOICE AND PUT /usr/obj in /FreeBSD!)
135 mkdir /FreeBSD/obj
136 cd /usr
137 rm -rf obj
138 ln -s /FreeBSD/obj obj
139 .Ed
140 .Pp
141 Alternatively you may chose simply to leave /usr/obj in /usr.  If your
142 /usr is large enough this will work, but I do not recommend it for 
143 safety reasons (/usr/obj is constantly being modified, /usr is not).
144 .Pp
145 Note that exporting /usr/obj via read-only NFS to your other boxes will
146 allow you to build on your main server and install from your other boxes.
147 If you also want to do builds on some or all of the clients you can simply
148 have /usr/obj be a local directory on those clients.
149 You should never export /usr/obj read-write, it will lead to all sorts of
150 problems and issues down the line and presents a security problem as well.
151 It is far easier to do builds on the master server and then only do installs
152 on the clients.
153 .Pp
154 I usually maintain my ports tree via CVS.
155 It is sitting right there in the master CVS archive and I've even told you
156 to check it out (see above).
157 With some fancy softlinks you can make the ports tree available both on your
158 master server and on all of your other machines.
159 Note that the ports tree exists only on the HEAD cvs branch, so its always
160 -CURRENT even on a -STABLE box.  This is what you do:
161 .Bd -literal -offset 4n
162 (THESE COMMANDS ON THE MASTER SERVER AND ON ALL CLIENTS)
163 cd /usr
164 rm -rf ports
165 ln -s /FreeBSD/FreeBSD-current/ports ports
166
167 cd /usr/ports                           (this pushes into the softlink)
168 rm -rf distfiles                        (ON MASTER SERVER ONLY)
169 ln -s /usr/ports.distfiles distfiles    (ON MASTER SERVER ONLY)
170
171 mkdir /usr/ports.distfiles
172 mkdir /usr/ports.workdir
173 .Ed
174 .Pp
175 Since /usr/ports is softlinked into what will be read-only on all of your
176 clients, you have to tell the ports system to use a different working
177 directory to hold ports builds.
178 You want to add a line to your /etc/make.conf file on the master server
179 and on all your clients:
180 .Bd -literal -offset 4n
181 WRKDIRPREFIX=/usr/ports.workdir
182 .Ed
183 .Pp
184 You should try to make the directory you use for the ports working directory
185 as well as the directory used to hold distfiles consistent across all of your
186 machines.
187 If there isn't enough room in /usr/ports.distfiles and /usr/ports.workdir I
188 usually make those softlinks (since this is on /usr these are per-machine) to
189 where the distfiles and working space really are.
190 .Sh EXPORTING VIA NFS FROM THE MASTER SERVER
191 The master server needs to export /FreeBSD and /usr/obj via NFS so all the
192 rest of your machines can get at them.
193 I strongly recommend using a read-only export for both security and safety.
194 The environment I am describing in this manual page is designed primarily
195 around read-only NFS exports.
196 Your exports file on the master server should contain the following lines:
197 .Bd -literal -offset 4n
198 /FreeBSD -ro -alldirs -maproot=root: -network YOURLAN -mask YOURLANMASK
199 /usr/obj -ro -alldirs -maproot=root: -network YOURLAN -mask YOURLANMASK
200 .Ed
201 .Pp
202 Of course, NFS server operations must also be configured on that machine.
203 This is typically done via your /etc/rc.conf:
204 .Bd -literal -offset 4n
205 nfs_server_enable="YES"
206 nfs_server_flags="-u -t -n 4"
207 .Ed
208 .Sh THE CLIENT ENVIRONMENT
209 All of your client machines can import the development/build environment
210 directory simply by NFS mounting /FreeBSD and /usr/obj from the master
211 server.
212 A typical /etc/fstab entry on your client machines will be something like this:
213 .Bd -literal -offset 4n
214 masterserver:/FreeBSD     /FreeBSD        nfs     ro,bg    0       0
215 masterserver:/usr/obj     /usr/obj        nfs     ro,bg    0       0
216 .Ed
217 .Pp
218 And, of course, you should configure the client for NFS client operations
219 via /etc/rc.conf.
220 In particular, this will turn on nfsiod which will improve client-side NFS
221 performance:
222 .Bd -literal -offset 4n
223 nfs_client_enable="YES"
224 .Ed
225 .Pp
226 Each client should create softlinks for /usr/ports and /usr/src that point
227 into the NFS-mounted environment.
228 If a particular client is running -CURRENT, /usr/src
229 should be a softlink to /FreeBSD/FreeBSD-current/src.
230 If it is running -STABLE, /usr/src should be a softlink to
231 /FreeBSD/FreeBSD-4.x/src.  I do not usually create a /usr/src2 softlink on
232 clients, that is used as a convenient shortcut when working on the source
233 code on the master server only and could create massive confusion (of the
234 human variety) on a client.
235 .Bd -literal -offset 4n
236 (ON EACH CLIENT)
237 cd /usr
238 rm -rf ports src
239 ln -s /FreeBSD/FreeBSD-current/ports ports
240 ln -s /FreeBSD/FreeBSD-XXX/src src
241 .Ed
242 .Pp
243 Don't forget to create the working directories so you can build ports, as
244 previously described.
245 If these are not good locations, make them softlinks to the correct location.
246 Remember that /usr/ports/distfiles is exported by
247 the master server and is therefore going to point to the same place
248 (typically /usr/ports.distfiles) on every machine.
249 .Bd -literal -offset 4n
250 mkdir /usr/ports.distfiles
251 mkdir /usr/ports.workdir
252 .Ed
253 .Sh BUILDING KERNELS
254 Here is how you build a -STABLE kernel (on your main development box).
255 If you want to create a custom kernel, cp GENERIC to YOURKERNEL and then
256 edit it before configuring and building.
257 The kernel configuration file lives in /usr/src/sys/i386/conf/KERNELNAME.
258 .Bd -literal -offset 4n
259 cd /usr/src
260 make buildkernel KERNCONF=KERNELNAME
261 .Ed
262 .Pp
263 .Sy WARNING!
264 If you are familiar with the old config/cd/make method of building
265 a -STABLE kernel, note that the config method will put the build 
266 environment in /usr/src/sys/compile/KERNELNAME instead of in /usr/obj.
267 .Pp
268 Building a -CURRENT kernel
269 .Bd -literal -offset 4n
270 cd /usr/src2            (on the master server)
271 make buildkernel KERNCONF=KERNELNAME
272 .Ed
273 .Sh INSTALLING KERNELS
274 Installing a -STABLE kernel (typically done on a client.
275 Only do this on your main development server if you want to install a new
276 kernel for your main development server):
277 .Bd -literal -offset 4n
278 cd /usr/src
279 make installkernel KERNCONF=KERNELNAME
280 .Ed
281 .Pp
282 If you are using the older config/cd/make build mechanism for stable, you
283 would install using:
284 .Bd -literal -offset 4n
285 cd /usr/src/sys/compile/KERNELNAME
286 make install
287 .Ed
288 .Pp
289 Installing a -CURRENT kernel (typically done only on a client)
290 .Bd -literal -offset 4n
291 (remember /usr/src is pointing to the client's specific environment)
292 cd /usr/src
293 make installkernel KERNCONF=KERNELNAME
294 .Ed
295 .Pp
296 .Sh BUILDING THE WORLD
297 This environment is designed such that you do all builds on the master server,
298 and then install from each client.
299 You can do builds on a client only if /usr/obj is local to that client.
300 Building the world is easy:
301 .Bd -literal -offset 4n
302 cd /usr/src
303 make buildworld
304 .Ed
305 .Pp
306 If you are on the master server you are running in a -STABLE environment, but
307 that does not prevent you from building the -CURRENT world.
308 Just cd into the appropriate source directory and you are set.  Do not
309 accidentally install it on your master server though!
310 .Bd -literal -offset 4n
311 cd /usr/src2
312 make buildworld
313 .Ed
314 .Sh INSTALLING THE WORLD
315 You can build on your main development server and install on clients.
316 The main development server must export /FreeBSD and /usr/obj via
317 read-only NFS to the clients.
318 .Pp
319 .Em NOTE!!!
320 If /usr/obj is a softlink on the master server, it must also be the EXACT
321 SAME softlink on each client.
322 If /usr/obj is a directory in /usr or a mount point on the master server,
323 then it must be (interchangeably) a directory in /usr or a mount point on
324 each client.
325 This is because the
326 absolute paths are expected to be the same when building the world as when
327 installing it, and you generally build it on your main development box
328 and install it from a client.
329 If you do not setup /usr/obj properly you will not be able to build on
330 machine and install on another.
331 .Bd -literal -offset 4n
332 (ON THE CLIENT)
333 (remember /usr/src is pointing to the client's specific environment)
334 cd /usr/src
335 make installworld
336 .Ed
337 .Pp
338 .Sy WARNING!
339 If builds work on the master server but installs do not work from the
340 clients, for example you try to install and the client complains that
341 the install tried to write into the read-only /usr/obj, then it is likely
342 that the /etc/make.conf file on the client does not match the one on the
343 master server closely enough and the install is trying to install something
344 that was not built.
345 .Sh DOING DEVELOPMENT ON A CLIENT (NOT JUST INSTALLING)
346 Developers often want to run buildkernel's or buildworld's on client
347 boxes simply to life-test the box.
348 You do this in the same manner that you buildkernel and buildworld on your
349 master server.
350 All you have to do is make sure that /usr/obj is pointing to local storage.
351 If you followed my advise and made /usr/obj its own partition on the master
352 server,
353 then it is typically going to be an NFS mount on the client.
354 Simply unmounting /usr/obj will leave you with a /usr/obj that is a
355 subdirectory in /usr which is typically local to the client.
356 You can then do builds to your heart's content!
357 .Sh MULTIPLE VERSIONS OF THE SOURCE TREE
358 I have described how to maintain two versions of the source tree, a stable
359 version in /FreeBSD/FreeBSD-4.x and a current version
360 in /FreeBSD/FreeBSD-current.
361 There is absolutely nothing preventing you
362 from breaking out other versions of the source tree
363 into /FreeBSD/XXX.
364 In fact, my /FreeBSD partition also contains
365 .Ox ,
366 .Nx ,
367 and various flavors of Linux.
368 You may not necessarily be able to build non-FreeBSD operating systems on
369 your master server, but being able
370 to collect and manage source distributions from a central server is a very
371 useful thing to be able to do and you can certainly export to machines
372 which can build those other operating systems.
373 .Sh UPDATING VIA CVS
374 The advantage of using cvsup to maintain an updated copy of the CVS
375 repository instead of using it to maintain source trees directly is that you
376 can then pick and choose when you bring your source tree (or pieces of your
377 source tree) up to date.
378 By using a cron job to maintain an updated CVS repository, you can update
379 your source tree at any time without any network cost as follows:
380 .Bd -literal -offset 4n
381 (on the main development server)
382 cd /usr/src
383 cvs -d /home/ncvs update
384 cd /usr/src2
385 cvs -d /home/ncvs update
386 cd /usr/ports
387 cvs -d /home/ncvs update
388 .Ed
389 .Pp
390 It is that simple, and since you are exporting the whole lot to your
391 clients, your clients have immediately visibility into the updated
392 source.
393 This is a good time to also remind you that most of the cvs operations
394 you do will be done as root, and that certain options are
395 required for CVS to operate properly on the
396 .Fx
397 repository.  For example,
398 .Fl Pd
399 is necessary when running "cvs update".
400 These options are typically placed in your ~/.cvsrc (as already described)
401 so you do not have to respecify them every time you run a CVS command.
402 Maintaining the CVS repository also gives you far more flexibility
403 in regards to breaking out multiple versions of the source tree.
404 It is a good idea to give your /FreeBSD partition a lot of space (I recommend
405 8-12GB) precisely for that reason.
406 If you can make it 15GB I would do it.
407 .Pp
408 I generally do not cvs update via a cron job.
409 This is because I generally want the source to not change out from under me
410 when I am developing code.
411 Instead I manually update the source every so often... when I feel it is
412 a good time.
413 My recommendation is to only keep the cvs repository synchronized via cron.
414 .Sh SEE ALSO
415 .Xr crontab 1 ,
416 .Xr crontab 5 ,
417 .Xr build 7 ,
418 .Xr firewall 7 ,
419 .Xr release 7 ,
420 .Xr tuning 7 ,
421 .Xr diskless 8
422 .Sh HISTORY
423 The
424 .Nm
425 manual page was originally written by
426 .An Matthew Dillon Aq dillon@FreeBSD.org
427 and first appeared
428 in
429 .Fx 5.0 ,
430 December 2002.