• Pl chevron_right

      Compiling and installing the Gentoo Linux kernel on emerge without genkernel

      pubsub.slavino.sk / planetdebian · Thursday, 28 January, 2021 - 09:45 · 1 minute

    Gentoo emerges of sys-kernel/gentoo-sources will nicely install the current kernel into /usr/src/linux-* but it will not compile them.

    The Gentoo wiki kernel documentation has a script snippet to automate the kernel build with genkernel .

    I do not like to use genkernel as it brings in lots of firmware files to build initrds that are not needed on virtual hardware. It also makes building the kernel slower.

    So, the plain approach:

    Make emerge sys-kernel/gentoo-sources symlink the latest kernel to /usr/src/linux so we can find it easily:

    echo "sys-kernel/gentoo-sources symlink" >> / etc / portage / package.use / gentoo-sources

    Create /etc/portage/env/sys-kernel/gentoo-sources with the following:

    post_pkg_postinst ( ) {
    CURRENT_KV =$ ( uname -r )
    unset ARCH
    if [ [ -f " ${EROOT:-/} usr/src/linux- ${CURRENT_KV} /.config" ] ] ; then
    cp -n " ${EROOT:-/} usr/src/linux- ${CURRENT_KV} /.config" " ${EROOT:-/} usr/src/linux/.config"
    cd " ${EROOT:-/} usr/src/linux/" && \
    make olddefconfig && \
    make -j5 && make modules_install && make install && \
    grub-mkconfig -o / boot / grub / grub.cfg
    fi
    }

    This will compile the next kernel on the basis of the config of the currently running kernel, install the modules and the kernel bzImage and update grub so it knows about the new kernel for the next reboot.

    If you forget to unset ARCH the Linux build system will complain like:

    Makefile:583: arch/amd64/Makefile: No such file or directory
    make: *** No rule to make target 'arch/amd64/Makefile'.  Stop.
    

    You can test the new magic by re-emerging the latest kernel, e.g. currently emerge =sys-kernel/gentoo-sources-5.4.80-r1 :


    Značky: #Debian

    • wifi_tethering open_in_new

      This post is public

      daniel-lange.com /archives/169-Compiling-and-installing-the-Gentoo-Linux-kernel-on-emerge-without-genkernel.html