Thursday, 26 December 2013

OS ASSIGNMENT- kernel module

                                                    OS ASSIGNMENT
                                                                                                                                 - GAJJAR PREMAL

Hello, kernel module:
Reference: The Linux Kernel Module Programming Guide

1. Find out the right kernel headers package matching your running
kernel [Hint: use uname −a]
If the kernel headers are not installed on your machine then use sudo aptitude
install linux−headers−‘uname −r'
 or equivalent command to install them.

2. Make a directory to store your "Hello, world!" kernel module:
mkdir hello−lkm && cd hello−lkm

3. In hello−lkm directory, write a hello−1.c.
(See The Linux Kernel Module Programming Guide chapter 2 for details.)

4. Write a Makefile

5. make
make
If everything went ok, there should be a hello−1.ko
file in your hello−lkm directory.

6. Install the module into the running kernel
sudo insmod hello−1.ko

7. See if it’s running
lsmod | grep hello
Does it show up? Then you can see "Hello,world!" here:
dmesg | tail

8. Now, you can remove this useless module from the kernel by:
sudo rmmod hello_1

9. See if it’s removed:
lsmod | grep hello
And you should see "Goodbye, world!" here:
dmesg | tail

Now answer these questions:

1. What’s a kernel module?

Ans:
Modules are pieces of code that can be loaded and unloaded into the
kernel upon demand. They extend the functionality of the kernel without the
need to reboot the system.
For example, one type of module is the device driver, which allows the kernel to
access hardware connected to the system.
Without modules, we would have to build monolithic kernels and add new
functionality directly into the kernel image. Besides having larger kernels, this
has the disadvantage of requiring us to rebuild and reboot the kernel every time
we want new functionality.

2. How do modules get into the kernel?

Ans:
using command
>sudo insmod hi.ko
here. Insmod is for install loadable kernel module

3. How do you know a kernel module is loaded?

Using command
> lsmod
hi is the module name

4. How do you know a module is working properly or not?

To know a module is working or not....
open second terminal
and type
>dmesg

5. How do you unload a module?

Using command
>sudo rmmod hi.ko
>dmesg // for check in second terminal

6. What’s the major problems you met in this section?
And how did you solve (or try solving) them?

Ans:
i have face problem in creat Makefile
obj−m += hello−1.o
all:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
clean:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean

No comments: