]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: Optionally build a kernel image from mkosi.kernel/ 24629/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 9 Sep 2022 06:53:37 +0000 (08:53 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 29 Sep 2022 18:15:57 +0000 (20:15 +0200)
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
mkosi.build
mkosi.default.d/10-systemd.conf
mkosi.default.d/arch/10-mkosi.arch
mkosi.default.d/centos_epel/10-mkosi.centos_epel
mkosi.default.d/debian/10-mkosi.debian
mkosi.default.d/fedora/10-mkosi.fedora
mkosi.default.d/opensuse/10-mkosi.opensuse
mkosi.default.d/ubuntu/10-mkosi.ubuntu

index 33b5ac166a4c91b3d9c25c48d8cf8a69cb0790df..42874033b5407dd1d86cd03dc2e0ae678bf7e7de 100644 (file)
@@ -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
+```
index 1154e738f4c32ddec31fd94d85083c526ed616b8..7a32673bb48c06a3c7f8aa635a276abf0ed17e5e 100755 (executable)
@@ -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
index 3a82298ca44cc1d59c4e24885dc26ad16c0fccae..c144c86816b9c73df6d66f7554eab448e4d55d11 100644 (file)
@@ -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]
index bd54b08c541997ad88f5571bd76de6ae2ec8cd3b..50194b960b5b78589e4b27e759329d1c862b1159 100644 (file)
@@ -31,6 +31,7 @@ BuildPackages=
         docbook-xsl
         libxslt
         linux-api-headers
+        pahole
         perl
         python-jinja
         python-lxml
index 482b5935ce962551229794abb1b10b7e4e5979db..c09eb418008ba4b771159c4dfb75474b78fb6a55 100644 (file)
@@ -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
index 2b712d677851f1e8e3ff67740c1171950f49717a..c7ffad037815d528903b564303be306a36e6d53d 100644 (file)
@@ -62,6 +62,7 @@ BuildPackages=
         libssl-dev
         libxkbcommon-dev
         libzstd-dev
+        pahole
         python3-jinja2
         python3-lxml
         xsltproc
index 86a44aba4e7d574e94acebfbfc6a20caea500975..a0ba8b06371a8dfade1658d7328f69da45a6fc00 100644 (file)
@@ -33,6 +33,7 @@ Packages=
 BuildPackages=
         bpftool
         docbook-xsl
+        dwarves
         gnu-efi-devel
         pam-devel
         pkgconfig # pkgconf shim to provide /usr/bin/pkg-config
index b7514a575f0d3c277b23c5ed65f3cfce1f151cc1..4ee497c6025ad31273e433dca1831b0e59bbd739 100644 (file)
@@ -35,6 +35,7 @@ BuildPackages=
         bpftool
         dbus-1-devel
         docbook-xsl-stylesheets
+        dwarves
         fdupes
         gcc-c++
         glib2-devel
index 60e1bcfa6670e2eaf30ef41d36222bbc9123e8fa..50b42bdb5a385bcb96b2430f2e2527665daeb555 100644 (file)
@@ -63,6 +63,7 @@ BuildPackages=
         libssl-dev
         libxkbcommon-dev
         libzstd-dev
+        pahole
         python3-jinja2
         python3-lxml
         xsltproc