[arch-projects] [mkinitcpio] Build image into the kernel?
greg at kroah.com
Tue Aug 27 21:33:48 EDT 2013
On Tue, Aug 27, 2013 at 09:16:57PM -0400, Dave Reisner wrote:
> On Tue, Aug 27, 2013 at 03:39:20PM -0700, Greg KH wrote:
> > Hi all,
> > I was playing around with the kernel cpio image creation, and was
> > wanting to add an already-built cpio image to an already-built kernel
> > image.
> > Instead of writing yet-another-script to do this type of thing, I
> > noticed that mkinitcpio's documentation said that it supported this:
> > Support for the inclusion of the initial ramdisk image in a
> > kernel, thus making a self-contained kernel image possible.
> > But, I couldn't find this option anywhere in the tool.
> > Am I missing something here?
> This feature doesn't exist anymore. Rewind about 2 years, we used to use
> the gen_init_cpio program from the usr/ dir of the kernel tree. I
> suppose, based on Documentation/filesystems/ramfs-rootfs-initramfs.txt,
> that the input list for gen_init_cpio can be used during the kernel
> build to incorporate the initramfs into the image. mkinitcpio's -s
> option would stop the initramfs build prior to image creation, leaving
> behind this input list.
Ah, that makes sense.
> Sorry, it seems the wiki page was simply never updated to reflect this.
> We (ok, I did it) switched to using bsdcpio because it proved to be
> significantly more efficient and accurate.
> I'm curious about your idea to write a script which would incorporate
> the built initramfs into the bzImage -- I didn't realize such a thing
> was possible.
Yes, there is a kernel config option that asks for the cpio image to add
to the kernel image at kernel build time. This lets you do fun things
like where you only have to worry about the kernel image itself, and not
the initramfs, as some environments only let you do one thing (kexec,
some hypervisors, secure boot UEFI, pxeboot, etc.)
Right now the 3 step process of:
- build a kernel
- build a cpio image
- rebuild the kernel with the cpio image
is a pain, and one that a number of build systems really don't handle
As the cpio image is really just a byte stream in a special linked-in
section in the uncompressed kernel image, it "should" be possible to:
- uncompress the kernel image
- convert the cpio image to a bytestream
- strip out the existing cpio image from the kernel
- relink the kernel with the new cpio image
- recompress the kernel
But, I'll let you know if that turns out to be impossible :)
> If it's feasible to incorporate into mkinitcpio, I'd accept such a
> patch (or feature request with documentation on how to do this).
Ok, I'll take a look at using the mkinitcpio codebase to do this, as
it's a good of a place as any.
More information about the arch-projects