FreeBSD_NanoBSD NanoBSD tru2life style :-)

Table of Contents

Introduction to NanoBSD
NanoBSD Howto
references
NanoBSD files
NanoBSD script
NanoBSD obj files/directories
tru2life NanoBSD packages
Man Pages useful with NanoBSD
Commands used with NanoBSD
The original "article.html" file blatenly plagurized... :-)

FreeBSD is a registered trademark of the FreeBSD Foundation.

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this document, and the FreeBSD Project was aware of the trademark claim, the designations have been followed by the “™” or the “®” symbol.

This document provides information about the NanoBSD tools, which can be used to create FreeBSD system images for embedded applications, suitable for use on a Compact Flash card (or other mass storage medium).

Introduction to NanoBSD

NanoBSD is a tool currently developed by Poul-Henning Kamp . It creates a FreeBSD system image for embedded applications, suitable for use on a Compact Flash card (or other mass storage medium).

It can be used to build specialized install images, designed for easy installation and maintenance of systems commonly called “computer appliances”. Computer appliances have their hardware and software bundled in the product, which means all applications are pre-installed. The appliance is plugged into an existing network and can begin working (almost) immediately.

The features of NanoBSD include:

NanoBSD Howto

The design of NanoBSD

Once the image is present on the medium, it is possible to boot NanoBSD. The mass storage medium is divided into three parts by default:

These partitions are normally mounted read-only.

The /etc and /var directories are md(4) (malloc) disks.

The configuration file partition persists under the /cfg directory. It contains files for /etc directory and is briefly mounted read-only right after the system boot, therefore it is required to copy modified files from /etc back to the /cfg directory if changes are expected to persist after the system restarts.

Example 1. Making persistent changes to /etc/resolv.conf

# vi /etc/resolv.conf
  [...]
# mount /cfg
# cp /etc/resolv.conf /cfg
# umount /cfg

Note: The partition containing /cfg should be mounted only at boot time and while overriding the configuration files.

Keeping /cfg mounted at all times is not a good idea, especially if the NanoBSD system runs off a mass storage medium that may be adversely affected by a large number of writes to the partition (i.e. when the filesystem syncer flushes data to the system disks).

Building a NanoBSD image

A NanoBSD image is built using a simple nanobsd.sh shell script, which can be found in the /usr/src/tools/tools/nanobsd directory. This script creates an image, which can be copied on the storage medium using the dd(1) utility.

The necessary commands to build a NanoBSD image are:

(1) # cd /usr/src/tools/tools/nanobsd
(2) # sh nanobsd.sh -c nanobsd.conf
(3) # cd /usr/obj/nanobsd.${NANO_NAME}(ie: full, custom, tru2life)...
(4) # dd if=_.disk.full of=/dev/da0 bs=64k
  1. Change the current directory to the base directory of the NanoBSD build script.
  2. Start the build process.
  3. Change the current directory to the place where the built images are located.
  4. Install NanoBSD onto the storage medium.

Customizing a NanoBSD image

This is probably the most important and most interesting feature of NanoBSD.

This is also where you will be spending most of the time when developing with NanoBSD.

Invocation of the following command will force the nanobsd.sh to read its configuration from the nanobsd.conf file located in the current directory:

# sh nanobsd.sh -c conf.nano

Customization is done in two ways:

2.3.1 Configuration options

With configuration settings, it is possible to configure options passed to both the buildworld and installworld stages of the NanoBSD build process, as well as internal options passed to the main build process of NanoBSD. Through these options it is possible to cut the system down, so it will fit on as little as 64MB. You can use the configuration options to trim down FreeBSD even more, until it will consists ofjust the kernel and two or three files in the userland.

The configuration file consists of configuration options, which override the default values. The most important directives are:

2.3.2 Custom functions

It is possible to fine-tune NanoBSD using shell functions in the configuration file. The following example illustrates the basic model of custom functions:

cust_foo()
(
  echo "bar=topless" > \
  ${NANO_WORLDDIR}/etc/foo
)

customize_cmd cust_foo

A more useful example of a customization function is the following, which changes the default size of the /etc directory from 5MB to 30MB:

cust_etc_size()
(
  cd ${NANO_WORLDDIR}/conf
  echo 30000 > default/etc/md_size
)

customize_cmd cust_etc_size

There are a few default pre-defined customization functions ready for use:

2.3.3 Adding packages

Packages can be added to a NanoBSD image using a custom function. The following fuction will install all the packages located in /usr/src/tools/tools/nanobsd/packages:


install_packages()
(
  mkdir -p ${NANO_WORLDDIR}/packages

  cp /usr/src/tools/tools/nanobsd/packages/* ${NANO_WORLDDIR}/packages

  chroot ${NANO_WORLDDIR} sh -c 'cd packages; pkg_add -v *;cd ..;'

  rm -rf ${NANO_WORLDDIR}/packages
)

customize_cmd install_packages

2.3.4 Configuration file example

A complete example of a configuration file for building a custom NanoBSD image can be:

NANO_NAME=custom
NANO_SRC=/usr/src
NANO_KERNEL=MYKERNEL
NANO_IMAGES=2

CONF_BUILD='
NO_KLDLOAD=YES
NO_NETGRAPH=YES
NO_PAM=YES
'

CONF_INSTALL='
NO_ACPI=YES
NO_BLUETOOTH=YES
NO_CVS=YES
NO_FORTRAN=YES
NO_HTML=YES
NO_LPR=YES
NO_MAN=YES
NO_SENDMAIL=YES
NO_SHAREDOCS=YES
NO_EXAMPLES=YES
NO_INSTALLLIB=YES
NO_CALENDAR=YES
NO_MISC=YES
NO_SHARE=YES
'

CONF_WORLD='
NO_BIND=YES
NO_MODULES=YES
NO_KERBEROS=YES
NO_GAMES=YES
NO_RESCUE=YES
NO_LOCALES=YES
NO_SYSCONS=YES
NO_INFO=YES
'

nanobsd_dev SanDisk 1G

cust_nobeastie()
(
  touch ${NANO_WORLDDIR}/boot/loader.conf

  echo "beastie_disable=\"YES\"" >> ${NANO_WORLDDIR}/boot/loader.conf
)

customize_cmd cust_comconsole

customize_cmd cust_install_files

customize_cmd cust_allow_ssh_root

customize_cmd cust_nobeastie

Updating NanoBSD

The update process of NanoBSD is relatively simple:

  1. Build a new NanoBSD image, as usual.

  2. Upload the new image into an unused partition of a running NanoBSD appliance.

    The most important difference of this step from the initial NanoBSD installation is that now instead of using the _.disk.full file (which contains an image of the entire disk), the _.disk.image image is installed (which contains an image of a single system partition).

  3. Reboot, and start the system from the newly installed partition.

  4. If all goes well, the upgrade is finished.

  5. If anything goes wrong, reboot back into the previous partition (which contains the old, working image), to restore system functionality as fast as possible. Fix any problems of the new build, and repeat the process.

To install new image onto the running NanoBSD system, it is possible to use either the updatep1 or updatep2 script located in the /root directory, depending from which partition is running the current system.

According to which services are available on host serving new NanoBSD image and what type of transfer is preferred, it is possible to examine one of these three ways:

2.4.1 Using ftp(1)

If the transfer speed is in first place, use this example:

# ftp myhost get _.disk.image "| sh updatep1"

2.4.2 Using ssh(1)

If a secure transfer is preferred, consider using this example:

# ssh myhost cat _.disk.image.gz | zcat | sh updatep1

2.4.3 Using nc(1)

Try this example if the remote host is not running neither ftp(1) or sshd(8) service:

  1. At first, open a TCP listener on host serving the image and make it send the image to client:

    myhost# nc -l 2222 < _.disk.image
    

    Note: Make sure that the used port is not blocked to receive incoming connections from NanoBSD host by firewall.

  2. Connect to the host serving new image and execute updatep1 script:

    # nc myhost 2222 | sh updatep1
    

NanoBSD References

Poul-Henning Kamp, Author of NanoBSD...

www.freebsd.org/~phk phk.freebsd.dk phk.freebsd.dk_build_options

FreeBSD Mailing Lists:

FreeBSD_Embedded FreeBSD_Small FreeBSD_USB FreeBSD_MailLists

FreeBSD Documents

The original NanoBSD article is here (tru2life copy): NanoBSD


The original NanoBSD article is here (at FreeBSD site): NanoBSD


For questions about FreeBSD, read the: FreeBSD Documents.


FreeBSD documents, can be downloaded from: ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

NanoBSD files

nanobsd.dev
Info on nanobsd.dev file use at tru2life...
Clone/copy of original FlashDevice.sub file...
Descriptions added for pny4g, pny8g, sandisk256m, and kingston256m usb flash drives.
nanobsd.conf
config file for NanoBSD (tru2life style of course :-)
Includes knobs for Files/root/updatep1 and Files/root/updatep2
nanobsd.sh
NanoBSD Build Script
(includes functions from updatep1 and updatep2 with knobs in nanobsd.conf)...
build_options
Local copy of build_options from Poul-Henning Kamp's web site...
docs/
NanoBSD Documents
orig/
Original files (b4 i hacked em :-)
Pkg/
Packages installed in the tru2life NanoBSD image
Files/
NanoBSD update support scripts
change_password
save_sshkeys
updatep1
updatep2

NanoBSD script

Running the tru2life version of the script nanobsd.sh requires a bit more setup up front than the original version.

Much of the original flavor has been retained, so it should not be hard to follow...

The following shows how to go about it:

tru2life NanoBSD obj files/directories

Current directory is /usr/obj/nanobsd.tru2life/

Subdirectories:

    drwxr-xr-x    2 root     wheel        512 Oct 12 10:20 _.mnt
    drwxr-xr-x   18 root     wheel        512 Oct 12 10:19 _.w
    drwxr-xr-x    3 root     wheel        512 Oct 12 08:24 usr

Files:

    -rw-r--r--    1 root     wheel    2526128 Oct 12 10:15 _.bk
    -rw-r--r--    1 root     wheel    11122475 Oct 12 09:49 _.bw
    -rw-r--r--    1 root     wheel       3958 Oct 12 10:44 _.di
    -rw-r--r--    1 root     wheel    -289288192 Oct 12 10:36 _.disk.full
    -rw-r--r--    1 root     wheel    1990485504 Oct 12 10:44 _.disk.image
    -rw-r--r--    1 root     wheel         53 Oct 12 10:19 _.dl
    -rw-r--r--    1 root     wheel      21823 Oct 12 10:25 _.du
    -rw-r--r--    1 root     wheel       1045 Oct 12 08:24 _.env
    -rw-r--r--    1 root     wheel      12373 Oct 12 10:18 _.etc
    -rw-r--r--    1 root     wheel        134 Oct 12 10:20 _.fdisk
    -rw-r--r--    1 root     wheel     111667 Oct 12 10:19 _.ik
    -rw-r--r--    1 root     wheel    1615879 Oct 12 10:18 _.iw
    -rw-r--r--    1 root     wheel    1130704 Oct 12 10:25 _.mtree
    -rw-r--r--    1 root     wheel          4 Oct 12 10:15 make.conf

 clean_build()
 ...
 printenv > ${MAKEOBJDIRPREFIX}/_.env
build_world()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.bw"
build_kernel()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.bk"
install_world()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.iw"
install_etc()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.etc"
install_kernel()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.ik"
run_customize()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.cust.$c"
setup_nanobsd()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.dl"
create_i386_diskimage()
(
  ...
  echo "### log: ${MAKEOBJDIRPREFIX}/_.di"
create_i386_diskimage()
(
  ...
    awk '
    {
      #-----------------------------------------------------------------------
      # ...top.[awk.code]...
      #-----------------------------------------------------------------------
      ...
      #-----------------------------------------------------------------------
      # ...end.[awk.code]...
      #-----------------------------------------------------------------------
    }

    ' > ${MAKEOBJDIRPREFIX}/_.fdisk
  ...
)

# 7807590 2 63 255 0 2048 -1
g c486 h255 s63
p 1 165 63 3887667
p 2 165 3887793 3887667
p 3 165 7775460 16065
p 4 165 7791525 7807590

tru2life NanoBSD packages

nanobsd_pkg.html

Man Pages useful with NanoBSD

Created via man2web from FreeBSD 7-RELEASE man pages...
If you desire a man page not listed here, use the "FreeBSD_Man_Pages" link in the footer below...

awk(1) basename(1) boot(8) boot.config(8) boot0cfg(8) bsdlabel(8) builtin(1) chflags(1) chroot(8) cp(1) cpio(1l) cpio(gnu) cut(1) dd(1) df(1) disktab(5) echo(1) expr(1) fdisk(8) find(1) fsck(8) fsck_ffs(8) fstab(5) ftp(1) geom(4) geom(8) getty(8) grep(1) install(1) ln(1) loader.4th(8) loader(8) loader.conf(5) ls(1) make(1) mdmfs(8) md(4) mdconfig(8) mkdir(1) mmap(2) mount(8) mtree(8) nanobsd(8) nc(1) newfs(8) passwd(1) pkg_add(1) pkg_create(1) pkg_info(1) printenv(1) printf(1) printf(3) resolver(3) resolver(5) rc.conf(5) rm(1) rmdir(1) sed(1) sh(1) signal(3) ssh(1) sshd(8) test(1) tr(1) touch(1) umount(8) usb(4) umass(4) wc(1)

Commands used with NanoBSD

command man page command man page command man page command man page
command man page command man page command man page command man page
awk awk(1) basename basename(1) boot0cfg boot0cfg(8) bsdlabel bsdlabel(8)
case sh(1) cd sh(1) chflags chflags(1) chroot chroot(8)
cp sh(1) cut cut(1) dd dd(1) df df(1)
echo sh(1) echo(1) expr expr(1) fdisk fdisk(8) find find(1)
grep grep(1) for sh(1) fsck_ffs fsck_ffs(8) getopt getopt(1)
if sh(1) ln ln(1) ls ls(1) mdconfig mdconfig(8)
mkdir mkdir(1) mount mount(8) mtree mtree(8) nc nc(1)
newfs newfs(8) passwd passwd(1) pkg_add pkg_add(1) print awk(1)
printenv printenv(1) printf printf(1) rc.conf rc.conf(5) rm sh(1) rm(1)
rmdir rmdir(1) sed sed(1) set -e sh(1) ssh ssh(1)
touch touch(1) tr tr(1) trap builtin(1) umount umount(8)
while sh(1) xargs xargs(1)

hacker emblem Valid HTML 4.01! Valid CSS! Made with CSS rtfm vi [Powered by FreeBSD] [Powered by Apache] [Powered by Interchange DeCSS Now! Firefox3 SpreadBSD truebsd FreeBSD Man Pages FreeBSD FreeBSD_NanoBSD tidy .:. .:. .:. .:. .:. .:. .:. .:. .:. .:. .
    Visit: 666     Modified: 2008.10.24.16.27     RemoteIP: 38.103.63.56