/Ubuntu-20.04-Kernel-Setup-Instructions

A basic guide on how to install and setup kernel to completing a syscall

Stargazers Issues

   

Chicken1

Mr.ChickenCombo's Guide to Kernel Setup

An great guide towards making your own personal Kernel on Linux!
Explore the docs »

Home · Report an Issue · Ubuntu Error Wiki

Ubuntu-20.04-Kernel-Setup-Instructions

A basic guide on how to install and setup kernel to complete a syscall (Note: This guide is fully complete. If you see anything that needs to be emphaisized or changed add a comment )

Indirect Contributors: @DanTheMan#1494 , @Aturasu#8710

Table of Contents
  1. Setup for VM
  2. After you Install Ubuntu
  3. Recommend Optional Steps to Fix Screen
  4. Terminal Stage
  5. Making a Syscall Successfully
  6. Summary

Setup for VM

-Install Ubuntu 20.04 from https://ubuntu.com/download/desktop?version=20.04&architecture=amd64

-Open virtual box and Select Linux ubuntu 64

-Video Memory set to 3010

-Create a virtual hard disk

-Pick VDI

-Pick Dynamic Allocation

-Allocate at least 25GB to it

-Go to storage on VM click disk icon and pick "choose disk image file"

-Insert the ISO file ubuntu 20.04

-Power Up VM

-Pick ubuntu 20.04

After you Install Ubuntu

-Click install Ubuntu

-Click next on all default options including erase disk option

-After Instalation finishes make note of your root password(dont forget it)

-Log In to Ubuntu

-Go to https://www.kernel.org/ on firefox

-Download stable or longterm version kernel

-Drag the zipped file into Documents from recent

-Right click and click "extract here"(give it a min or 2 to fully extract all files)

Recommend Optional Steps to Fix Screen

These steps are to fix your screen size resolution and to make things easier

-Click devices

-Select "Insert Guest Additions CD"

image

-Click "Run"

-Type in your root password when Prompted

-Click Enter

If nothing pops up to run use this in your terminal

sudo apt-get install virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11

-Click "Devices" then "Shared Clipboard"

-Select "Bidirectional"

-Close VM and select "power off" or "send shutdown signal"

-Power on VM to see changes

-Select "View" -> "Virtual Screen1" -> Choose whatever resolution you want

Terminal Stage

-Go to apps click or search for settings->power->set power saving to never (this will keep VM from sleeping)

-Right click in the extracted Kernel file and select "open in Terminal"

image

Run

cp -v /boot/config-$(uname -r) .config

Run

sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev

Run

scripts/config --disable SYSTEM_TRUSTED_KEYS

~MAKE SURE KEYS ARE REVOKED:==================================

go into the .config file using,

sudo nano .config

Type this to activate search

ctrl+w

and then search for

SYSTEM_REVOCATION_KEYS

Set ="debian/canonical-revoked-certs.pem" to this =""

Then do

ctrl+s

to save file. Then do the following below to leave file editor.

ctrl+x

===================================================================

Run ->If you get an error stretch terminal screen a then rerun command

make menuconfig

->Click enter on general

->set local version to your first and last name(no spaces) EX: JohnDoe.config

->Click exit(Use Tab button on keyboard)

->Click Enter on "Binary Emulations"

->turn off 32x abi for 64 bit mode by clicking "N" on it (should be second option)

->save as .config then exit the GUI

Run

make bzImage -j 4

Run

make modules -j 4

[optional]Run

sudo apt install binutils

Run

sudo make -j 4

Run

sudo make modules_install -j 4

Run

sudo make install -j 4

Run

sudo update-grub

Run -> change timeout to -1

sudo nano /etc/default/grub file

Run

sudo update-grub

Run

reboot

-When it finishes booting go to "advanced Ubuntu Options" and select kernel with your name to boot up

-You can run the command below to ensure you booted the right kernel. It should have your name or whatever you named the .config file

uname -r

Making a Syscall Successfully

-Make sure your inside your booted kernel

-Start out by going into the kernel folder directory

image

-Write to a new C file using the following

nano -w nameOfFile.c

-Type some code for the C file and be sure to add at the top of it

#include <linux/syscalls.h>
#include <linux/printk.h>

-In the kernel folder directory edit the Makefile

nano Makefile

Add nameOfFile.o to the end of this line in the file image

Save the file

ctrl+s

-Go to the linux-5.14.2/arch/x86/entry/syscalls directory path and edit the files syscall_32.tbl and syscalls_64.tbl

NOTE: use TAB since these files don't support spaces

In the 32x file go to the bottom and add the proper formatting like so image

In the 64x file go to the bottom and add the proper formatting like so image

-Navigate back to kernel directory then run

sudo make kernel/mycall.o

-Now navigate back to the base kernel directory linux-5.14.2[or whatever version you have] and run

sudo make -j 4

-When that finishes run

sudo make install -j 4

-When that finishes run

reboot

-When Ubuntu loads back up select a file outside of your kernel folder (ie downloads or desktop for example) and write to a new C file

nano -w secondFile.c

-Add some code to the file using this format at the top. For the arguments add the integer of the line added in the 64x.tbl file

#include <unistd.h>
#include <linux/kernel.h>
#include <sys/syscall.h>

-Save and exit the file with

ctrl+s ctrl+x

-Run in the terminal your second C file

gcc secondFile.c

-Run in the terminal your output file

./a.out

-Run this command to see syscall logs as well as your syscall

sudo dmesg

Your Done Congrats! Easy wasn't it?

No message Popped up! If it didnt work try redoing sudo make, there is a possibility that your computer may have sleep and inadvertenly stop the download. If errors appeared in the log or at any point check here Ubuntu Error Wiki

Summary

Hopefully this helped you set up the VM and kernel properly. If you do find issues please let me know via comments or commits. This guide was intended for new Linux users who want to know how to build a kernel on Ubuntu as well as a reference for me if my VM ever gets corrupted.

Jokes Card