# How can I compress the gentoo-sources kernel to vmlinux.bz2?

## Crimjob

The bootloader I use looks for vmlinux.bz2 or vmlinux.gz to decompress and boot. I'm able to boot non-gentoo kernels in this format. I need to know how I can build a Gentoo kernel like this. Do I have to do something other than make && make modules_install? I need the kernel compressed properly in one of these formats so my boot loader can decompress it properly and boot it. I can't find information on this anywhere for some reason.

----------

## poly_poly-man

it either wants a bzImage (just rename it, using the correct compression ending - there is config for this), or a gzipped/bzipped vmlinux

run "file vmlinux.gz" where vmlinux.gz should include the full path to a working vmlinux.gz or vmlinux.bz2, and post the output here...

----------

## Crimjob

 *poly_poly-man wrote:*   

> it either wants a bzImage (just rename it, using the correct compression ending - there is config for this)

 

Tried this already, with gzip and bzip2 configured in the kernel, and running a cp arch/x86/boot/bzImage /boot/vmlinux.gz or .bz2 respectively. All came back with error:

```
Second stage kernel: Decompressing -Error bunzip2ing kernel. Trying gunzip

ERROR: unknown compression method

ERROR: internal error, invalid method

Error gunziping kernel. Giving up. 
```

 *poly_poly-man wrote:*   

> run "file vmlinux.gz" where vmlinux.gz should include the full path to a working vmlinux.gz or vmlinux.bz2, and post the output here...

 

```
vmlinux.bz2: bzip2 compressed data, block size = 900K
```

----------

## poly_poly-man

oh wow.. that thing actually uses a gzipped vmlinux...

make vmlinux, look either in the boot folder or just in /usr/src/linux, find that file, gzip it, and drop it where it needs to go.

----------

## Crimjob

Okay I tried make vmlinux in /usr/src/linux, then grabbed the vmlinux file from there, ran 

```
gzip -9c vmlinux > /boot/vmlinux.gz
```

Attempted to boot, it didn't give an error decompressing, but now the kernel is over 1.8MB compressed (ROM limitation requires it to be lower than 1.8MB). I'm going to have to try doing it with bzip2 and see what happens size wise.

You've made the most sense so far though, thanks.

----------

## Crimjob

Urgh. Figured I'd hit another wall. The vmlinux file is a ton bigger than the bzImage. Even using bzip2 -9c vmlinux outputs 1910KB, I need it below 1800KB, and I don't know what else I can rip from the Kernel, if I haven't already ripped too much. >.<

----------

## Crimjob

As 1 wall falls, another is built. I forgot about the "strip" command, ran strip vmlinux, then bzip2, got to 1600KB. New problem, kernel won't boot.

```
BOOTLOADER: Mapping in physical locations

BOOTLOADER: load_addr=0xc2004000 ret_data=0xc2205cc4

BOOTLOADER: opening "/boot/vmlinux.bz2"

BOOTLOADER: reading "/boot/vmlinux.bz2"

BOOTLOADER: read 1686097bytes

BOOTLOADER: unmounting /

BOOTLOADER: calling reboot notifiers

md: stopping all md devices.

flushing ide devices: hda

BOOTLOADER: mapping 22M-32M for ride home

BOOTLOADER: disabling interrupts

BOOTLOADER: flushing cache

BOOTLOADER: Leap of faith!

Back in ramcode: done

Second stage kernel: Decompressing  - done

command line: 'console=ttyS0,115200 debug ip=off '

booting kernel... 

(reboots here)
```

I can't figure out what I'm doing wrong

----------

## poly_poly-man

just btw, don't strip the kernel.

You can try gzipping the bzImage - since the first sectors are identical to a vmlinux image, it might work - that's if the bzImage is under 1800k...

Otherwise - move a ton of drivers to modules?

----------

## Crimjob

Ok, gzipping or bzip2ing the bzImage provides the same results

I also think the only real thing I can module is my NIC's. This is non standard hardware, I already removed support for USB, Video Card, Input devices etc., and I know I'll need hard drive and fs built in. Will see what happens though.

----------

## Crimjob

Found this elsewhere also:

 *Quote:*   

> The Second Stage Kernel is a gzipped vmlinux. It is NOT a bzImage or zImage. If you want to load a kernel on a cobalt it MUST be built as a vmlinux kernel FIRST then gzip -9 used to zip the kernel with the highest compression. This produces a vmlinux.gz. NO BOOT SECTOR OR SETUP HEADERS! It is important that the kernel be built in that manner. 

 

----------

