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