01_Prerequisite - ned0000/Linux-kernel-notes GitHub Wiki
Update Linux system
I update the Ubuntu system to the latest version 19.04, so I can install the tools mentioned in this section with the latest binary package instead of building them from source code, this really saves my time and let me focus on kernel hacking.
For the update procedure, refer to the ubuntu website.
Install xwindow xfce4
I install xwindow as the machine emulator QEMU needs it. I'm suggesting xfce4 as the xwindow. The following command is used to install xfce4 on the Ubuntu system:
sudo apt-get install xfce4 xfce4-goodies
Install VNC server
The reason why I install VNC server is that I'm working with laptop connecting to the server with Ubuntu system, the server doesn't have display and even the mouse and keyboard. The following command is used to install vnc server on the Ubuntu system:
sudo apt-get install vnc4server
Setup VNC server password
Use following command to setup VNC server password. The password is required when using VNC viewer.
vncpasswd
Install machine emulator QEMU
The following command is used to install QEMU on the Ubuntu system:
sudo apt-get install qemu-system
Install VNC viewer
VNC viewer is installed to my laptop, so I can get GUI for xwindow and the guest OS.
Install compile tools
Gcc, gdb and other compile tools are required to build and debug kernel. Some tools may be also necessary and if I forget to mention them, we can easily install them with apt command.
Download kernel source
The following command is used to download kernel source:
sudo apt-get install linux-source
The kernel source code is installed at "/usr/src/linux-source-5.0.0.tar.bz2". Ubuntu 19.04 is based on the linux release series 5.0.
Build kernel image
Processor family
The processor type is x86-64. It's 64-bit kernel.
Generate config file.
make menuconfig
Load the kernel config file at "/boot/config-5.0.0-21-generic", make sure the following configurations are build into the kernel:
Kernel hacking -> Compile-time checks and compiler options -> Compile the kernel with debug info
Save the current configuration to .config file.
Build bzImage
Using following command to build bzImage file. Use '-j' option to speed up the building process. Here I'm taking 12 as number of simultaneous jobs because the number of cpu core on my Ubuntu server is 6.
make bzImage -j12
After build, the bzImage is located at following position:
arch/x86_64/boot/bzImage
The unzipped image file "vmlinux" is at the root of the kernel source code directory.
Generate tags file for editor
Use following command to generate TAGS file for Emacs editor. The size of the generated TAGS file will be about 170MB, so it will take a while for the generation process.
make TAGS