]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: Package a erofs usr partition with signed verity 27571/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 May 2023 14:06:41 +0000 (16:06 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 13 May 2023 08:49:17 +0000 (10:49 +0200)
Let's start moving towards a more involved partitioning setup to
test our stuff more when using mkosi.

The root partition is generated on boot with systemd-repart.

CentOS supports neither erofs nor btrfs so we use squashfs and xfs
instead.

We also enable SecureBoot= locally for additional coverage. This
and the use of verity means users need to run `mkosi genkey` once
to generate the keys necessary to do secure boot and verity.

20 files changed:
.github/workflows/mkosi.yml
docs/HACKING.md
mkosi.conf.d/10-systemd.conf
mkosi.presets/00-base/mkosi.conf.d/10-debian-ubuntu.conf
mkosi.presets/00-base/mkosi.conf.d/10-opensuse.conf
mkosi.presets/10-initrd/mkosi.conf.d/10-centos.conf
mkosi.presets/10-initrd/mkosi.conf.d/10-default.conf
mkosi.presets/20-final/mkosi.conf.d/10-centos-fedora.conf
mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.extra/usr/lib/repart.d/20-root.conf.d/xfs.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.repart/10-usr.conf.d/squashfs.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.conf.d/10-ubuntu.conf
mkosi.presets/20-final/mkosi.extra/usr/lib/repart.d/20-root.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.extra/usr/lib/systemd/mkosi-check-and-shutdown.sh
mkosi.presets/20-final/mkosi.extra/usr/lib/systemd/system/mkosi-check-and-shutdown.service
mkosi.presets/20-final/mkosi.repart/00-esp.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.repart/10-usr.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.repart/10-usr.conf.d/squashfs.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.repart/11-usr-verity.conf [new file with mode: 0644]
mkosi.presets/20-final/mkosi.repart/12-usr-verity-sig.conf [new file with mode: 0644]

index 8c71748df87d2af6e1aaed0b62264db042259b8b..7d3ef4b1867570f0da0fcf1c5fda40dbdbcb0ad4 100644 (file)
@@ -84,11 +84,10 @@ jobs:
         [Distribution]
         Distribution=${{ matrix.distro }}
         Release=${{ matrix.release }}
-        SecureBoot=yes
 
         [Content]
         Environment=CI_BUILD=1
-                    DEFAULT_TIMEOUT_SEC=90
+                    DEFAULT_TIMEOUT_SEC=120
                     SLOW_TESTS=true
 
         [Output]
@@ -101,6 +100,15 @@ jobs:
         ExtraSearchPaths=!*
         EOF
 
+        # 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/20-final/mkosi.repart/10-usr.conf.d
+        tee mkosi.presets/20-final/mkosi.repart/10-usr.conf.d/squashfs.conf <<- EOF
+        [Partition]
+        Format=squashfs
+        EOF
+
     - name: Generate secure boot key
       run: mkosi --debug genkey
 
@@ -113,11 +121,5 @@ jobs:
     - name: Boot ${{ matrix.distro }} systemd-nspawn
       run: sudo mkosi --debug boot
 
-    - name: Check ${{ matrix.distro }} systemd-nspawn
-      run: sudo mkosi --debug shell bash -c "[[ -e /testok ]] || { cat /failed-services; exit 1; }"
-
     - name: Boot ${{ matrix.distro }} QEMU
       run: timeout -k 30 10m mkosi --debug qemu
-
-    - name: Check ${{ matrix.distro }} QEMU
-      run: sudo mkosi --debug shell bash -c "[[ -e /testok ]] || { cat /failed-services; exit 1; }"
index 3af58f6b27f1fc471118cd05ecee99056d01e05d..0aa92333452747031748c4f99e0a0fb331ce15dc 100644 (file)
@@ -40,9 +40,11 @@ the [GitHub repository](https://github.com/systemd/mkosi). `mkosi` will build an
 image for the host distro by default. Currently, the latest github commit is
 required. `mkosi` also requires systemd v253 (unreleased) or newer. If systemd v253
 is not available, `mkosi` will automatically use executables from the systemd build
-directory if it's executed from the systemd repository root directory. It is
-sufficient to type `mkosi` in the systemd project directory to generate a disk image
-you can boot either in `systemd-nspawn` or in a UEFI-capable VM:
+directory if it's executed from the systemd repository root directory. First, run
+`mkosi genkey` to generate a key and certificate to be used for secure boot and
+verity signing. After that is done, it is sufficient to type `mkosi` in the systemd
+project directory to generate a disk image you can boot either in `systemd-nspawn`
+or in a UEFI-capable VM:
 
 ```sh
 $ sudo mkosi boot # nspawn still needs sudo for now
index 41a8c2e856cdb7e81728df47881b0cad8b2c3026..ec0f690d4e8e039d21f7d1b05b8fbf981f9dbeca 100644 (file)
@@ -11,6 +11,11 @@ OutputDirectory=mkosi.output
 BuildDirectory=mkosi.builddir
 CacheDirectory=mkosi.cache
 
+[Validation]
+SecureBoot=yes
+# Disabled until systemd-measure can operate without a TPM device.
+SignExpectedPcr=no
+
 [Host]
 QemuMem=2G
 ExtraSearchPaths=build/
@@ -29,3 +34,5 @@ KernelCommandLineExtra=systemd.crash_shell
                        ip=enp0s1:any
                        # Make sure sulogin works even with a locked root account.
                        SYSTEMD_SULOGIN_FORCE=1
+                       # Make sure /sysroot is mounted rw in the initrd.
+                       rw
index f5c3afbef459f1e47980ae42716801e334a97e36..920e50e42b9d82d3c57202443262e3c949bc0c49 100644 (file)
@@ -5,6 +5,7 @@ Distribution=debian ubuntu
 
 [Content]
 Packages=
+        dmsetup
         libfdisk1
         libfido2-1
         libglib2.0-0
index 4ed5f6ff7c641094bc3e3d7f5103a589c18f210c..c5c44b8df86f978c54faaedae96f0cf7bf7bfaa1 100644 (file)
@@ -6,6 +6,7 @@ Distribution=opensuse
 [Content]
 # We install gawk, gzip, grep, xz here explicitly so that the busybox versions don't get installed instead.
 Packages=
+        device-mapper
         gawk
         grep
         gzip
index c25a17a030b1ccbb057b47e379d4b97911af98a7..89a207dc71972aefa31b853aa45d5f9c042f4009 100644 (file)
@@ -6,3 +6,6 @@ Distribution=centos
 [Output]
 # TODO: Switch to zstd once we stop building CentOS Stream 8.
 CompressOutput=xz
+
+[Content]
+Packages=xfsprogs
index 98f0b7dffb208b847a8a9040a541afc73fccda80..a2a935226692f5b30c17b208bb26eebeabffb871 100644 (file)
@@ -5,3 +5,6 @@ Distribution=arch debian fedora opensuse ubuntu
 
 [Output]
 CompressOutput=zst
+
+[Content]
+Packages=btrfs-progs
index d89f827839d4251dcdec2b25dad9cc72b41fcf7b..02e11d095f0b0cd72f1906716fe846b3ea52594b 100644 (file)
@@ -12,6 +12,7 @@ Packages=
         iproute
         iproute-tc
         kernel-core
+        kernel-modules # For squashfs support
         libcap-ng-utils
         netcat
         openssh-server
diff --git a/mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.conf b/mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.conf
new file mode 100644 (file)
index 0000000..af4862d
--- /dev/null
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Match]
+Distribution=centos
diff --git a/mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.extra/usr/lib/repart.d/20-root.conf.d/xfs.conf b/mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.extra/usr/lib/repart.d/20-root.conf.d/xfs.conf
new file mode 100644 (file)
index 0000000..99b846d
--- /dev/null
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# CentOS does not support btrfs so we use xfs instead.
+[Partition]
+Format=xfs
diff --git a/mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.repart/10-usr.conf.d/squashfs.conf b/mkosi.presets/20-final/mkosi.conf.d/10-centos/mkosi.repart/10-usr.conf.d/squashfs.conf
new file mode 100644 (file)
index 0000000..393d5f0
--- /dev/null
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# CentOS does not support erofs so we use squashfs instead.
+[Partition]
+Format=squashfs
index eb88ca764460cfe475fdb1cff8660b91602e7f04..e677797c734134e886303d0aad6da33ad26efa38 100644 (file)
@@ -5,4 +5,6 @@ Distribution=ubuntu
 
 [Content]
 Packages=
-        linux-virtual
+        # We would like to use linux-image-kvm but it does not have support for dm-verity
+        # See https://bugs.launchpad.net/ubuntu/+source/linux-meta-kvm/+bug/2019040.
+        linux-image-generic
diff --git a/mkosi.presets/20-final/mkosi.extra/usr/lib/repart.d/20-root.conf b/mkosi.presets/20-final/mkosi.extra/usr/lib/repart.d/20-root.conf
new file mode 100644 (file)
index 0000000..2f92af2
--- /dev/null
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Partition]
+Type=root
+Format=btrfs
+SizeMinBytes=1G
index b86d2d3e6901e41c2a0a53d316f438554c946b96..e6259c42db858529f10e464521fa72e03e4c7c79 100755 (executable)
@@ -11,5 +11,3 @@ fi
 
 # Exit with non-zero EC if the /failed-services file is not empty (we have -e set)
 [[ ! -s /failed-services ]]
-
-: >/testok
index 6539325108cbd5ea598389045b19c88bb82b7902..6e35b6f2885e4bd1d8dc008ccc38ef0da2b457cf 100644 (file)
@@ -4,11 +4,9 @@ Description=Check if any service failed and then shutdown the machine
 After=multi-user.target network-online.target
 Requires=multi-user.target
 Wants=systemd-resolved.service systemd-networkd.service network-online.target
-OnFailure=poweroff.target
-OnFailureJobMode=replace-irreversibly
+SuccessAction=exit
+FailureAction=exit
 
 [Service]
 Type=oneshot
-ExecStartPre=-rm -f /failed-services
 ExecStart=/usr/lib/systemd/mkosi-check-and-shutdown.sh
-ExecStartPost=systemctl poweroff --no-block
diff --git a/mkosi.presets/20-final/mkosi.repart/00-esp.conf b/mkosi.presets/20-final/mkosi.repart/00-esp.conf
new file mode 100644 (file)
index 0000000..96b292e
--- /dev/null
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Partition]
+Type=esp
+Format=vfat
+CopyFiles=/efi:/
+SizeMinBytes=512M
+SizeMaxBytes=512M
diff --git a/mkosi.presets/20-final/mkosi.repart/10-usr.conf b/mkosi.presets/20-final/mkosi.repart/10-usr.conf
new file mode 100644 (file)
index 0000000..343761d
--- /dev/null
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Partition]
+Type=usr
+Format=erofs
+CopyFiles=/usr:/
+Verity=data
+VerityMatchKey=usr
+Minimize=yes
diff --git a/mkosi.presets/20-final/mkosi.repart/10-usr.conf.d/squashfs.conf b/mkosi.presets/20-final/mkosi.repart/10-usr.conf.d/squashfs.conf
new file mode 100644 (file)
index 0000000..1e54ee1
--- /dev/null
@@ -0,0 +1,2 @@
+[Partition]
+Format=squashfs
diff --git a/mkosi.presets/20-final/mkosi.repart/11-usr-verity.conf b/mkosi.presets/20-final/mkosi.repart/11-usr-verity.conf
new file mode 100644 (file)
index 0000000..b4d45dd
--- /dev/null
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Partition]
+Type=usr-verity
+Verity=hash
+VerityMatchKey=usr
+Minimize=yes
diff --git a/mkosi.presets/20-final/mkosi.repart/12-usr-verity-sig.conf b/mkosi.presets/20-final/mkosi.repart/12-usr-verity-sig.conf
new file mode 100644 (file)
index 0000000..1841d0a
--- /dev/null
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+[Partition]
+Type=usr-verity-sig
+Verity=signature
+VerityMatchKey=usr