# Identify OS version on a mounted memstick



## Keve (Nov 22, 2021)

I have _FreeBSD-13.0-RELEASE-i386-memstick.img_ which I wrote to an USB stick. I also have _FreeBSD-13.0-RELEASE-amd64-memstick.img_ on another, and _FreeBSD-12.2-RELEASE-xxx-memstick.img_ on yet another.  
Now, from the comfort of the FreeBSD installed and loaded from my HDD/SSD:
*How can I tell that any of those sticks has WHAT version of a FreeBSD installer set on it, and for WHAT architecture?*

The UFS volume label is always _FreeBSD_install_*.* So that is not going to help.
Mounting the volume and looking at the contents used to provide a README or HARDWARE txt, in which I could find what FreeBSD version it was for. But I no longer see such files on the sticks. I tried looking inside some files under /boot/ and /etc/, but I found nothing to clarify the version/arch of that particular installer set. And my inability to identify something this simple, bugs me.
Yes, I can boot the sticks, one after the other, and then I can tell which one is what release. But, how would I tell without booting them? Just by mounting it.
Suggestions are welcome!


----------



## Tieks (Nov 22, 2021)

You need to look at the kernel, I suppose. Something like `strings /boot/kernel/kernel | tail -n 7`?


----------



## _martin (Nov 22, 2021)

Since you have i386 and amd64 versions you can distinguish by that. Simple check on some files from bin with readelf(1) can help (`readelf -h /path/to/bin/ls`). There is no lib32 under i386 version,etc.
Edit: for simplicity you can even use file(1) instead of readelf.


----------



## eternal_noob (Nov 22, 2021)

I use self adhesive labels.


----------



## Vull (Nov 22, 2021)

For 13.0-RELEASE, mount the ufs partition number 5 on /mnt and run `/mnt/bin/freebsd-version`

It outputs `13.0-RELEASE`

Then `ls /mnt/usr/freebsd-dist/lib32.txt` will display that filename on amd64, but, (I'm guessing,) an error on i386.


----------



## T-Daemon (Nov 23, 2021)

Keve said:


> How can I tell that any of those sticks has WHAT version of a FreeBSD installer set on it, and for WHAT architecture?


The ABI (Application binary interface) of a binary can be queried. From pkg.conf(5):

```
ABI: string      The ABI of the package you want to install.  Default:
                      derived from the ABI of the /usr/bin/uname binary, if
                      not found then /bin/sh binary.
```

Mounted USB installer image (12.2-RELEASE):

```
# file /mnt/usr/bin/uname
/mnt/usr/bin/uname: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.2, FreeBSD-style, stripped
```

Mounted USB installer image (13.0-RELEASE):

```
# file /mnt/usr/bin/uname
/mnt/usr/bin/uname: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 13.0 (1300139), FreeBSD-style, stripped
```


----------



## pyc (Nov 23, 2021)

eternal_noob said:


> I use self adhesive labels.
> View attachment 12094



You definitely made my day!


----------



## covacat (Nov 23, 2021)

```
ADDR=$(nm -D /boot/kernel/kernel |grep sccs|cut -f1 -w|tr '[a-f]' '[A-F]');SOF=$(readelf --headers /boot/kernel/kernel |grep " \\.data .*PROGBITS"|cut -w -f5,6|tr '[a-f]' '[A-F]'|tr "\\t" "+");dd if=/boot/kernel/kernel bs=1 count=128 iseek=$(echo -e "ibase=16\n$ADDR-$SOF" |bc) 2>/dev/null|tr -s '\0' '\n'
```
 !#$!@#$@
tested on 10 to 13
dumps the sccs string from the file
sccs is generated by newvers.sh at buildtime


----------



## SirDice (Nov 23, 2021)

From 13.0 onward you can look at /etc/os-release:

```
NAME=FreeBSD
VERSION=13.0-RELEASE-p5
VERSION_ID=13.0
ID=freebsd
ANSI_COLOR="0;31"
PRETTY_NAME="FreeBSD 13.0-RELEASE-p5"
CPE_NAME=cpe:/o:freebsd:freebsd:13.0
HOME_URL=https://FreeBSD.org/
BUG_REPORT_URL=https://bugs.FreeBSD.org/
```


----------



## Keve (Nov 27, 2021)

SirDice said:


> From 13.0 onward you can look at /etc/os-release:


Unfortunately, no such file is present on the 13.0-Release installer memstick. 
Interestingly, there is a difference in HOW it is not there, between the i386 and the amd64 sets. The i386 installer memstick has a symlink named os-release in /etc/, pointing to ../var/run/os-release. But, the file being referenced does not exist. The amd64 installer memstick does not contain a /var/run/os-release file either. And it is also missing the /etc/os-release symlink.  

I would have spotted something this obvious when I was browsing through the files on the memstick in search of any content to identify the version.


----------



## Keve (Nov 27, 2021)

covacat said:


> ```
> ADDR=$(nm -D /boot/kernel/kernel |grep sccs|cut -f1 -w|tr '[a-f]' '[A-F]');SOF=$(readelf --headers /boot/kernel/kernel |grep " \\.data .*PROGBITS"|cut -w -f5,6|tr '[a-f]' '[A-F]'|tr "\\t" "+");dd if=/boot/kernel/kernel bs=1 count=128 iseek=$(echo -e "ibase=16\n$ADDR-$SOF" |bc) 2>/dev/null|tr -s '\0' '\n'
> ```


I cannot be anything other than completely amazed by people who come up with answers like this.  
On my part though, I would rather just boot the installer memstick to see what version it is than ever run a command like the one above, as its complexity kind of beats the point.  
Still, well done, covacat!


----------



## grahamperrin@ (Nov 28, 2021)

Keve said:


> Identify OS version on a mounted memstick



<https://unix.stackexchange.com/a/327146/13260> answered a similar question, _Getting the version level of FreeBSD for a ZFS boot environment that is mounted but not booted_


----------



## VladiBG (Nov 28, 2021)

man freebsd-version(1)



> To    inspect    a system being repaired    using a    live CD:
> 
> mount -rt ufs /dev/ada0p2 /mnt
> env ROOT=/mnt /mnt/bin/freebsd-version -ku


----------



## Keve (Nov 28, 2021)

VladiBG said:


> ```
> To    inspect    a system being repaired    using a    live CD:
> mount -rt ufs /dev/ada0p2 /mnt
> env ROOT=/mnt /mnt/bin/freebsd-version -ku
> ```


Excellent point. Thanks for bringing this to my attention!
I did not read the freebsd-version(1) manual. Or if I did, I failed to recognize at the time what I was looking at. This is ALMOST as good as I hoped.
Much appreciated!


----------

