LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   anyway to extract a version string from a non running vmlinuz ? (https://www.linuxquestions.org/questions/slackware-14/anyway-to-extract-a-version-string-from-a-non-running-vmlinuz-506993/)

rcorkum 12-02-2006 10:55 PM

anyway to extract a version string from a non running vmlinuz ?
 
as I said in an earlier post i am getting kernelitis and need to do some labeling now i could start tossing and redoing but if there is a way to get the version out already would make life easier and quicker (p233)

or the uncompressed vmlinux even.

thanks

gnashley 12-03-2006 03:23 AM

grep reads binary files so you can get it that way. at least in a round-about fashion:

grep "2.4.33" ./vmlinuz
returns true

In other words you'd have to write a script which would loop through the possible version numbers until it finds a match. Not very dependable...

archtoad6 12-07-2006 01:46 PM

You could improve the reliability & possibly the speed of your script if you can determine the area of the vmlinu[z|x] the the string is located in, then use dd to limit your examination to that range of bytes:
Code:

F=<target_file>
M=<irrelevant_leading_bytes>
N=<interesting_bytes>
V=<list_of_version_strings>
X=$(dd bs=1 count=$N skip=$M if=$F)
for v in $V
do
  grep $v $F
done

also using fgrep may be faster. Sorry I'm on the road on <barf>an XP</barf> machine & cannot test my suggested code. caveat emptor

gnashley 12-08-2006 01:57 AM

Yeah, at first I thought of the 'magic' bytes that rdev reads/modifies and that the version string might be readable in a similar way.
I think there's no problem with speed using grep -it returns an answer right away. But having to loop through every possible version number could take a very long time. grep returns no location info -the kernel is a single long line of code I guess.
The version info is probably in a specific spot, though as you suggest -if we could just find out where then dd would be the way to get it.
Frankly, I think the exercise is mostly useless. The OP is obviously a newbie and if he really wants to know which kernel he's running, should install a known version and label it anyway he likes. Even if we get the version number, that still tells us very little about the kernel. I can see the utility of something like this though: if the kernel would print out a copy of it's config file -like the way busybox does. That way you could duplicate the kernel if needed.
I don't mean to be unhelpful -I gave the only solution I could think of since no one had answered the post. Some sort of loop using dd/seek should be able to find the location of the bits in question, then it would be fairly simple to query any given kernel.

kodon 12-08-2006 09:54 AM

its location doesn't seem to be nailed down

xflow7 12-08-2006 10:39 AM

Why iterate through every possible kernel version? Couldn't you use a regular expression as the pattern for grep. Something like:

Code:

grep -e "2\.[46]\.[0-9]*" ./vmlinuz
if you knew that it could only be a 2.4 or 2.6 kernel. (apologies if I messed up the syntax, i can't test it at the moment)

You'd want to check that grep returned a single value to protect against there happening to be some other string in the image that would match a valid kernel version number but that's an issue even if you iterate through.

xflow7 12-08-2006 12:12 PM

Oh just tried my suggestion and now I understand. grep won't return the actual match from a binary file, just whether or not it matches. Not such a hot idea after all, I guess. :p

kodon 12-08-2006 01:36 PM

decent idea

just use sed instead

rcorkum 12-08-2006 02:33 PM

Quote:

Originally Posted by gnashley
Yeah, at first I thought of the 'magic' bytes that rdev reads/modifies and that the version string might be readable in a similar way.
I think there's no problem with speed using grep -it returns an answer right away. But having to loop through every possible version number could take a very long time. grep returns no location info -the kernel is a single long line of code I guess.
The version info is probably in a specific spot, though as you suggest -if we could just find out where then dd would be the way to get it.
Frankly, I think the exercise is mostly useless. The OP is obviously a newbie and if he really wants to know which kernel he's running, should install a known version and label it anyway he likes. Even if we get the version number, that still tells us very little about the kernel. I can see the utility of something like this though: if the kernel would print out a copy of it's config file -like the way busybox does. That way you could duplicate the kernel if needed.
I don't mean to be unhelpful -I gave the only solution I could think of since no one had answered the post. Some sort of loop using dd/seek should be able to find the location of the bits in question, then it would be fairly simple to query any given kernel.

oh I appreciated the help I really did, thats what I did load each one I was questioning rebooted and unamed it and then renamed the system.map and kernel to match what it was and repeated till done. just been intrigued and following the responses.

Rob


All times are GMT -5. The time now is 07:22 PM.