convert vmlinuz to vmlinux
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: convert vmlinuz to vmlinux

  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    convert vmlinuz to vmlinux

    Hello everyone,


    I am using oprofile on Linux to profile a C/C++ application. Oprofile needs to use vmlinux other than vmlinuz (on my machine, under /boot, I only have vmlinuz -- compressed format). I have tried to use gzip to un-compress vmlinuz, but I have got an error message which indicates un-recognized zip format.

    Any ideas about how to get a vmlinux?


    thanks in advance,
    George

  2. #2
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: convert vmlinuz to vmlinux

    Not sure how this is relevant in this forum but anyway

    The vmlinuz isn't just the compressed kernel, it's complete bootable image including the decompressor. To get just the image search for the GZ signature - 1f 8b 08 00. Now i'm sure there are scripts for it somewhere, but you can do it old-fashioned way - in my case:

    > od -A d -t x1 vmlinuz | grep '1f 8b 08 00'
    0024576 24 26 27 00 ae 21 16 00 1f 8b 08 00 7f 2f 6b 45

    so the image begins at 24576+8 => 24584 . Then just copy the image from the point and decompress it -

    >dd if=vmlinuz bs=1 skip=24584 | zcat > vmlinux
    1450414+0 records in
    1450414+0 records out
    1450414 bytes (1.5 MB) copied, 6.78127 s, 214 kB/s

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: convert vmlinuz to vmlinux

    Thanks JohnyDog,


    Quote Originally Posted by JohnyDog
    Not sure how this is relevant in this forum but anyway

    The vmlinuz isn't just the compressed kernel, it's complete bootable image including the decompressor. To get just the image search for the GZ signature - 1f 8b 08 00. Now i'm sure there are scripts for it somewhere, but you can do it old-fashioned way - in my case:

    > od -A d -t x1 vmlinuz | grep '1f 8b 08 00'
    0024576 24 26 27 00 ae 21 16 00 1f 8b 08 00 7f 2f 6b 45

    so the image begins at 24576+8 => 24584 . Then just copy the image from the point and decompress it -

    >dd if=vmlinuz bs=1 skip=24584 | zcat > vmlinux
    1450414+0 records in
    1450414+0 records out
    1450414 bytes (1.5 MB) copied, 6.78127 s, 214 kB/s
    I have tried your method, but it is still not working. I am using Red Hat Linux Enterprise 4.

    I have monitored my output from your output. Here are some differences.

    > dd if=/boot/vmlinuz-2.6.9-11.EL bs=1 skip=13844 | zcat > vmlinux
    > 1421660+0 records in
    > 1421660+0 records out

    You can see I have no information dumped as yours, such as "1450414 bytes (1.5 MB) copied, 6.78127 s, 214 kB/s".

    When executing oprofile, there are still such errors,

    > /root/opcontrol --vmlinux=/root/vmlinux
    > The specified file /root/vmlinux does not seem to be valid
    > Make sure you are using vmlinux not vmlinuz

    Any ideas?


    regards,
    George

  4. #4
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: convert vmlinuz to vmlinux

    I've just realized that when vmlinux image is converted to vmlinuz, the symbols, along with the ELF header are stripped to save space. As the symbols are the thing for which oprofile requires the image, i guess you're out of luck and will have to either find the vmlinux for your distribution somewhere, or recompile the kernel yourself.

  5. #5
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: convert vmlinuz to vmlinux

    Thanks JohnyDog,


    Quote Originally Posted by JohnyDog
    I've just realized that when vmlinux image is converted to vmlinuz, the symbols, along with the ELF header are stripped to save space. As the symbols are the thing for which oprofile requires the image, i guess you're out of luck and will have to either find the vmlinux for your distribution somewhere, or recompile the kernel yourself.
    I am wondering in which step of recompile kernel, vmlinux could be generated? I have recompiled kernel before, but I think either make zImage or make bzImage will generate vmlinuz other than vmlinux, right?

    Another question is, do you know why oprofile needs a Linux kernel (vmlinux)? I think if I recompile a Linux kernel to generate a vmlinux (without make install), but in my real Linux environment, the /boot/vmlinuz is the kernel image I actally used, will it take effect to oprofile?


    regards,
    George

  6. #6
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: convert vmlinuz to vmlinux

    Quote Originally Posted by George2
    I am wondering in which step of recompile kernel, vmlinux could be generated? I have recompiled kernel before, but I think either make (b)zImage or make bzImage will generate vmlinuz other than vmlinux, right?
    It's created at near-final stage, then it is copied, striped, compressed, have bootloader prepended and renamed to zImage. If you do 'make bzImage', the original is still preserved - after compilation is done you should have 'vmlinux' in the same directory you did the make from (/usr/src/linux) - in older kernel versions i think it was stored somewhere under arch/ .

    Quote Originally Posted by George2
    Another question is, do you know why oprofile needs a Linux kernel (vmlinux)? I think if I recompile a Linux kernel to generate a vmlinux (without make install), but in my real Linux environment, the /boot/vmlinuz is the kernel image I actally used, will it take effect to oprofile?
    Probably for symbols, but that is just my guess. I've never been into kernel debugging that much, sorry If the kernel is the same version and was compiled with the same options, then the resulting image should be the same.

  7. #7
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: convert vmlinuz to vmlinux

    Thanks JohnyDog,


    Quote Originally Posted by JohnyDog
    It's created at near-final stage, then it is copied, striped, compressed, have bootloader prepended and renamed to zImage. If you do 'make bzImage', the original is still preserved - after compilation is done you should have 'vmlinux' in the same directory you did the make from (/usr/src/linux) - in older kernel versions i think it was stored somewhere under arch/ .


    Probably for symbols, but that is just my guess. I've never been into kernel debugging that much, sorry If the kernel is the same version and was compiled with the same options, then the resulting image should be the same.
    I think I have to recompile the kernel.

    To be safe, I think of two more points,

    1. Reserve current settings. Do you know some smart way from which I could get the current kernel settings -- if I run make xconfig, the settings displayed is my current kernel settings?

    2. Reserve current vmlinuz kernel. I think I could stop after step make bzImage in order to get vmlinux, without running step make install to overwrite my current kernel. Do you think it is all right?


    regards,
    George

  8. #8
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: convert vmlinuz to vmlinux

    Quote Originally Posted by George2
    1. Reserve current settings. Do you know some smart way from which I could get the current kernel settings -- if I run make xconfig, the settings displayed is my current kernel settings?
    If you compiled it yourself or using the distribution kernel with sources it should have. Further, if the kernel was compiled with CONFIG_IKCONFIG=y, then the running kernel exports the config used to build it as /proc/config.gz.

    When you run make (b)zImage/install etc., the script will use file '.config' (note the dot at beggining) in current directory (/usr/src/linux) as kernel settings. When you do make xconfig/menuconfig, it simply reads the ".config" file and displays the options presented there (or defaults, if the .config doesn't exist).

    Quote Originally Posted by George2
    2. Reserve current vmlinuz kernel. I think I could stop after step make bzImage in order to get vmlinux, without running step make install to overwrite my current kernel. Do you think it is all right?
    Yes, it's right. TBH, back in the days when i was compiling my kernel, i never trusted make install, so i always ran make bzImage and copied the image myself

  9. #9
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: convert vmlinuz to vmlinux

    Thanks JohnyDog,


    Quote Originally Posted by JohnyDog
    If you compiled it yourself or using the distribution kernel with sources it should have. Further, if the kernel was compiled with CONFIG_IKCONFIG=y, then the running kernel exports the config used to build it as /proc/config.gz.

    When you run make (b)zImage/install etc., the script will use file '.config' (note the dot at beggining) in current directory (/usr/src/linux) as kernel settings. When you do make xconfig/menuconfig, it simply reads the ".config" file and displays the options presented there (or defaults, if the .config doesn't exist).
    I have searched some tutorials, and I find a way to safely apply current kernel settings to new re-compile kernel. The method is simple, just copy <kernel name + version>.config under /boot to kernel source directory to overwrite .config.

    How do you think this method? Do you suppose it works?


    regards,
    George

  10. #10
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: convert vmlinuz to vmlinux

    If your distribution puts the config under /boot, i'd say its preffered method. After all, the config file should be identical to the one in /proc/config.gz.

  11. #11
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: convert vmlinuz to vmlinux

    Thanks JohnyDog,


    Quote Originally Posted by JohnyDog
    If your distribution puts the config under /boot, i'd say its preffered method. After all, the config file should be identical to the one in /proc/config.gz.
    I have downloaded a new 2.6.9 kernel from kernel.org, and find in its Makefile that .config is referred. I think .config is a standard configuration file for all kernels, not only for Red Hat, right?


    regards,
    George

  12. #12
    Join Date
    Dec 2005
    Location
    Prague, Czech Republic
    Posts
    208

    Re: convert vmlinuz to vmlinux

    Yes thats right. As a side note, if you want to recompile the kernel you should use sources provided by your distribution, as they usually differ from the ones in official kernel at kernel.org (added patches etc.).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center