# pre-built kernels -- the gentoo way?

## adsmith

I manage many machines with nearly identical gentoo installations.  I use distcc to build once quickly, and then I use tbz2 binary packages and "emerge -k" to install everywhere -- basically I have my own little binary distribution.

There is only one thing lacking:

Is there a "gentoo way" (or at least a "sane way") to use a pre-built kernel?

I have considered using "make targz-pkg" in /usr/src/linux and manually un-tarring it on all machines, but this seems a little hackish somehow, especially since installed third-party modules may not build correctly, since the /usr/src/linux on each client would not contain the right config, headers, et cetera. (kernel gurus, am I right about this?)

Is there a better method than this?   

I am also somewhat loathe to write a new ebuild for each kernel version, but I suppose I could...

----------

## NeddySeagoon

adsmith,

For a binary kernel, you need only /lib/modules/`uname -r`/ and the bzImage file.

You want the bzImage under its name in boot.

If the kernel is monolithic, you don't need /lib/modules/`uname -r`/ as its empty.

How about tarring them up into a single tarball and writing a kernel-bin ebuild to untar them ?

----------

## Hu

The kernel Makefile supports the INSTALL_PATH and INSTALL_MOD_PATH variables to install the files into a temporary location, which may make it easier to install the files into a temporary location, so that you can tar them all up with a simple tar -c -f mykernel.tar -C /my/kernel/staging/area ..

----------

## adsmith

Both,

Yes, that was generally my original though.  I was hoping there was a better way.

What both you outline is exactly what "make targz-pkg" does in the standard kernel Makefile -- it just tars up everything that would come out of "make install" and "make modules_install", namely /boot/vmlinuz, /boot/config, /boot/System-map, and /lib/modules/ (all of these with version extensions)

So it looks like I do indeed have to write a kernel-bin ebuild to unpack the binary, and keep it up-to-date with my kernel version. 

NeddySeagoon,

That is technically correct, but I think (?) just the vmlinuz and modules are not enough for some purposes. What if I were to do something like "emerge nvidia-drivers lirc madwifi", where it builds/installs kernel modules and need to check that dependencies are set properly in /usr/src/linux/.config (really /lib/modules/$(uname)/build)? Based on my (possibly false) recollection, it will fail unless the .config is OK.  

Since the goal is to never really touch the /usr/src/linux directories on any client, such emerges may fail?  

Maybe I'm just being too picky, and I should make sure ALL potential 3rd party modules are pre-built on the build master.

----------

## dsd

genkernel might be able to help you here

----------

## adsmith

I thought genkernel still builds locally?

----------

## NeddySeagoon

adsmith,

If you use any 3rd party kernel modules, they are still put into /lib/modules/`uname -r`/....

After you have the binararies, the sources are no longer required.

You will have to do your own tarring to pick up the binaray 3rd party modules because make targz-pkg will only pick up offical kernel tree things.

As a minimum you need bzImage and /lib/modules/`uname -r`/ after all the 3rd party suff is installed.

System.Map is only needed for debugging

You may need /etc/modules.d/ as nvidia-drivers puts things there.

I'm not sure if you can make a binary package of nvidia-drivers that you can later use with emerge -K but I don't see why not.

That may be another option. Use make targz-pkg on the kernel and build binary packages of any 3rd party kernel additions.

----------

## adsmith

OK, so something like this should do it

```

# Distributed under the terms of the GNU General Public License v2

# adsmith's ebuild for installing pre-built kernels

DESCRIPTION="admith's pre-built linux kernel image"

HOMEPAGE="http://tock.no-ip.org"

MY_PVR="${PV}-suspend2-${PR}-adsmith"

## the prebuild binary of /boot/* and /lib/modules/* is at 

SRC_URI="http://tock.no-ip.org/portbin/linux-${MY_PVR}.tar.gz"

LICENSE="GPL2"

SLOT="0"

KEYWORDS="x86"

IUSE="nvidia madwifi lirc"

DEPEND="=sys-kernel/suspend2-sources-${PVR}"

PDEPEND="nvidia? ( || ( x11-drivers/nvidia-drivers 

                        x11-drivers/nvidia-legacy-drivers

                        )

                )

        madwifi? ( net-wireless/madwifi-ng ) 

        lirc? ( app-misc/lirc )"

src_unpack(){

   unpack ${A}

}

src_install(){

    cd ${WORKDIR}

    # move symlinks that doins cannot handle

    mkdir -p ${D}/lib/modules/${MY_PVR}

    mv -v lib/modules/${MY_PVR}/{source,build} \

        ${D}/lib/modules/${MY_PVR}/

    # remove useless uncompressed kernel image

    rm boot/vmlinux-${MY_PVR}

    # install everything else normally

    doins -r boot || die "could not install kernel into /boot"

    doins -r lib  || die "could not install kernel modules into /lib"

}

pkg_postinst(){

    einfo

    einfo "Please remember to update your grub.conf as appropriate!"

    einfo "This kernel is installed as /boot/vmlinuz-${MY_PVR}"

    einfo

}

```

EDIT: whoops, I forgot a src_install, so the ebuild was useless... more-or-less fixed now.

----------

