Skip to content

Instantly share code, notes, and snippets.

@grahamperrin
Last active September 14, 2025 14:34
Show Gist options
  • Save grahamperrin/9570092c127bd43777961b6f016e75ba to your computer and use it in GitHub Desktop.
Save grahamperrin/9570092c127bd43777961b6f016e75ba to your computer and use it in GitHub Desktop.
Using pkgbasify to repair a broken installation of FreeBSD 14.3-RELEASE

Using pkgbasify to repair a broken installation of FreeBSD 14.3-RELEASE

Condensed steps

  1. Use a memstick.img file to write a FreeBSD installer to a memory stick
  2. boot from the stick in single user mode
  3. /bin/csh
  4. use gpart(8) to resize things
  5. growfs /
  6. mount -uw /
  7. assuming vt(4)
  8. setenv TERM xterm-clear
  9. bsdconfig vt_keymap
  10. select, and continue with, a keymap that matches your keyboard layout
  11. reboot -r
  12. live system
  13. login as root, no password
  14. mount -uw /
  15. bsdconfig networking
  16. get an Internet connection – for example, enable DHCP for a network interface
  17. assuming root-on-ZFS
  18. zpool import
  19. note the name of the pool that you want to import – for example, damp
  20. zpool import -R /tmp/altroot damp
  21. zpool get bootfs damp
  22. note the value – for example, damp/ROOT/test
  23. zfs mount damp/ROOT/test
  24. pkg bootstrap
  25. add a minimal FreeBSD-base repository configuration to /etc/pkg/FreeBSD.confurl https://pkg.freebsd.org/FreeBSD:14:amd64/base_release_3
  26. pkg --rootdir /tmp/altroot install --repository FreeBSD-base FreeBSD-certctl FreeBSD-pkg-bootstrap FreeBSD-utilities
  27. chroot /tmp/altroot
  28. cd /root
  29. fetch https://tinyurl.com/pkgbasify-foundation -o ./pkgbasify.lua
  30. chmod +x ./pkgbasify.lua
  31. mkdir -p /var/db/etcupdate/current
  32. ./pkgbasify.lua
@grahamperrin
Copy link
Author

Origin:

Notes:

  1. the tiny URL for pkgbasify.lua is not official
  2. /var/db/etcupdate features in FreeBSD bug 288295 – bsdinstall does not bootstrap etcupdate database for pkgbase installations
  3. https://reviews.freebsd.org/D51916#1186602 wishes for inclusion of a FreeBSD-base repo configuration in the FreeBSD-pkg-bootstrap package.

Tested with:

Special thanks to:

@grahamperrin
Copy link
Author

bsdinstall keymap

Alternatively, whilst in single user mode, for me:

sysrc keymap="uk.kbd"

@grahamperrin
Copy link
Author

@grahamperrin
Copy link
Author

grahamperrin commented Aug 17, 2025

  • fetch-o ./pkgbasify.lua
  • chmod +x ./pkgbasify.lua

For simplicity, expect pkgbasify to be packaged:

@grahamperrin
Copy link
Author

Repairing an installation of 15.0

Simpler. The FreeBSD-base repo is preconfigured, and pkg is already bootstrapped.

Instead of FreeBSD-certctl, install FreeBSD-caroot.

Tested: FreeBSD-15.0-PRERELEASE-amd64-20250822-027be99b1f33-279771-memstick.img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment