bashlinux-kernelkernel

Extract vmlinux from vmlinuz or bzImage


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.

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

Solution

  • To extract the uncompressed kernel from the kernel image, you can use the extract-vmlinux script from the scripts directory in the kernel tree (available at least in kernel version 3.5). The command is $path_to_kernel_tree/scripts/extract-vmlinux $kernel_image >vmlinux. Define $path_to_kernel_tree and $kernel_image as appropriate.

    If the extracted kernel binary contains symbol information, you should¹ be able to create the System.map file using the mksysmap script from the same subdirectory. The command here is NM=nm $path_to_kernel_tree/scripts/mksysmap vmlinux System.map.

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