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