systemd-boot-overlay: Don't install kernel if not applicable
Trying to do so fails on Debian bullseye. At the moment we see it in bullseye autopkgtests (debusine.debian.net instance), testbed setup fails if ever the kernel is installed.
A minimal reproducer, in a Docker container, looks like that:
apt update
apt install -y systemd linux-image-amd64
kver=$(ls /boot/vmlinuz-* | cut -d- -f2-)
/usr/bin/kernel-install add $kver /boot/vmlinuz-$kverOutput:
install: cannot create regular file '/boot/f0b73be1967425f7a560d4e66a4efc7b/5.10.0-45-amd64/initrd': No such file or directory
Could not copy '/boot/initrd.img-5.10.0-45-amd64' to '/boot/f0b73be1967425f7a560d4e66a4efc7b/5.10.0-45-amd64/initrd'.We can fix it by adding a guard, ie. what's already done in the systemd
package, in file debian/extra/kernel/postinst.d/zz-systemd-boot [1].
However, if we want to support older Debian releases (ie. from stretch
onward), we need to make it a bit more sophisticated.
Indeed, the bootctl verb 'is-installed' was added in v243. For prior versions we can instead use the verb 'status'. However, we can't rely on the exit code of the verb 'status', because it changed over time. When running in a container, it returns 1 in systemd v232 (stretch), but it returns 0 in systemd v241 (buster). So instead we match what's printed to stderr, which works for both versions.
Note that the reproducer above doesn't fail for buster or stretch, it fails only for bullseye, and it's caused by a Debian-specific script, which was fixed in [2]. So we don't really need the guard for other Debian releases, but it shouldn't hurt either.
Fixes: #1521 (closed)