Preparing a Diskless (PXE boot) image with packages

My PXE boot setup is working well. I can boot two different machines. Once up, I have to 'pkg install' any missing packages. I'd like to put those packages into the diskless image before hand.

I need to figure out how to install a package onto a diskless image. Would chroot(8) do the trick or is it more involved?

I currently fill out the base system by tar(1) extract of base.txz and kernel.txz. That works well but things are changing with the coming 15.1-RELEASE so I also need to learn how to do this step in pkgbase.
 
As a side note, some of the online "how to" blogs and articles for diskless suggest enabling ssh(1) root logins. Not necessary. Instead, just create an "ordinary" user on your diskless image. After booting, you can login via ssh(1) and then su(1) to root as needed.
 
I need to figure out how to install a package onto a diskless image. Would chroot(8) do the trick or is it more involved?
Before chroot(8) make sure host/etc/resolv.conf is copied to /diskless/etc, and host/dev is mount_nullfs(8) to diskless/dev.

I currently fill out the base system by tar(1) extract of base.txz and kernel.txz. That works well but things are changing with the coming 15.1-RELEASE so I also need to learn how to do this step in pkgbase.
This will do: assuming /diskless/15.0-RELEASE root directory

Install from remote FreeBSD-base repository:

Host: /usr/local/etc/pkg/repos/FreeBSD-BASE.conf
Code:
FreeBSD-BASE: {
  url: "https://pkg.FreeBSD.org/${ABI}/base_release_${VERSION_MINOR}",
  enabled: yes
}
For some reason url: "pkg+..', signature_type, fingerprints results in errors with pkg-2.5.1.

Code:
pkg  -r  /diskless/15.0-RELEASE  install  -r  FreeBSD-BASE  FreeBSD-set-base   FreeBSD-kernel-generic  pkg
See pkg(8) for -r /diskless/15.0-RELEASE and pkg-install(8) for -r FreeBSD-BASE options.

You can also use a 15.0 memstick.img, disc1.iso, dvd1.iso as attached and mounted memory disk (mdconfig(8)) to pkg-add(8) those files. Make sure to specify full path-filename, e.g.:
Code:
cd /mnt/usr/freebsd-packages/offline
pkg -r /diskless/15.0-RELEASE add `pwd`/FreeBSD-set-base*

Or copy /mnt/usr/freebsd-packages/repos and modify FreeBSD-base-offline.conf to include the mount point (e.g.: url: "file:///mnt/usr/...").

Install:
Code:
pkg  -r  /diskless/15.0-RELEASE  -R  /tmp/repos  install  -r  FreeBSD-base  FreeBSD-set-base   FreeBSD-kernel-generic  pkg
See pkg(8) for -R /tmp/repos option.
 
As a side note, some of the online "how to" blogs and articles for diskless suggest enabling ssh(1) root logins. Not necessary. Instead, just create an "ordinary" user on your diskless image. After booting, you can login via ssh(1) and then su(1) to root as needed.
For those not aware of the situation, after adding a user, don't forget to rebuild the etc.cpio.gz file.

diskless/etc/passwd and diskless/etc/master.passwd are updated when a user is added, but etc.cpio.gz is used as tmpfs(4) /etc in diskless mode, see handbook 34.10.1. Setting Up the PXE Environment for details.
 
Another option I forgot about is bsdinstall(8). This option is the easiest way to install from a remote pkgbase repository. Make sure /etc/pkg/FreeBSD.conf FreeBSD-base: is set to enabled: yes.
Code:
env BSDINSTALL_CHROOT=/diskless/15.0-RELEASE  bsdinstall  pkgbase
 
Back
Top