---
# System prepended metadata

title: Linux Kernel 6.0 Patching

---

# Linux Kernel 6.0 Patching

IPFS CID - QmQgVfyKKFC8afn1hRKpApZZQZuQSrhPGN2CkwegGVTj1y

## Overview

* What is the Linux Kernel?
* Installing Linux
* Git / Download
* Dependencies
* Building
* Installing
* Next steps
* References

## What is the Linux Kernel?

* user to hardware communication
* the Linux kernel is monolithic, although it is also modular

## Installing Linux

* VirtualBox
* Live USB
* Bare metal (full installation)

## Dependencies

* [minimum requirements](https://docs.kernel.org/process/changes.html)
* most modern laptops should suffice
* dont forget the kernel headers (`kernel-dev, kernel-devel, etc.`)
* if udevd is not on the path: `/lib/systemd/systemd-udevd --version`
* if `grub --version` not working try: `grub2 --version||grub2-install --version`
* sphinx install is `python3-sphinx`

## Git / Download

* [linux-next](https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/)
* [mainline](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/)
* [stable](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git)

Let's go to the latest stable branch.

```bash
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux_stable
cd linux_stable
git branch -a | grep linux-6
git checkout linux-6.0.y
```

## Building

Copy the current configuration.

```bash
ls /boot
cp /boot/<config-x.x.x-xx-> .config
```

Generate the kernel configuration file.

```bash
make oldconfig
```

Create configuration based on currently loaded modules.

```bash
lsmod > /tmp/my-lsmod
make LSMOD=/tmp/my-lsmod localmodconfig
```

Time to compile!

```bash
make -j$(echo "($(nproc) - 1)" | bc) all
```

Note: since this takes a while depending on cpu, perfect time for coffee!

## Installing

Let's make sure this thing works!
Run the command below as root (`sudo su`)

```bash!
"make modules_install install"
```

Then `exit` back to normal user.

It is a good idea to check system messages for errors.

```bash!
dmesg -t > dmesg_current
dmesg -t -k > dmesg_kernel
dmesg -t -l emerg > dmesg_current_emerg
dmesg -t -l alert > dmesg_current_alert
dmesg -t -l crit > dmesg_current_crit
dmesg -t -l err > dmesg_current_err
dmesg -t -l warn > dmesg_current_warn
dmesg -t -l info > dmesg_current_info
```

Kernel hackers disable secure boot, but just to check...

```bash~
mokutil --sb-state
```

Disable validation:

```bash!
sudo mokutil --disable-validation
root password
mok password: 12345678
mok password: 12345678
```

### Boot it up

* there is no guarantee that this custom kernel will boot
* below are Ubuntu specific grub configurations for the grub

`sudo vim /etc/default/grub`

* Uncomment `GRUB_TIMEOUT` and set it to 10: `GRUB_TIMEOUT=10`
* Comment out `GRUB_TIMEOUT_STYLE=hidden`
* enable printing of early boot messages `GRUB_CMDLINE_LINUX="earlyprintk=vga"`

Fingers crossed, here goes nothing!

`sudo reboot`

## Next Steps

* moar hacking
* create your own tools
* [static analysis with csbuild](https://hackmd.io/BXQrVcy2TJi4-ksisZctIA)
* [smatch](https://repo.or.cz/w/smatch.git)

## References

* [kernel wikipedia](https://en.wikipedia.org/wiki/Kernel_(operating_system))
* [docs](https://docs.kernel.org/index.html)