Rav*_*i A 3 linux shell linux-kernel embedded-linux
我正在研究一个shell脚本.我有一个预先构建的zImage.是否有可能知道创建此zImage的内核版本?
我已尝试更新命令@ 从压缩内核映像获取uname信息,但这两个命令都失败了.
$ dd if=zImage bs=1 skip=$(LC_ALL=C grep -a -b -o $'\x1f\x8b\x08\x00\x00\x00\x00\x00' zImage | \
cut -d ':' -f 1) | zcat | grep -a 'Linux version'
dd: unrecognized operand `3165585'
Try `dd --help' for more information.
gzip: stdin: unexpected end of file
$ dd if=zImage bs=1 skip=$(LC_ALL=C grep -a -b -o $'\xFD\x37\x7A\x58\x5A\x00' zImage | \
head -n 1 | cut -d ':' -f 1) | xzcat | grep -a 'Linux version'
xzcat: (stdin): File format not recognized
Run Code Online (Sandbox Code Playgroud)
你能指导我从zImage中识别内核版本吗?
很可能你zImage是用LZMA压缩机压缩的.您可以在下一个文件中查看它:
.config文件中(如果你自己构建内核)/boot/config-`uname -r`文件中(如果您使用的是您的发行版)/proc/config.gz文件中(如果CONFIG_IKCONFIG_PROC已启用)寻找CONFIG_KERNEL_*参数:
$ cat .config | grep '^CONFIG_KERNEL_[^_]\+='
Run Code Online (Sandbox Code Playgroud)
如果已CONFIG_KERNEL_LZMA=y设置,则表示使用LZMA压缩机.
LZMA格式具有 5d 00 00标题签名.因此可以通过这种方式Image在zImage文件中找到压缩文件的位置:
$ grep -P -a -b -m 1 --only-matching '\x5D\x00\x00' zImage | cut -f 1 -d :
Run Code Online (Sandbox Code Playgroud)
提取压缩Image:
$ pos=$(grep -P -a -b -m 1 --only-matching '\x5D\x00\x00' zImage | cut -f 1 -d :)
$ dd if=arch/arm/boot/zImage of=piggy.lzma bs=1 skip=$pos
Run Code Online (Sandbox Code Playgroud)
现在确保它piggy.lzma实际上是LZMA存档:
$ file piggy.lzma
Run Code Online (Sandbox Code Playgroud)
piggy.lzma:LZMA压缩数据,流式传输
解压缩piggy.lzma:
$ unlzma -c piggy.lzma > Image
Run Code Online (Sandbox Code Playgroud)
现在您已经解压缩Image,您可以使用strings工具找到Linux版本:
$ strings Image | grep 'Linux version'
Run Code Online (Sandbox Code Playgroud)
哪个应该给你这样的东西:
Linux版本4.4.11-188843-g94c4bf5-dirty(joe @ joe-laptop)(gcc版本4.8(GCC))#1 SMP预览5月26日星期五20:55:27 EEST 2016