7f3a913fadfc56b28e9df1ab0a38d25c2e70f494
[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 DragonFly 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 .\" $DragonFly: src/share/man/man7/development.7,v 1.9 2007/12/15 16:49:43 thomas Exp $
7 .\"
8 .Dd December 15, 2007
9 .Dt DEVELOPMENT 7
10 .Os
11 .Sh NAME
12 .Nm development
13 .Nd introduction to development with the DragonFly codebase
14 .Sh DESCRIPTION
15 This manual page describes how an ordinary sysop,
16 .Ux admin, or developer
17 can, without any special permission, obtain, maintain, and modify the
18 .Dx
19 codebase as well as how to maintaining a master build which can
20 then be exported to other machines in your network.
21 This manual page
22 is targeted to system operators, programmers, and developers.
23 .Pp
24 Please note that what is being described here is based on a complete
25 .Dx
26 environment, not just the
27 .Dx
28 kernel.
29 The methods described
30 here are as applicable to production installations as it is to development
31 environments.
32 You need a good 12-17GB of disk space on one machine to make this work
33 conveniently.
34 .Sh SETTING UP THE ENVIRONMENT ON THE MASTER SERVER
35 Your master server should always run a stable, production version of the
36 .Dx
37 operating system.
38 This does not prevent you from doing -PREVIEW or -DEVELOPMENT
39 builds or development.
40 The last thing you want to do is to run an
41 unstable environment on your master server which could lead to a situation
42 where you lose the environment and/or cannot recover from a mistake.
43 .Pp
44 Create a partition called
45 .Pa /DragonFly .
46 8-12GB is recommended.
47 This partition will contain nearly all the development environment,
48 including the CVS tree, broken-out source, and possibly even object files.
49 You are going to export this partition to your other machines via a
50 .Sy read-only
51 NFS export so do not mix it with other more security-sensitive
52 partitions.
53 .Pp
54 You have to make a choice in regards to
55 .Pa /usr/obj .
56 You can put
57 .Pa /usr/obj
58 in
59 .Pa /DragonFly
60 or you can make
61 .Pa /usr/obj
62 its own partition.
63 I recommend making it a separate partition for several reasons.
64 First,
65 as a safety measure since this partition is written to a great deal.
66 Second, because you typically do not have to back it up.
67 Third, because it makes it far easier to mix and match the development
68 environments which are described later in this document.
69 I recommend a
70 .Pa /usr/obj
71 partition of at least 5GB.
72 .Pp
73 On the master server, use cvsup to automatically pull down and maintain
74 the
75 .Dx
76 CVS archive once a day.
77 The first pull will take a long time,
78 it is several gigabytes, but once you have it the daily syncs will be quite
79 small.
80 .Bd -literal -offset 4n
81 mkdir /DragonFly/DragonFly-CVS
82 rm -rf /home/dcvs
83 ln -s /DragonFly/DragonFly-CVS /home/dcvs
84 .Ed
85 .Pp
86 The cron job should look something like this (please randomize the time of
87 day!).
88 Note that you can use the cvsup file example directly from
89 .Pa /usr/share/examples
90 without modification by supplying appropriate arguments
91 to cvsup. Please use a cvsup mirror, see the
92 .Dx
93 site.
94 .Bd -literal -offset 4n
95 33 6 * * * /usr/local/bin/cvsup -gr 20 -L 2 -h cvsup.dragonflybsd.org \\
96   /usr/share/examples/cvsup/DragonFly-cvs-supfile
97 .Ed
98 .Pp
99 Run the cvsup manually the first time to pull down the archive.
100 It could take
101 all day depending on how fast your connection is!
102 You will run all cvsup and cvs operations as root and you need to set
103 up a
104 .Pa ~/.cvsrc
105 .Pa ( /root/.cvsrc )
106 file, as shown below, for proper cvs operation.
107 Using
108 .Pa ~/.cvsrc
109 to specify cvs defaults is an excellent way
110 to "file and forget", but you should never forget that you put them in there.
111 .Bd -literal -offset 4n
112 # cvs -q
113 diff -u
114 update -Pd
115 checkout -P
116 .Ed
117 .Pp
118 Now use cvs to checkout a -RELEASE source tree and a -DEVELOPMENT source tree,
119 as well as docs, to create your initial source environment.
120 Keeping the broken-out source in
121 .Pa /DragonFly
122 allows you to export
123 it to other machines via read-only NFS.
124 This also means you only need to edit/maintain files in one place and all
125 your clients automatically pick up the changes.
126 .Bd -literal -offset 4n
127 mkdir /DragonFly/DragonFly-RELEASE
128 mkdir /DragonFly/DragonFly-DEVELOPMENT
129
130 cd /DragonFly/DragonFly-RELEASE
131 cvs -d /home/dcvs checkout -r DragonFly_RELEASE_1_10_Slip src
132
133 cd /DragonFly/DragonFly-DEVELOPMENT
134 cvs -d /home/dcvs checkout src
135 cvs -d /home/dcvs checkout doc
136 .Ed
137 .Pp
138 Now create a softlink for
139 .Pa /usr/src
140 and
141 .Pa /usr/src2 .
142 On the main server I always point
143 .Pa /usr/src
144 at -RELEASE and
145 .Pa /usr/src2
146 at
147 -DEVELOPMENT.
148 On client machines I usually do not have a
149 .Pa /usr/src2
150 and I make
151 .Pa /usr/src
152 point at whatever version of
153 .Dx
154 the client box is intended to
155 run.
156 .Bd -literal -offset 4n
157 cd /usr
158 rm -rf src src2
159 ln -s /DragonFly/DragonFly-RELEASE/src src      (could be -DEVELOPMENT on a client)
160 ln -s /DragonFly/DragonFly-DEVELOPMENT/src src2 (MASTER SERVER ONLY)
161 .Ed
162 .Pp
163 Now you have to make a choice for
164 .Pa /usr/obj .
165 Well, hopefully you made it already and chose the partition method.
166 If you
167 chose poorly you probably intend to put it in
168 .Pa /DragonFly
169 and, if so, this is
170 what you want to do:
171 .Bd -literal -offset 4n
172 (ONLY IF YOU MADE A POOR CHOICE AND PUT /usr/obj in /DragonFly!)
173 mkdir /DragonFly/obj
174 cd /usr
175 rm -rf obj
176 ln -s /DragonFly/obj obj
177 .Ed
178 .Pp
179 Alternatively you may chose simply to leave
180 .Pa /usr/obj
181 in
182 .Pa /usr .
183 If your
184 .Pa /usr
185 is large enough this will work, but I do not recommend it for
186 safety reasons
187 .Pa ( /usr/obj
188 is constantly being modified,
189 .Pa /usr
190 is not).
191 .Pp
192 Note that exporting
193 .Pa /usr/obj
194 via read-only NFS to your other boxes will
195 allow you to build on your main server and install from your other boxes.
196 If you also want to do builds on some or all of the clients you can simply
197 have
198 .Pa /usr/obj
199 be a local directory on those clients.
200 You should never export
201 .Pa /usr/obj
202 read-write, it will lead to all sorts of
203 problems and issues down the line and presents a security problem as well.
204 It is far easier to do builds on the master server and then only do installs
205 on the clients.
206 .Pp
207 .Sh EXPORTING VIA NFS FROM THE MASTER SERVER
208 The master server needs to export
209 .Pa /DragonFly
210 and
211 .Pa /usr/obj
212 via NFS so all the
213 rest of your machines can get at them.
214 I strongly recommend using a read-only export for both security and safety.
215 The environment I am describing in this manual page is designed primarily
216 around read-only NFS exports.
217 Your
218 .Pa /etc/exports
219 file on the master server should contain the following lines:
220 .Bd -literal -offset 4n
221 /DragonFly -ro -alldirs -maproot=root: -network YOURLAN -mask YOURLANMASK
222 /usr/obj   -ro -alldirs -maproot=root: -network YOURLAN -mask YOURLANMASK
223 .Ed
224 .Pp
225 Of course, NFS server operations must also be configured on that machine.
226 This is typically done via your
227 .Pa /etc/rc.conf :
228 .Bd -literal -offset 4n
229 nfs_server_enable="YES"
230 .Ed
231 .Sh THE CLIENT ENVIRONMENT
232 All of your client machines can import the development/build environment
233 directory simply by NFS mounting
234 .Pa /DragonFly
235 and
236 .Pa /usr/obj
237 from the master
238 server.
239 A typical
240 .Pa /etc/fstab
241 entry on your client machines will be something like this:
242 .Bd -literal -offset 4n
243 masterserver:/DragonFly   /DragonFly      nfs     ro,bg    0       0
244 masterserver:/usr/obj     /usr/obj        nfs     ro,bg    0       0
245 .Ed
246 .Pp
247 And, of course, you should configure the client for NFS client operations
248 via
249 .Pa /etc/rc.conf .
250 In particular, this will turn on nfsiod which will improve client-side NFS
251 performance:
252 .Bd -literal -offset 4n
253 nfs_client_enable="YES"
254 .Ed
255 .Pp
256 Each client should create softlink for
257 .Pa /usr/src
258 that point
259 into the NFS-mounted environment.
260 If a particular client is running -DEVELOPMENT,
261 .Pa /usr/src
262 should be a softlink to
263 .Pa /DragonFly/DragonFly-DEVELOPMENT/src .
264 If it is running -RELEASE,
265 .Pa /usr/src
266 should be a softlink to
267 .Pa /DragonFly/DragonFly-RELEASE/src .
268 I do not usually create a
269 .Pa /usr/src2
270 softlink on
271 clients, that is used as a convenient shortcut when working on the source
272 code on the master server only and could create massive confusion (of the
273 human variety) on a client.
274 .Bd -literal -offset 4n
275 (ON EACH CLIENT)
276 cd /usr
277 ln -s /DragonFly/DragonFly-XXX/src src
278 .Ed
279 .Pp
280 .Sh BUILDING KERNELS
281 Here is how you build a -RELEASE kernel (on your main development box).
282 If you want to create a custom kernel, copy
283 .Pa GENERIC
284 to
285 .Pa YOURKERNEL
286 and then
287 edit it before configuring and building.
288 The kernel configuration file lives in
289 .Pa /sys/config/KERNELNAME .
290 .Bd -literal -offset 4n
291 cd /usr/src
292 make buildkernel KERNCONF=KERNELNAME
293 .Ed
294 .Pp
295 Building a -DEVELOPMENT kernel
296 .Bd -literal -offset 4n
297 cd /usr/src2            (on the master server)
298 make buildkernel KERNCONF=KERNELNAME
299 .Ed
300 .Sh INSTALLING KERNELS
301 Installing a -RELEASE kernel (typically done on a client.
302 Only do this on your main development server if you want to install a new
303 kernel for your main development server):
304 .Bd -literal -offset 4n
305 cd /usr/src
306 make installkernel KERNCONF=KERNELNAME
307 .Ed
308 .Pp
309 Installing a -DEVELOPMENT kernel (typically done only on a client)
310 .Bd -literal -offset 4n
311 (remember /usr/src is pointing to the client's specific environment)
312 cd /usr/src
313 make installkernel KERNCONF=KERNELNAME
314 .Ed
315 .Sh BUILDING THE WORLD
316 This environment is designed such that you do all builds on the master server,
317 and then install from each client.
318 You can do builds on a client only if
319 .Pa /usr/obj
320 is local to that client.
321 Building the world is easy:
322 .Bd -literal -offset 4n
323 cd /usr/src
324 make buildworld
325 .Ed
326 .Pp
327 If you are on the master server you are running in a -RELEASE environment, but
328 that does not prevent you from building the -DEVELOPMENT world.
329 Just cd into the appropriate source directory and you are set.
330 Do not
331 accidentally install it on your master server though!
332 .Bd -literal -offset 4n
333 cd /usr/src2
334 make buildworld
335 .Ed
336 .Sh INSTALLING THE WORLD
337 You can build on your main development server and install on clients.
338 The main development server must export
339 .Pa /DragonFly
340 and
341 .Pa /usr/obj
342 via
343 read-only NFS to the clients.
344 .Pp
345 .Em NOTE!!!
346 If
347 .Pa /usr/obj
348 is a softlink on the master server, it must also be the EXACT
349 SAME softlink on each client.
350 If
351 .Pa /usr/obj
352 is a directory in
353 .Pa /usr
354 or a mount point on the master server,
355 then it must be (interchangeably) a directory in
356 .Pa /usr
357 or a mount point on
358 each client.
359 This is because the
360 absolute paths are expected to be the same when building the world as when
361 installing it, and you generally build it on your main development box
362 and install it from a client.
363 If you do not setup
364 .Pa /usr/obj
365 properly you will not be able to build on
366 machine and install on another.
367 .Bd -literal -offset 4n
368 (ON THE CLIENT)
369 (remember
370 .Pa /usr/src
371 is pointing to the client's specific environment)
372 cd /usr/src
373 make installworld
374 .Ed
375 .Pp
376 .Sy WARNING!
377 If builds work on the master server but installs do not work from the
378 clients, for example you try to install and the client complains that
379 the install tried to write into the read-only
380 .Pa /usr/obj ,
381 then it is likely
382 that the
383 .Pa /etc/make.conf
384 file on the client does not match the one on the
385 master server closely enough and the install is trying to install something
386 that was not built.
387 .Sh DOING DEVELOPMENT ON A CLIENT (NOT JUST INSTALLING)
388 Developers often want to run buildkernel's or buildworld's on client
389 boxes simply to life-test the box.
390 You do this in the same manner that you buildkernel and buildworld on your
391 master server.
392 All you have to do is make sure that
393 .Pa /usr/obj
394 is pointing to local storage.
395 If you followed my advise and made
396 .Pa /usr/obj
397 its own partition on the master
398 server,
399 then it is typically going to be an NFS mount on the client.
400 Simply unmounting
401 .Pa /usr/obj
402 will leave you with a
403 .Pa /usr/obj
404 that is a
405 subdirectory in
406 .Pa /usr
407 which is typically local to the client.
408 You can then do builds to your heart's content!
409 .Sh MAINTAINING A LOCAL BRANCH
410 I have described how to maintain two versions of the source tree, a stable
411 version in
412 .Pa /DragonFly/DragonFly-RELEASE
413 and a current version
414 in
415 .Pa /DragonFly/DragonFly-DEVELOPMENT .
416 There is absolutely nothing preventing you
417 from breaking out other versions of the source tree
418 into
419 .Pa /DragonFly/XXX .
420 In fact, my
421 .Pa /DragonFly
422 partition also contains
423 .Fx ,
424 .Ox ,
425 .Nx ,
426 and various flavors of Linux.
427 You may not necessarily be able to build non-DragonFly operating systems on
428 your master server, but being able
429 to collect and manage source distributions from a central server is a very
430 useful thing to be able to do and you can certainly export to machines
431 which can build those other operating systems.
432 .Pp
433 Many developers choose to maintain a local branch of
434 .Dx
435 to test patches or build a custom distribution.
436 This can be done with CVS or another source code management system
437 (SubVersion, Perforce, BitKeeper) with its own repository.
438 Since the main
439 .Dx
440 tree is based on CVS, the former is convenient.
441 .Pp
442 First, you need to modify your cvsup environment to avoid it modifying
443 the local changes you have committed to the repository.
444 It is important to remove the "delete" keyword from your supfile and to
445 add the CVSROOT subdirectory to your refuse file.
446 For more information, see
447 .Xr cvsup 1 .
448 .Pp
449 The
450 .Dx
451 version of CVS examines a custom environmental variable,
452 CVS_LOCAL_BRANCH_NUM, which specifies an integer to use when doing a cvs
453 tag/rtag.
454 Set this number to something high (say 1000) to avoid colliding
455 with potential future branches of the main repository.
456 For example,
457 branching a file with version 1.4 produces 1.4.1000.
458 Future commits to this branch will produce revisions 1.4.1000.1,
459 1.4.1000.2, etc.
460 .Pp
461 To fork your local branch, do:
462 .Bd -literal -offset 4n
463 cvs rtag -r DragonFly_RELEASE_1_10_Slip -b LOCAL_DragonFly_RELEASE_1_10 src
464 .Ed
465 .Pp
466 After this, you can check out a copy from your local repository using the
467 new tag and begin making changes and committing them.
468 For more information on using cvs, see
469 .Xr cvs 1 .
470 .Pp
471 .Sy WARNING!
472 The cvsup utility may blow away changes made on a local branch in
473 some situations.
474 This has been reported to occur when the master CVS repository is
475 directly manipulated or an RCS file is changed.
476 At this point, cvsup notices that the client and server have entirely
477 different RCS files, so it does a full replace instead of trying to
478 send just deltas.
479 Ideally this situation should never arise, but in the real world it
480 happens all the time.
481 .Pp
482 While this is the only scenario where the problem should crop up,
483 there have been some suspicious-sounding reports of
484 CVS_LOCAL_BRANCH_NUM lossage that can't be explained by this alone.
485 Bottom line is, if you value your local branch then you
486 should back it up before every update.
487 .Sh UPDATING VIA CVS
488 The advantage of using cvsup to maintain an updated copy of the CVS
489 repository instead of using it to maintain source trees directly is that you
490 can then pick and choose when you bring your source tree (or pieces of your
491 source tree) up to date.
492 By using a cron job to maintain an updated CVS repository, you can update
493 your source tree at any time without any network cost as follows:
494 .Bd -literal -offset 4n
495 (on the main development server)
496 cd /usr/src
497 cvs -d /home/dcvs update
498 cd /usr/src2
499 cvs -d /home/dcvs update
500 .Ed
501 .Pp
502 It is that simple, and since you are exporting the whole lot to your
503 clients, your clients have immediately visibility into the updated
504 source.
505 This is a good time to also remind you that most of the cvs operations
506 you do will be done as root, and that certain options are
507 required for CVS to operate properly on the
508 .Dx
509 repository.
510 For example,
511 .Fl Pd
512 is necessary when running "cvs update".
513 These options are typically placed in your
514 .Pa ~/.cvsrc
515 (as already described)
516 so you do not have to respecify them every time you run a CVS command.
517 Maintaining the CVS repository also gives you far more flexibility
518 in regards to breaking out multiple versions of the source tree.
519 It is a good idea to give your
520 .Pa /DragonFly
521 partition a lot of space (I recommend
522 8-12GB) precisely for that reason.
523 If you can make it 15GB I would do it.
524 .Pp
525 I generally do not cvs update via a cron job.
526 This is because I generally want the source to not change out from under me
527 when I am developing code.
528 Instead I manually update the source every so often...\& when I feel it is
529 a good time.
530 My recommendation is to only keep the cvs repository synchronized via cron.
531 .Sh SEE ALSO
532 .Xr crontab 1 ,
533 .Xr cvs 1 ,
534 .Xr cvsup 1 ,
535 .Xr crontab 5 ,
536 .Xr exports 5 ,
537 .Xr kernconf 5 ,
538 .Xr make.conf 5 ,
539 .Xr build 7 ,
540 .Xr firewall 7 ,
541 .Xr release 7 ,
542 .Xr tuning 7 ,
543 .Xr diskless 8
544 .Sh HISTORY
545 The
546 .Nm
547 manual page was originally written by
548 .An Matthew Dillon Aq dillon@FreeBSD.org
549 and first appeared
550 in
551 .Fx 5.0 ,
552 December 2002.