mirror of
https://git.proxmox.com/git/pve-kernel-meta
synced 2025-04-30 20:22:36 +00:00
proxmox-boot: add --next-boot option kernel pin command
by setting the desired version in a dedicated file, which is used by the systemd service as condition for removing it and refreshing upon reboot. Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com> Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Tested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
83a41a1a03
commit
d5a182ad1d
@ -288,11 +288,17 @@ list_kernels() {
|
|||||||
echo "$boot_kernels"
|
echo "$boot_kernels"
|
||||||
|
|
||||||
pinned_kernel="$(get_first_line "$PINNED_KERNEL_CONF")"
|
pinned_kernel="$(get_first_line "$PINNED_KERNEL_CONF")"
|
||||||
|
nextboot_kernel="$(get_first_line "$NEXT_BOOT_PIN")"
|
||||||
if [ -n "$pinned_kernel" ]; then
|
if [ -n "$pinned_kernel" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "Pinned kernel:"
|
echo "Pinned kernel:"
|
||||||
echo "${pinned_kernel}"
|
echo "${pinned_kernel}"
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$nextboot_kernel" ]; then
|
||||||
|
echo ""
|
||||||
|
echo "Kernel pinned on next-boot:"
|
||||||
|
echo "${nextboot_kernel}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@ -303,8 +309,8 @@ usage() {
|
|||||||
warn " $0 clean [--dry-run]"
|
warn " $0 clean [--dry-run]"
|
||||||
warn " $0 refresh [--hook <name>]"
|
warn " $0 refresh [--hook <name>]"
|
||||||
warn " $0 kernel <add|remove> <kernel-version>"
|
warn " $0 kernel <add|remove> <kernel-version>"
|
||||||
warn " $0 kernel pin <kernel-version>"
|
warn " $0 kernel pin <kernel-version> [--next-boot]"
|
||||||
warn " $0 kernel unpin"
|
warn " $0 kernel unpin [--next-boot]"
|
||||||
warn " $0 kernel list"
|
warn " $0 kernel list"
|
||||||
warn " $0 status [--quiet]"
|
warn " $0 status [--quiet]"
|
||||||
warn " $0 help"
|
warn " $0 help"
|
||||||
@ -332,14 +338,16 @@ help() {
|
|||||||
echo " add/remove pve-kernel with ABI <kernel-version> to list of synced kernels, in addition to automatically selected ones."
|
echo " add/remove pve-kernel with ABI <kernel-version> to list of synced kernels, in addition to automatically selected ones."
|
||||||
echo " NOTE: you need to manually run 'refresh' once you're finished with adding/removing kernels from the list"
|
echo " NOTE: you need to manually run 'refresh' once you're finished with adding/removing kernels from the list"
|
||||||
echo ""
|
echo ""
|
||||||
echo "USAGE: $0 kernel pin <kernel-version>"
|
echo "USAGE: $0 kernel pin <kernel-version> [--next-boot]"
|
||||||
echo ""
|
echo ""
|
||||||
echo " pin pve-kernel with ABI <kernel-version> as the default entry to be booted."
|
echo " pin pve-kernel with ABI <kernel-version> as the default entry to be booted."
|
||||||
|
echo " with --next-boot sets <kernel-version> only for the next boot."
|
||||||
echo " NOTE: you need to manually run 'refresh' once you're finished with pinning kernels"
|
echo " NOTE: you need to manually run 'refresh' once you're finished with pinning kernels"
|
||||||
echo ""
|
echo ""
|
||||||
echo "USAGE: $0 kernel unpin"
|
echo "USAGE: $0 kernel unpin [--next-boot]"
|
||||||
echo ""
|
echo ""
|
||||||
echo " unpin sets the latest kernel as the default entry (undoes a previous pin)"
|
echo " unpin removes pinned and next-boot kernel settings."
|
||||||
|
echo " with --next-boot only removes the pin for the next boot."
|
||||||
echo ""
|
echo ""
|
||||||
echo "USAGE: $0 kernel list"
|
echo "USAGE: $0 kernel list"
|
||||||
echo ""
|
echo ""
|
||||||
@ -412,6 +420,7 @@ status() {
|
|||||||
|
|
||||||
pin_kernel() {
|
pin_kernel() {
|
||||||
ver="$1"
|
ver="$1"
|
||||||
|
pin_file="$2"
|
||||||
|
|
||||||
if [ -z "$ver" ]; then
|
if [ -z "$ver" ]; then
|
||||||
warn "E: <kernel-version> is mandatory"
|
warn "E: <kernel-version> is mandatory"
|
||||||
@ -419,17 +428,25 @@ pin_kernel() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$pin_file" ]; then
|
||||||
|
pin_file="$PINNED_KERNEL_CONF"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -e "/boot/vmlinuz-$ver" ]; then
|
if [ ! -e "/boot/vmlinuz-$ver" ]; then
|
||||||
warn "E: no kernel image found in /boot for '$ver', not setting default."
|
warn "E: no kernel image found in /boot for '$ver', not setting default."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$ver" > "$PINNED_KERNEL_CONF"
|
echo "$ver" > "$pin_file"
|
||||||
echo "Set kernel '$ver' $PINNED_KERNEL_CONF. Use the 'refresh' command to update the ESPs."
|
echo "Set kernel '$ver' in $pin_file. Use the 'refresh' command to update the ESPs."
|
||||||
}
|
}
|
||||||
|
|
||||||
unpin_kernel() {
|
unpin_kernel() {
|
||||||
|
rm -f "$NEXT_BOOT_PIN"
|
||||||
|
echo "Removed $NEXT_BOOT_PIN. Use the 'refresh' command to update the ESPs."
|
||||||
|
if [ -z "$1" ]; then
|
||||||
rm -f "$PINNED_KERNEL_CONF"
|
rm -f "$PINNED_KERNEL_CONF"
|
||||||
echo "Removed $PINNED_KERNEL_CONF. Use the 'refresh' command to update the ESPs."
|
echo "Removed $PINNED_KERNEL_CONF. Use the 'refresh' command to update the ESPs."
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
@ -501,11 +518,25 @@ case "$1" in
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
'pin')
|
'pin')
|
||||||
|
if [ "$#" -eq 3 ] && [ "$3" = '--next-boot' ]; then
|
||||||
|
pin_kernel "$2" "${NEXT_BOOT_PIN}"
|
||||||
|
elif [ "$#" -eq 2 ]; then
|
||||||
pin_kernel "$2"
|
pin_kernel "$2"
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
'unpin')
|
'unpin')
|
||||||
|
if [ "$#" -eq 2 ] && [ "$2" = '--next-boot' ]; then
|
||||||
unpin_kernel "$2"
|
unpin_kernel "$2"
|
||||||
|
elif [ "$#" -eq 1 ]; then
|
||||||
|
unpin_kernel
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
1
debian/pve-kernel-helper.install
vendored
1
debian/pve-kernel-helper.install
vendored
@ -2,6 +2,7 @@ etc/grub.d/000_proxmox_boot_header
|
|||||||
etc/kernel/postinst.d/*
|
etc/kernel/postinst.d/*
|
||||||
etc/kernel/postrm.d/*
|
etc/kernel/postrm.d/*
|
||||||
etc/initramfs/post-update.d/proxmox-boot-sync
|
etc/initramfs/post-update.d/proxmox-boot-sync
|
||||||
|
lib/systemd/system/proxmox-boot-cleanup.service
|
||||||
usr/sbin/proxmox-boot-tool
|
usr/sbin/proxmox-boot-tool
|
||||||
usr/sbin/grub-install
|
usr/sbin/grub-install
|
||||||
usr/share/pve-kernel-helper/scripts/functions
|
usr/share/pve-kernel-helper/scripts/functions
|
||||||
|
3
debian/rules
vendored
3
debian/rules
vendored
@ -12,5 +12,8 @@ debian/control: $(wildcard debian/*.in)
|
|||||||
%:
|
%:
|
||||||
dh $@
|
dh $@
|
||||||
|
|
||||||
|
override_dh_installsystemd:
|
||||||
|
dh_installsystemd --no-start
|
||||||
|
|
||||||
.PHONY: build clean
|
.PHONY: build clean
|
||||||
build clean:
|
build clean:
|
||||||
|
@ -2,12 +2,14 @@ KERNEL_HOOKSCRIPTS = proxmox-auto-removal zz-proxmox-boot
|
|||||||
INITRAMFS_HOOKSCRIPTS = proxmox-boot-sync
|
INITRAMFS_HOOKSCRIPTS = proxmox-boot-sync
|
||||||
SHARE_FILES = functions
|
SHARE_FILES = functions
|
||||||
GRUB_CFG_SNIPPET = 000_proxmox_boot_header
|
GRUB_CFG_SNIPPET = 000_proxmox_boot_header
|
||||||
|
SYSTEMD_SERVICES = proxmox-boot-cleanup.service
|
||||||
|
|
||||||
POSTINSTHOOKDIR = ${DESTDIR}/etc/kernel/postinst.d
|
POSTINSTHOOKDIR = ${DESTDIR}/etc/kernel/postinst.d
|
||||||
POSTRMHOOKDIR = ${DESTDIR}/etc/kernel/postrm.d
|
POSTRMHOOKDIR = ${DESTDIR}/etc/kernel/postrm.d
|
||||||
POSTINITRAMFSHOOKDIR = ${DESTDIR}/etc/initramfs/post-update.d
|
POSTINITRAMFSHOOKDIR = ${DESTDIR}/etc/initramfs/post-update.d
|
||||||
SHARE_SCRIPTDIR = ${DESTDIR}/usr/share/pve-kernel-helper/scripts
|
SHARE_SCRIPTDIR = ${DESTDIR}/usr/share/pve-kernel-helper/scripts
|
||||||
GRUB_CFG_DIR = ${DESTDIR}/etc/grub.d
|
GRUB_CFG_DIR = ${DESTDIR}/etc/grub.d
|
||||||
|
SERVICE_DIR = ${DESTDIR}/lib/systemd/system
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all:
|
all:
|
||||||
@ -23,6 +25,8 @@ install:
|
|||||||
install -m 0755 ${SHARE_FILES} ${SHARE_SCRIPTDIR}
|
install -m 0755 ${SHARE_FILES} ${SHARE_SCRIPTDIR}
|
||||||
install -d ${GRUB_CFG_DIR}
|
install -d ${GRUB_CFG_DIR}
|
||||||
install -m 0755 ${GRUB_CFG_SNIPPET} ${GRUB_CFG_DIR}
|
install -m 0755 ${GRUB_CFG_SNIPPET} ${GRUB_CFG_DIR}
|
||||||
|
install -d ${SERVICE_DIR}
|
||||||
|
install -m 0644 ${SYSTEMD_SERVICES} ${SERVICE_DIR}
|
||||||
|
|
||||||
.PHONY: clean distclean
|
.PHONY: clean distclean
|
||||||
distclean:
|
distclean:
|
||||||
|
@ -6,6 +6,7 @@ ESPTYPE='c12a7328-f81f-11d2-ba4b-00a0c93ec93b'
|
|||||||
|
|
||||||
MANUAL_KERNEL_LIST="/etc/kernel/pve-efiboot-manual-kernels"
|
MANUAL_KERNEL_LIST="/etc/kernel/pve-efiboot-manual-kernels"
|
||||||
PINNED_KERNEL_CONF="/etc/kernel/proxmox-boot-pin"
|
PINNED_KERNEL_CONF="/etc/kernel/proxmox-boot-pin"
|
||||||
|
NEXT_BOOT_PIN="/etc/kernel/next-boot-pin"
|
||||||
|
|
||||||
MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts"
|
MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts"
|
||||||
# relative to the ESP mountpoint
|
# relative to the ESP mountpoint
|
||||||
@ -60,6 +61,7 @@ kernel_keep_versions() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
pinned_kernel="$(get_first_line "$PINNED_KERNEL_CONF")"
|
pinned_kernel="$(get_first_line "$PINNED_KERNEL_CONF")"
|
||||||
|
nextboot_kernel="$(get_first_line "$NEXT_BOOT_PIN")"
|
||||||
|
|
||||||
kernels="$(cat <<-EOF
|
kernels="$(cat <<-EOF
|
||||||
$running_version
|
$running_version
|
||||||
@ -69,6 +71,7 @@ kernel_keep_versions() {
|
|||||||
$series_metapackages
|
$series_metapackages
|
||||||
$oldseries_latest_kernel
|
$oldseries_latest_kernel
|
||||||
$pinned_kernel
|
$pinned_kernel
|
||||||
|
$nextboot_kernel
|
||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
|
|
||||||
|
13
proxmox-boot/proxmox-boot-cleanup.service
Normal file
13
proxmox-boot/proxmox-boot-cleanup.service
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Clean up bootloader next-boot setting
|
||||||
|
After=systemd-remount-fs.service
|
||||||
|
ConditionPathExists=/etc/kernel/next-boot-pin
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
ExecStart=/usr/sbin/proxmox-boot-tool kernel unpin --next-boot
|
||||||
|
ExecStart=/usr/sbin/proxmox-boot-tool refresh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -93,6 +93,9 @@ update_esp_func() {
|
|||||||
|
|
||||||
pinned_kernel=$(get_first_line "${PINNED_KERNEL_CONF}")
|
pinned_kernel=$(get_first_line "${PINNED_KERNEL_CONF}")
|
||||||
|
|
||||||
|
if [ -e "${NEXT_BOOT_PIN}" ]; then
|
||||||
|
pinned_kernel=$(get_first_line "${NEXT_BOOT_PIN}")
|
||||||
|
fi
|
||||||
if [ -d /sys/firmware/efi ]; then
|
if [ -d /sys/firmware/efi ]; then
|
||||||
set_systemd_boot_default "${mountpoint}" "${pinned_kernel}"
|
set_systemd_boot_default "${mountpoint}" "${pinned_kernel}"
|
||||||
remove_old_kernels_efi "${mountpoint}"
|
remove_old_kernels_efi "${mountpoint}"
|
||||||
|
Loading…
Reference in New Issue
Block a user