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