explaingit

sysprog21/lkmpg

8,465TeXAudience · developerComplexity · 4/5LicenseSetup · hard

TLDR

A free, continuously updated book teaching C programmers how to write Linux kernel modules, with working code examples tested against modern 5.x and 6.x kernels and available as a PDF or HTML download.

Mindmap

mindmap
  root((lkmpg))
    What it is
      Free kernel book
      Updated examples
      PDF and HTML
    Topics
      Module basics
      Device drivers
      Build environment
    Audience
      C programmers
      Kernel developers
      Systems learners
    Tech
      C language
      TeX source
      Linux 5.x 6.x
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Learn to write a Linux kernel module from scratch by following the book's step-by-step chapters

USE CASE 2

Build and test device driver code examples against a modern 5.x or 6.x Linux kernel

USE CASE 3

Download a PDF of the guide for offline reading while writing kernel code

USE CASE 4

Build the book from source using TeXLive to produce an up-to-date local PDF or HTML version

Tech stack

CTeXTeXLiveLinux

Getting it running

Difficulty · hard Time to first run · 1day+

Building from TeX source requires TeXLive (a container image with all tools bundled is available), running the code examples requires a Linux kernel build environment.

Sample code is under GPL v2 (same as the Linux kernel), the book text uses the Open Software License, which permits reproduction and modification.

In plain English

This repository is an updated edition of the Linux Kernel Module Programming Guide, a book originally published in 2001 that teaches programmers how to write kernel modules for the Linux operating system. The original guide covered 2.6.x kernels from that era, so this project maintains a current version with working code examples tested against modern 5.x and 6.x kernels. You can read the book for free online or download a PDF from the GitHub releases page. A kernel module is a piece of code that can be loaded into and removed from the Linux kernel without restarting the system. Writing one is different from ordinary application development because the code runs in a privileged environment and interacts directly with hardware and system internals. This guide walks through that process in steps, starting from setting up a build environment and working through device drivers and other advanced topics. The book source is written in TeX, a document preparation format common in technical publishing. To build the book yourself from source, you need a TeX toolchain such as TeXLive. The README provides installation commands for Ubuntu, Arch Linux, and macOS. Alternatively, you can use a pre-packaged container image that bundles all the required tools, which avoids installing them individually. Once the prerequisites are in place, a single build command produces either a PDF or an HTML version. The sample code in each chapter is licensed under GNU GPL version 2, the same license as the Linux kernel. The book text uses the Open Software License, which allows reproduction and modification. This is a documentation project, not a runnable application. Its intended readers are C programmers who want to extend the Linux kernel, such as people building device drivers or low-level system tools.

Copy-paste prompts

Prompt 1
I am learning to write Linux kernel modules in C. Walk me through the lkmpg Hello World example, explain each line of the Makefile and the C source file.
Prompt 2
Using the Linux Kernel Module Programming Guide examples, write a simple character device driver that lets user-space programs read a message from /dev.
Prompt 3
Build the lkmpg PDF locally on Ubuntu, give me the exact apt-get commands to install TeXLive and the make command to produce the PDF.
Prompt 4
Explain step by step what happens when you run insmod to load a kernel module, based on the lkmpg description of the init and exit functions.
Open on GitHub → Explain another repo

← sysprog21 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.