Kernel native compilation
Contents
1 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.
2 dirtree hierarchy
- /home/yourself/build/kernel/linux-4.4/
- /home/yourself/build/kernel/srclinux/linux-4.4/
3 recipe
- with octopi install abs and run abs in a Konsole (not the calculator abs though, but the arch build system ABS.) ABS was replaced by asp.
- 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/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/my-build-subdir
then your kernel image will reside at:
/var/abs/kernels/linux-libre-lts/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
4 prepare and make initcpio
To obtain a fallback rescue image rich of driver modules, it is expedient to issue in the kernel src dir:
make 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
5 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... ;-)
6 Conclusion
A recompiled kernel & initcpio were created and booted up no problem. Don't forget manual depmod.