For the complete documentation index, see llms.txt. This page is also available as Markdown.

13.2 Updating FreeBSD from Source

Building FreeBSD from source allows customization of kernel options and compilation parameters, suitable for architectures not supported by freebsd-update or scenarios requiring a trimmed system.

The basic approach is to obtain the FreeBSD source code, then compile and install it. You can use Git to pull the code directly, download txz compressed files from the FreeBSD download site, or download the zip archive of the current FreeBSD project from GitHub.

For the compilation process, refer to other chapters in this book.

Obtaining Source Code from Git

Installing Git

Install Git using pkg:

# pkg install git

Or install Git using Ports:

# cd /usr/ports/devel/git/
# make install clean

Git Proxy Configuration

In restricted network environments, you may need to configure a proxy for Git to pull source code properly. Below are methods for setting and removing Git proxies.

  • Set Git global proxy:

# git config --global http.proxy http://192.168.X.X:7890  # Set Git global HTTP proxy
# git config --global https.proxy http://192.168.X.X:7890  # Set Git global HTTPS proxy
  • Remove Git global proxy:

Pulling Source Code with Git

Pulling CURRENT

Pull the source code from the official FreeBSD repository. Clone the FreeBSD source repository to /usr/src using a shallow clone to reduce download size:

Explanation of the --depth 1 parameter: Uses shallow clone mode, fetching only the latest commit without the complete commit history.

Pull the source code from GitHub (GitHub is a mirror of the src repository on FreeBSD.org, synchronized every 10 minutes).

Pulling a Specific RELEASE

Pull from the official FreeBSD repository. Clone the FreeBSD 15.0 release branch source code to /usr/src, using a shallow clone with only that branch:

Option explanation:

  • --branch releng/15.0: Specifies the branch to pull (the version of the FreeBSD RELEASE)

  • --single-branch: Clones only one branch, containing no other refs besides the single cloned branch.

Or pull from GitHub. Clone the FreeBSD 15.0 release branch source code to /usr/src from GitHub, using a shallow clone with only that branch:

References

Obtaining Source Code from Compressed Archives (Convenient but Not Latest)

This method is simple to operate.

Taking FreeBSD 15.0-RELEASE as an example:

Why extract to /?

Because the archive contains paths, extracting to / will place the source code in /usr/src. If you change the path above to /usr/src, the source code will be extracted to /usr/src/usr/src.

Tip

If the download is slow, you can switch to https://mirrors.ustc.edu.cn/freebsd/releases/amd64/amd64/15.0-RELEASE/src.txz

Starting the Build

Appendix: Resolving Conflicts

  • Conflicts remain from previous update, aborting.

Conflicts need to be resolved.

Tip

Unlike most modern Linux distributions, vi on FreeBSD (and OpenBSD) is nvi (a reimplementation of the original ex/vi), not a symbolic link to vim. This editor is used infrequently, so it is recommended to switch to another text editor.

Merge conflicts. Use etcupdate to merge configuration file updates:

etcupdate automatically triggers post-processing for several system files after merging:

Changed File
Triggered Command

/etc/master.passwd

pwd_mkdb

/etc/login.conf

cap_mkdb

/etc/mail/aliases

newaliases

/etc/services

services_mkdb

/etc/localtime (when /var/db/zoneinfo exists)

tzsetup

/etc/motd

/etc/rc.d/motd

Resolve conflicts:

Troubleshooting and Outstanding Issues

Git: fatal: unable to update url base from redirection

The FreeBSD source repository address was used without the .git suffix.

Git: fatal: unable to access 'https://git.FreeBSD.org/src.git/': SSL certificate problem: certificate is not yet valid

This is caused by incorrect system time. Use ntpd -q -g pool.ntp.org to synchronize the system time. For detailed instructions, refer to other relevant chapters in this book.

References

Exercises

  1. Summarize the complete process of obtaining source code from the FreeBSD Git repository, listing the required commands and their parameter meanings.

  2. Use etcupdate to manage configuration file updates in the /etc directory, and document a complete conflict resolution process.

  3. Modify /etc/src.conf to exclude unnecessary components (such as certain debugging tools), and measure the change in make buildworld compilation time.

Last updated