6

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"?

Dmitry Frank
  • 2,738
  • What about the compiler options? Are they the same? – Faheem Mitha Jul 28 '14 at 07: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 08: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 09:08
  • @Mat, thanks for the tip, but it's my old laptop for experiments, just one core there. – Dmitry Frank Jul 28 '14 at 09:08
  • I'd suggest checking for and removing/redefining any options for debug symbols. – Hannu Jul 28 '14 at 12:08
  • This is a good question -- while the actual kernel binary is about the same size, the same simple core modules (e.g. crypto implementations) are 5-10 times the size on disk when compiled from source than they are in my distro (fedora) package. That's probably pretty noticeably if you use an external initrd, since it is mostly modules. It's not @Hannu because of debugging symbols AFAICT; file reports them both as "not stripped". – goldilocks Jul 28 '14 at 13:47
  • "not stripped" - i.e. they contain "unstripped debug symbols" -> $ ld --help | grep -i strip – Hannu Jul 28 '14 at 13:50
  • @Hannu But they are both like that, so that's not the issue; don't bother stripping them. What's interesting is I build most things in (i.e., I don't need any external initrd), but again, the actual kernel is only about 10% bigger. It's the .kos specifically. – goldilocks Jul 28 '14 at 13:51
  • =) considering the facts pointed out by Bruce in his answer, the kernel may well have the symbols too - within the compressed image. – Hannu Jul 28 '14 at 13:52
  • I'm sure it does, but those things aren't normally loaded and don't make any difference at runtime, so stripping them out is pointless. Dunno what all the extra bulk in the modules is though. – goldilocks Jul 28 '14 at 13:54
  • Howto: http://serverfault.com/a/251139 – Hannu Jul 28 '14 at 13:55
  • ^^ Again, that's obviously not the issue here. – goldilocks Jul 28 '14 at 13:56
  • Right -:-) "not stripped" ^-- above. I give up. – Hannu Jul 28 '14 at 13:57
  • @Hannu I'm wrong! It was debugging symbols (added an answer). – goldilocks Jul 28 '14 at 15:34
  • That is a big 'LOL' :-) – Hannu Jul 28 '14 at 15:45

2 Answers2

6

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.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • 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
0

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.