Solved Which version contains my flash drive?

Hi guys!

I try to find out which FreeBSD version is currently on my "FreeBSD install" USB flash drive, which I dd the installation images to.
/var/run/os-version does not exist (of course.)
/usr/freebsd-dist/MANIFEST only reveals keys for each txz, which could be used to find the according version, but before I start to sherlock there have to be a file where it's simply written into it but maybe I'm simply too stupid/blind to find it.
Best I found was /bin/freebsd-version which tells me USERLAND_VERSION="14.2-RELEASE"
Okay, assuming in an unmodified installation image kernel version = userland version my question is answered.
But somehow I feel not fully satisfied.
Did I miss the file I'm looking for, just a simple version.txt somewhere containing This is FreeBSD 14.2-RELEASE, does such exist at all?

Thanks.
 
I've ran find on the iso but couldn't find anything other than what you've found.
Code:
freebsd:/tmp/iso
# find . -type f -iname "*version*" -exec grep -H "[.][0-9]-RELEASE" {} + > & /tmp/log
freebsd:/tmp/iso
# cat /tmp/log
./bin/freebsd-version:USERLAND_VERSION="14.2-RELEASE"


Run it and enter freebsd-version -kru
I think just knowing the release version without need of booting it would be easiest.

I'm on 14.3-R and this is what it shows for me.
Code:
freebsd:~
% grep "[.][0-9]-RELEASE" /bin/freebsd-version
USERLAND_VERSION="14.3-RELEASE"
 
Have a look at:
Code:
% awk '/^ \* __FreeBSD_version|awk/' < /usr/src/sys/sys/param.h
 * __FreeBSD_version numbers are documented in the Porter's Handbook.
 * __FreeBSD_version is bumped every time there's a change in the base system
 *      awk '/^\#define[[:space:]]*__FreeBSD_version/ {print $3}'

Edit: or, as mentioned, /usr/include/sys/param.h
 
grep __FreeBSD_version /usr/include/sys/param.h | grep ^#define
This did work!

Code:
freebsd:/tmp/iso
# grep "^#define.*__FreeBSD_version" ./usr/include/sys/param.h
#define __FreeBSD_version 1402000

Try:
Code:
% awk '/^ \* __FreeBSD_version|awk/' < /usr/src/sys/sys/param.h
 * __FreeBSD_version numbers are documented in the Porter's Handbook.
 * __FreeBSD_version is bumped every time there's a change in the base system
 *      awk '/^\#define[[:space:]]*__FreeBSD_version/ {print $3}'
That too but I don't think the iso have the source tree extracted.

Code:
freebsd:/usr/home/yusuf
# tree /tmp/iso/usr/src/
/tmp/iso/usr/src/

0 directories, 0 files
freebsd:/usr/home/yusuf
# tree /tmp/iso/usr/freebsd-dist
/tmp/iso/usr/freebsd-dist
├── base.txz
├── kernel-dbg.txz
├── kernel.txz
├── lib32.txz
├── MANIFEST
├── ports.txz
├── src.txz
└── tests.txz

1 directory, 8 files

Code:
freebsd:~
% awk '/^\#define[[:space:]]*__FreeBSD_version/ {print $3}' /usr/src/sys/sys/param.h
1403000
 
Code:
# dd if=FreeBSD-13.3-RELEASE-amd64-memstick.img of=/dev/da0 bs=1M status=progress
  1324351488 bytes (1324 MB, 1263 MiB) transferred 178.067s, 7437 kB/s
1264+1 records in
1264+1 records out
1326436864 bytes transferred in 178.504712 secs (7430823 bytes/sec)
# mount /dev/da0s2a /mnt
# chroot /mnt
# freebsd-version -ku
13.3-RELEASE
13.3-RELEASE

If you only care about the kernel you can do a dirty grep against the binary:
Code:
# grep -aor '..\..-RELEASE' /mnt/boot/kernel/kernel
kernel/kernel:13.3-RELEASE
kernel/kernel:13.3-RELEASE
kernel/kernel:13.3-RELEASE
(you'd have to extend the regexp to also search for RC|BETA|STABLE|CURRENT... versions - but TBH freebsd-version[cmd] is as easy as it gets...
 
Code:
# dd if=FreeBSD-13.3-RELEASE-amd64-memstick.img of=/dev/da0 bs=1M status=progress
  1324351488 bytes (1324 MB, 1263 MiB) transferred 178.067s, 7437 kB/s
1264+1 records in
1264+1 records out
1326436864 bytes transferred in 178.504712 secs (7430823 bytes/sec)
# mount /dev/da0s2a /mnt
# chroot /mnt
# freebsd-version -ku
13.3-RELEASE
13.3-RELEASE

If you only care about the kernel you can do a dirty grep against the binary:
Code:
# grep -aor '..\..-RELEASE' /mnt/boot/kernel/kernel
kernel/kernel:13.3-RELEASE
kernel/kernel:13.3-RELEASE
kernel/kernel:13.3-RELEASE
(you'd have to extend the regexp to also search for RC|BETA|STABLE|CURRENT... versions - but TBH freebsd-version[cmd] is as easy as it gets...

How's that memstick image written to the drive is not mounted as read-only or is it so only if you just boot it live? I was tried chrooting into mounted iso.


Dang, that seems to work too...
Code:
freebsd:/usr/home/yusuf
# chroot /tmp/iso/
root@freebsd:/ # freebsd-version
14.2-RELEASE
 
Wow. That was a lot of answers in a short time!
:oops:
Thanks Guys!!

To summarize:
There are at least four five ways:
0. what -s /mnt/boot/kernel/kernel ✅

1. mount it, chroot and do freebsd-version ✔️
2. look into /usr/include/sys/param.h - kernel ✔️
3. look into /bin/freebsd-version - userland ✔️
4. elfdump -a /bin/sh | grep FREEBSD_ABI ✔️

Question answered.
Thanks again!
 
Since freebsd-version is using what(1).
what -s /mnt/boot/kernel/kernel

Of course! This is the best answer!
Totally forgot that freebsd-version is merely a shellscript - so just look what it does to get the kernel version:

Code:
 62 # Extract the kernel version from the installed kernel.
 63 #
 64 kernel_version() {
 65     kernfile=$(kernel_file)
 66     if [ ! -f "$kernfile" -o ! -r "$kernfile" ] ; then
 67         error "unable to locate kernel"
 68     fi
 69     what -qs "$kernfile" | sed -n "s/$KERNEL_RE/\\1/p"
 70 }

But for the userland version it is somewhat underwhelming:
Code:
 31 USERLAND_VERSION="14.3-RELEASE"
[...]
 82 userland_version() {
 83     echo $USERLAND_VERSION
 84 }
I feel betrayed...
 
By principle that's what I was looking for.
It's just that my flash-drive for installation/live-system has "FreeBSD" written on. (I don't do a new sticker every couple of months :cool:)
Now I need it again and wondered: "Is it still 14.2, maybe even 14.1, or already 14.3?" :-/ (Such things my get forgotten.)
So, simply all I wanted to know was "which image I dded on it?" Since I don't tinker (much) with that later, it's not really about kernel vs userland, but just "it was the 14.2 img".
And I didn't find easily where to read just this information easy and quickly from.
We collected several possibilities to answer that, but of course
Since freebsd-version is using what(1).
what -s /mnt/boot/kernel/kernel
was the quickest and most easy one! (edited my summerize post above)
Thanks.
 
Back
Top