I suppose it’s unsurprising that the build process for Linux is a very moving target. Most projects you can just do make
then make install
and things just kinda work. Building the Linux kernel seems to be ever so slightly more complicated.
Note: I am not a Linux expert, C++/Rust/ASM/C/whatever expert, make
expert, or any anything expert. This isn’t guaranteed to be perfect or proper.
The process seems to boil down (as simply as possible) to this:
Use a Linux OS (I’m using Ubuntu in the Windows WSL).
Make sure you’ve got the latest catalogs
sudo apt update && sudo apt full-upgrade
Install the necessary software and libraries (THIS seems to evolve a LOT… I’ll try to keep this line updated)
sudo apt-get install git fakeroot build-essential \ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison
Make sure your git ssh keys are properly installed. If you’re not familiar and don’t have existing keys, do this (if you do have keys, you should know what to do)
ssh-keygen
Clone the repo (yup, going straight to the source)
git clone git@github.com:torvalds/linux.git
Change to the directory (yeah, I’m being that guy)
cd linux
Decide what platform you want to build for in the arch folders. You should find files in this general structure:
arch/<architecture>/configs/<something-config>
Run the build:
make all KCONFIG_CONFIG=arch/<architecture>/configs/<something-config>
Answer all of the questions (I just held down Enter to accept the defaults).
Have lunch (or a coffee, depending on how fast your machine is).
Do what you want with your resulting kernel, which should be here:
arch/<architecture>/boot/bzImage
This bzImage
file is the compressed kernel and should be usable wherever a kernel loader loads a kernel (or a woodchuck chucks). I was tinkering with it as the loader for the Windows WSL itself (with the right config, the 6.5 kernel loads WSL just fine, apparently), which feels very chicken-and-egg, and this was the most basic “it just works” I could come to.
As I mentioned, I’m not claiming to be an expert here. I’d even say I’m aspiring for novice. But it worked, so I’m happy with it.
To other aspiring novices: Try this. Poke through the code. Learn some stuff. Have some of those “Ohhhh… That’s how OS’s do that!”. Give yourself the chance to “get” something new… even if you’re not going to build a Linux variant, it’s still fun to see how the gears work. :)