Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add steps to compile and boot a custom kernel in RHCOS environment for dev/debug purposes #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions boot_custom_kernel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Steps/Commands to compile and boot into a custom kernel on RHCOS node:

```
# cd /var/home/core

# cat Dockerfile
FROM fedora:latest

RUN dnf install -y kexec-tools make gcc git openssl-devel bison flex autoconf automake bc
#

*** Setup container image to build the kernel ***
# podman build -t fedora:build -f Dockerfile

# cp /lib/modules/`uname -r`/config .

# podman run -it -v /var/home/core:/root --privileged=true -- fedora:build bash

*** Build the kernel in container ***
# cd /root

# git clone --depth=1 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

# cp config linux/.config

# cd linux

# make oldconfig

# make vmlinux; make modules

# make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=/root modules_install

# cp vmlinux /root/vmlinux-<kver>

# cp /sbin/kexec /root

# exit

*** Back to RHCOS host ***

*** To build initrd image, pick dracut options from existing RHCOS initrd in /boot/ostree and use the same options,
*** plus "--kmoddir '/var/home/core/lib/modules/5.9.0-rc5'" to find the modules since we could not install kernel modules
*** at the usual place as /lib/modules directory is read-only. ***
# mkdir /tmp/dracut
# dracut --reproducible --gzip -v --add 'ostree' --tmpdir '/tmp/dracut' -f --add 'ignition' --no-hostonly --add-drivers 'mptspi vmw_pvscsi' --omit-drivers 'nouveau' --omit 'nfs' --add 'iscsi' --add 'ifcfg' --add 'fips' --kmoddir '/var/home/core/lib/modules/<kver>' initramfs-<kver>.img <kver>

** Ready to load and kexec into the just built kernel ***
# ./kexec -l --append="`cat /proc/cmdline`" --initrd=initramfs-<kver>.img vmlinux-<kver>

# ./kexec -e

Note: After booting past initrd, 'modprobe' would fail to find modules as the modules for the custom kernel could not be placed in
/lib/modules directory (read-only) where they are looks for. Three options to workaround it:
a. Use alias "modprobe -d /var/home/core" for "modprobe"
b. Build the missing kernel modules into the initrd with add-drivers option
c. Compile the modules into the kernel (=y instead of =m)
```