bash 从 vmlinuz 或 bzImage 中提取 vmlinux

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12002315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:32:56  来源:igfitidea点击:

Extract vmlinux from vmlinuz or bzImage

bashlinux-kernelkernel

提问by hellolwq

I want to generate System.map from vmlinuz,cause most of machines don't have the file System.map.In fact,vmlinuz are compressed to vmlinuz or bzImage.

我想从vmlinuz生成System.map,因为大多数机器没有文件System.map。实际上,vmlinuz被压缩为vmlinuz或bzImage。

It's any tool or script can do this?

任何工具或脚本都可以做到这一点?

I tried:

我试过:

dd if=/boot/vmlinuz skip=`grep -a -b -o -m 1 -e $'\x1f\x8b\x08\x00' /boot/vmlinuz | cut -d: -f 1` bs=1 | zcat > /tmp/vmlinux

It was failed:

失败了:

zcat: stdin: not in gzip format
32769+0 records in
32768+0 records out

回答by Abrixas2

To extract the uncompressed kernel from the kernel image, you can use the extract-vmlinuxscript from the scriptsdirectory in the kernel tree (available at least in kernel version 3.5) (if you get an error like

要从内核映像中提取未压缩的内核,您可以使用内核树目录中的extract-vmlinux脚本scripts(至少在内核版本 3.5 中可用)(如果您收到类似

mktemp: Cannot create temp file /tmp/vmlinux-XXX: Invalid argument

mktemp:无法创建临时文件 /tmp/vmlinux-XXX:无效参数

you need to replace $(mktemp /tmp/vmlinux-XXX)by $(mktemp /tmp/vmlinux-XXXXXX)in the script). The command is /path/to/kernel/tree/scripts/extract-vmlinux <kernel image> >vmlinux.

您需要在脚本中替换$(mktemp /tmp/vmlinux-XXX)$(mktemp /tmp/vmlinux-XXXXXX))。命令是/path/to/kernel/tree/scripts/extract-vmlinux <kernel image> >vmlinux.

If the extracted kernel binary contains symbol information, you should1 be able to create the System.mapfile using the mksysmapscript from the same subdirectory. The command here is NM=nm /path/to/kernel/tree/scripts/mksysmap vmlinux System.map.

如果提取的内核二进制文件包含符号信息,您应该能够System.map使用mksysmap来自同一子目录的脚本创建文件。这里的命令是NM=nm /path/to/kernel/tree/scripts/mksysmap vmlinux System.map.

1 The kernel images shipped with my distribution seem to be stripped, so the script was not able to get the symbols.

1 我的发行版附带的内核映像似乎已被剥离,因此脚本无法获取符号。

回答by Daniel Genin

As Abrixas2 wrote, you will need a kernel image with symbol information in order to create System.map files and a packed vmlinuz image is not likely to have symbols in it. I can, however, verify that the script in your original post works with '-e' replaced with '-P' and '$' dropped, i.e.,

正如 Abrixas2 所写,您将需要一个包含符号信息的内核映像来创建 System.map 文件,并且打包的 vmlinuz 映像中不太可能包含符号。但是,我可以验证您原始帖子中的脚本是否可以将“-e”替换为“-P”并删除“$”,即,

$ dd if=vmlinuz-3.8.0-19-generic skip=`grep -a -b -o -m 1 -P '\x1f\x8b\x08\x00' vmlinuz-3.8.0-19-generic | cut -d: -f 1` bs=1 | zcat > /tmp/vmlinux
gzip: stdin: decompression OK, trailing garbage ignored

回答by mug896

I'm on ubuntu linux.
you can change $'\037\213\010\000'to "$(echo '\037\213\010\000')"in sh

我在 ubuntu linux 上。
你可以改变$'\037\213\010\000',以"$(echo '\037\213\010\000')"在SH

bash$ N=$(grep -abo -m1  $'730##代码##0' vmlinuz-4.13.0-37-generic | awk -F: '{print +1}') && 
tail -c +$N vmlinuz-4.13.0-37-generic | gzip -d > /tmp/vmlinuz