Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/CI_RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ every new build. Old kernels are removed by `apt autoremove`, which keeps the
running and newest ones. The versioned headers package also `Provides:
linux-headers`, for DKMS packages that depend on the generic name.

`linux-image-smoothkernel` also keeps GRUB booting the newest installed
SmoothKernel, by package version: its kernel hooks set `GRUB_TOP_LEVEL` in
`/etc/default/grub.d/50-smoothkernel.cfg` whenever a kernel is installed or
removed. GRUB's own ordering compares release strings and would rank an older
`7.2.10-smoothkernel` above `7.2.10-74-smoothkernel`. To boot another kernel,
set `GRUB_TOP_LEVEL` or `GRUB_DEFAULT` in `/etc/default/grub`; either wins.

The DKMS module version of OpenZFS stays the upstream version (`2.4.4`); only
the package revision carries the build number.

Expand Down
58 changes: 56 additions & 2 deletions recipes/build-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,70 @@ add_headers_virtual_provides() {
rm -rf "$tmp"
}

# Lay out, under <root>, the boot-newest script, the /etc/kernel hooks that run
# it (before GRUB's zz-update-grub) and the maintainer scripts that apply it
# when the package itself is installed or removed.
add_boot_newest_hooks() {
local root="$1" dir
install -d "$root/usr/share/smoothkernel"
sed "s/@LOCALVERSION@/${LOCALVERSION}/g" "$ROOT/templates/boot-newest-kernel.in" \
> "$root/usr/share/smoothkernel/boot-newest"
chmod 755 "$root/usr/share/smoothkernel/boot-newest"
sh -n "$root/usr/share/smoothkernel/boot-newest"
for dir in postinst.d postrm.d; do
install -d "$root/etc/kernel/$dir"
cat > "$root/etc/kernel/$dir/zy-smoothkernel-boot-newest" <<'HOOK'
#!/bin/sh
# linux-image-smoothkernel: keep GRUB on the newest installed SmoothKernel.
# zz-update-grub runs after this and writes it into grub.cfg.
[ -x /usr/share/smoothkernel/boot-newest ] || exit 0
exec /usr/share/smoothkernel/boot-newest
HOOK
chmod 755 "$root/etc/kernel/$dir/zy-smoothkernel-boot-newest"
echo "/etc/kernel/$dir/zy-smoothkernel-boot-newest" >> "$root/DEBIAN/conffiles"
done
# The kernel this package depends on is configured before the package, so
# its hooks ran without this one; apply it now, as zz-update-grub would.
cat > "$root/DEBIAN/postinst" <<'POSTINST'
#!/bin/sh
set -e
if [ "$1" = configure ]; then
/usr/share/smoothkernel/boot-newest
if command -v update-grub >/dev/null 2>&1 && [ -e /boot/grub/grub.cfg ]; then
update-grub
fi
fi
POSTINST
cat > "$root/DEBIAN/postrm" <<'POSTRM'
#!/bin/sh
set -e
if [ "$1" = remove ] || [ "$1" = purge ]; then
rm -f /etc/default/grub.d/50-smoothkernel.cfg
if command -v update-grub >/dev/null 2>&1 && [ -e /boot/grub/grub.cfg ]; then
update-grub
fi
fi
POSTRM
chmod 755 "$root/DEBIAN/postinst" "$root/DEBIAN/postrm"
}

# Build a metapackage <name>_<PKG_VERSION>_<arch>.deb that depends on exactly
# this build's <target>. Systems install the metapackage; each new build's
# metapackage pulls in that build's kernel through an ordinary apt upgrade.
#
# With "boot-newest" as a fourth argument it also carries the kernel hooks that
# keep GRUB booting the newest installed SmoothKernel (see
# templates/boot-newest-kernel.in).
build_metapackage() {
local name="$1" target="$2" description="$3"
local name="$1" target="$2" description="$3" extra="${4:-}"
local tmp deb maintainer
# Same maintainer as the packages bindeb-pkg built in this run.
maintainer="$(dpkg-deb -f "$OUT_DIR/linux-image-${KERNEL_RELEASE}_${PKG_VERSION}_${DEB_ARCH}.deb" Maintainer)"
tmp="$(mktemp -d)"
mkdir -p "$tmp/DEBIAN"
if [[ "$extra" == boot-newest ]]; then
add_boot_newest_hooks "$tmp"
fi
cat > "$tmp/DEBIAN/control" <<CONTROL
Package: ${name}
Version: ${PKG_VERSION}
Expand Down Expand Up @@ -641,7 +695,7 @@ fi

echo "==> building metapackages"
build_metapackage linux-image-smoothkernel "linux-image-${KERNEL_RELEASE}" \
"SmoothKernel image (latest build)"
"SmoothKernel image (latest build)" boot-newest
build_metapackage linux-headers-smoothkernel "linux-headers-${KERNEL_RELEASE}" \
"SmoothKernel headers (latest build)"
echo "==> done. Built ${#moved[@]} .debs + 2 metapackages for ${KERNEL_RELEASE} in $OUT_DIR"
44 changes: 44 additions & 0 deletions templates/boot-newest-kernel.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh
# Boot the newest installed SmoothKernel. Shipped by linux-image-smoothkernel
# and run from its kernel hooks on every kernel install and removal.
#
# GRUB ranks kernels by their release string, which puts an older build first
# when the names differ in shape: the installer's 7.2.10@LOCALVERSION@ sorts
# above the archive's 7.2.10-74@LOCALVERSION@. This picks the kernel with the
# highest package version instead and has GRUB put it first, through
# GRUB_TOP_LEVEL.
#
# To boot another kernel, set GRUB_TOP_LEVEL or GRUB_DEFAULT yourself in
# /etc/default/grub; either takes precedence over this.

set -e

cfg=/etc/default/grub.d/50-smoothkernel.cfg

newest=""
newest_version=""
for entry in $(dpkg-query -W -f '${Package}=${Version}\n' 'linux-image-*@LOCALVERSION@' 2>/dev/null); do
pkg=${entry%%=*}
version=${entry#*=}
release=${pkg#linux-image-}
# A kernel being removed is still known to dpkg; one being installed is
# not configured yet. Its image in /boot is what counts.
[ -e "/boot/vmlinuz-${release}" ] || continue
if [ -z "$newest" ] || dpkg --compare-versions "$version" gt "$newest_version"; then
newest=$release
newest_version=$version
fi
done

if [ -z "$newest" ]; then
rm -f "$cfg"
exit 0
fi

mkdir -p "${cfg%/*}"
cat > "${cfg}.new" << EOF
# Written by linux-image-smoothkernel: boot the newest installed SmoothKernel.
# To boot another kernel, set GRUB_TOP_LEVEL or GRUB_DEFAULT in /etc/default/grub.
GRUB_TOP_LEVEL="\${GRUB_TOP_LEVEL:-/boot/vmlinuz-${newest}}"
EOF
mv "${cfg}.new" "$cfg"
Loading