[plug] What's the best way to get kernel version from a binary?

Bill Kenworthy billk at iinet.net.au
Thu Nov 24 12:51:20 AWST 2016


On 24/11/16 12:11, Brad Campbell wrote:
> On 24/11/16 11:35, Bill Kenworthy wrote:
>> What's the best way to get kernel version from a binary?
>>
>> Context is that the raspberry pi stock firware doesn’t use version
>> numbers in the filename and I want to know what kernel version I am
>> building a custom initrd using dracut for a btrfs on root filesystem.
>>
>> Easy to get manually (strings|grep the file) but its clumsy and hard to
>> get precision in a script and uname doesn’t work on a file :(
>>
>> BillK
>> _______________________________________________
>> PLUG discussion list: plug at plug.org.au
>> http://lists.plug.org.au/mailman/listinfo/plug
>> Committee e-mail: committee at plug.org.au
>> PLUG Membership: http://www.plug.org.au/membership
>>
> 
> This is how I've done it for years now, it works no matter what weird
> extensions get put on the version. :
> 
> brad at srv:/raid10/src/linux-stable$ strings vmlinux | grep "Linux
> version" | awk '{print $3}'
> 4.8.6
> brad at srv:/raid10/src/linux-stable$ strings vmlinux | grep "Linux version"
> Linux version 4.8.6 (brad at srv) (gcc version 4.7.2 (Debian 4.7.2-5) ) #8
> SMP Mon Nov 7 14:36:58 AWST 2016
> 
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://lists.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.org.au
> PLUG Membership: http://www.plug.org.au/membership

Thanks all, I think Brads method will work best:

rpi2 ~ # file /boot/kernel7.img
/boot/kernel7.img: Linux kernel ARM boot executable zImage (little-endian)
rpi2 ~ # strings /boot/kernel7.img | grep "Linux version" | awk '{print $3}'
4.4.34-v7+
rpi2 ~ #

I realise there is also the option of ls -1 /lib/modules as the install
process from git installs under the correct version number, but there
could still be several versions present.

BillK





More information about the plug mailing list