From d12e9bdc768532d76c680879271e495e4fd93743 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 9 Sep 2022 08:53:37 +0200 Subject: [PATCH] mkosi: Optionally build a kernel image from mkosi.kernel/ If mkosi.kernel/ exists, the mkosi script will try to build a kernel image from it. We use the architecture defconfig as a base and add our own extra configuration on top. We also add some extra tooling to the build image required to build the kernel and include some documentation in HACKING.md on how to use this new feature. To avoid the kernel sources from being copied into the build or final image (which we don't want because it takes a while), we put the mkosi.kernel/ directory in .gitignore and use "SourceFileTransfer=mount" so that the sources are still accessible in the build image. --- docs/HACKING.md | 20 ++++++++++ mkosi.build | 37 +++++++++++++++++++ mkosi.default.d/10-systemd.conf | 6 +++ mkosi.default.d/arch/10-mkosi.arch | 1 + .../centos_epel/10-mkosi.centos_epel | 1 + mkosi.default.d/debian/10-mkosi.debian | 1 + mkosi.default.d/fedora/10-mkosi.fedora | 1 + mkosi.default.d/opensuse/10-mkosi.opensuse | 1 + mkosi.default.d/ubuntu/10-mkosi.ubuntu | 1 + 9 files changed, 69 insertions(+) diff --git a/docs/HACKING.md b/docs/HACKING.md index 33b5ac166a..42874033b5 100644 --- a/docs/HACKING.md +++ b/docs/HACKING.md @@ -414,3 +414,23 @@ To debug systemd-boot in an IDE such as VSCode we can use a launch configuration ] } ``` + +## Hacking on the kernel + systemd + +If you're hacking on the kernel in tandem with systemd, you can clone a kernel repository in mkosi.kernel/ in +the systemd repository, and mkosi will automatically build that kernel and install it into the final image. +To prevent the distribution's kernel from being installed (which isn't necessary since we're building our +own kernel), you can add the following snippets to mkosi.default.d/20-local.conf: + +(This snippet is for Fedora, the list of packages will need to be changed for other distributions) + +``` +[Distribution] +CacheInitrd=no + +[Content] +BasePackages=conditional +Packages=systemd + util-linux + dracut +``` diff --git a/mkosi.build b/mkosi.build index 1154e738f4..7a32673bb4 100755 --- a/mkosi.build +++ b/mkosi.build @@ -259,3 +259,40 @@ fi # Make sure services aren't enabled by default on Debian/Ubuntu. mkdir -p "$DESTDIR/etc/systemd/system-preset" echo "disable *" > "$DESTDIR/etc/systemd/system-preset/99-mkosi.preset" + +if [ -d mkosi.kernel/ ]; then + cd "$SRCDIR/mkosi.kernel" + mkdir -p "$BUILDDIR/mkosi.kernel" + + make O="$BUILDDIR/mkosi.kernel" defconfig + + scripts/config \ + --file $BUILDDIR/mkosi.kernel/.config \ + --enable BPF_SYSCALL \ + --enable BPF_JIT \ + --enable BPF_JIT_ALWAYS_ON \ + --enable BPF_JIT_DEFAULT_ON \ + --enable BPF_UNPRIV_DEFAULT_OFF \ + --enable USERMODE_DRIVER \ + --enable BPF_PRELOAD \ + --enable BPF_PRELOAD_UMD \ + --enable BPF_LSM \ + --enable BTRFS_FS \ + --enable BTRFS_FS_POSIX_ACL \ + --enable PSI \ + --enable CGROUPS \ + --enable CGROUP_BPF \ + --enable MEMCG \ + --enable MEMCG_SWAP \ + --enable MEMCG_KMEM + + # Make sure all unset options are set to their default value. + make O="$BUILDDIR/mkosi.kernel" olddefconfig + + make O="$BUILDDIR/mkosi.kernel" -j "$(nproc)" + + KERNEL_RELEASE="$(make O=$BUILDDIR/mkosi.kernel -s kernelrelease)" + mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" + make O="$BUILDDIR/mkosi.kernel" INSTALL_MOD_PATH="$DESTDIR/usr" modules_install + make O="$BUILDDIR/mkosi.kernel" INSTALL_PATH="$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" install +fi diff --git a/mkosi.default.d/10-systemd.conf b/mkosi.default.d/10-systemd.conf index 3a82298ca4..c144c86816 100644 --- a/mkosi.default.d/10-systemd.conf +++ b/mkosi.default.d/10-systemd.conf @@ -43,17 +43,23 @@ Packages= zsh BuildPackages= + bc + binutils + bison clang + flex gcc gettext git gnu-efi gperf llvm + make meson pkgconf rpm rsync + tar zstd [Host] diff --git a/mkosi.default.d/arch/10-mkosi.arch b/mkosi.default.d/arch/10-mkosi.arch index bd54b08c54..50194b960b 100644 --- a/mkosi.default.d/arch/10-mkosi.arch +++ b/mkosi.default.d/arch/10-mkosi.arch @@ -31,6 +31,7 @@ BuildPackages= docbook-xsl libxslt linux-api-headers + pahole perl python-jinja python-lxml diff --git a/mkosi.default.d/centos_epel/10-mkosi.centos_epel b/mkosi.default.d/centos_epel/10-mkosi.centos_epel index 482b5935ce..c09eb41800 100644 --- a/mkosi.default.d/centos_epel/10-mkosi.centos_epel +++ b/mkosi.default.d/centos_epel/10-mkosi.centos_epel @@ -38,6 +38,7 @@ Packages= BuildPackages= bpftool docbook-xsl + dwarves gnu-efi-devel libgcrypt-devel # CentOS Stream 8 libgcrypt-devel doesn't ship a pkg-config file. libxslt diff --git a/mkosi.default.d/debian/10-mkosi.debian b/mkosi.default.d/debian/10-mkosi.debian index 2b712d6778..c7ffad0378 100644 --- a/mkosi.default.d/debian/10-mkosi.debian +++ b/mkosi.default.d/debian/10-mkosi.debian @@ -62,6 +62,7 @@ BuildPackages= libssl-dev libxkbcommon-dev libzstd-dev + pahole python3-jinja2 python3-lxml xsltproc diff --git a/mkosi.default.d/fedora/10-mkosi.fedora b/mkosi.default.d/fedora/10-mkosi.fedora index 86a44aba4e..a0ba8b0637 100644 --- a/mkosi.default.d/fedora/10-mkosi.fedora +++ b/mkosi.default.d/fedora/10-mkosi.fedora @@ -33,6 +33,7 @@ Packages= BuildPackages= bpftool docbook-xsl + dwarves gnu-efi-devel pam-devel pkgconfig # pkgconf shim to provide /usr/bin/pkg-config diff --git a/mkosi.default.d/opensuse/10-mkosi.opensuse b/mkosi.default.d/opensuse/10-mkosi.opensuse index b7514a575f..4ee497c602 100644 --- a/mkosi.default.d/opensuse/10-mkosi.opensuse +++ b/mkosi.default.d/opensuse/10-mkosi.opensuse @@ -35,6 +35,7 @@ BuildPackages= bpftool dbus-1-devel docbook-xsl-stylesheets + dwarves fdupes gcc-c++ glib2-devel diff --git a/mkosi.default.d/ubuntu/10-mkosi.ubuntu b/mkosi.default.d/ubuntu/10-mkosi.ubuntu index 60e1bcfa66..50b42bdb5a 100644 --- a/mkosi.default.d/ubuntu/10-mkosi.ubuntu +++ b/mkosi.default.d/ubuntu/10-mkosi.ubuntu @@ -63,6 +63,7 @@ BuildPackages= libssl-dev libxkbcommon-dev libzstd-dev + pahole python3-jinja2 python3-lxml xsltproc