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
  2. Obtain the Linux Kernel sources and unpack them into the appropriate directory.
    1. sudo chmod 777 /usr/src
    2. cd /usr/src
    3. git config --global user.email yourumbcemail@umbc.edu
    4. git config --global user.name "Your Full Name"
    5. git clone git@github.com:umbc-cmsc421-fa2020/project0-yourusername vanilla-project0
    6. 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 the repository you created when you accepted the assignment, into the folder /usr/src/project0. From now on, when we refer to "root directory" we mean this folder (/usr/src/project0).
    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.
  3. Make a modification to the kernel

    This is where you will be doing your first modification to the Linux Kernel. You will need to change the version of the kernel, to include your own username. 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 and Linux Kernel in a Nutshell

    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 instructions we have provided in this website.
  4. 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 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)

    4. make localmodconfig

      If you get any prompts here you can just hit enter and accept the defaults

    5. make deb-pkg

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

      Only run this the first time you compile a version of the kernel. For subsequent times, 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 and make -jn deb-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.