Kernel native compilation - ParabolaWiki

# Kernel native compilation

Note: This walkthrough was tested successfully against Parabola current in April of 2016. But certain packages, which the MATE live ISO does not install, need to be installed manually. A package list for "out-of-the-box kernel hacking" will be posted real soon now right in this wiki article.

## How to compile your own kernel real quick

Ideally, one would run

    makeworld

with the -march=native but without -mtune=native CPU settings (C++ compiler switch), which also are part of some kernel Makefiles accessible via make gconfig, then choose your CPU options.

We will start with an natively optimized kernel.

## dirtree hierarchy

- /var/abs/kernels/linux-libre-lts-knock/
- /home/yourself/build/kernel/linux-4.4/
- /home/yourself/build/kernel/srclinux/linux-4.4/

## recipe

- with octopi install abs and run abs in a Konsole (not the calculator abs though, but the arch build system ABS.)
- edit /etc/abs.conf so that you get the kernel sources too, i.e. remove the !
- rerun abs
- then find the PKGBUILD for some decent kernel under /var/abs
- copy that subdir to your build dir, preferrably /home/yourself/build/kernel/linux-4.1/
- run makepgk inside there
- This will download the kernel sources and make kernel and modules. This will take maybe 30+ minutes.
- then manually run sudo make modules_install so those will end up in /usr/lib for mkinitcpio to pick them up for the initial ramdisk to put in /boot/grub/grub.cfg
- The kernel Makefile will e.g. reside at /home/YOURSELF/build/kernel/lili-knok/linux-libre-knock/src/linux-4.4/Makefile

From there, you should later run

make gconfig

so you can set "native mode" (a cc compiler switch) under CPU settings of the kernel Makefile, or put it manually into the kernel Makefile.

- Assuming you built the kernel right under it's abs entry, for example in

/var/abs/kernels/linux-libre-lts-knock/my-build-subdir

then your kernel image will reside at:

    /var/abs/kernels/linux-libre-lts-knock/my-build-subdir/src/linux-4.1/arch/x86/boot/bzImage

to then be manually copied below /boot

- So we need a init-ramdisk, see mkinitcpio

## prepare and make initcpio

To obtain a fallback rescue image rich of driver modules, it is expedient to issue in the kernel src dir:

    modules_prepare    # Set up for building external modules
    depmod -a   4.4.5-1Altkern1    # or whatever you named the kernel - else you risk the dreaded WARNING: No modules were added to the image.
    make modules         # may take 1 hour or more on a laptop computer
    depmod -a   4.4.5-1Altkern1    # or whatever you named the kernel - else you may get a WARNING: No modules were added to the image.
    make modules_install   # which places the modules at /usr/lib/modules

it is furthermore expedient to write two text files that control mkinitcpio while generating a custom RAM-disk:

    custom1.preset
    custom1hooks.conf

with custom1.preset containing

    ALL_config="/home/YOU/AltKern/mki/A2-hook.conf"
    #
    #ALL_kver="/home/YOU/AltKern/mki/A2bzImage"
    ALL_kver="/boot/A2bzImage"    # saves the bother of copying Img manually
    #
    PRESETS=('Altkern2ps')
    Altkern2ps_config="/home/YOU/AltKern/mki/A2-hook.conf"
    #
    #Altkern2ps_image="/home/YOU/AltKern/mki/A2-RD"
    Altkern2ps_image="/boot/A2-RD"     #  dir used by grub

and custom1hooks.conf containing

    HOOKS="base      udev            autodetect modconf block filesystems keyboard fsck"

Use either udev XOR systemd. Omitting "autodetect" will generate a fallback image including modules which were not needed on the build machine itself. Run

    mkinitcpio -c  ./custom1hooks.conf     -p ./custom1.preset

Note: Any CLI parameters will not override the content of the above 2 files, i.e. --kernel 6.0-custom inserted would have no effect in the above CLI line - which may be a little bit of unexpected software behaviour.

## Errors

- The make target "install" tries to use LILO but Parabola usually is grub2 based, i.e. make install does not work here.
- make isoimage allegedly fails for lack of certs -- fix
- current mkinitcpio has a problem, some options don't work.
- -> Running build hook: [/usr/lib/initcpio/install/block] ==> ERROR: module not found: `zram' ... and all others
- more problems with mkinitcpio with pristine makepkg run
- "==> WARNING: No modules were added to the image. This is probably not what you want." Indeed. This happens because there is a problem with make modules_install - to fix it issue

    depmod -a   4.4.5-1Altkern1    # or whatever you named the kernel

- - in the kernel src dir and the dreaded problem is a goner.
- # make --keep-going V=2 modules # push ahead on errors regardless - but it will break modpost later on - so better not do it to begin with...

- # make allmodconfig # poor idea... better start with this Linuxkernel .config here
- # make allmodconfig # tries to compile as many modules as possible - this usually breaks at some stage of compilation
- # but never mind, use the "--keep-going" switch od make to encourage the CPU... ;-)

## Conclusion

A recompiled kernel & initcpio were created and booted up no problem. Don't forget manual depmod.

Categories:

- Kernel
- Software