Package: kernelmaker
KernelMakerAutomate building and updating your custom kernel with ease. KernelMaker can automatically detect and fix common errors, like unknown pgp keys orpkgbasein a URL.It's already not that hard but I'm lazy and don't want to manually sift through files every time, so I wrote this. :3Installingpython3-mpipinstallkernelmaker
python3-mkernelmaker--helpEasy.UsageMy workflow using this tool is the following:There exists a folder,~/build, that contains config overrides and patches:build
├── configs
│   ├── vivepro2-configs
│   ├── apparmor-enable
│   └── perf-configs
└── patches
    └── OpenRGB.patchAny time I feel like updating to the latest kernel, I runkernelmaker:cd~/build
python3-mkernelmaker\linux-hardenedlinux-custom\-d"Custom kernel based on linux-hardened"\-cconfigs-ppatches\--use-modprobed-db--makepkg-flags="-sCfL"After that finishes I just install the new kernels:pacman -U linux-custom-*
# in case this is a new kernel, repopulate grub.cfg
grub-mkconfig -o /boot/grub/grub.cfgIn actuality I have this all in a shell script, but, y'know.Just wanna do it yourself, for curiosity or paranoia's sake?The script really is quite simple, most of the lines of code are value type checks and the like. If you already know what you want, go ahead and do it yourself:If you don't much care to keep the build files around after generating your new custom kernel, you can make a temporary directory in RAM (/tmp) to make things faster:tmpdir = $(mktemp -d)
cd tmpdirNote that/tmpis cleared when you shut down or reboot, so any customization will be lost.(Alternatively, just use the folder of your choice, and it'll be saved just fine.)Downloading the kernel build filesYou'll need to have theextra/devtoolspackage installed to use pkgctl and make.First, The base kernel config files can be downloaded:# change 'linux' to the kernel of your choice, e.x. linux-hardened or linux-zenpkgctlrepoclone--protocol=httpslinuxcdlinuxThis should result in a directory tree like the following (the top-level directory has the name of the base kernel):linux
├── config
├── keys
│   └── pgp
│       ├── 647F28654894E3BD457199BE38DBBDC86092693E.asc
│       ├── 83BC8889351B5DEBBB68416EB8AC08600F108CDF.asc
│       └── ABAF11C65A2970B130ABE3C479BE3E4300411886.asc
└── PKGBUILDDon't worry about thekeysfolder. The two files to edit arePKGBUILDandconfig.Setting new kernel name and descriptionThe file that configures the metadata of the package is thePKGBUILDfile.ThePKGBUILDfile will have lines near the top that should look something like:pkgbase=linux# <-- EDIT THIS ONEpkgver=6.6.9.arch1pkgrel=1pkgdesc='Linux'# <-- AND THIS ONENote the two lines with comments,pkgbaseandpkgdesc. You can,and should,edit them. (If you know what you're doing, go ham. Edit what you want.)Note that the pacman package name and kernel name (in e.x. neofetch) will be whatever is inpkgbase. This is why you should change these values -- if you make a fancy shiny new kernel, but don't change the name fromlinux, it'll be replaced as soon as there's a new kernel release by the base kernel. All your changes and custom configuration will be lost.Disabling docsA large chunk of the compilation time will be just generating documentation. It's pretty safe to skip these.Further down in thePKGBUILDfile you'll probably find the following:build(){cd$_srcnamemakeallmakehtmldocs# <-- COMMENT THIS LINE}Same applies here:pkgname=("$pkgbase""$pkgbase-headers""$pkgbase-docs"# <-- COMMENT THIS LINE)Main configThe main config file (named, well,config) is where the kernel configuration parameters are. Most values are a simpleyorn, ormto install it as a module, or a specialis not setwith that line commented. Some are a little more, but those are mostly names, descriptions, lists of modules, etc. Nothing too exquisite.A sample from the linux-6.6.9 kernel, more specifically the kernel hz regulators:# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
CONFIG_HZ_300=y
# CONFIG_HZ_1000 is not set
CONFIG_HZ=300
CONFIG_SCHED_HRTICK=yIf you're curious about what the current kernel is using asconfig,zcatit to a file or file viewer, orzgrepthe key you're looking for:zcat/proc/config.gz|most
zgrep"CONFIG_SCHED_HRTICK"/proc/config.gzThis DOES have to bezcatandzgrep, not just regularcatorgrep, because it's a gzip-compressed file. You could also cat it into gunzip and cat/grep that, but you do you.Patch filesSometimes it may be useful to apply a patch file, like in the case of theOpenRGB .patch filefor certain motherboards. This is as simple as placing them in the base kernel directory, and makepkg will detect and apply them:linux
├── config
├── keys
│   └── ...
├── OpenRGB.patch
└── PKGBUILDCompilation and installationOnce all your changes are made, patches in place, etc etc, runupdpkgsumsandmakepkg.NOTE THAT YOU SHOULD NOT BE THE ROOT USER TO COMPILE THE KERNEL. DOING SO WILL CAUSEmakepkgTO ERROR AND THINGS MIGHT BREAK.Note thatupdpkgsumswill download the base kernel source code; what you downloaded before, withpkgctl, was just the configuration files.updpkgsumsI usually use the following makepkg flags, although-swill do just fine. If you wish to use all available cores to compile with, use-j ${nproc}as your makeflags; otherwise, put the number of cores you want to use. If you don't want to know how long the compilation took, just remove thetime envpart of the second line.exportMAKEFLAGS="-j 8"timeenvmakepkg-sCcfLTo install the packages once they're built, install them with pacman (might need to usesudofor this):pacman-U<KERNEL_NAME>-*# ex: pacman -U linux-custom-*Make sure both the kernel AND headers packages get installed. Just the headers means you won't be using the custom kernel, and just the kernel means you won't be able to compile any packages for your kernel.If pacman doesn't automatically do it, you'll need to refresh your bootloader with the new kernels to use them, e.x. forgrub, run:grub-mkconfig-o/boot/grub/grub.cfg...to re-detect the new kernels in/bootand add them as entries.