NANOBSD(8)
πΈ NANOBSD(8) β the nanobsd.sh glow-up guide πΈ
okay bestie, sit down, grab a strawberry drink π β we're talking about nanobsd.sh, from the System Manager's Manual. yes it's a shell script, yes it makes a whole entire tiny FreeBSD, and yes it's iconic. π
β¨ NAME β¨
nanobsd.sh β create an embedded FreeBSD system image π«Ά
π SYNOPSIS π
nanobsd.sh [-BbfhIiKknqvWwX] [-c config-file]
that's it. that's the whole vibe check. β
π DESCRIPTION π
so nanobsd.sh is a script that produces a minimal implementation of FreeBSD (called NanoBSD), which typically fits on a small media such as a Compact Flash card, or other mass storage medium. like, small small. it can be used to build specialized install images, designed for easy installation and maintenance. obsessed. π₯
The following options are available:
-Bβ Skip the install stages (both for kernel and world).-bβ Skip the build stages (both for kernel and world).-cconfig-fileβ Specify the configuration file to use.-fβ Skip the code slice extraction.-hβ Display usage information.-Iβ Build the disk image from an existing build/install.-iβ Skip the disk image build stage.-Kβ Skip theinstallkernelstage of the build.-kβ Skip thebuildkernelstage of the build.-nβ Do not cleanup before each build stage. This suppresses the normal cleanup work done before thebuildworldstage and adds-DNO_CLEANto themakecommand line used for each build stage (world and kernel).-qβ Make output more quiet. π€«-vβ Make output more verbose. π£οΈ-Wβ Skip theinstallworldstage of the build.-wβ Skip thebuildworldstage of the build.-Xβ Makenative-xtools.
The features of NanoBSD include:
- Ports and packages work as in FreeBSD. Every single application can be installed and used in a NanoBSD image, the same way as in FreeBSD. no cap. π
- No missing functionality. If it is possible to do something with FreeBSD, it is possible to do the same thing with NanoBSD, unless the specific feature or features were explicitly removed from the NanoBSD image when it was created.
- Everything is read-only at run-time. It is safe to pull the power-plug. There is no necessity to run
fsck(8)after a non-graceful shutdown of the system. literally just yank it, she'll be fine πβ¨ - Easy to build and customize. Making use of just one shell script and one configuration file it is possible to build reduced and customized images satisfying any arbitrary set of requirements. one script, one config, infinite possibilities, we love a low-effort queen π
π¦ NanoBSD Media Layout π¦
The mass storage medium is divided into three parts by default (which are normally mounted read-only):
- Two image partitions:
code#1andcode#2. - The configuration file partition, which can be mounted under the
/cfgdirectory at run time.
The /etc and /var directories are md(4) (malloc backed) 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.
ok this part is the one people always forget π β if you edit something in/etcand want it to survive a reboot, you must copy it back to/cfg. otherwise it's giving temporary. main character energy only in/cfg.
π₯ BUILDING NanoBSD π₯
A NanoBSD image is built using a simple nanobsd.sh shell script, which can be found in the src/tools/tools/nanobsd directory. This script creates a bootable image, which can be copied on the storage medium using the dd(1) utility.
The necessary commands to build and install a NanoBSD image are:
cd /usr/src/tools/tools/nanobsd
sh nanobsd.sh
cd /usr/obj/nanobsd.full
dd if=_.disk.full of=/dev/da0 bs=64k
three commands and a dream, bestie π
π CUSTOMIZING NanoBSD π
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. like, most of the time. this is the whole personality. β¨
Customization is done in two ways:
- Configuration options.
- Custom functions.
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 the system even more, until it will consist of just the kernel and two or three files in the userland. two or three files!! tiny little baby system π
The configuration file consists of configuration options, which override the default values. The most important directives are:
NANO_NAMEβ Build name (used to construct the working directory names).NANO_SRCβ Path to the source tree used to build the image.NANO_KERNELβ Name of the kernel configuration file used to build the kernel.NANO_ARCHβ Machine processor architecture to build. Defaults to output ofuname -p.NANO_BOOT0CFGβ Controls the options passed toboot0cfg(8); these dictateboot0's behaviour.NANO_BOOTLOADERβ Theboot0loader to use relative to theNANO_WORLDDIRvariable. This defaults toboot/boot0sioand should be overridden toboot/boot0to provide a VGA console.CONF_BUILDβ Options passed to thebuildworldstage of the build.CONF_INSTALLβ Options passed to theinstallworldstage of the build.CONF_WORLDβ Options passed to both thebuildworldandinstallworldstages of the build.FlashDeviceβ Defines the type of media to use. Check theFlashDevice.subfile for more details.
For more configuration options, please check the nanobsd.sh script.
To build NanoBSD image using the nanobsd.conf configuration file, use the following command:
sh nanobsd.sh -c nanobsd.conf
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
There are a few pre-defined customization functions ready for use:
cust_comconsoleβ Disablesgetty(8)on the virtualsyscons(4)orvt(4)terminals (/dev/ttyv*) and enables the use of the first serial port as the system console.cust_allow_ssh_rootβ Allow root to log in viasshd(8).cust_install_filesβ Installs files from thenanobsd/Filesdirectory, which contains some useful scripts for system administration.
β οΈ heads up:cust_allow_ssh_rootdoes exactly what it says on the tin β root oversshd(8). know what you're doing before you turn it on, k? π«Ά
β FILES β
src/tools/tools/nanobsdβ Base directory of the NanoBSD build script.
π EXAMPLES π
Making persistent changes to /etc/resolv.conf:
vi /etc/resolv.conf
...
mount /cfg
cp /etc/resolv.conf /cfg
umount /cfg
see? /etc β /cfg β survives reboot. that's the whole trick, iykyk π
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
π SEE ALSO π
make.conf(5), boot(8), boot0cfg(8)
πΈ HISTORY πΈ
The nanobsd.sh utility first appeared in FreeBSD 6.0. vintage but still slaying π
π«Ά AUTHORS π«Ά
NanoBSD was developed by Poul-Henning Kamp <phk@FreeBSD.org>. This manual page was written by Daniel Gerzo <danger@FreeBSD.org>.
and that's the page, bestie β brought to you from the Debian corner of the world, dated July 14, 2025, on the NANOBSD(8) page. go build something tiny and invincible πβ¨π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- π the page's license: BSD-2-Clause
- Copyright (c) 2006 Daniel Gerzo <danger@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms