Jumat, 16 November 2018

Kernel ProgrammingHello World using Ubuntu in a Virtual Box 1

Kernel ProgrammingHello World
Assalam Alaykum! This is Abdulrhman, a student
from King Faisal University I am currently taking Operating System course that interests me so much because of
my excellent professors, Dr. Khaled Rajab and Dr. Shakeel. This is to record
an explanation of everything
that I did to answer the Bonus Work
for this course.

First, I visited www.Virtualbox.Org/wiki/Downloads to download the virtual box
from Oracle and installed it
in my computer. Next, I visited
www.Ubuntu.Com/download/desktop to download ubuntu 17.10
Which I plan to install in my virtual box. In my early research,
I found out from several threads that the 32-bit Ubuntu works well with Virtual Box. However, after visiting the site and knowing
that the latest version has only 64-bit for Desktop, I decided to download and install
an earlier version, the 16.04.03.

I found an ISO file from http://releases.Ubuntu.Com/16.04/
After installing Virtual Box in my Windows 10 and Ubuntu in Virtual Box. I started with my kernel programming Lets start Ubuntu. Lets open terminal application
Lets list all the files. Lets create Modules directory.

This is where we will save our files for Kernels
Hello World. Lets change our directory to Modules
Lets start kernel programming by creating a C source code file using nano editor. We will name it AboodeSaysHello.C
The header files we need for kernel programming are init, kernel and module. We will define information such as license,
author and description for our code.

We will create static functions hello_init
and hello_exit that will be called when module initializes and when it exits. Printk is a command that is similar to Cs
printf. KERN_INFO is a soft display of text, while
KERN_ALERT is loud as you will see it later in red color. Lets declare the 2 functions for module_init
and module_exit Save the file and exit from nano,
Before we create the Makefile, lets try to know the kernels directory by typing
uname-r.

We will need this later. Lets create a second file, the Makefile
which is used as a map for C programs compilation and works with the make utility. This line tells where to point for the source. This is the kernel directory.

Remember this name when we typed uname
-r ? Pwd tells where you are in the file system. Make sure to use tab not space when indenting. This line cleans up all files. Save the file and exit from nano,
Lets run make.

Lets look at the new files created. Do you see AboodeSaysHello.Ko? That is our module file. Lets look at the current modules by using
lsmod. Notice that our file AboodeSaysHello
is not listed.

Lets insert AboodeSaysHello.Ko by using
super user do and the insmod command To see if our module has been added, lets
list the modules again. Did you see AboodeSaysHello now? Since its already added, lets see how
it works by using dmesg command. Do you see our initial message? Well done. Lets look at its information by using
modinfo Finally, remove our module by using sudo and
rmmod.

Lets see how it works again by using dmesg
command. Do you see our exit message? Thats a simple application of kernel programming
and is a good start to learn more about the many functions in OS. I surely learned a lot from this course. Thank you for listening..

Tidak ada komentar:

Posting Komentar