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

ADVERTISEMENTS



Command to update source tree at /usr/src

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?: 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.

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

OR

# 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 https://svn.freebsd.org/base/releng/11.2 /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

OR

$ 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:

11.2-RELEASE-p12

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:

jls

Sample outputs:

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

Conclusion

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.