4 # adapted from '/etc/kernel/postinst.d/zz-update-grub and
5 # /usr/lib/kernel/install.d/90-loaderentry.install, see also
6 # https://kernel-team.pages.debian.net/kernel-handbook/ch-update-hooks.html
8 # relative to the ESP mountpoint
9 PMX_ESP_DIR
="EFI/proxmox"
11 MOUNTROOT
="${TMPDIR:-/var/tmp}/espmounts"
14 # - no mount on /boot/efi - mount all available esps on /var/tmp/esp-UUID
15 # and copy the stuff for all of them (or copy onto first and sync for the
16 # others - or don't copy if unchanged
17 # - trap error-conditions and make sure stuff gets unmounted
18 # - cleanup - gently delete all kernels not in kernel-keep-list
20 #[ -f "${LOADERDIR}/loader.conf" ] || exit 0
21 #[ -d "${ESPMOUNT}/${PMX_ESP_DIR}" ] || exit 0
23 if command -V systemd-detect-virt
>/dev
/null
2>&1 &&
24 systemd-detect-virt
--quiet --container; then
30 warn
"unmounting ESPs"
31 for mount
in "${MOUNTROOT}"/* ; do
32 if echo "${mount}" |
grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}' && \
33 mountpoint
-q "${mount}"; then
40 trap cleanup EXIT INT TERM QUIT
42 .
/usr
/share
/pve-kernel-helper
/scripts
/functions
44 BOOT_KVERS
="$(boot_kernel_list "$@
")"
46 if [ -f /etc
/kernel
/cmdline
]; then
47 CMDLINE
="$(cat /etc/kernel/cmdline)"
49 warn
"No /etc/kernel/cmdline found - falling back to /proc/cmdline"
50 CMDLINE
="$(cat /proc/cmdline)"
55 esps
="$(lsblk --list -o PATH,UUID,FSTYPE,PARTTYPE,MOUNTPOINT |
56 awk -v OFS=';' '$3 == "vfat
" && $4 == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b
" && $5 == "" {print $1,$2}')"
58 for esp
in ${esps}; do
59 path
="$(echo "${esp}" | cut -d ';' -f1)"
60 uuid
="$(echo "${esp}" | cut -d ';' -f2)"
61 mountpoint
="${MOUNTROOT}/${uuid}"
63 mkdir
-p "${mountpoint}"
64 mount
"${path}" "${mountpoint}" || \
65 { warn
"mount of ${esp} failed - skipping"; continue; }
66 if [ ! -f "${mountpoint}/loader/loader.conf" ]; then
67 warn
"${path} contains no loader.conf - skipping"
70 if [ ! -d "${mountpoint}/EFI/proxmox" ]; then
71 warn
"${path} contains no EFI/proxmox - skipping"
75 warn
"Copying and configuring kernels on ${path}"
76 copy_and_config_kernels
"${mountpoint}"
77 remove_old_kernels
"${mountpoint}"
79 umount
"${mountpoint}" || \
80 { warn
"umount of ${esp} failed - failure"; exit 2; }
87 copy_and_config_kernels
() {
91 for kver
in ${BOOT_KVERS}; do
93 linux_image
="/boot/vmlinuz-${kver}"
94 initrd
="/boot/initrd.img-${kver}"
96 if [ ! -f "${linux_image}" ]; then
97 warn
"No linux-image ${linux_image} found - skipping"
100 if [ ! -f "${initrd}" ]; then
101 warn
"No initrd-image ${initrd} found - skipping"
105 warn
" Copying kernel and creating boot-entry for ${kver}"
106 KERNEL_ESP_DIR
="${PMX_ESP_DIR}/${kver}"
107 KERNEL_LIVE_DIR
="${esp}/${KERNEL_ESP_DIR}"
108 mkdir
-p "${KERNEL_LIVE_DIR}"
109 cp -u --preserve=timestamps
"${linux_image}" "${KERNEL_LIVE_DIR}/"
110 cp -u --preserve=timestamps
"${initrd}" "${KERNEL_LIVE_DIR}/"
112 # create loader entry
113 cat > "${esp}/loader/entries/proxmox-${kver}.conf" <<- EOF
117 linux /${KERNEL_ESP_DIR}/vmlinuz-${kver}
118 initrd /${KERNEL_ESP_DIR}/initrd.img-${kver}
124 remove_old_kernels
() {
127 for kerneldir
in "${esp}/${PMX_ESP_DIR}"/*; do
128 if [ ! -d "${kerneldir}" ]; then
129 warn
" ${kerneldir} is not a directory - skipping"
133 kver
="$(echo "${kerneldir}" | sed -r "s#^${esp}/${PMX_ESP_DIR}/(.
+)\
$#\\1#")"
135 echo "${BOOT_KVERS}" |
grep -q "${kver}" && continue;
136 warn
" Removing old version ${kver}"
137 rm -rf "${kerneldir}"
138 rm -f "${esp}/loader/entries/proxmox-${kver}.conf"
143 set -- $DEB_MAINT_PARAMS
147 # Only run on postinst configure and postrm remove, to avoid wasting
148 # time by calling update-grub multiple times on upgrade and removal.
149 # Also run if we have no DEB_MAINT_PARAMS, in order to work with old
151 */postinst.d
/*:|
*/postinst.d
/*:configure|
*/postrm.d
/*:|
*/postrm.d
/*:remove
)