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