So, I decided to mess around with the Linux kernel a bit and thought, “Why not change the entry point address?” Just for kicks, you know? Here’s how I did it.
First, I grabbed the kernel source. I already had it downloaded, but if you don’t, you can find it on the internet. Then, I opened up the Makefile. This file is like the instruction manual for building the kernel.
In the Makefile, I found the place where they set the base address for the kernel. It was in a section called something like “x86 uImage target,” but it might be different depending on your setup. I changed that base address to what I wanted it to be, just a random address for fun.
Then I was like, “Okay, let’s build this thing!” So, I ran the make command with the new base address. It was pretty much just `make` but with a little extra telling it where to start.
While it was compiling, I did some digging around in the source files. I stumbled upon this file called head_64.S in the arch/x86/kernel/ directory. It looked important, and it seemed like that’s where the actual entry point was defined. This file, what it do is initialize the early page tables, it is so important.
After the compilation was done, I had to figure out how to boot this modified kernel. I tried a few different things, like messing with the bootloader settings, but honestly, it was a bit of trial and error. And I also searched some tutorials on the internet like this one “Learn the steps to install the latest Linux kernel version on Ubuntu 20.04 LTS Focal Fossa or Ubuntu 22.04 Jammy Jelly Fish to change the default using the command terminal.”
Eventually, I figured out a way to load the kernel at the address I specified. It was a bit tricky, but basically, I had to tell the bootloader where to find the kernel image and where to jump to start executing it.
The whole process was a bit messy, to be honest. Lots of trial and error, and a few headaches along the way. But in the end, I managed to change the entry point address of the Linux kernel and boot it up. It was a fun little experiment, and I learned a lot about how the kernel works under the hood.
This is my story about how to change the Linux kernel entry point address, I am so excited to do this kind of thing and share with you.