Modify The Linux Kernel

Something should go here

published: 

For the 3rd task (this task) in The Eudyptula Challenge, we continue our work from the last challenge, compiling the absolute latest Linux Kernel from the source code. This time we focus on modifying the Makefiles and .config files that help us compile the kernel.

Before we begin, if you wish to work on The Eudyptula Challenge yourself before you read my notes (recommended), you can use my git repository, which has all 20 tasks and the code I used to complete each one.

Task No.3

Now that you have your custom kernel up and running, it's time to modify it!

The tasks for this round is:

  • take the kernel git tree from Task 02 and modify the Makefile to and modify the EXTRAVERSION field. Do this in a way that the running kernel (after modifying the Makefile, rebuilding, and rebooting) has the characters "-eudyptula" in the version string.
  • show proof of booting this kernel. Extra cookies for you by providing creative examples, especially if done in interpretive dance at your local pub.
  • Send a patch that shows the Makefile modified. Do this in a manner that would be acceptable for merging in the kernel source tree. (Hint, read the file Documentation/SubmittingPatches and follow the steps there.)

—Little Penguin

Depending on how literally we interpret "modifying the Makefile", there are multiple ways we can accomplish this challenge. One of which we briefly talked about in the last challenge was to override variables in our make command when compiling the kernel.

Override Directives

Just like with a lot of userspace projects, the Linux kernel uses GNU make to compile the various files into its final form. This means we can use make's ability to pass variable assignments as command line arguments.

From Chapter 6 of make's documentation, if we use a command line argument to set the EXTRAVERSION variable, then all other assignments to EXTRAVERSION within the Makefile will be ignored. For example, we can override EXTRAVERSION by using a make command like this:

$ make -j `getconf _NPROCESSORS_ONLN` EXTRAVERSION=-eudyptula

This will force make to set EXTRAVERSION to -eudyptula and ignore the value set in the kernel's Makefile, accomplishing our task for The Little Penguin.

Modify the Makefile

Our second option, if you want to take "modifying the Makefile" literally, is to do exactly that.

Simply open the kernel's Makefile, located in the root directory in the source code we copied from Linus in the last challenge, with your favorite text editor. The first five lines will have EXTRAVERSION somewhere in it. Change the value to -eudyptula and save.

-EXTRAVERSION = -rc1
+EXTRAVERSION = -eudyptula

Now that the kernel's Makefile will append -eudyptula to the kernel's version string by default, we can simplify our make command to build the kernel into:

$ make -j `getconf _NPROCESSORS_ONLN`

Modify menuconfig

Our third option and arguably the least accurate of the three ways to interpret "modifying the Makefile" is to use the ncurses configuration tool that we briefly talked about in the last challenge. I say this is the least accurate because this method modifies the CONFIG_LOCALVERSION variable and not the EXTRAVERSION variable, which will add -eudyptula to our kernel's version string, however not technically in the correct place.

We can start the ncurses menu with the following terminal command:

$ make menuconfig

where you should see a screen that looks something like this:

Something

From here, navigate to the General setup option and press ENTER to move into the next menu. Next, use the arrow keys to highlight the Local version option and press ENTER. A new menu will appear letting you enter a value.

Else

Type in -eudyptula and press TAB to move our cursor to the <OK> option and press ENTER to return back to the General setup menu. If everything went according to plan you should see "-eudyptula" set in the Local version menu:

else

From here, press TAB a few more times to move our cursor to highlight the <SAVE> option at the bottom. Then press ENTER to save the changes we made to our .config file.

After we've saved our changes press TAB a couple more times to highlight the <EXIT> option and ENTER to exit the ncurses menu.

Finally, with the changes to our .config file saved, we can re-compile our kernel with the same simpified command from above:

$ make -j `getconf _NPROCESSORS_ONLN`