Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 138528 - genkernel does not append initramfs to kernel with --initramfs
Summary: genkernel does not append initramfs to kernel with --initramfs
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: genkernel (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Gentoo Genkernel Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-29 14:46 UTC by Eli Ben-Shoshan
Modified: 2008-06-26 17:49 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eli Ben-Shoshan 2006-06-29 14:46:32 UTC
According to "genkernel --help" adding an --initramfs is supposed to:

"Builds initramfs before kernel and embeds it into the kernel."

What seems to really happen is genkernel builds an _initrd_ in the form of an initramfs.

What is the difference you ask? 

An initrd has to be loaded by your bootloader ( grub in most cases ). In the 2.6 series of kernels, the initrd can be either a file with a filesystem on it ( usually ext2 ) or a set of cpio archives. The later is what genkernel does. It compiles all the pieces of the initrd, snarfs them up as gzipped cpio archives and then joins them all together.

An initramfs is actually a cpio archive jammed onto the end of the kernel image itself. This means no extra line in grub. There are also some differences in the name of the first program executed. In an initrd, it is linuxrc. While using initramfs it is actually init. genkernel already seems to account for this.

I would like to know if initramfs in an initrd is the expected behavior? If it is, how open are you guys to a patch that actually creates an initramfs? If it is not, then what am I doing wrong in my genkernel commandline:

 genkernel --debuglevel=4 \
           --debugfile=/var/tmp/genkernel.log \
           --no-color \
           --no-menuconfig \
           --no-save-config \
           --mrproper \
           --no-bootsplash \
           --no-gensplash \
           --no-install \
           --initramfs \
           --kerneldir=/usr/src/linux-2.6.17.1 \   --kernel-config=/etc/kernels/kernel-config-pentium4-pxe-2.6.17.1 
--no-mountboot \
--lvm2 \
--dmraid \
--disklabel \
all

Thanks.
Comment 1 Tim Yamin (RETIRED) gentoo-dev 2006-07-18 15:59:49 UTC
(In reply to comment #0)
> An initrd has to be loaded by your bootloader ( grub in most cases ). In the
> 2.6 series of kernels, the initrd can be either a file with a filesystem on it
> ( usually ext2 ) or a set of cpio archives. The later is what genkernel does.
> It compiles all the pieces of the initrd, snarfs them up as gzipped cpio
> archives and then joins them all together.

Correct; and we call this an initramfs... because there's nothing stopping you from taking the resultant .cpio.gz and jamming that onto a kernel image.

> An initramfs is actually a cpio archive jammed onto the end of the kernel image
> itself. This means no extra line in grub. There are also some differences in
> the name of the first program executed. In an initrd, it is linuxrc. While
> using initramfs it is actually init. genkernel already seems to account for
> this.

... and this is basically where we jam it into the kernel for you; in either case, if the destination kernel is 2.6 the flavour is an initramfs (i.e. cpio style, not loopback style); the difference between having the flag and not is whether it ends up getting stuffed into your kernel image or not.

> I would like to know if initramfs in an initrd is the expected behavior? If it
> is, how open are you guys to a patch that actually creates an initramfs? If it
> is not, then what am I doing wrong in my genkernel commandline:

You mean something that stuffs it onto the kernel? That's what --initramfs should exactly do...
Comment 2 Eli Ben-Shoshan 2006-07-19 07:32:23 UTC
> You mean something that stuffs it onto the kernel? That's what --initramfs
> should exactly do...

Thats my point. Adding --initramfs does not jam the cpio archive onto the tail end of the kernel that is built even if it is a v2.6 kernel.
Comment 3 Tim Yamin (RETIRED) gentoo-dev 2006-07-20 14:56:33 UTC
(In reply to comment #2)
> > You mean something that stuffs it onto the kernel? That's what --initramfs
> > should exactly do...
> 
> Thats my point. Adding --initramfs does not jam the cpio archive onto the tail
> end of the kernel that is built even if it is a v2.6 kernel.

Try with genkernel-3.4.0_pre3; if it still doesn't do what it claims it should <TM> then it's a bug and we need to fix that :)
Comment 4 Tim Yamin (RETIRED) gentoo-dev 2006-08-04 06:14:49 UTC
(In reply to comment #3)
> Try with genkernel-3.4.0_pre3; if it still doesn't do what it claims it should
> <TM> then it's a bug and we need to fix that :)

Try with 3.4.0 now that it's out, reopen bug if issues persist. Thanks.
Comment 5 Eli Ben-Shoshan 2006-08-29 09:01:13 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > Try with genkernel-3.4.0_pre3; if it still doesn't do what it claims it should
> > <TM> then it's a bug and we need to fix that :)
> 
> Try with 3.4.0 now that it's out, reopen bug if issues persist. Thanks.
> 

I have now tryed with genkernel 3.4.0-r1

pixie genkernel # genkernel --version
3.4.0

pixie genkernel # emerge -pv genkernel 

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] sys-kernel/genkernel-3.4.0-r1  USE="-ibm" 0 kB 

with the following cmdline:

genkernel --debuglevel=5 
--debugfile=/var/tmp/genkernel.log 
--no-color 
--no-save-config 
--clean 
--mrproper 
--no-gensplash 
--no-install 
--no-devfs 
--initramfs 
--kerneldir=/usr/src/linux-2.6.17.6 --kernel-config=/etc/kernels/kernel-config-pentium4-pxe-2.6.17.6 
--no-mountboot 
--lvm2 
--slowusb 
--disklabel 
--kernname=test-pentium4-pxe --kerncache=/var/tmp/genkernel/test-kerncache-pentium4-pxe-2.6.17.6.tar.bz2 --initramfs-overlay=/var/tmp/genkernel/local-initramfs-overlay --linuxrc=/usr/share/genkernel/pxe-x86/linuxrc
  all

Here are the things that it generated:

pixie genkernel # du -sk *test* initramfs-2.6.17.6 
881     System.map-test-pentium4-pxe-x86-2.6.17.6
1898    kernel-test-pentium4-pxe-x86-2.6.17.6
5521    test-kerncache-pentium4-pxe-2.6.17.6.tar.bz2
2783    initramfs-2.6.17.6

As you can see the initramfs is about 2.7M while the kernel is 1.9Mb. I don't think the initramfs is being jammed onto the end of the kernel. Is this the behavior that is expected?
Comment 6 Chris Gianelloni (RETIRED) gentoo-dev 2007-09-17 20:18:47 UTC
My apologies on this sitting for so long.  To answer your question, no.  The initramfs is supposed to be appended to the kernel, just as you expect that it should.
Comment 7 Andrew Gaffney (RETIRED) gentoo-dev 2007-09-17 21:12:50 UTC
There are a few problems with doing this.

If you build the initramfs first and then modify the kconfig to point to it, so that it's includes in the built kernel, you can't put kernel modules in the initramfs (not without building the kernel twice).

If you build the initramfs afterward, you have to modify the ELF headers of the resulting kernel binary, since the initramfs is appended to the DATA section of the binary (I believe).

Both of these solutions are problematic. For what the OP wanted to do, you don't really want/need a combined image, anyway. PXE only supports loading up to a 1MB kernel (iirc), which isn't enough for even the kernel itself. That's why we use PXE loaders such as pxelinux and grub's PXE loader. AFAIK, both of these have the ability to load an initramfs separate (I know pxelinux does, because I do it regularly).
Comment 8 Chris Gianelloni (RETIRED) gentoo-dev 2007-09-17 22:53:57 UTC
(In reply to comment #7)
> If you build the initramfs first and then modify the kconfig to point to it, so
> that it's includes in the built kernel, you can't put kernel modules in the
> initramfs (not without building the kernel twice).

Why?  Would the modules not work just fine if CONFIG_MODVERSIONS is set?

Is there something else causing an issue?
Comment 9 Andrew Gaffney (RETIRED) gentoo-dev 2007-09-17 23:59:53 UTC
The problem is that the initramfs is built before the kernel (and the modules), so it's not physically (or chronologically) possible to include the modules built with the kernel in the initramfs.

You can get around this with a bit of a kludge, though. First, you build the kernel and the modules. Then build the initramfs and include whatever modules you need. Then build the kernel a second time after modifying the kconfig to automatically include the initramfs, which contains the modules from the first run. The second kernel compile run shouldn't take very long, since you wouldn't have switched compilers and will still have all the .o files.
Comment 10 Chris Gianelloni (RETIRED) gentoo-dev 2007-09-18 18:51:32 UTC
I must be missing something here.  Why not build the modules first, then the kernel, with the same .config the whole way?  It is exactly what we do on --genzimage and it was how I had thought that this worked, but I haven't looked at the code recently and could be wrong.
Comment 11 Andrew Gaffney (RETIRED) gentoo-dev 2008-03-14 16:20:24 UTC
This is no longer an issue. I've just removed the --initramfs option in genkernel, and it's been replaced with the --integrated-initramfs option, which does what you expected --initramfs to do.
Comment 12 Chris Gianelloni (RETIRED) gentoo-dev 2008-06-26 17:49:40 UTC
OK.  This is resolved in genkernel 3.4.10, which is now in the tree and stable.