# sysprog21/lkmpg: a kernel module guide that still builds on 6.x kernels

> The Linux Kernel Module Programming Guide is a TeX book with compilable examples for 5.x and 6.x kernels, maintained by sysprog21. It is a build-from-source document, not a package you install, and its value depends on whether you keep the examples in step with your kernel headers.

**sysprog21/lkmpg** — The Linux Kernel Module Programming Guide (updated for 5.0+ kernels)

- Repository: https://github.com/sysprog21/lkmpg
- Website: https://sysprog21.github.io/lkmpg/
- Stars: 8,599 · Forks: 623
- Language: TeX
- License: OSL-3.0
- Published: 2026-09-21 · Updated: 2026-09-21 · Language: en
- Canonical page: https://hysenlabs.com/projects/sysprog21-lkmpg

## The problem lkmpg solves: stale copies of a 2001 book

Most copies of the Linux Kernel Module Programming Guide circulating on the web describe 2.6.x kernels. The README states this directly, and it is the reason the sysprog21 fork exists: the guide has been around since 2001, and the text people find by searching is often the original from the Linux Documentation Project, written for an API that has since changed. A reader who follows a 2.6-era example on a modern kernel hits removed symbols, changed function signatures, or build failures that the text never warned about.

The project targets two audiences. The first is someone learning kernel module programming who needs examples that compile on a recent kernel. The second is a working engineer who wants a single reference for module basics, character devices, locking primitives, and interrupt handling without assembling it from scattered sources. The repository keeps both the prose and the code in one tree: lkmpg.tex holds the book, and examples/ holds the C files it discusses, including hello-1.c through hello-5.c, chardev.c, chardev2.c, and files covering mutexes, RCU, spinlocks, rwlocks, tasklets, DMA, and device tree overlays.

This is a documentation project, not a library. There is no package to install and no API to call. The deliverable is a PDF or an HTML page, plus a set of example modules you compile yourself. That distinction matters when you evaluate maintenance: a stale README is annoying, but a stale example that no longer builds against current headers is a correctness problem, and the project's stated purpose is to keep those examples working.

## How the book is built: TeX source, latexmk, and make4ht

The build is a LaTeX pipeline. The Makefile defines three targets. The default target, all, depends on lkmpg.pdf, which depends on lkmpg.tex, and it runs latexmk -shell-escape lkmpg.tex -pdf after clearing the _minted-lkmpg directory. The shell-escape flag is there because the document uses minted for code listings, which shells out to Pygments to highlight source. That is why the README notes that Pygments may need to be installed separately on macOS.

The html target is a different path. It first rewrites lkmpg.tex into lkmpg-for-ht.tex, converting tabs to four spaces with a sed expression, then calls make4ht with html.cfg to produce HTML5 output in a directory named html. After that, an inline Python script post-processes the generated HTML to fix spacing inside numeric spans, and the Makefile symlinks lkmpg-for-ht.html to html/index.html and copies the Manrope font from assets/ into the output directory. The target then deletes the intermediate files it created.

Two consequences follow from this design. First, the PDF and HTML outputs are generated from the same TeX source, so an edit to the book appears in both, but they are not byte-identical: the HTML path applies its own transformations, and the Makefile's cleanup step removes the intermediates, so debugging an HTML rendering issue means re-running make html and inspecting the output before the cleanup runs. Second, the build is heavy. texlive-full is a large dependency, and the README's own recommendation to use Docker exists because reproducing the toolchain by hand is fiddly.

## Installing lkmpg and building the PDF or HTML

There is nothing to install in the sense of a system package. You clone the repository and build the document. The README's first step is:

```bash
git clone https://github.com/sysprog21/lkmpg.git && cd lkmpg
```

After that you need a TeX distribution. The README lists the commands per platform. On Debian or Ubuntu it is `sudo apt install make texlive-full`; on Arch or Manjaro it is `sudo pacman -S make texlive-binextra texlive-bin`; on macOS it is `brew install mactex` followed by `sudo tlmgr update --self`. The README also notes that latexmk is required for the PDF and may already be present, and links to a separate installation guide if it is not.

If you would rather not install TeXLive, the README recommends Docker because it matches the project's GitHub Actions workflow. The image is twtug/lkmpg:

```bash
docker pull twtug/lkmpg
docker run --rm -it -v $(pwd):/workdir twtug/lkmpg
```

The volume mount maps the current directory to /workdir inside the container, so the generated files land in your clone. The README also states that nerdctl, a Docker-compatible CLI for containerd, can replace the docker commands.

With the toolchain in place, the build targets are short:

```bash
make all              # Generate PDF document
make html             # Convert TeX to HTML
make clean            # Delete generated files
```

On success, make all leaves lkmpg.pdf in the repository root. make html leaves a directory named html containing index.html, which is a symlink to lkmpg-for-ht.html. The README also points to a hosted copy at sysprog21.github.io/lkmpg/ and to a latest PDF attached to the GitHub releases, so building locally is optional if you only want to read the current text. Building matters when you want to modify the book or confirm that the examples in the tree match the prose.

## The examples directory is the part that ages fastest

The repository's real maintenance burden is in examples/. The README describes the examples as working for recent 5.x and 6.x kernel versions, and the file list shows the breadth: hello-1.c through hello-5.c for the introductory modules, chardev.c and chardev2.c for character devices, and separate files for atomic operations, mutexes, RCU, rwlocks, spinlocks, and tasklets. There are also less common topics: blkram.c for a RAM-backed block device, dma.c, devicemodel.c, devicetree.c, and a dt-overlay.dts device tree overlay, plus hardware-adjacent examples like dht11.c.

Two constraints are visible from the layout. First, examples/Makefile exists, and the top-level Makefile has an indent target that delegates with `$(MAKE) -C examples indent`, so the sample code is formatted as a unit using the .clang-format file in the same directory. That is a sign the examples are treated as maintained source rather than pasted snippets. Second, the examples are licensed differently from the book. The README states that the complementary sample code is under GNU GPL version 2, the same as the Linux kernel, and the repository root contains a GPL-2 file alongside LICENSE. If you copy an example into your own module, the GPL-2 terms apply to that code, not the book's OSL-3.0 terms.

What the README does not document is a compatibility matrix mapping each example to specific kernel versions, nor a rollback procedure if a build fails after a kernel upgrade. The devtools/ directory and the prebuilt kernel 6.12.6 release assets suggest the project tests against a pinned kernel, but the README does not describe that workflow, so a reader cannot tell from the documentation alone which kernel version a given example was last verified on.

## Where lkmpg is the wrong tool

The guide is a book, and it behaves like one. It is not a course with graded exercises, and the README documents no support channel, no issue triage policy, and no errata process. If you want structured progression with feedback, this is not that.

It is also not a substitute for the kernel's own documentation. The guide covers module mechanics and a set of core primitives, but a reader looking for subsystem-specific material, such as the networking stack or a particular driver class, will not find it here. The examples list is broad in primitives and narrow in subsystems.

There is a harder boundary: building the book requires a full TeXLive installation or Docker, and the PDF target needs latexmk and, for code highlighting, Pygments. If your environment cannot install these, the practical path is the hosted HTML or the release PDF, and then you are trusting the published version rather than the source you cloned. The README gives no lightweight build option.

Finally, kernel module programming itself is not a beginner topic. Writing a module means working in kernel address space, where a mistake can panic the machine rather than crash a process. The guide's examples are written to be loadable, but the README does not present the material as safe for experimentation on a production host, and nothing in the documentation suggests otherwise.

## Alternatives and what the difference in approach means

The most direct alternative is the original guide from the Linux Documentation Project, which the README links. The difference is version coverage: the original describes 2.6.x kernels, while this project targets 5.x and 6.x and keeps examples in the tree. If you are working on a modern kernel, the original is a historical document; if you are working on an old kernel, it may still be the right text.

A second comparison point is the broader set of free books the README itself points to, including the Free Ebook Foundation's searchable list and The Online Books Page's Linux collection. Those are indexes, not a single maintained text, so the difference is curation: lkmpg is one book with one build, while an index leaves you to judge which book is current.

Search results for Linux kernel programming also surface books such as Linux Kernel Programming by Kaiwan and Demystifying the Linux CPU Scheduler. Those are separate works with their own scope, and this article does not describe their contents. The relevant distinction is that lkmpg is a guide to writing modules, with compilable examples, under a copyleft license, and it is free to read and rebuild. A book you buy is a different transaction with different update guarantees. If your need is a printable reference you can patch yourself, lkmpg's build-from-source model is the differentiator. If your need is a single stable edition with editorial review, a published book is the differentiator.

## Licence, maintenance, and what upgrading costs

The book and the code carry different licences, and the README is explicit about both. The guide is under the Open Software License, described in the README as a copyleft license, with the text in the LICENSE file. The sample code is under GNU GPL version 2, matching the kernel. That split is worth checking before you redistribute: quoting a passage from the book and copying an example file into your driver are governed by different terms. This is a description of what the repository states, not legal advice.

The repository is not archived, and the last push was on 2026-09-07, which is recent. The release list shows a latest release dated 2026-04-23 and two devtools releases from 2026-05-18 tagged for kernel 6.12.6 on x86_64. The presence of prebuilt devtools assets indicates the project ships a pinned kernel environment rather than only prose, though the README does not document how to use those assets.

Upgrade cost falls into two buckets. Rebuilding the document after pulling changes costs one make all or make html run, plus whatever time TeXLive takes on your machine. Keeping your own modules in step with a new kernel is the larger cost, and it is not something the book can do for you: when kernel APIs change, the examples in the tree are updated by the maintainers, but your code is not. The practical check before adopting the guide for a project is to compile one example against your target kernel's headers and see whether it builds cleanly.

## Conclusion

Adopt lkmpg if you want a free, buildable reference with runnable examples for 5.x and 6.x kernels, and you are willing to build it yourself with TeXLive or the twtug/lkmpg container. Do not adopt it as a structured course or as a substitute for kernel API reference documentation; the guide is a book, and the README documents no exercises, no video, and no support channel. Before relying on it, clone the repository, run make all or make html, and compile one example from examples/ against your own kernel headers to confirm the version you are reading matches the kernel you are targeting.

## FAQ

### How do I build the lkmpg PDF?

Clone the repository, install TeXLive and latexmk, then run make all. The README lists the per-platform install commands, and the resulting file is lkmpg.pdf in the repository root.

### Can I read lkmpg without installing TeXLive?

Yes. The README states the book is freely accessible at https://sysprog21.github.io/lkmpg/ and that a latest PDF is attached to the GitHub releases. The alternative to a local TeXLive install is the twtug/lkmpg Docker image, which the README recommends because it matches the project's GitHub Actions workflow.

### What licence applies to the lkmpg examples?

The README states that the complementary sample code is licensed under GNU GPL version 2, the same as the Linux kernel, while the book itself is under the Open Software License. The repository root contains both LICENSE and GPL-2.

### Which kernel versions does lkmpg cover?

The README describes the project as keeping the guide up to date with working examples for recent 5.x and 6.x kernels. The README does not provide a per-example compatibility matrix, and the devtools release assets are tagged for kernel 6.12.6 on x86_64.

### What does kmalloc do?

The README does not describe kmalloc's behaviour. The repository includes examples/example_atomic.c, examples/example_mutex.c, examples/example_rcu.c and other primitive-focused files, but the README does not summarise their contents.

## Sources

- [License: OSL-3.0](https://github.com/sysprog21/lkmpg/blob/master/LICENSE)
- [Project website](https://sysprog21.github.io/lkmpg/)
- [README](https://github.com/sysprog21/lkmpg/blob/master/README.md)
- [Releases](https://github.com/sysprog21/lkmpg/releases)
- [sysprog21/lkmpg on GitHub](https://github.com/sysprog21/lkmpg)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/sysprog21-lkmpg
