Kernel Debugging Using GDB & QEMU

The effect of a bug in the kernel is catastrophic and may lead to system crash. Kernel debugging is an important step for kernel developers to find out bugs or debugging kernel execution. Many developers use virtual machine while working on kernel level. QEMU is a famous virtualization tool among the kernel developers. In this tutorial we’ll learn kernel debugging using GDB and QEMU. We’ll use QEMU to run our guest kernel(the one to debug) and in the host machine we’ll run GDB which will connect to QEMU. I’ll use 32-bit Ubuntu-12.04 kernel in this tutorial. Continue reading “Kernel Debugging Using GDB & QEMU”

Writing Char Device Driver Part 2

This is the second part of our char device driver development tutorial. In part1, we learnt how to write a simple char device driver that supports read or write functions. We dynamically assigned a major number for our driver and using the assigned major, we manually created a device file in /dev directory. Continue reading “Writing Char Device Driver Part 2”

Writing Char Device Driver Part 1

In this post we’ll take our 1st step of writing a char device driver for Linux. In our previous post, which I would recommend you to read unless you already did, we created a very simple kernel module. Other than dumping some log message, it didn’t do anything fancy. In this post we’ll create a char device driver which creates a device file in /dev directory. We’ll also show how a user space program can read from or write to this device file. And finally we’ll modify it to reverse a string. We’ll name our device driver as “reversedev“. I also assume, by now you know how to compile and install a kernel module and how to test kernel log using dmesg command. If you don’t you definitely need to read this. Continue reading “Writing Char Device Driver Part 1”

Testing Slob Allocator

Linux Kernel hast three memory allocator named SLOB, SLAB and SLUB. SLOB allocator is the memory allocator that is used to allocate small amount of memory for Linux kernel objects. Linux kernel objects are different from user mode objects. So we can’t use a user mode application for testing SLOB allocator. For example, if we modify the algorithm used in SLOB allocator, we have to test it using some kernel module which can make memory request to our new SLOB allocator. Continue reading “Testing Slob Allocator”

Writing Linux Kernel Module

Writing Linux kernel module is a daunting task. This easy to follow, step by step guide will show us all the steps of writing Linux kernel module. Read this writing to learn about what is a kernel module.

This tutorial will be our starting point for writing Linux kernel module. For this one we won’t be using any real hardware. But gradually we’ll learn how to write a device driver for an actual hardware. Our approach will start from learning most basic module to advanced device driver. Continue reading “Writing Linux Kernel Module”

Linux Kernel Module

Kernel module is a piece of program which can be loaded or unloaded in the kernel dynamically. It is used to extend the functionality of the kernel without rebooting the system. When we attach a new hardware in our computer we have to install a device driver for it. Device driver is a kernel module which allows the kernel to communicate with the hardware device. Continue reading “Linux Kernel Module”