Migrating to FreeBSD PkgBase 22 feb 2025

Maintaining an up-to-date FreeBSD base with packages.

Migrating to FreeBSD PkgBase

It's considered experimental and work-in-progress... See PkgBase on the FreeBSD wiki for more info. That's the documentation I used to do this. The pkgbasify lua script was helpful in this journey too.

Decided to give it a go anyway!

Safety first

We'll use a boot-environment as that's easier to recover from!

bectl create FreeBSD-14.2-p2

Mount the new BE, add devfs and dive into it. Decided on chroot to prevent foot-shooting.\

mkdir /mnt/FreeBSD-14.2-p2
bectl mount FreeBSD-14.2-p2 /mnt/FreeBSD-14.2-p2
mount -t devfs devfs /mnt/FreeBSD-14.2-p2/dev

We're now working inside the new Boot-Environment.

Add pkg repo

Adding the new repo config in /etc/pkg/ so it's persistent after the reboot.

cat <<'EOF' >/etc/pkg/FreeBSD-base.conf
FreeBSD-base: {
  url: "pkg+https://pkg.FreeBSD.org/${ABI}/base_release_2",
  mirror_type: "srv",
  signature_type: "fingerprints",
  fingerprints: "/usr/share/keys/pkg",
  enabled: yes
}
EOF

and update the local pkg database.

$ pkg update
Updating FreeBSD-base repository catalogue...
FreeBSD-base repository is up to date.
All repositories are up to date.

What to install

My system doesn't have or need the lib32, tests, src and some other stuff. Here I retrieve the list of available packages from the FreeBSD-base repo and filter some. For your own purposes, start with the full list and see what you want to remove. You can also do this in a text-editor.

pkg rquery -r FreeBSD-base %n | \
    grep -Ev -- '-(lib32|dbg|tests|src|mmccam|minimal|sendmail)'

The mmccam and minimal remove the non-generic kernels.

Install!

I ended up with a looong list of packages to install, shortened here.

FreeBSD-acct FreeBSD-acct-man FreeBSD-acpi FreeBSD-acpi-man ...

Ended up installing ca. 240 new packages.

Restore configuration and cleanup

The installation of the packages leaves behind a large number of .pkgsave files. Most are safe to delete, but at minimum check ALL files in /etc.

To find out what .pkgsave files you have, use find.

find / -name \*.pkgsave

Fix system configuration

At minimum, you'll have to restore user databases and some other files in /etc

mv /etc/master.passwd.pkgsave /etc/master.passwd
mv /etc/group.pkgsave /etc/group
mv /etc/ssh/sshd_config.pkgsave /etc/ssh/sshd_config
mv /etc/sysctl.conf.pkgsave /etc/sysctl.conf.pkgsave

pwd_mkdb -p /etc/master.passwd
cap_mkdb /etc/login.conf

Review all other .pkgsave files in /etc so you don't loose any of your modifications.

Remove files

There's some large categories that are easily fixed... Do check before taking this drastic action. You can always revert back to your previous boot-environment, but then there's a lot of redo.

find /boot -name \*.pkgsave -delete
find /bin -name \*.pkgsave -delete
find /lib -name \*.pkgsave -delete
find /sbin -name \*.pkgsave -delete
find /usr/bin -name \*.pkgsave -delete
find /usr/lib -name \*.pkgsave -delete
find /usr/sbin -name \*.pkgsave -delete
find /usr/share/man -name \*.pkgsave -delete
...

Keep working through the find / -name \*.pkgsave output untill everything's cleaned up.

Activate

Now you can activate your new Boot-Environment.

bectl activate FreeBSD-14.2-p2

Reboot into the new environment.

shutdown -p now

If all's well, you're now booting into a PkgBase system.

Easier updating than before.