How to update source tree at /usr/src using svn on FreeBSD

I compiled custom FreeBSD kernel for my FreeBSD jail to use vnet. How do I update my FreeBSD /usr/src/ code tree? How can I update source tree at /usr/src on FreeBSD using svn command to patch and compile kernel again?

Introduction: Subversion is a software versioning and revision control system distributed as open source under the Apache License. FreeBSD uses Subversion as the only version control system for storing all of FreeBSD’s source code, documentation, and the Ports Collection. So to update /usr/src/ and /usr/ports/ use the svn command. This page shows how to use Subversion to update /usr/src/ source code.

Command to update source tree at /usr/src

A lightweight version of Subversion is already installed on FreeBSD as svnlite. However, I like svn. If you want you can use the svnlite instead of svn command.
So I am going to install svn client.

Install ca_root_nss package

The ca_root_nss package includes root certificates from certificate authorities included in the Mozilla NSS library and thus in Firefox and Thunderbird. It means you can use Subversion to verify the identity of HTTPS repository servers too. Type the following pkg command to install ca_root_nss:
# pkg install ca_root_nss
# cd /usr/ports/security/ca_root_nss
# make install clean

Install svn command on FreeBSD

Type the following pkg command to install subversion.
# pkg install subversion

Subversion can also be installed as a port:
# cd /usr/ports/devel/subversion
# make install clean

How to update FreeBSD source code tree installed at /usr/src/

Run the following command to update existing tree:
# svn update /usr/src/
OR if you are using svnlight, run:
# svnlight update /usr/src/

If you never used or run svn command on /usr/src/ before you must delete or move old /usr/src/:
# cd /usr/src/
# rm -rf *

Now run svn update /usr/src/
# svn update /usr/src/
OR Find the current FreeBSD version
# uname -r # <--- says version 11.2 and so get 11.2 latest source code
# svn checkout /usr/src/

Wait for some time. Before you compile the FreeBSD kernel or do buildworld, read /usr/src/UPDATING using the cat command or vi command $ cat /usr/src/UPDATING | more
$ vi /usr/src/UPDATING

How to compile kernel from updated /usr/src/

Say you want compile FreeBSD kernel with a VIMAGE enabled. Use the cp command as follows to copy kernel config:
$ sudo cp -v /usr/src/share/examples/jails/VIMAGE /usr/src/sys/amd64/conf/VIMAGE
$ cd /usr/src/

Compile it:
$ sudo make KERNCONF=VIMAGE kernel
You can specify the maximum number of jobs that make may have running at any one time by passing the -j option. For example:
$ sudo make -j 16 KERNCONF=VIMAGE kernel
You must reboot the FreeBSD box:
$ sudo reboot
Verify new version after reboot:
$ uname -mrs

How to do both buildworld and kernel compile

Commands are as follows:
# vim /usr/src/UPDATING
# cd /usr/src
# make -j16 buildworld
# make -j16 kernel
# reboot
# cd /usr/src
# make installworld
# mergemaster -Ui
# reboot

To verify new FreeBSD kernel run the following commands after rebooting the FreeBSD server/box:
$ uname -a
Sample outputs:


OR use the freebsd-version command to find out FreeBSD version and patch level:
$ freebsd-version

For example, I need to make sure that jails started too. So I type:
Sample outputs:

   JID  IP Address      Hostname                      Path
     1                  rsnapshot                     /jails/rsnapshot
     2                  www                           /jails/www


You just learned how to update FreeBSD by compiling from source code. It has few advantages over binary updates done by freebsd-update command. For example, I often build the kernel to match my needs for jails and to take advantage of the specific hardware. For more info see this page here.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Comments are closed. Still have questions? Post it on our forum