Part 1 (2.0 Points) : Build The Linux Kernel
Part 1 (2.0 Points) : Build The Linux Kernel
Submission:
- A report describes clearly how did you solve problems
- All programs (in both kernel-level codes and user-level codes for testing) with comments (DON’T
ZIP the files)
*** Note: At the first step, it will be better if you install an old version of OS kernel. Then, the process
of building a new Linux kernel will be clear
Download a new kernel from https://www.kernel.org/ (e.g., 5.19) and extract the source:
Do not change anything. Press ESC to save and exit the configuration menu. The configuration file will be
generated.
Troubleshooting: Run command: # sudo apt-get install libelf-dev to install libelf-dev package.
The fix: use nano .config, Ctrl+W to find the lines with 'debian/canonical-certs.pem' and delete them, then
use Ctrl+O to save and Ctrl+E to exit.
Fix: Use command # sudo apt install dwarves to install dwarves package.
Run # make and # make bzImage commands before running # make_modules to avoid unpredictable errors.
F. REBOOT VM
1. Reboot to the new kernel
# reboot
2. After boot, check if you have the new kernel:
# uname -r
You will see something like: 5.19.0
PART 2 (1.5 points): ADD A NEW SYSTEM CALL INTO THE LINUX KERNEL
We add a simple system call helloworld to the Linux kernel. The system call prints out a “Hello! My name
is XXX” message to the syslog (XXX is your student name and your student ID). You need to implement the
system call in the kernel and write a program at the user-level to test your created system call.
I – PREPARATION:
1. # sudo -i
2. Update my OS: # apt update && apt upgrade
3. Download essential packages:
$sudo apt-get install -y gcc libncurses5-dev make wget
$sudo apt-get install -y gcc libssl-dev
$sudo apt-get install bison
$sudo apt-get install flex
$sudo apt-get install libelf-dev
$sudo apt-get install dwarves
$sudo apt-get install zstd
$sudo apt-get install dkms
$sudo apt-get install vim
4. Clean up installed packages: # sudo apt clean && sudo apt autoremove
5. See current kernel version: # uname -r
You will see something like: 5.19.0-69-generic
6. Download kernel source code with higher version than current kernel:
# wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.19.tar.gz
7. Extract the source code of the downloaded kernel: # tar xvzf linux-5.19.tar.gz
8. Reboot my computer.
II – CREATION:
1. Move to directore linux-5.19: # cd ~/linux-5.19/
2. Create a directory named hello and change the directory to hello:
Lecturer: Lam Nhut Khang
15
CT104H – Operating System
# mkdir hello
# cd hello
3. Create a new file hello.c and write the following code in the editor:
# nano hello.c
Find to line
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
core-$(CONFIG_BLOCK) += block/
Then add the hello directory at the end
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
core-$(CONFIG_BLOCK) += block/ hello/
6. Add the system call (sys_hello()) to the kernel’s system call table.
Open the table with the following command:
cd arch/x86/entry/syscalls/
nano syscall_64.tbl
Add code:
451 common hello sys_hello
8. Scroll to the bottom of the page and add a line of code above the #endif line:
asmlinkage long sys_hello(void);
III – INSTALLATION
Create configuration file. Make sure the current path is at ~/linux-5.19/
# make menuconfig
# make -j4
# make modules
# make modules_install
# make install
# update-grub
Reboot my computer
IV - RESULT
1. Return to root directory
$ cd ~
$ nano report.c
4. Run the command $ dmesg and check the last line of the output:
Implement a print_self system call such that this system call will identify the calling process at the user-level
and print out the Process id, running state, and program name.
HINT: https://linuxgazette.net/133/saha.html
I – PREPARATION:
1. # sudo -i
2. Update my OS: # apt update && apt upgrade
3. Download essential packages:
$sudo apt-get install -y gcc libncurses5-dev make wget
$sudo apt-get install -y gcc libssl-dev
$sudo apt-get install bison
$sudo apt-get install flex
$sudo apt-get install libelf-dev
$sudo apt-get install dwarves
$sudo apt-get install zstd
$sudo apt-get install dkms
$sudo apt-get install vim
4. Clean up installed packages: # sudo apt clean && sudo apt autoremove
5. See current kernel version: # uname -r
You will see something like: 5.19.0-69-generic
6. Download kernel source code with higher version than current kernel:
# wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.19.tar.gz
7. Extract the source code of the downloaded kernel: # tar xvzf linux-5.19.tar.gz
II
II– CREATION:
8. Move to directore linux-5.19: # cd ~/linux-5.19/
9. Create a directory named print_self and change the directory to print_self:
# mkdir print_self
# cd print_self
10. Create a new file print_self.c and write the following code in the editor:
# nano print_self.c
Find to line
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
core-$(CONFIG_BLOCK) += block/
Then add the print_self directory at the end
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
core-$(CONFIG_BLOCK) += block/ print_self/
Save and exit the editor.
11. Add the system call (sys_hello()) to the kernel’s system call table.
Open the table with the following command:
cd arch/x86/entry/syscalls/
nano syscall_64.tbl
Add code:
451 common print_self sys_print_self
13. Scroll to the bottom of the page and add a line of code above the #endif line:
asmlinkage long sys_print_self(void);
III – INSTALLATION
Create configuration file. Make sure the current path is at ~/linux-5.19/
# make menuconfig
# make -j4
# make modules
# make modules_install
# make install
# update-grub
Reboot my computer
IV - RESULT
1. See current kernel version: # uname -r
$ gedit Part5.c
Write some code in this file like this:
2. Run the command $ dmesg and check the last line of the output:
Example: the number of processes provided by a user is n=3. Then, the user provides parameters of
processes as 1 0 2 1 3 2 2. The output of the program will be as following:
3. gedit TruongB2111965.c
Write code like this: