Sean’s Obsessions

  • Archives

17 Apr

make bzImage vs make zImage

What’s the difference between the bzImage and zImage targets when compiling a kernel?

If you said that the former used bzip2 compression while the latter used gzip, then read on for the real reason.

I ran into this one a few years ago when I was digging into RPM and some custom kernels. A couple of years later I noticed a column that made mention of the compression angle. (Note that this is otherwise a superb column, and was probably the largest influence on my writing over the past few years… I was deeply saddened when the magazine went under). I’m also currently looking through some LPI material that mentions the same reasoning, and have heard that it may even appear on the exam the wrong way!

I then asked a coworker who has a brilliant Linux mind, and he got it wrong, too.

So, let’s stop the bzImage == bzip2 compression myth! :)
Take a look at
/usr/src/linux-2.4/arch/i386/boot/setup.S:

# Now we move the system to its rightful place ... but we check if we have a
# big-kernel. In that case we *must* not move it ...
        testb   $LOADED_HIGH, %cs:loadflags
        jz      do_move0                        # .. then we have a normal low
                                                # loaded zImage
                                                # .. or else we have a high
                                                # loaded bzImage
        jmp     end_move                        # ... and we skip moving

Basically, a “b” kernel is loaded into high memory, a regular kernel into low memory. All compressed kernels are compressed with gzip -9.

This document provides some eye watering detail on the whole bootup process. Or just take it from me, a bz kernel is a “big” kernel, and gets loaded into high memory.

2 Responses to “make bzImage vs make zImage”

  1. 1
    David Bouthillier Says:

    Sean:

    I have a question about a zImage. I have a TimeSys Linux kernel in a zImage format. What I would like to do is have some users already set up in the /etc/passwd file that is in the zImage file. Is there a way I can decompress the zImage on my Linux machine, edit the /etc/passwd file and then re-zip it?

    When the zImage is made, it uses the Linux kernel and also the all files its needs (the bins and stuff) right? I have all of the source for the TimeSys Linux kernel but I dont know where to look for these other files that are used in the zImage. Do you know where I could look to figure this out?

    Thanks

  2. 2
    Sean Says:

    Don’t confuse a zImage kernel with a disk image. A disk image contains a
    kernel and a filesystem, the zImage kernel is just the kernel itself in a
    compressed format.

    It’s been a while, but the disk image is usually a msdos file system
    containing the kernel and a compressed ext2 file system. Mount the floppy
    as per normal, and see what’s on it. One of the files (there may only be
    one) is the compressed file system. Copy that to your hard drive, gunzip
    it, and remount it with the loop option, ie

    mkdir /mnt/loop
    cp /mnt/floppy/the_filesystem /tmp
    gunzip /tmp/the_filesystem
    mount /tmp/the_filesystem /mnt/loop -o loop

    At that point you can edit the files in /mnt/loop, unmount /mnt/loop,
    compress /tmp/the_filesystem, copy it back over the old file in
    /mnt/floppy, and unmount /mnt/floppy (whew)

© 2008 Sean’s Obsessions | Entries (RSS) and Comments (RSS)

Powered by Wordpress, design by Web4Sudoku, based on Pinkline byGPS Gazette