Maintain the NetBSD Base System Using pkg *Tools
Yuuki Enomoto∗Ken’ichi Fukamachi†

Abstract
This paper describes the script ”basepkg.sh” for base system packaging
to make NetBSD base system more granular.
Today, fine granular systems are expected to provide more rapid security update and more flexible customization in creating a very small basesystem for sensor network.
In ”NetBSD”, base system packaging mechanism called ”syspkg” hasbeen developed, but now, its development is stagnant. In addition, it istroubled to deal with ”syspkg” consisting of a lot of Makefiles and shell
scripts.
Thus we developed a shell script simpler than ”syspkg” framework.
This script uses src/distrib/sets/lists files and pkg create command togenerate a fine granular base package. We verified our system can provide
minimum functionality that our package can replace a part of NetBSD
base system. It provides the first step for more granular NetBSD basesystem.

1

Introduction”Unix” such as Linux distribution and*BSD is used mainly as servers. It isvery important to keep operating systems up to date for security. If a software is found to be vulnerable, server
administrators must update the software as soon as possible.

Many Unix systems have its own
package manager(s) to manage software. The scope managed by thepackage manager depends the system.
Some developers consider that thewhole system consists of packages, another consider that the operating system consists of the base and optional
packages.

This updating process should berapid. So, it must be useful to replace avulnerable software with the latest binary by using some rapid mechanism
e.g. package managers.

For example, Debian Linux packages the whole system to update
and upgrade it easily.
FreeBSD
11.0 introduced a framework called
PkgBase[FreeBSD 2017]. to divide the∗ Chitose Institute of Science and Technology, 758-90, Bibi, Chitose, Hokkaido, 066-8655,
mailto: m2160020@photon.chitose.ac.jp https://e-yuuki.org/† Chitose Institute of Science and Technology, 758-90, Bibi, Chitose, Hokkaido, 066-8655,
mailto:k-fukama@photon.chitose.ac.jp http://www.nsrg.fml.org/

1managers (e.g. ”Portage”) compile thesource code and install it into the system.

base system into 757 packages wherepkg(8) can manage the FreeBSD basesystem.
On the other hand, NetBSD had
developed ”syspkg” under the same
concept described above, but its development is stagnant[NetBSD 2017].
Currently updating a base software
on NetBSD needs building from thesource code (or replacing the binary if
the major upgrade is available). It is
no quick response. So, NetBSD basesystem packaging is required.

22.2”FreeBSD” has a package systemcalled ”ports” to handle optional
3rd party packages[FreeBSD 2017].
”ports” consists of a lot of Makefiles
to describe configurations. ”pkg” command manages actual installation/deinstall action et.al.
By default, ”ports” do not install the binary package directly, but”ports” can get and compile the source
code, and install it into the system using the ”pkg” command.
Also, ”ports” can fetch and installbinary packages provided by FreeBSD.
Instead of using ”ports”, FreeBSD
users can use ”pkg” command to manipulate packages.

ComparisonofPackage
Management Systems”Package” is a collection of software,configuration files and documents.
This collection is usually packed into asingle archive file in the format .tar.gz,.zip, et.al. ”Package Manager” is asoftware that manages package installation, deinstallation and updating.
Almost all Unix clone systems consist of a base mandatory system, auxiliary systems (e.g. compilers, documents, X11 Window) and optional 3rdparty packages. The package manager
can modify the system by adding ordeleting optional binary packages.

2.1

FreeBSD

2.3

NetBSDNetBSD has a portable package system called ”pkgsrc”[NetBSD 2017] derived from the FreeBSD ”ports” system. ”pkgsrc” is mainly developedfor NetBSD but also can be available on a lot of platforms: NetBSD,FreeBSD, OpenBSD, DragonFlyBSD,Solaris, Linux, Darwin and other commercial UNIX systems. Some systems
such as DragonFlyBSD use ”pkgsrc”
as the package management system bydefault.
”pkgsrc” is similar to FreeBSD”ports” but different to use anotherutilities called ”pkg *” to install or remove compiled software.

Linux Distribution”Debian” Linux and the derived distributions use ”dpkg”, ”apt-get” and”apt” commands for package managements.
”CentOS” and the derived distributions use ”rpm” and ”yum” commands
as package management systems.
There are a few Linux distributions(e.g. ”Gentoo”) where the package
22.3.1

NetBSD pkg * Utility

system[Debian 2017]. Software andfunctions in the base system can beeasily added and deleted by handlingthem as a set of packages.
In the case of BSD Unix(s),FreeBSD 11.0 introduced a mechanism called PkgBase. FreeBSD divides
the base system into 757 packages forpkg(8) to be able to manage the basesystem.
Today NetBSD does not support
base system packaging. NetBSD costs
us a little bit of time to update a basesoftware. We need to build from thesource code and install it. Or we needto fetch and extract the binary distribution to overwrite the binary if thelatest major distribution is available.
For example, consider that you
want to install or remove only ”groff”
on your system.
We have roughly granular tar-balls
on NetBSD where the base system is
not packaged. We download text.tgz
from the ftp site and unpack it in theroot directory. So software other thangroff will be installed together.
Instead of using text.tgz, we
can install groff from ”pkgsrc”(pkgsrc/textproc/groff).
But
in this case, after further updates, two ”groff” will be installed such as in /usr/bin/groff and/usr/pkg/bin/groff. It may confuses
users. Such a problem can be solved
by packaging the base system with finegranularity.
NetBSD had developed ”syspkg”
under the same ideas described above,
but its development is stagnant. Theoretically ”syspkg” can manage the basesystem, but it is incomplete and notused well. We can run build.sh withthe option -syspkgs to create a compiled base package, but the compiled
package cannot be installed.

In NetBSD, the pkg * utility consistsof the following commands.
• pkg add
• pkg admin• pkg create• pkg delete• pkg info
”pkg create” creates a binary package and saves it in ”tgz” format.
”pkg add” installs and upgrades
package(s) created using pkg create.
”pkg delete” removes the specified package(s) from the system.
”pkg info” displays the package information. ”pkg admin” executes management tasks for the package system.

2.4

OpenBSD

OpenBSD package system is similar toNetBSD one. But the package utility
is written in Perl not C. Commands
such as pkg add and pkg delete are thesame Perl script, which changes the behavior by the called argument.
OpenBSD users can write arbitrary package management scripts
by using these Perl modules in/usr/libdata/perl5/OpenBSD/.

3Base System Packaging

3.1

Base System Packaging

There are Linux distributions managing the base system as a collectionof packages. Debian Linux is a typical one. Debian’s ”Essential” package provides the minimum functionality required to generate a small base33.2

Benefits of Base SysThe style of ”syspkg” frameworkis traditional.
It mainly
tem Packaging
consists of a lot of Makefiles
underusr/src/distrib/sets/
andusr/src/distrib/syspkg/. It looks beyond our control to reconstruct thecurrent ”syspkg”. We determined that
it would be easier to develop anotherscript that creates base packages.
Instead of traditional Makefile
style, our script is a wrapper to use
pkg tools based on information in
usr/src/distrib/sets/lists/. Currently
pkg tools is used only for ”pkgsrc”,
but these tools are used for all software in the base system if we canprepare proper configuration files forpkg * tools.

A system packaging a base system withfine granularity must has advantages toenable rapid update and flexible customization of base system.
Typical examples needed for rapid
security updates in base system
are some critical libraries such as”OpenSSL” and fundamental daemonssuch as ”OpenSSH” and ”Postfix”.
From the other point of viewon flexibility, it looks that demand
to create a small base system easily increases since cheap tiny devices
for sensor network are wished. Forexample, omega2[Omega2 2016] is a
$5 micro computer ready for Linuxand FreeBSD. Also, Intel at CES
in 2017 released a credit card size
computer[Intel 2017]. But $5 must be
too expensive to use billions of devices over the world. Devices withmore small storage and memory arepreferrable, so easily customized small
operating systems must be required.

44.2

basepkg.sh”basepkg.sh” creates a binary package based on information under”usr/src/distrib/sets/lists/”.
The
script runs in two steps.
(1)
prepare configuration files based on”usr/src/distrib/sets/lists/”. (2) callpkg * tools to create packages actually.

Yet Another NetBSD 4.2.1 Preparation of Configuration Files
Base System PackFiles under ”usr/src/distrib/sets/lists/”
aging

problems on ”syspkg”
framework

contains program and configuration
paths with classified information. Our
script resolves the package name basedon ”usr/src/distrib/sets/lists/”.
In addition, a configuration file isnecessary to create a compiled package. basepkg.sh uses the following setting files, which is same as ”pkgsrc”
ones.

NetBSD source tree contains incomplete ”syspkg” framework, but its development is stagnant.

• +BUILD INFO
Information on the environment
in which the package was created

Instead of ”syspkg”, We have developed a ”basepkg.sh”[Enomoto 2016].
It is a just shell script simpler than”syspkg” framework.

4.1

4• +COMMENT
Comment of the packageneed to find the criterion of the graduality and classification. It is also required when we add a new software.
Secondly, packaging should beenhanced to run a hook since
installation/deinstallation of sharedlibrary package needs the corresponding daemon restarting.
We
can use PRE-INSTALL and POSTINSTALL scripts of pkg add command, but we should prepare thescripts, which are not covered by
usr/src/distrib/sets/lists/. We needto arrange another configurations forsuch scripts.
Lastly, we need to fix the master database for package creation process. There are some empty packages since there are not corresponding
binaries in +CONTENTS. For example, ”comp-obsolete” package contains/usr/bin/atf-compile command, butthere is no /usr/bin/atf-compile in thebinary set of NetBSD-7.0.2/amd64.

• +CONTENTS
Information on the path of thefile to be stored in the package• +DESC
Description of the package
4.2.2

Package Creation”basepkg.sh” calls pkg create command to create the corresponding compiled packages in using configuration
files created above.
The created compiled package canbe installed using the pkg add command. We can use the pkg delete command to remove it from the system.
pkg info command shows informationon the binary package. However, at
this moment, useful information is not
displayed since our package does notcontain the corresponding +DESC file.
We confirmed that we can install compiled packages basepkg.sh creates on NetBSD-7.0.2/amd64 by using pkgsrc/pkgtools/pkg install version 20160410.

56ConclusionWe
havedeveloped
ascript”basepkg.sh” for base system packaging to make NetBSD base system
more granular. It provides the firststep for more granular NetBSD basesystem.
Fine granular systems become
more important for rapid update andflexible customization of system in thefuture Internet and sensor networks.
We believe that our system helps one
small step for it.

Future WorkAs a result of development, it has
turned out that difficulty of base system packaging comes from packageclassification rather than package creation process.
Firstly, we need to investigate thatthe number of packages are proper ornot. Currently ”basepkg.sh” generates
879 binary packages as classified by
usr/src/distrib/sets/lists. The numberis almost same as one of FreeBSD basepackages. But it is not clear that thegraduality is proper for operation. We

Acknowledgments
I would like to thanks Ken’ichi Fukamachi, NetBSD developers and Japan5NetBSD Users Group.

[NetBSD 2017]
http://wiki.netbsd.org/projects/
project/syspkgs/

References[NetBSD 2017]
http://www.netbsd.org/docs/
software/packages.html[Omega2 2016]
https://www.kickstarter.com/
projects/onion/omega2-5-iot-computerwith-wi-fi-powered-by-linux/
description[Debian 2017]https://www.debian.org/doc/
manuals/
debian-reference/ch02.html[Intel 2017]
http://www.intel.com/content/www/us/en/
compute-card/intel-computecard.html[FreeBSD 2017]https://www.freebsd.org/ports/[Enomoto 2016][FreeBSD 2017]https://github.com/user340/basepkg
https://wiki.freebsd.org/PkgBase/6