Update to mkosi v19

- Use mkosi.images/ instead of mkosi.presets/
- Use the .chroot suffix to run scripts in the image
- Use BuildSources= match for the kernel build
- Move 10-systemd.conf to mkosi.conf and rely on mkosi.local.conf
  for local configuration
This commit is contained in:
Daan De Meyer 2023-11-28 18:38:22 +01:00
parent b0f666f817
commit bcb335ac68
63 changed files with 205 additions and 83 deletions

View File

@ -81,11 +81,11 @@ jobs:
echo 'deb http://azure.archive.ubuntu.com/ubuntu jammy-proposed restricted main universe' | sudo tee /etc/apt/sources.list.d/proposed.list
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: systemd/mkosi@16e63baaeadf7a5b100c5b5bf780c61c29878cfc
- uses: systemd/mkosi@bbe715f42911f9660712377a5b39335b9391ae22
- name: Configure
run: |
tee mkosi.conf <<- EOF
tee mkosi.local.conf <<- EOF
[Distribution]
Distribution=${{ matrix.distro }}
Release=${{ matrix.release }}
@ -112,17 +112,17 @@ jobs:
# For erofs, we have to install linux-modules-extra-azure, but that doesn't match the running kernel
# version, so we can't load the erofs module. squashfs is a builtin module so we use that instead.
mkdir -p mkosi.presets/system/mkosi.repart/10-usr.conf.d
tee mkosi.presets/system/mkosi.repart/10-usr.conf.d/squashfs.conf <<- EOF
mkdir -p mkosi.images/system/mkosi.repart/10-usr.conf.d
tee mkosi.images/system/mkosi.repart/10-usr.conf.d/squashfs.conf <<- EOF
[Partition]
Format=squashfs
EOF
# The emergency shell is not useful in the CI, as it just blocks for a long time before the job
# eventually times out. Override it to just shutdown immediately.
mkdir -p mkosi.presets/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/
mkdir -p mkosi.presets/system/mkosi.extra/usr/lib/systemd/system/emergency.service.d/
tee mkosi.presets/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf <<- EOF
mkdir -p mkosi.images/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/
mkdir -p mkosi.images/system/mkosi.extra/usr/lib/systemd/system/emergency.service.d/
tee mkosi.images/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf <<- EOF
[Unit]
FailureAction=exit
[Service]
@ -130,7 +130,7 @@ jobs:
ExecStart=
ExecStart=false
EOF
cp mkosi.presets/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf mkosi.presets/system/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf
cp mkosi.images/initrd/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf mkosi.images/system/mkosi.extra/usr/lib/systemd/system/emergency.service.d/poweroff.conf
- name: Generate secure boot key
run: mkosi --debug genkey

4
.gitignore vendored
View File

@ -34,9 +34,7 @@ __pycache__/
/mkosi.installdir/
/mkosi.key
/mkosi.crt
# Ignore any mkosi config files with "local" in the name
/mkosi.conf.d/**/*local*.conf
mkosi.conf
mkosi.local.conf
/tags
.dir-locals-2.el
.vscode/

View File

@ -35,7 +35,7 @@ possible, however. In order to simplify testing for cases like this we provide
a set of `mkosi` build files directly in the source tree.
[mkosi](https://github.com/systemd/mkosi) is a tool for building clean OS images
from an upstream distribution in combination with a fresh build of the project
in the local working directory. To make use of this, please install `mkosi` v18
in the local working directory. To make use of this, please install `mkosi` v19
or newer using your distribution's package manager or from the
[GitHub repository](https://github.com/systemd/mkosi). `mkosi` will build an
image for the host distro by default. First, run `mkosi genkey` to generate a key
@ -60,8 +60,8 @@ Putting this all together, here's a series of commands for preparing a patch
for systemd:
```sh
$ git clone https://github.com/systemd/mkosi.git # If mkosi v18 or newer is not packaged by your distribution
$ ln -s $PWD/mkosi/bin/mkosi /usr/local/bin/mkosi # If mkosi v18 or newer is not packaged by your distribution
$ git clone https://github.com/systemd/mkosi.git # If mkosi v19 or newer is not packaged by your distribution
$ ln -s $PWD/mkosi/bin/mkosi /usr/local/bin/mkosi # If mkosi v19 or newer is not packaged by your distribution
$ git clone https://github.com/systemd/systemd.git
$ cd systemd
$ git checkout -b <BRANCH> # where BRANCH is the name of the branch
@ -234,7 +234,7 @@ QEMU.
To allow VSCode's debugger to attach to systemd running in a mkosi image, we have to make sure it can access
the virtual machine spawned by mkosi where systemd is running. mkosi makes this possible via a handy SSH
option that makes the generated image accessible via SSH when booted. Thus you must build the image with
`mkosi --ssh`. The easiest way to set the option is to create a file `mkosi.conf` in the root of the
`mkosi --ssh`. The easiest way to set the option is to create a file `mkosi.local.conf` in the root of the
repository and add the following contents:
```
@ -343,7 +343,7 @@ To debug systemd-boot in an IDE such as VSCode we can use a launch configuration
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.conf.d/20-local.conf:
own kernel), you can add the following snippets to `mkosi.local.conf`:
(This snippet is for Fedora, the list of packages will need to be changed for other distributions)

View File

@ -15,8 +15,7 @@ compiler you want to use and which part of the test suite you want to run.
## mkosi
To build with sanitizers in mkosi, create a file 20-local.conf in mkosi.conf.d/ and add the following
contents:
To build with sanitizers in mkosi, create a file `mkosi.local.conf` and add the following contents:
```
[Content]

View File

@ -1,7 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Preset]
Presets=system
[Config]
Images=system
[Output]
OutputDirectory=mkosi.output

View File

@ -5,13 +5,6 @@ set -e
# This is a build script for OS image generation using mkosi (https://github.com/systemd/mkosi).
# Simply invoke "mkosi" in the project directory to build an OS image.
if [ "${container:-}" != "mkosi" ]; then
exec mkosi-chroot "$SCRIPT" "$@"
fi
# Run commands as the user invoking mkosi.
SU="setpriv --reuid=${MKOSI_UID:-0} --regid=${MKOSI_GID:-0} --clear-groups"
# We don't want to install our build of systemd in the base image, but use it as an extra tree for the
# initrd and system images, so override DESTDIR to store it in the output directory so we can reference it as
# an extra tree in the initrd and system image builds.
@ -206,10 +199,10 @@ if [ ! -f "$BUILDDIR"/build.ninja ]; then
)
fi
( set -x; $SU meson setup "$BUILDDIR" "$SRCDIR" "${CONFIGURE_OPTS[@]}" )
( set -x; meson setup "$BUILDDIR" "$SRCDIR" "${CONFIGURE_OPTS[@]}" )
fi
( set -x; $SU ninja -C "$BUILDDIR" "$@" )
( set -x; ninja -C "$BUILDDIR" "$@" )
if [ "$WITH_TESTS" = 1 ]; then
if [ -n "$SANITIZERS" ]; then
export ASAN_OPTIONS="$MKOSI_ASAN_OPTIONS"

View File

@ -1,6 +1,6 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Preset]
[Config]
Dependencies=base
[Output]

View File

@ -2,10 +2,6 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
if [ "${container:-}" != "mkosi" ]; then
exec mkosi-chroot "$SCRIPT" "$@"
fi
# OpenSUSE insists on blacklisting erofs by default because its supposedly a legacy filesystem.
# See https://github.com/openSUSE/suse-module-tools/pull/71
rm -f /usr/lib/modprobe.d/60-blacklist_fs-erofs.conf
rm -f "$BUILDROOT/usr/lib/modprobe.d/60-blacklist_fs-erofs.conf"

View File

@ -0,0 +1,36 @@
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
cd "$SRCDIR/kernel"
BUILDDIR="$BUILDDIR/kernel"
mkdir -p "$BUILDDIR"
# Prevent a distro's custom installkernel script from being used.
if [ -x /sbin/installkernel ]; then
mount --bind /dev/null /sbin/installkernel
fi
# Ensure fast incremental builds by fixating these values which usually change for each build.
export KBUILD_BUILD_TIMESTAMP="Fri Jun 5 15:58:00 CEST 2015"
export KBUILD_BUILD_HOST="mkosi"
scripts/kconfig/merge_config.sh -O "$BUILDDIR" \
../mkosi.kernel.config \
tools/testing/selftests/bpf/config.x86_64 \
tools/testing/selftests/bpf/config
# Make sure systemd-boot boots this kernel and not the distro provided one by overriding the version.
make O="$BUILDDIR" VERSION=99 -j "$(nproc)"
make O="$BUILDDIR" VERSION=99 -j "$(nproc)" headers
KERNEL_RELEASE=$(make O="$BUILDDIR" VERSION=99 -s kernelrelease)
mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_RELEASE"
make O="$BUILDDIR" VERSION=99 INSTALL_MOD_PATH="$DESTDIR/usr" modules_install
make O="$BUILDDIR" VERSION=99 INSTALL_PATH="$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" install
mkdir -p "$DESTDIR/usr/lib/kernel/selftests"
make -C tools/testing/selftests -j "$(nproc)" O="$BUILDDIR" VERSION=99 KSFT_INSTALL_PATH="$DESTDIR/usr/lib/kernel/selftests" SKIP_TARGETS="hid" install
mkdir -p "$DESTDIR"/usr/bin
ln -sf /usr/lib/kernel/selftests/bpf/bpftool "$DESTDIR/usr/bin/bpftool"

View File

@ -0,0 +1,19 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Match]
BuildSources=kernel/
[Content]
BuildPackages=
bc
binutils
bison
clang
flex
gcc
lld
llvm
make
make
rsync
tar

View File

@ -0,0 +1,19 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Match]
Distribution=arch
[Content]
Packages=
alsa-lib
fuse3
libcap
libcap-ng
libelf
libmnl
numactl
popt
BuildPackages=
pahole
python-docutils

View File

@ -0,0 +1,34 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Match]
Distribution=|centos
Distribution=|fedora
[Content]
Packages=
alsa-lib
elfutils-libelf
fuse3
glibc.i686
libcap
libcap-ng
libcap-ng-utils
libmnl
numactl-libs
popt
BuildPackages=
dwarves
glibc-devel.i686
glibc-static
glibc-static.i686
pkgconfig(alsa)
pkgconfig(fuse3)
pkgconfig(libcap-ng)
pkgconfig(libcap)
pkgconfig(libelf)
pkgconfig(libmnl)
pkgconfig(numa)
pkgconfig(openssl)
pkgconfig(popt)
python3-docutils

View File

@ -0,0 +1,32 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Match]
Distribution=|debian
Distribution=|ubuntu
[Content]
Packages=
fuse3
libasound2
libc6-i386
libcap-ng0
libcap2
libelf1
libmnl0
libnuma1
libpopt0
BuildPackages=
gcc-multilib
libasound-dev
libc6-dev
libc6-dev-i686
libcap-ng-dev
libcap-dev
libelf-dev
libfuse3-dev
libmnl-dev
libnuma-dev
libpopt-dev
pahole
python3-docutils

View File

@ -0,0 +1,8 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Match]
Distribution=fedora
[Content]
BuildPackages=
libcap-static

View File

@ -0,0 +1,34 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Match]
Distribution=opensuse
[Content]
Packages=
fuse3
glibc-32bit
libasound2
libcap-ng0
libcap2
libelf1
libmnl0
libnuma1
libpopt0
BuildPackages=
alsa-devel
dwarves
fuse3-devel
gcc-32bit
glibc-devel-32bit
glibc-devel-static-32bit
glibc-static
libcap-devel
libcap-ng-dev
libelf-devel
liblz4-dev
libmnl-dev
libnuma-devel
pcre-devel
popt-devel
python3-docutils

View File

@ -1,6 +1,6 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Preset]
[Config]
Dependencies=base
[Content]

View File

@ -5,7 +5,7 @@ Bootable=!no
Format=|disk
Format=|directory
[Preset]
[Config]
Dependencies=initrd
[Content]

View File

@ -6,10 +6,6 @@ if [ "$1" = "build" ]; then
exit 0
fi
if [ "${container:-}" != "mkosi" ]; then
exec mkosi-chroot "$SCRIPT" "$@"
fi
if [ -n "$SANITIZERS" ]; then
LD_PRELOAD=$(ldd /usr/lib/systemd/systemd | grep libasan.so | awk '{print $3}')

View File

@ -1,42 +0,0 @@
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
if [ "${container:-}" != "mkosi" ]; then
exec mkosi-chroot "$SCRIPT" "$@"
fi
if [ -d "$SRCDIR"/mkosi.kernel/ ]; then
SRCDIR="$SRCDIR/mkosi.kernel"
BUILDDIR="$BUILDDIR/mkosi.kernel"
cd "$SRCDIR"
mkdir -p "$BUILDDIR"
# Prevent a distro's custom installkernel script from being used.
if [ -x /sbin/installkernel ]; then
mount --bind /dev/null /sbin/installkernel
fi
# Ensure fast incremental builds by fixating these values which usually change for each build.
export KBUILD_BUILD_TIMESTAMP="Fri Jun 5 15:58:00 CEST 2015"
export KBUILD_BUILD_HOST="mkosi"
scripts/kconfig/merge_config.sh -O "$BUILDDIR" \
../mkosi.kernel.config \
tools/testing/selftests/bpf/config.x86_64 \
tools/testing/selftests/bpf/config
# Make sure systemd-boot boots this kernel and not the distro provided one by overriding the version.
make O="$BUILDDIR" VERSION=99 -j "$(nproc)"
make O="$BUILDDIR" VERSION=99 -j "$(nproc)" headers
KERNEL_RELEASE=$(make O="$BUILDDIR" VERSION=99 -s kernelrelease)
mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_RELEASE"
make O="$BUILDDIR" VERSION=99 INSTALL_MOD_PATH="$DESTDIR/usr" modules_install
make O="$BUILDDIR" VERSION=99 INSTALL_PATH="$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" install
mkdir -p "$DESTDIR/usr/lib/kernel/selftests"
make -C tools/testing/selftests -j "$(nproc)" O="$BUILDDIR" VERSION=99 KSFT_INSTALL_PATH="$DESTDIR/usr/lib/kernel/selftests" SKIP_TARGETS="hid" install
mkdir -p "$DESTDIR"/usr/bin
ln -sf /usr/lib/kernel/selftests/bpf/bpftool "$DESTDIR/usr/bin/bpftool"
fi