Knowing the FreeBSD you are running
Knowing 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:
luca@miguel ~ % uname -a
FreeBSD miguel 12.1-RELEASE-p1 FreeBSD 12.1-RELEASE-p1 GENERIC amd64
12.1-RELEASE-p1
part.
However,
uname(1)
looks at the running kernel, and does not know anything about any update you could have done on your system.
Entering
freebsd-version
.
freebsd-version
is a shell script that does a lot of efforts in trying to understand what you are managing. It accepts three options:
-k
to inspect the installed kernel;-u
to 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:
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-p2
but 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-version
understands 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:
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
sysctl
set, as in
luca@miguel ~ % sysctl kern.osrelease
kern.osrelease: 12.1-RELEASE-p1
freebsd-version
with an hardcoded value:
luca@miguel ~ % grep USERLAND_VERSION $(which freebsd-version)
USERLAND_VERSION="12.1-RELEASE-p2"
echo $USERLAND_VERSION