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