I'm using Linux Mint 13 MATE 32bit, I'm trying to build the kernel (primarily for experience and for fun).

For now, I like to build it with the same configuration as precompiled kernel, so firstly I've installed precompiled kernel 3.16.0-031600rc6 from kernel.ubuntu.com, booted to it successfully.

Then I've downloaded 3.16.rc6 kernel from kernel.org, unpacked it, configured it to use config from existing precompiled kernel:

$ make oldconfig

It didn't ask me anything, so, precompiled kernel contains all necessary information. Then I've built it (it took about 6 hours) :

$ make

And then installed:

$ sudo make modules_install install

Then I've booted into my manually-compiled kernel, and it works, boot process is somewhat slower though. But then I've found out that all the binaries (/boot/initrd.img-3.16.0-rc6 and all the *.ko modules in /lib/modules/3.16.0-rc6/kernel are about 10 times larger than precompiled versions! Say, initrd.img-3.16.0-rc6 is 160 658 665 bytes, but precompiled initrd.img-3.16.0-031600rc6-generic is 16 819 611 bytes. Each *.ko module is similarly larger.

Why is this? I haven't specified any special options for build (I typed exactly the same commands as I mentioned above). How to build it "correctly"?

  • What about the compiler options? Are they the same? – Faheem Mitha Jul 28 '14 at 7:57
  • (Tip: if you have more than 1 core/thread, use make -jX in the second step, with X the number of parallel processes make can use - start with #cores.) – Mat Jul 28 '14 at 8:05
  • @FaheemMitha, as far as I understand, all the compiler options are specified in Makefile, of course I haven't changed it in any way, and I haven't provided any special options: just make oldconfig and make. So, compiler options should be the same, right? – Dmitry Frank Jul 28 '14 at 9:08
  • @Mat, thanks for the tip, but it's my old laptop for experiments, just one core there. – Dmitry Frank Jul 28 '14 at 9:08
  • I'd suggest checking for and removing/redefining any options for debug symbols. – Hannu Jul 28 '14 at 12:08

Despite what file says, it turns out to be debugging symbols after all. A thread about this on the LKML led me to try:

make INSTALL_MOD_STRIP=1 modules_install

And low and behold, a comparison from within the /lib/modules/x.x.x directory; before:

> ls -hs kernel/crypto/anubis.ko 
112K kernel/crypto/anubis.ko

And after:

> ls -hs kernel/crypto/anubis.ko 
16K kernel/crypto/anubis.ko

More over, the total size of the directory (using the same .config) as reported by du -h went from 185 MB to 13 MB.

Keep in mind that beyond the use of disk space, this is not as significant as it may appear. Debugging symbols are not loaded during normal runtime, so the actual size of each module in memory is probably identical regardless of the size of the .ko file. I think the only significant difference it will make is in the size of the initramfs file, and the only difference it will make there is in the time needed to uncompress the fs. I.e., if you use an uncompressed initramfs, it won't matter.

strip --strip-all also works, and file reports them correctly as stripped either way. Why it says not stripped for the distro ones remains a mystery.

  • 2
    Thank you so much! It's quite strange that INSTALL_MOD_STRIP isn't set by default. My resulting initrd.img-3.16.0-rc6 now takes 16 MB. Previously (with 160-MB initrd) when GRUB is finished, there was just black screen for about 7 seconds (unpacking, it seems), and only after it I see kernel messages. Now, with 16-MB initrd, kernel messages are echoed immediately after GRUB is finished. So, it is rather significant. Thanks again. – Dmitry Frank Jul 28 '14 at 20:31

After your make oldconfig, do a make vmlinuz. I think you'll find that the pre-compiled kernel is a "executable bzImage", which means it's compressed on-disk. If you watch boot messages closely, you'll see it uncompressing the kernel very early on in the process.

  • Thanks I'll try soon, but does this affect all the modules (*.ko) too? – Dmitry Frank Jul 28 '14 at 13:36
  • I don't know about modules. That was one question I had before I recommeded make vmlinuz. – Bruce Ediger Jul 28 '14 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.