]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - share/man/man8/picobsd.8
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / share / man / man8 / picobsd.8
1 .\" -*- nroff-fill -*-
2 .\" $FreeBSD$
3 .Dd June 25, 2009
4 .Os
5 .Dt PICOBSD 8
6 .Sh NAME
7 .Nm picobsd
8 .Nd building small FreeBSD disk images
9 .Sh SYNOPSIS
10 .Nm
11 .Op Ar options
12 .Op Ar config-name Op Ar site-name
13 .Sh DESCRIPTION
14 The
15 .Nm
16 utility is a script which produces a minimal implementation of
17 .Fx
18 (historically called
19 .Nm PicoBSD )
20 which typically fits on a small media such as a floppy disk,
21 or can be downloaded as a
22 single image file from some media such as CDROM, flash memory, or through
23 .Xr etherboot .
24 .Pp
25 The
26 .Nm
27 utility was originally created to build simple standalone systems
28 such as firewalls or bridges, but because of the ability to
29 cross-build images with different source trees than the one
30 in the server, it can be extremely useful to developers to
31 test their code without having to reinstall the system.
32 .Pp
33 The boot media (historically a floppy disk, but also small
34 CDROM or USB keys) contains a boot loader and a
35 compressed kernel which includes a memory file system.
36 Depending on the media, it might also contain a number of
37 additional files, which can be updated at run time, and are
38 used to override/update those in the memory file system.
39 .Pp
40 The system loads the kernel in the normal way, uncompresses
41 the memory file system and mounts it as root.
42 It then updates the memory
43 file system with files from the boot media (if present),
44 and executes a specialized version of
45 .Pa /etc/rc .
46 The boot media (floppy, etc.) is
47 required for loading only, and typically used read-only.
48 After the boot phase, the system runs entirely from RAM.
49 .Pp
50 The following options are available (but also check the
51 .Nm
52 script for more details).
53 The most important options for common operations are
54 .Fl src ,
55 .Fl init ,
56 .Fl n and
57 .Fl v.
58 .Pp
59 .Bl -tag -width indent
60 .\"
61 .It Fl -all_in_mfs
62 Put the entire contents of the file system in the
63 memory file system image which is contained in the
64 kernel.
65 This is the default behaviour, and is
66 extremely useful as the kernel itself can be loaded,
67 using
68 .Xr etherboot
69 or
70 .Xr pxeboot 8 ,
71 .\"
72 .It Fl c , Fl clean
73 Clean the product of previous builds.
74 .\"
75 .It Fl -cfg Ar file
76 Specify a file that contains additional config commands.
77 .\"
78 .It Fl -floppy_size Ar size
79 Set the size of the disk image.
80 Typical values for a floppy disk are 1440 or 2880,
81 but other values can be used for other media (flash memories,
82 CDROM, network booted kernels).
83 Note that this option is overridden by the content of the
84 config files (config in the image tree, or the one
85 specified with
86 .Fl Fl cfg )
87 .\"
88 .It Fl -init
89 When used together with the
90 .Fl -src
91 option, this initializes the
92 .Ao Ar SRC_PATH Ac Ns Pa /../usr
93 subtree as necessary to subsequently build
94 .Nm
95 images.
96 .\"
97 .It Fl -iso
98 Generate an ISO image, picobsd.iso, in addition to the disk image picobsd.bin
99 .\"
100 .It Fl -modules
101 Also build kernel modules.
102 These are not stored on the
103 .Nm
104 image but are left available in the build directory.
105 .\"
106 .It Fl n
107 Make the script non-interactive, skipping the initial menu
108 and proceeding with the build process without requiring user input.
109 .\"
110 .It Fl -no_all_in_mfs
111 Leaves files contained in the
112 .Pa floppy.tree
113 on the
114 .Nm
115 image, so they can be loaded separately
116 from the kernel (and updated individually to
117 customize the image).
118 .\"
119 .It Fl -no_loader
120 Omit /boot/loader, just rely on boot2 to load the kernel.
121 This saves some space but may have problems with kernels > 4MB.
122 .\"
123 .It Fl -objdir Ar directory
124 Specify a directory with the result of a previous buildworld.
125 This saves the need for an
126 .Fl Fl init
127 call before creating an image.
128 .\"
129 .It Fl -src Ar SRC_PATH
130 Use the source tree at
131 .Ar SRC_PATH
132 instead the one at
133 .Pa /usr/src .
134 This can be useful for cross-building
135 .Nm
136 images.
137 When using this option, you must also create and initialize the subtree at
138 .Ao Ar SRC_PATH Ac Ns Pa /../usr
139 with the correct header files, libraries, and tools (such as the
140 .Xr config 8
141 program) that are necessary for the cross-build (see the
142 .Fl -init
143 option).
144 The source files are unmodified by the
145 .Nm
146 script.
147 However the source tree is not completely read-only,
148 because
149 .Xr config 8
150 expects the kernel configuration file to be in one of
151 its subdirectories, and also the process of initializing the
152 .Pa usr
153 subtree touches some parts of the source tree (this is a bug
154 in the release build scripts which might go away with time).
155 .\"
156 .It Fl v
157 Make the script verbose, showing
158 commands to be executed and waiting for user
159 input before executing each of them.
160 Useful for debugging.
161 as a fully functional system.
162 .El
163 .Sh ENVIRONMENT
164 As a result of extreme size limitations, the
165 .Nm
166 environment differs from the normal
167 .Fx
168 in a number of ways:
169 .Bl -bullet
170 .It
171 There are no dynamic libraries, and there is no directory
172 .Pa /usr/lib .
173 As a result, only static executables may be executed.
174 .It
175 In order to reduce the size of the executables, all executables on a specific
176 floppy are joined together as a single executable built with
177 .Xr crunchgen 1 .
178 .It
179 Some programs are supplied in minimalistic versions, specifically
180 .Nm ns ,
181 a cut-down version of
182 .Xr netstat 1 ,
183 and
184 .Nm vm ,
185 a cut-down version of
186 .Xr vmstat 8 .
187 .El
188 .Sh BUILDING PicoBSD
189 The
190 .Nm
191 sources reside in the hierarchy
192 .Pa /usr/src/release/picobsd .
193 In the following discussion, all relative path names are relative to this
194 directory.
195 .Pp
196 The supported build script is
197 .Pa /usr/src/release/picobsd/build/picobsd
198 which can be run from anywhere, and relies on the
199 .Xr sysutils/makefs
200 port to build a filesystem without requiring
201 .Xr mdconfig
202 or root privileges to mount a filesystem.
203 When run in interactive mode (the default without the
204 .Fl n
205 option), the script will let you configure the various parameters
206 used to build the PicoBSD image.
207 An image is configured
208 using the files and directories described below.
209 The base system contains a template, called
210 .Pa bridge
211 for historical reasons,
212 that can be used as a base for building various kinds
213 of network appliances.
214 .Pp
215 You can define your own PicoBSD configuration, by creating a directory
216 with a name of your choice (e.g.\&
217 .Pa FOO )
218 which contains
219 some of the following files and directories.
220 For more
221 information on how to construct these files, look at one
222 of the standard
223 .Nm
224 configurations as a reference.
225 .Bl -tag -width indent
226 .It Pa PICOBSD
227 The kernel configuration file (required).
228 This is a mostly standard
229 kernel configuration file, possibly stripped down by removing
230 unnecessary drivers and options to reduce the kernel's size.
231 .Pp
232 To be recognised as a
233 .Nm
234 kernel config file, the file must also contain the line
235 beginning with
236 .Dq Li #PicoBSD
237 below, and a matching
238 .Dv MD_ROOT_SIZE
239 option:
240 .Bd -literal -offset indent
241 #marker    def_sz  init   MFS_inodes    floppy_inodes
242 #PicoBSD   4200    init   8192          32768
243 options MD_ROOT_SIZE=4200      # same as def_sz
244 .Ed
245 .Pp
246 This informs the script of the size of the memory file system and
247 provides a few other details on how to build the image.
248 .It Pa crunch.conf
249 .Xr crunchgen 1
250 configuration (required).
251 It contains the list of directories containing program sources,
252 the list of binaries to be built, and the list of libraries that
253 these programs use.
254 See the
255 .Xr crunchgen 1
256 manpage for the exact details on the syntax of this file.
257 .Pp
258 The following issues are particularly important when dealing
259 with
260 .Nm
261 configurations:
262 .Bl -bullet
263 .It
264 We can pass build options to those makefiles which understand
265 that, in order to reduce the size of the programs.
266 This is achieved with a line of the form
267 .Pp
268 .Dl "buildopts -DNO_PAM -DRELEASE_CRUNCH ..."
269 .It
270 When providing the list of directories where source files are, it
271 is convenient to list the following entry first:
272 .Pp
273 .Dl "srcdirs /usr/src/release/picobsd/tinyware"
274 .Pp
275 so that
276 .Nm Ns -specific
277 versions of the programs will be found there.
278 .It
279 The string
280 .Dq Li @__CWD__@
281 is replaced with the full pathname of the directory where the
282 .Nm
283 configuration resides (i.e., the one where we find
284 .Pa PICOBSD , crunch.conf ,
285 and so on).
286 This can be useful to refer source code that resides within a
287 configuration, e.g.\&
288 .Pp
289 .Dl "srcdirs @__CWD__@/src"
290 .El
291 .It Pa config
292 Shell variables, sourced by the
293 .Nm
294 script (optional).
295 The most important variables here are:
296 .Bl -tag -width ".Va MY_DEVS"
297 .It Va MY_DEVS
298 (Not used in
299 .Fx 5.0
300 where we have
301 .Xr devfs 5 ) .
302 Should be set to the list of devices to be created in the
303 .Pa /dev
304 directory of the image (it is really the argument passed to
305 .Xr MAKEDEV 8 ,
306 so refer to that manpage for the names).
307 .It Va fd_size
308 Size (in kilobytes) of the
309 .Nm
310 image.
311 By default,
312 .Va fd_size
313 is set to 1440
314 which produces an image suitable for a standard floppy.
315 .Pp
316 If you plan to store the image on a CDROM (e.g.\& using
317 the
318 .Dq "El Torito"
319 floppy emulation), you can set
320 .Va fd_size
321 equal to 2880.
322 If you are planning to dump the image onto a hard disk
323 (either in a partition or on the whole disk), you
324 are not restricted to one of the standard floppy sizes.
325 Using a large image size per se does not waste RAM at runtime,
326 because only the files that are actually loaded from the image
327 contribute to the memory usage.
328 .It Va import_files
329 Contains a list of files to be imported in the floppy tree.
330 Absolute names refer to the standard file system, relative
331 names refer to the root of the source tree being used
332 (i.e.\&
333 .Va SRC_PATH/.. ) .
334 You can normally use this option if you want to import
335 files such as shared libraries, or databases, without
336 having to replicate them first in your configuration
337 under the
338 .Pa floppy.tree/
339 directory.
340 .El
341 .It Pa floppy.tree.exclude
342 List of files from the standard floppy tree which
343 we do not want to be copied (optional).
344 .It Pa floppy.tree/
345 Local additions to the standard floppy tree (optional).
346 The content of this subtree will be copied as-is into the
347 floppy image.
348 .It Pa floppy.tree. Ns Aq Ar site-name
349 Same as above, but site-specific (optional).
350 .El
351 .Pp
352 More information on the build process can be found in the
353 comments in the
354 .Nm
355 script.
356 .Sh USING ALTERNATE SOURCE TREES
357 The build script can be instructed to use an alternate source tree
358 using the
359 .Fl -src Ar SRC_PATH
360 option.
361 The tree that you specify must contain full sources for the kernel
362 and for all programs that you want to include in your image.
363 As an example, to cross-build the
364 .Pa bridge
365 floppy
366 using RELENG_4 sources, you can do the following:
367 .Bd -literal -offset indent
368 cd <some_empty_directory>
369 mkdir FOO
370 (cd FOO; cvs -d<my_repository> co -rRELENG_4 src)
371 picobsd --src FOO/src --init    # this is needed only once
372 picobsd --src FOO/src -n -v bridge
373 .Ed
374 .Pp
375 If the build is successful, the directory
376 .Pa build_dir-bridge/
377 will contain a
378 .Pa kernel
379 that can be downloaded with
380 .Xr etherboot ,
381 a floppy image called
382 .Pa picobsd.bin ,
383 plus the products of the compilation in other directories.
384 If you want to modify the source tree in
385 .Pa FOO/src ,
386 a new image can be produced by simply running
387 .Pp
388 .Dl "picobsd --src FOO/src -n -v bridge"
389 .Pp
390 whereas if the change affects include files or libraries
391 you first need to update them, e.g.\& by re-running
392 .Pp
393 .Dl "picobsd --src FOO/src --init  # this is needed only once"
394 .Pp
395 as you would normally do for any change of this kind.
396 .Sh INSTALLING PicoBSD
397 .Ss Floppy Install
398 Historically,
399 .Nm
400 is run from a floppy disk, where it can be installed with a simple
401 .Pp
402 .Dl "dd if=picobsd.bin of=/dev/rfd0"
403 .Pp
404 and the floppy is ready to boot.
405 .Ss Hard Disk Install
406 The same process can be used to store the image on a hard disk
407 (entire volume or one of the slices):
408 .Bd -literal -offset indent
409 dd if=picobsd.bin of=/dev/ad2
410 dd if=picobsd.bin of=/dev/ad2s3
411 dd if=picobsd.bin of=/dev/ad2 oseek=NN
412 .Ed
413 .Pp
414 The first form will install the image on the entire disk, and it
415 should work in the same way as for a floppy.
416 .Pp
417 The second form will install the image
418 on slice number 3 (which should be large enough to store the
419 contents of the image).
420 However, the process will only have success if the
421 partition does not contain a valid disklabel, otherwise the kernel will
422 likely prevent overwriting the label.
423 In this case you can use the
424 third form, replacing
425 .Ar NN
426 with the actual start of the partition
427 (which you can determine using
428 .Xr fdisk 8 ) .
429 Note that after saving the image to the slice, it will not yet be
430 recognised.
431 You have to use the
432 .Xr disklabel 8
433 command to properly initialize the label (do not ask why!).
434 One way to do this is
435 .Bd -literal -offset indent
436 disklabel -w ad0s2 auto
437 disklabel -e ad0s2
438 .Ed
439 .Pp
440 and from the editor enter a line corresponding to the actual partition, e.g.\&
441 if the image has 2.88MB (5760 sectors) you need to enter the following
442 line for the partition:
443 .Pp
444 .Dl "a: 5760   0    4.2BSD   512   4096"
445 .Pp
446 At this point the partition is bootable.
447 Note that the image size can be smaller than the slice size
448 (indicated as partition
449 .Dq Li c: ) .
450 .Ss CDROM Install
451 .Nm
452 can produce an ISO image named picobsd.iso,
453 which does not use
454 .Dq "El Torito"
455 emulation, so it has no size restrictions.
456 Installing means just burning a media with the file.
457 .Ss Booting From The Network
458 Yet another way to use
459 .Nm
460 is to boot the image off the network.
461 For this purpose you should use the uncompressed kernel which is
462 available as a byproduct of the compilation.
463 Refer to the documentation
464 for network booting for more details, the
465 .Nm
466 kernel is bootable as a standard
467 .Fx
468 kernel.
469 .Sh BOOTING PicoBSD
470 To boot
471 .Nm ,
472 insert the floppy and reset the machine.
473 The boot procedure is similar to the
474 standard
475 .Fx
476 boot.
477 Booting from a floppy is normally rather slow (in the order of 1-2
478 minutes), things are much faster if you store your image on
479 a hard disk, Compact Flash, or CDROM.
480 .Pp
481 You can also use
482 .Xr etherboot
483 to load the preloaded, uncompressed kernel image
484 which is a byproduct of the
485 .Nm
486 build.
487 In this case
488 the load time is a matter of a few seconds, even on a 10Mbit/s
489 ethernet.
490 .Pp
491 After booting,
492 .Nm
493 loads the root file system from the memory file system, starts
494 .Pa /sbin/init ,
495 and passes control to a first startup script,
496 .Pa /etc/rc .
497 The latter populates the
498 .Pa /etc
499 and
500 .Pa /root
501 directories with the default files, then tries to identify the boot
502 device (floppy, hard disk partition) and possibly override the contents
503 of the root file system with files read from the boot device.
504 This allows you to store local configuration on the same media.
505 After this phase the boot device is no longer used, unless the
506 user specifically does it.
507 .Pp
508 After this, control is transferred to a second script,
509 .Pa /etc/rc1
510 (which can be overridden from the boot device).
511 This script tries to associate a hostname to the system by using
512 the MAC address of the first ethernet interface as a key, and
513 .Pa /etc/hosts
514 as a lookup table.
515 Then control is passed to the main user configuration script,
516 .Pa /etc/rc.conf ,
517 which is supposed to override the value of a number of configuration
518 variables which have been pre-set in
519 .Pa /etc/rc.conf.defaults .
520 You can use the
521 .Va hostname
522 variable to create different configurations from the same file.
523 After taking control back,
524 .Pa /etc/rc1
525 completes the initializations, and as part of this
526 it configures network interfaces and optionally calls the
527 firewall configuration script,
528 .Pa /etc/rc.firewall ,
529 where the user can store his own firewall configuration.
530 .Pp
531 Note that by default
532 .Nm
533 runs entirely from main memory, and has no swap space, unless you
534 explicitly request it.
535 The boot device is also not used anymore after
536 .Pa /etc/rc1
537 takes control, again, unless you explicitly request it.
538 .Sh CONFIGURING a PicoBSD system
539 The operation of a
540 .Nm
541 system can be configured through a few files which are read at boot
542 time, very much like a standard
543 .Fx
544 system.
545 There are, however, some minor differences to reduce the
546 number of files to store and/or customize, thus saving space.
547 Among the files to configure we have the following:
548 .Bl -tag -width indent
549 .It Pa /etc/hosts
550 Traditionally, this file contains the IP-to-hostname mappings.
551 In addition to this, the
552 .Nm
553 version of this file also contains
554 a mapping between Ethernet (MAC) addresses and hostnames, as follows:
555 .Bd -literal -offset indent
556 #ethertable     start of the ethernet->hostname mapping
557 # mac_address           hostname
558 # 00:12:34:56:78:9a     pinco
559 # 12:34:56:*            pallino
560 # *                     this-matches-all
561 .Ed
562 .Pp
563 where the line containing
564 .Dq Li #ethertable
565 marks the start of the table.
566 .Pp
567 If the MAC address is not found, the script will prompt you to
568 enter a hostname and IP address for the system, and this
569 information will be stored in the
570 .Pa /etc/hosts
571 file (in memory) so you can simply store them on disk later.
572 .Pp
573 Note that you can use wildcards in the address part, so a line
574 like the last one in the example will match any MAC address and
575 avoid the request.
576 .It Pa /etc/rc.conf
577 This file contains a number of variables which control the
578 operation of the system, such as interface configuration,
579 router setup, network service startup, etc.
580 For the exact list and meaning of these variables see
581 .Pa /etc/rc.conf.defaults .
582 .Pp
583 It is worth mentioning that some of the variables let you
584 overwrite the contents of some files in
585 .Pa /etc .
586 This option is available at the moment for
587 .Pa /etc/host.conf
588 and
589 .Pa /etc/resolv.conf ,
590 whose contents are generally very short and suitable for this
591 type of updating.
592 In case you use these variables, remember to use newlines
593 as appropriate, e.g.\&
594 .Bd -literal -offset indent
595 host_conf="# this goes into /etc/host.conf
596 hosts
597 bind"
598 .Ed
599 .Pp
600 Although not mandatory, in this file you should only set the
601 variables indicated in
602 .Pa /etc/rc.conf.defaults ,
603 and avoid starting services which depend on having the network running.
604 This can be done at a later time: if you set
605 .Va firewall_enable Ns = Ns Qq Li YES ,
606 the
607 .Pa /etc/rc.firewall
608 script will be run after configuring the network interfaces,
609 so you can set up your firewall and safely start network services or enable
610 things such as routing and bridging.
611 .It Pa /etc/rc.firewall
612 This script can be used to configure the
613 .Xr ipfw 4
614 firewall.
615 On entry, the
616 .Va fwcmd
617 variable is set to the pathname of the firewall command,
618 .Va firewall_type
619 contains the value set in
620 .Pa /etc/rc.conf ,
621 and
622 .Va hostname
623 contains the name assigned to the host.
624 .El
625 .Pp
626 There is a small script called
627 .Nm update
628 which can be used to edit and/or save to disk a copy of the files
629 you have modified after booting.
630 The script takes one or more absolute pathnames, runs the
631 editor on the files passed as arguments, and then saves a
632 compressed copy of the files on the disk (mounting and
633 unmounting the latter around the operation).
634 .Pp
635 If invoked without arguments,
636 .Nm update
637 edits and saves
638 .Pa rc.conf , rc.firewall ,
639 and
640 .Pa master.passwd .
641 .Pp
642 If one of the arguments is
643 .Pa /etc
644 (the directory name alone),
645 then the command saves to disk (without editing)
646 all the files in the directory for which a copy
647 already exists on disk (e.g.\& as a result of a previous update).
648 .Sh SEE ALSO
649 .Xr crunchgen 1 ,
650 .Xr mdconfig 8 ,
651 .Xr swapon 8
652 .Sh AUTHORS
653 .An -nosplit
654 .An Andrzej Bialecki Aq abial@FreeBSD.org ,
655 with subsequent work on the scripts by
656 .An Luigi Rizzo Aq luigi@iet.unipi.it
657 and others.
658 Man page and
659 .Pa Makefiles
660 created by
661 .An Greg Lehey Aq grog@lemis.com .
662 .Sh BUGS
663 Documentation is still incomplete.