Knowing the FreeBSD you are runningKnowing what operating system version you are running is very important, especially in order to report bugs and open issues.
Sysadmins all around the world are used to old friend
uname(1)that reports, with different level of details, the version of the kernel:
The important information there is the
luca@miguel ~ % uname -a FreeBSD miguel 12.1-RELEASE-p1 FreeBSD 12.1-RELEASE-p1 GENERIC amd64
uname(1)looks at the running kernel, and does not know anything about any update you could have done on your system.
freebsd-versionis a shell script that does a lot of efforts in trying to understand what you are managing. It accepts three options:
-kto inspect the installed kernel;
-uto inspect the installed userland;
-r** to inspect the running kernel. <br/> **Wait a minute: is it possible that the running kernel does not match the installed kernel?** <br/> Yes, in particular after an upgrade (e.g.,freebsd-upgrade`) that has not done yeta reboot.
Here it is an example from the very same system:
As you can see, the installed kernel and userlands are
luca@miguel ~ % freebsd-version -k 12.1-RELEASE-p2 luca@miguel ~ % freebsd-version -r 12.1-RELEASE-p1 luca@miguel ~ % freebsd-version -u 12.1-RELEASE-p2
12.1-RELEASE-p2but the system is still running
12.1-RELEASE-p1, that leads us to conclude an updated has finished but the server has not reboot yet.
But how does
freebsd-versionunderstands the installed kernel if it is not running?
The secret is behind a small program,
what(1), that analyzes an executables and extracts a text string that indicates the version of the linked binary:
while the running kernel can be inspect into the
luca@miguel ~ % what /boot/kernel/kernel /boot/kernel/kernel: FreeBSD 12.1-RELEASE-p2 GENERIC luca@miguel ~ % what -qs /boot/kernel/kernel FreeBSD 12.1-RELEASE-p2 GENERIC
sysctlset, as in
And what about the userland? Well, there is nothing around the system that indicates the userland version, therefore the trick is that a new userland installs a new
luca@miguel ~ % sysctl kern.osrelease kern.osrelease: 12.1-RELEASE-p1
freebsd-versionwith an hardcoded value:
luca@miguel ~ % grep USERLAND_VERSION $(which freebsd-version) USERLAND_VERSION="12.1-RELEASE-p2" echo $USERLAND_VERSION