3 # Check if the running kernel has the same version string as the on-disk
6 # Copyright 2008 Peter Palfrader
8 # Permission is hereby granted, free of charge, to any person obtaining
9 # a copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish,
12 # distribute, sublicense, and/or sell copies of the Software, and to
13 # permit persons to whom the Software is furnished to do so, subject to
14 # the following conditions:
16 # The above copyright notice and this permission notice shall be
17 # included in all copies or substantial portions of the Software.
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 $i = index(<>, "'"$needle"'");
43 print $i,"\n"' < "$file"
47 local image GZHDR1 GZHDR2 off
51 GZHDR1="\x1f\x8b\x08\x00"
52 GZHDR2="\x1f\x8b\x08\x08"
54 off=`get_offset "$image" $GZHDR1`
55 [ "$?" != "0" ] && off="-1"
56 if [ "$off" -eq "-1" ]; then
57 off=`get_offset "$image" $GZHDR2`
58 [ "$?" != "0" ] && off="-1"
60 if [ "$off" -eq "0" ]; then
63 elif [ "$off" -ne "-1" ]; then
64 (dd ibs="$off" skip=1 count=0 && dd bs=512k) < "$image" 2>/dev/null | zcat 2>/dev/null
68 echo "ERROR: Unable to extract kernel image." 2>&1
74 "/boot/vmlinuz-`uname -r`"\
75 "/boot/vmlinux-`uname -r`"; do
77 if [ -e "$on_disk" ]; then
78 on_disk_version="`get_image "$on_disk" | strings | grep 'Linux version' | head -n1`"
79 [ -z "$on_disk_version" ] || break
80 on_disk_version="`cat "$on_disk" | strings | grep 'Linux version' | head -n1`"
81 [ -z "$on_disk_version" ] || break
83 echo "UNKNOWN: Failed to get a version string from image $on_disk"
86 searched="$searched $on_disk"
89 if ! [ -e "$on_disk" ]; then
90 echo "WARNING: Did not find a kernel image (checked$searched) - I have no idea which kernel I am running"
95 running_version="`cat /proc/version`"
96 if [ -z "$running_version" ] ; then
97 echo "UNKNOWN: Failed to get a version string from running system"
101 if [ "$running_version" != "$on_disk_version" ]; then
102 echo "WARNING: Running kernel does not match on-disk kernel image: [$running_version != $on_disk_version]"
105 echo "OK: Running kernel matches on disk image: [$running_version]"