]>
git.proxmox.com Git - pve-kernel-meta.git/blob - proxmox-boot/functions
4 ESP_LIST
="/etc/kernel/proxmox-boot-uuids"
5 ESPTYPE
='c12a7328-f81f-11d2-ba4b-00a0c93ec93b'
7 MANUAL_KERNEL_LIST
="/etc/kernel/proxmox-boot-manual-kernels"
8 PINNED_KERNEL_CONF
="/etc/kernel/proxmox-boot-pin"
9 NEXT_BOOT_PIN
="/etc/kernel/next-boot-pin"
11 MOUNTROOT
="${TMPDIR:-/var/tmp}/espmounts"
12 # relative to the ESP mountpoint
13 PMX_ESP_DIR
="EFI/proxmox"
14 PMX_LOADER_CONF
="loader/loader.conf"
15 GRUB_PIN_SNIPPET
="/etc/default/grub.d/proxmox-kernel-pin.cfg"
17 # adapted from /etc/kernel/postinst.d/apt-auto-removal as present in
18 # debian's apt package:
20 # Mark as not-for-autoremoval those kernel packages that are:
21 # - the currently booted version, if still installed
22 # - the kernel version we've been called for
23 # - the latest kernel version (as determined by debian version number)
24 # - the second-latest kernel version
25 # - the latest kernel version of each series (e.g. 4.13, 4.15, 5.0) by
26 # marking the meta-packages
27 # - the currently pinned kernel if any
29 kernel_keep_versions
() {
30 eval "$(apt-config shell DPKG Dir::bin::dpkg/f)"
31 test -n "$DPKG" || DPKG
="/usr/bin/dpkg"
33 list
="$("${DPKG}" -l | awk '/^[ih][^nc][ ]+pve-kernel-[0-9]+\./ && $2 !~ /-dbg(:.*)?$/ && $2 !~ /-dbgsym(:.*)?$/ { print $2; }' \
34 | sed -e 's#^pve-kernel-##' -e 's#:[^:]\+ # #')"
36 sorted_list
="$(echo "$list" | sort --unique --reverse --version-sort)"
38 [ -n "$1" ] && install_version
="$1"
40 running_version
="$(uname -r | tr 'A-Z' 'a-z')"
42 # ignore the currently running version if attempting a reproducible build
43 if [ -n "${SOURCE_DATE_EPOCH}" ]; then
45 elif [ ! -e "/boot/vmlinuz-$running_version" ]; then
46 # ignore the current version if it got removed, the "auto-remove" logic
47 # will not be affected, because either it is installed and thus we keep
48 # it in the list, or it's already removed anyway
52 latest_2_versions
="$(echo "$sorted_list" | grep -E '^[^ ]+-pve' | head -n2 )"
54 series_metapackages
="$(echo "$sorted_list" | grep -Ev '^[^ ]+-pve' | head -n2)"
56 oldseries
="$(echo "$series_metapackages" | tail -n1)"
57 oldseries_latest_kernel
="$(echo "$sorted_list" | grep -E "^
${oldseries}\.
[^
]+-pve" | head -n1 )"
59 if [ -e "$MANUAL_KERNEL_LIST" ]; then
60 manual_kernels
="$(cat "$MANUAL_KERNEL_LIST")"
63 pinned_kernel
="$(get_first_line "$PINNED_KERNEL_CONF")"
64 nextboot_kernel
="$(get_first_line "$NEXT_BOOT_PIN")"
72 $oldseries_latest_kernel
78 echo "$kernels" |
sort -u |
sed -e '/^$/ d'
81 #bootable kernels are the same as the no_autoremove ones without the meta-package
83 list
="$(kernel_keep_versions "$@
")"
85 echo "$list" |
grep -vE '^[0-9]+\.[0-9]+$' || true
93 if [ -z "$PVE_EFIBOOT_UNSHARED" ]; then
94 export PVE_EFIBOOT_UNSHARED
=1
95 echo "Re-executing '$0' in new private mount namespace.."
96 unshare
--mount --propagation private
"$0" "$@"
102 if [ ! -e ${ESP_LIST} ]; then
106 cat "${ESP_LIST}" |
while IFS
= read -r curr_uuid
; do
107 if [ -z "$curr_uuid" ]; then
116 if [ ! -e "$file" ]; then
121 while IFS
= read -r line ||
[ -n "$line" ]; do
130 if [ -z "${kver}" ]; then
131 rm -f "${GRUB_PIN_SNIPPET}"
133 # grub menu entry ids contain the internal root-device id (e.g. for zfs the GUID of
134 # the pool printed in hex) as this is independent of the ESP (or grub location)
135 # take it from /boot/grub/grub.cfg
136 root_devid
=$
(sed -rn "s/.*gnulinux-advanced-(.+)['] \{$/\1/p" \
138 entry
="gnulinux-advanced-${root_devid}>gnulinux-${kver}-advanced-${root_devid}"
139 echo "GRUB_DEFAULT=\"${entry}\"" > "${GRUB_PIN_SNIPPET}"
143 set_systemd_boot_default
() {
146 if [ -z "${kver}" ]; then
149 entry
="proxmox-${kver}.conf"
152 # replaces the current default entry, if one exists else append it at the end of the file
153 sed -ri "/^default /{h;s/ .*\$/ ${entry}/};\${x;/^$/{s//default ${entry}/;H};x}" \
154 "${mountpoint}/$PMX_LOADER_CONF"