Page 1 of 2

How to minimize the initramfs while compiling kernel

Posted: 2012/02/29 13:50:53
by duchri66
HI,

I have compiled my kernel 2.6.32-220.4.1.el6 with no error, so my problem is the initramfs has pass from 13M to 104M and this cause the boot time is too long.

Somebody know how to minimize this file when compiling the kernel.

thank's

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/02/29 15:16:11
by TrevorH
Unpack your new initramfs in a temporary directory using

[code]
zcat /boot/initramfs-whatever | cpio -idm
[/code]

and examine its contents to find out what's different from the usual one.

Setting hostonly="yes" in /etc/dracut.conf can dramatically reduce the size of the usual initramfs but I've never heard of one so bloated before.

How to minimize the initramfs while compiling kernel

Posted: 2012/02/29 18:08:46
by toracat
It is indeed unusually big. Just curious how many kernel modules you have in your custom kernel. After unpacking, can you run:

[code]
find . -type f -name *.ko | wc -l
[/code]
On my unmodified EL6 system (x86_64), I get 289.

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/02/29 18:43:32
by TrevorH
289 is how many I had before I used hostonly="yes" which dropped it to ~22 I think.

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/02/29 19:01:39
by toracat
Right. If the number of modules in the OP's custom kernel is in the same range, then either the bloat would come from other components of initramfs or the modules are not properly strip'ed. This depends on how the kernel was built ...

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/02/29 19:56:42
by duchri66
i got this



[root@vmomni tmp]# zcat /boot/initramfs-2.6.32-220.4.1.el6.i686.img |cpio -idm
538366 blocks
[root@vmomni tmp]# find . -type f -name *.ko | wc -l
291
[root@vmomni tmp]#
[root@vmomni tmp]#


and the #hostonly="yes" was comment in /etc/dracut.conf.
if I understand well ,I need to uncomment hostonly=yes and recompile the kernel?

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/02/29 20:44:39
by toracat
The number of kernel modules is almost the same. Now I wonder if they are "big". Mine is:

[code]
$ find lib -type f -name *.ko | wc -l
289
$ du -sk lib
34096 lib
[/code]

So, the average is about 118 KB/module. What's yours?

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/03/01 11:53:49
by duchri66
mine is 918KB/module


[root@vmomni tmp]# du -sk lib
267296 lib

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/03/01 12:19:31
by duchri66
Hi,

here is my procedure , so do I have to modify those commands? specialy the #3 rpmbuild ?


1. install rpm with rpm -i kernel-2.6.32-220.4.1.el6.src.rpm.
2. Go to rpmbuild/SPECS
3. run rpmbuild -bp kernel.spec
4. Go to rpmbuild/BUILD/kernel version/kernel version
5. cp /boot/config-2.6.32-220… ./.config
6. Run make menuconfig

modify thoses variables because I need pseudo tty

CONFIG_UNIX98_PTYS=y
CONFIG_LEGACY_PTYS=y
CONFIG_LEGACY_COUNT=256
CONFIG_LOCALVERSION="-220.4.1.el6.x86_64"

7. run make –j8 rpm

8. rpm –ivh new kernel locate in into /home/$USER/rpmbuild/RPMS/x86_64/kernel-version.x86_64.rpm

9. for 64 bit I ran mkinitrd /boot/initramfs-2.6.32-220.4.1.el6.x86_64.img 2.6.32-220.4.1.el6.x86_64

Re: How to minimize the initramfs while compiling kernel

Posted: 2012/03/01 13:17:57
by toracat
Your modules are big because they are not properly strip'ed. For details please see my blog [url=http://blog.toracat.org/2009/03/strip-it-but-not-all-of-it/]Strip it[/url].

Your steps 1 to 6 are just fine. Then I highly recommend you follow the instructions on this [url=http://wiki.centos.org/HowTos/Custom_Kernel]CentOS wiki[/url]. Everything will be taken care of when you're finished.