How to minimize the initramfs while compiling kernel

General support questions

How to minimize the initramfs while compiling kernel

Postby duchri66 » 2012/02/29 13:50:53

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
duchri66
 
Posts: 8
Joined: 2012/02/29 13:38:51
Location: Qc, Canada

Re: How to minimize the initramfs while compiling kernel

Postby TrevorH » 2012/02/29 15:16:11

Unpack your new initramfs in a temporary directory using

Code: Select all
zcat /boot/initramfs-whatever | cpio -idm


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.
User avatar
TrevorH
Forum Moderator
 
Posts: 9167
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

How to minimize the initramfs while compiling kernel

Postby toracat » 2012/02/29 18:08:46

It is indeed unusually big. Just curious how many kernel modules you have in your custom kernel. After unpacking, can you run:

Code: Select all
find . -type f -name *.ko | wc -l

On my unmodified EL6 system (x86_64), I get 289.
User avatar
toracat
Forum Moderator
 
Posts: 6696
Joined: 2006/09/03 16:37:24
Location: California, US

Re: How to minimize the initramfs while compiling kernel

Postby TrevorH » 2012/02/29 18:43:32

289 is how many I had before I used hostonly="yes" which dropped it to ~22 I think.
User avatar
TrevorH
Forum Moderator
 
Posts: 9167
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: How to minimize the initramfs while compiling kernel

Postby toracat » 2012/02/29 19:01:39

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 ...
User avatar
toracat
Forum Moderator
 
Posts: 6696
Joined: 2006/09/03 16:37:24
Location: California, US

Re: How to minimize the initramfs while compiling kernel

Postby duchri66 » 2012/02/29 19:56:42

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?
duchri66
 
Posts: 8
Joined: 2012/02/29 13:38:51
Location: Qc, Canada

Re: How to minimize the initramfs while compiling kernel

Postby toracat » 2012/02/29 20:44:39

The number of kernel modules is almost the same. Now I wonder if they are "big". Mine is:

Code: Select all
$ find lib -type f -name *.ko | wc -l
289
$ du -sk lib
34096   lib


So, the average is about 118 KB/module. What's yours?
User avatar
toracat
Forum Moderator
 
Posts: 6696
Joined: 2006/09/03 16:37:24
Location: California, US

Re: How to minimize the initramfs while compiling kernel

Postby duchri66 » 2012/03/01 11:53:49

mine is 918KB/module


[root@vmomni tmp]# du -sk lib
267296 lib
duchri66
 
Posts: 8
Joined: 2012/02/29 13:38:51
Location: Qc, Canada

Re: How to minimize the initramfs while compiling kernel

Postby duchri66 » 2012/03/01 12:19:31

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
duchri66
 
Posts: 8
Joined: 2012/02/29 13:38:51
Location: Qc, Canada

Re: How to minimize the initramfs while compiling kernel

Postby toracat » 2012/03/01 13:17:57

Your modules are big because they are not properly strip'ed. For details please see my blog Strip it.

Your steps 1 to 6 are just fine. Then I highly recommend you follow the instructions on this CentOS wiki. Everything will be taken care of when you're finished.
User avatar
toracat
Forum Moderator
 
Posts: 6696
Joined: 2006/09/03 16:37:24
Location: California, US

Next

Return to CentOS 6 - General Support

Who is online

Users browsing this forum: No registered users and 8 guests