CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old February 18th, 2007, 03:55 AM
    George2 George2 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2002
    Posts: 4,466
    George2 is on a distinguished road (30+)
    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
    Reply With Quote
      #2    
    Old February 18th, 2007, 05:56 AM
    JohnyDog JohnyDog is offline
    Member
     
    Join Date: Dec 2005
    Location: Prague, Czech Republic
    Posts: 208
    JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)
    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
    Reply With Quote
      #3    
    Old February 19th, 2007, 02:01 AM
    George2 George2 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2002
    Posts: 4,466
    George2 is on a distinguished road (30+)
    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
    Reply With Quote
      #4    
    Old February 19th, 2007, 05:37 AM
    JohnyDog JohnyDog is offline
    Member
     
    Join Date: Dec 2005
    Location: Prague, Czech Republic
    Posts: 208
    JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)
    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.
    Reply With Quote
      #5    
    Old February 19th, 2007, 07:21 AM
    George2 George2 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2002
    Posts: 4,466
    George2 is on a distinguished road (30+)
    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
    Reply With Quote
      #6    
    Old February 19th, 2007, 08:08 AM
    JohnyDog JohnyDog is offline
    Member
     
    Join Date: Dec 2005
    Location: Prague, Czech Republic
    Posts: 208
    JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)
    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.
    Reply With Quote
      #7    
    Old February 19th, 2007, 10:57 PM
    George2 George2 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2002
    Posts: 4,466
    George2 is on a distinguished road (30+)
    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
    Reply With Quote
      #8    
    Old February 19th, 2007, 11:57 PM
    JohnyDog JohnyDog is offline
    Member
     
    Join Date: Dec 2005
    Location: Prague, Czech Republic
    Posts: 208
    JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)
    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
    Reply With Quote
      #9    
    Old February 20th, 2007, 05:20 AM
    George2 George2 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2002
    Posts: 4,466
    George2 is on a distinguished road (30+)
    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
    Reply With Quote
      #10    
    Old February 20th, 2007, 07:52 AM
    JohnyDog JohnyDog is offline
    Member
     
    Join Date: Dec 2005
    Location: Prague, Czech Republic
    Posts: 208
    JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)
    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.
    Reply With Quote
      #11    
    Old February 20th, 2007, 11:59 PM
    George2 George2 is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2002
    Posts: 4,466
    George2 is on a distinguished road (30+)
    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
    Reply With Quote
      #12    
    Old February 22nd, 2007, 07:39 AM
    JohnyDog JohnyDog is offline
    Member
     
    Join Date: Dec 2005
    Location: Prague, Czech Republic
    Posts: 208
    JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)JohnyDog is a jewel in the rough (200+)
    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.).
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 06:40 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009