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.
- 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
- Obtain the Linux Kernel sources and unpack them into the appropriate directory.
sudo chmod 777 /usr/src
git config --global user.email yourumbcemail@umbc.edu
git config --global user.name "Your Full Name"
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
- Make a modification to the kernel
- Compile the kernel
- Make sure you are in the correct directory:
cd /usr/src/project0
-
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.
-
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.
-
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 underLibrary 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) -
make bindeb-pkg
This is the command that starts the build process. It's gonna take a while!
For subsequent compiles, read below.
Clone instructions
You can fill in the information here to get the full commands. Or you can replace them yourself in the terminal.
/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. 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 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).
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.