Link Search Menu Expand Document

Building the Kernel

In the section, you will obtain a copy of the Kernel’s source then compile it for yourself to get familiar with the process. The first time you compile will take quite a while. The compilation alone can easily take up to 1 hour! It is assumed that you have followed all the instructions up to now, including all the required reboots.

The instructions here are using project0 as an example. You should be able to replace the references to project0 with any other project. It also means that you should have accepted the project assignment through Piazza before proceeding.
  1. Install the require software packages for kernel development sudo apt-get install build-essential qt5-default qtcreator valgrind nano patch diffutils curl fakeroot git pkg-config gedit libssl-dev libncurses5-dev libelf-dev bison flex bc dkms rsync cmake clang-format
  2. Obtain the Linux Kernel sources and unpack them into the appropriate directory.
    1. sudo chmod 777 /usr/src
    2. git config --global user.email yourumbcemail@umbc.edu
    3. git config --global user.name "Your Full Name"
  3. Clone instructions

    You can fill in the information here to get the full commands. Or you can replace them yourself in the terminal.

    You can obtain a copy ready for your project with the following steps:
    • cd /usr/src
    • git clone git@github.com:umbc-cmsc421-sp2021/linux.git vanilla-project0
    • cd vanilla-project0
    • git remote remove origin
    • git remote add origin git@github.com:umbc-cmsc421-sp2021/project0-.git
    • git push origin main
    • cd /usr/src
    • cp -ra vanilla-project0 project0
    What we did here is configure git with your email and name. You only need to do this once. We then cloned a template repository, containing the source to the kernel, into the folder /usr/src/project0. This makes a copy of the code that is in that repository to your local machine. We then pushed that code to the repository you created when you accepted the assignment. From now on, when we refer to "root directory" we mean this folder (/usr/src/project0). Naturally, when we are talking about project1 it will refer to the project1 directory and so on.
    If the git clone command returns an error message about the repository not existing or you not having permission to access it, then make sure that the repository has been created (that is to say that you clicked on the link on the project assignment on Piazza and that your repository has correctly populated), that you have correctly created and added your SSH key to GitHub, and that you are not trying to run the command as root. Finally the command will fail if you didn't change the remote as the instructions say above.
  4. Make a modification to the kernel
  5. This is where you will be doing your first modification to the Linux Kernel. You need to change the version string of the kernel, to given it a unique name, including your own username. You will not find this version online, and you will not be modifying the currently installed kernel. You need to modify the top level Makefile in the source code you just obtained. So from 5.5.0 you will have to change it to 5.5.0-cmsc421project0-USERNAME, where USERNAME is your UMBC username. We have some resources that might help: Compiling a Kernel, Kernel Rebuild Guide

    You are NOT to follow any instructions in those links. Yes, that means you still have to read the articles themselves. Those links will help you figure out how to do the version change. You should be following the compilation and build instructions we have provided in this website.
  6. Compile the kernel
    1. Make sure you are in the correct directory: cd /usr/src/project0
    2. make mrproper

      This command will reset the kernel build artifacts to a "clean" state. It will NOT affect any of the files you have changed.

    3. make localmodconfig

      This command will grab some config specific to your VM and add it to the configuration. You can just hit enter on everything to accept the defaults. Depending on your real hardware you might have to do that a few times.

    4. make xconfig

      You have to enable two options here. One of them is under File Systems > CD-ROM/DVD Filesystems > ISO 9660 CDROM file system support, and the other one is under Library routines > CRC32c (Castagnoli, et al) Cyclic Redundancy-Check. To enable them you have to make sure there is a checkmark next to them so they are built-in to the kernel. A dot is NOT enough, make sure it's a checkmark. For the ISO 9660 support, you can also enable the two options under it (The Microsoft extensions and the decompression one)

    5. make bindeb-pkg

      This is the command that starts the build process. It's gonna take a while!

      For subsequent compiles, read below.

    You only need to run all of these steps once. After you have been through them, you can compile the kernel with running make bindeb-pkg alone (i.e no make mrproper or anything).

    If you have given your VM more than 1 core, you can change the builds commands to make -jn bindeb-pkg, where n is the number of cores you have given to your VM. If you are unsure how many you configured you can replace n with `getconf _NPROCESSORS_ONLN` (note the ` they are important).

    If there were no errors and the build reports that it finished successfully, you should be able to find the compiled kernel in /usr/src. You should check what files exist in there (either through the terminal with ls, or with a GUI application). There should be a file named linux-image-5.5.0-cmsc421project0-USERNAME+_5.5.0-cmsc421project0-USERNAME+-1_amd64.deb in there. Where USERNAME is your UMBC username. Make sure you check the names very closely. If the names do not match it means you did not properly change the version string. You can also disregard the +-1 at the end. That number will increase every time you compile.