# NanoBSD: adding packages on FreeBSD 10 or later



## Buzz Zaman (May 28, 2015)

The current NanoBSD documentation demonstrates how to add packages to your image, but uses the `pkg_add` command to do so. This is no longer working on FreeBSD 10 or later.

I used this method to add packages to my images, which seems to work well. For example to add python to the image:

```
install_packages () (
  #pkg -c ${NANO_WORLDDIR} install -y <package-name>
  pkg -c ${NANO_WORLDDIR} install -y python

  # remove diskspace used by pkg
  chroot ${NANO_WORLDDIR} sh -c 'rm -rf /var/cache/pkg var/db/pkg'
)
customize_cmd install_packages
```

In /usr/obj/nanobsd.nano/_.cust.install_packages the output of the above command is shown. In this case:

```
+ install_packages
+ pkg -c /usr/obj/nanobsd.nano//_.w install -y python
Updating FreeBSD repository catalogue...
Fetching meta.txz... done
Fetching packagesite.txz... done
Processing entries... done
FreeBSD repository update completed. 24160 packages processed.
The following 6 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        python: 2.7_2,2
        python27: 2.7.9_1
        libffi: 3.2.1
        indexinfo: 0.2.3
        gettext-runtime: 0.19.4
        python2: 2_3

The process will require 64 MiB more space.
10 MiB to be downloaded.
Fetching python-2.7_2,2.txz... done
Fetching python27-2.7.9_1.txz... done
Fetching libffi-3.2.1.txz... done
Fetching indexinfo-0.2.3.txz... done
Fetching gettext-runtime-0.19.4.txz... done
Fetching python2-2_3.txz... done
Checking integrity... done (0 conflicting)
[1/6] Installing indexinfo-0.2.3...
[1/6] Extracting indexinfo-0.2.3... done
[2/6] Installing libffi-3.2.1...
[2/6] Extracting libffi-3.2.1... done
[3/6] Installing gettext-runtime-0.19.4...
[3/6] Extracting gettext-runtime-0.19.4... done
[4/6] Installing python27-2.7.9_1...
[4/6] Extracting python27-2.7.9_1... done
[5/6] Installing python2-2_3...
[5/6] Extracting python2-2_3... done
[6/6] Installing python-2.7_2,2...
[6/6] Extracting python-2.7_2,2... done
Message for python27-2.7.9_1:
=====================================================================

Note that some standard Python modules are provided as separate ports
as they require additional dependencies. They are available as:

bsddb           databases/py-bsddb
gdbm            databases/py-gdbm
sqlite3         databases/py-sqlite3
tkinter         x11-toolkits/py-tkinter

=====================================================================
```


A difference with the original example is that for this case the packages are downloaded for every build, instead of copied from the filesystem.

In both the documented and above example you must be able to chroot into the tree being build, which must somehow limit your cross-build options (but I haven't tested it). I'm building an i386 image on a amd64 system and that works fine (packages from the right ABI are installed in the image).

What do you think? I'm looking forward on your feedback, I'll propose a documentation modification if it turns out to be working for you as well.


----------



## neogeo (Nov 9, 2015)

I've looked at some of the documentation about FreeBSD on embedded computing platforms - have made a short notes list, colloquially titled "_FreeBSD Embedded Computing Trifecta_," as to collect if not also to share some of the web resource references, in a single page. Personally, I'm still trying to make a transition from being a student of the distinctly Enterprise-oriented course material of one DeVry University -- that for-profit institution, ostensibly a school, teaching Cisco Networking and a superficial introduction to NI LabVIEW, basically, with a little bit about electrical sciences and not much about mathematics. I've been cautious of building a veritable grain silo about FreeBSD, moreover. Now reviewing the NanoBSD Howto more closely, I had not realized it's distributed as a part of the base system -- was not previoiusly aware of how the NanoBSD tools are distributed, whether as ports or as base system components.

Personally, I'm not immediately certain of how to integrate the NanoBSD and Crochet tools, if there can be an interface for integration between the two, and if not, then how to juxtapose each to the other. In a procedural manner, as in a manner proceeding from the Crochet and/or NanoBSD build of a FreeBSD kernel an base system, ultimately into some manner of a system image for any single embedded computing platform, I'm not all immediately certain of how to "Plug it in," so to speak, for a PXE/Netboot configuration. Focusing on BeagleBone Black, specifically, I know that there must be a bootloader configuration involved for netboot -- on the BeagleBone architecture, towards something about U-Boot and device trees, as I've read a short comment about. I'm afraid it could seem a bit mystifying, however, as at the point of bootloader selection and bootloader configuration, if not morevoer as any manner of a toolchain.

Focusing about a task of individual port/package selection for the respective embedded computing image, maybe there's a useful place to focus for determining if and how the NanoBSD and Crochet tools can be integrated, as kinds of toolchain components?

Of course Poudriere could be integrated into a build toolchain -- a sidebar about cross-compiling the kernel and base system, in some kind of a documentation -- another sidebar about selecting which kernel modules to build. Maybe it could be simple to put together. Perhaps I've been getting lost about a logical model of it.

Candidly, I've only recently realized that I can use one BeagleBone Black as an adapter for debugging another BeagleBone black -- no voltage level shifting needed, therefore -- with the first of the two single board computers being on LAN and the second, connected to the first as via a manner of a serial line, literally with jumper wires, IO headers, and the mystifying U-Boot configuration.

Maybe I've not picked the best platform to start off with. I'm not even sure "Which U-Boot?", considering that Texas Instruments publishes a fork of the U-Boot source tree. With so many individual parts to the overall toolchain, I think it can seem difficult to present a trivial logical model even for embedded computing with FreeBSD. Focusing on the package selection, though, there's a certain facet about which one may look at the source code?


----------



## OlliC (May 15, 2017)

So its 2017 and the documentation still did not got updatet?

I have the same problem on FreeBSD 11 now. I tried your custom script to add packages into my nanobsd but it did not work.

Here is the error log:


```
+ install_packages
+ pkg -c /usr/obj/nanobsd.nas/_.w install -y nano
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD load error: access repo file(/var/db/pkg/repo-FreeBSD.sqlite) failed: No such file $
pkg: http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly/meta.txz: No address record
repository FreeBSD has no meta file, using default settings
pkg: http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly/packagesite.txz: No address record
Unable to update repository FreeBSD
Error updating repositories!
```


----------



## SirDice (May 15, 2017)

OlliC said:


> I have the same problem on FreeBSD 11 now.


No, you have a different problem.



OlliC said:


> ```
> pkg: http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly/meta.txz: No address record
> ```


Your DNS is not working.


----------



## OlliC (May 15, 2017)

I have copied now /etc/resolv.conf into the nanobsd root before installing packages. Its compiling at the moment (Needs 1:30h in a virtualbox machine). Maybe it was the problem. Also i found a function fix_pkg() in /usr/src/tools/tools/nanobsd/embedded/common. Dont know if thats needed but i added it anyways.


----------



## OlliC (May 15, 2017)

Yeah that was the problem. But now i got another issue. 


```
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        nano: 2.8.0
        indexinfo: 0.2.6
        gettext-runtime: 0.19.8.1_1

Number of packages to be installed: 3

The process will require 3 MiB more space.
621 KiB to be downloaded.
[1/3] Fetching nano-2.8.0.txz: .......... done
[2/3] Fetching indexinfo-0.2.6.txz: . done
[3/3] Fetching gettext-runtime-0.19.8.1_1.txz: .......... done
pkg: http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly/All/gettext-runtime-0.19.8.1_1.txz: Operation timed out
```

That is the same problem i have on the host system (outside of the nanobsd generation). Everytime i do a pkg install it times out a few times. 
After running the same command over and over a few times pkg will eventually fetch all required packages. 
But thats not an option in the nanobsd generation. So i have to figure this one out first. 
This is a 64bit FreeBSD 11 installation in Virtualbox on an Arch Linux system with bridged network.


----------



## Phishfry (May 15, 2017)

Having fought resolv.conf before I discovered it is set by the command resolvconf. I see your host machine has issues too so I would run `resolvconf` and see what is using. I have seen where routes were messed up and even though resolv.conf had the right settings when you ran `resolvconf` it was showing no resolv addresses. So route flush helps sometimes. Using a virtual machine adds a layer of complexity I am sure.


----------



## OlliC (May 15, 2017)

I solved the timeouts by switching to NAT instead of bridging in Virtualbox. Didn't encounter a timeout since then. So it was probably a problem with the bridged network. 

The build runs in the /usr/src/tools/tools/nanobsd directory like this: sh nanobsd.sh -c nas.cfg 
I stayed away from the embedded directory for now because i don't really get all the things the common config file is doing. 
And also my build is not for embedded but for a server. I want it to boot from a usb drive running nanobsd and plan to use the ZFS filesystem with raidz.

Thanks for the input!


----------



## Phishfry (Jul 29, 2017)

I have found a way to do this with the stock NanoBSD build scripts.
There is a script function named *cust_pkgng* in /nanobsd/default.sh.

So what you do is add to your custom build.cfg file the following line to activate it:
`customize_cmd cust_pkgng`

This command requires you make a directory called: /usr/src/tools/tools/nanobsd/Pkg
In this directory you place your package files.
Package files are files that have a *.txz extension and reside in /var/cache/pkg/*
Any packages you want to install in your image that you don't want to install on buildbox can be downloaded:
http://pkg.freebsd.org/FreeBSD:11:amd64/latest/
Use the /all directory above and download packages into your /usr/src/tools/tools/nanobsd/Pkg  directory.
The pkg.txz package file is not on my buildbox machine so I needed to download it
from the above website.
The needed pkg.txz must be included in the /nanobsd/Pkg directory or packages will not be built.


----------



## vic patel (Sep 9, 2017)

Hello Phishfry:

There is bug in cust_pkgng script. See the bug reported and solution suggested. 

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219405

Thanks for very help.

Vic


----------



## fishfox (Mar 9, 2019)

Just a note -- the above big (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219405) is patched out in 12.

I am running 11.2 and just replaced the defaults.sh script with the newer one.  Now packages put in ./Pkg install fine.


----------

