Automatically hide systemd-boot menu on blessed boot

Adds a service which checks if the boot was successfully blessed and if the user does not have any other operating systems installed. If this is the case, hide systemd-boot for the next bootup, assuming the user doesn't force shut down the system and uptime is greater than 5 minutes.
This commit is contained in:
Thomas Duckworth
2025-11-20 20:21:53 +11:00
committed by Nate Graham
parent e81ab5c531
commit b8d2be9d12
3 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2025 Thomas Duckworth <tduck@filotimoproject.org>
set -eu
case "${1:-}" in
show)
/usr/bin/bootctl set-timeout ""
;;
hide)
OTHER_OS_COUNT="$(bootctl list | grep "^\s*id:" | grep -vE "kde-linux_.*\.efi|auto-efi-shell|auto-reboot-to-firmware-setup" | wc -l)"
if [ "$OTHER_OS_COUNT" -gt 0 ]; then
echo "Multiple operating systems detected, not hiding bootloader."
exit 0
fi
UPTIME_SECONDS="$(cut -d. -f1 /proc/uptime)"
if [ "$UPTIME_SECONDS" -lt 300 ]; then
echo "System uptime was less than 5 minutes, not hiding bootloader."
exit 0
fi
if [ "$(systemctl show -p Result --value kde-linux-bless-boot.service 2>/dev/null || echo "failed")" = "success" ]; then
/usr/bin/bootctl set-timeout 0
fi
;;
*)
echo "Usage: $0 {show|hide}"
exit 1
;;
esac

View File

@@ -30,6 +30,7 @@ enable nvidia-resume.service
enable kde-linux-btrfs.service
enable kde-linux-live-setup.service
enable kde-linux-volatile-var-lib-flatpak.service
enable kde-linux-auto-hide-bootloader.service
enable plasma-setup-live-system.service
enable var-lib-snapd-snap.mount
# also one of ours but not prefixed with kde-linux- so others can use it too

View File

@@ -0,0 +1,21 @@
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2025 Thomas Duckworth <tduck@filotimoproject.org>
[Unit]
Description=Automatically hide the bootloader if the image is good
After=local-fs.target
Before=kde-linux-bless-boot.service
[Service]
Type=oneshot
RemainAfterExit=yes
# If the system either is not blessed or is forcibly shut down for some reason,
# the boot menu timeout is reset to default, and the menu is shown.
ExecStart=/usr/lib/auto-hide-bootloader show
# If the boot was blessed, the user shuts the system down normally, and the uptime
# is greater than 5 minutes, the bootloader is hidden, because the current image should work.
# This is idempotent if more than one operating system is installed.
ExecStop=/usr/lib/auto-hide-bootloader hide
[Install]
WantedBy=kde-linux-bless-boot.service