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 ESP_LIST
="/etc/kernel/pve-efiboot-uuids"
10 PMX_ESP_DIR
="EFI/proxmox"
12 MOUNTROOT
="${TMPDIR:-/var/tmp}/espmounts"
14 # - cleanup - gently delete all kernels not in kernel-keep-list
16 if command -V systemd-detect-virt
>/dev
/null
2>&1 &&
17 systemd-detect-virt
--quiet --container; then
23 warn
"unmounting ESPs"
24 for mount
in "${MOUNTROOT}"/* ; do
25 if echo "${mount}" |
grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}' && \
26 mountpoint
-q "${mount}"; then
33 trap cleanup EXIT INT TERM QUIT
35 .
/usr
/share
/pve-kernel-helper
/scripts
/functions
37 BOOT_KVERS
="$(boot_kernel_list "$@
")"
39 if [ -f /etc
/kernel
/cmdline
]; then
40 CMDLINE
="$(cat /etc/kernel/cmdline)"
42 warn
"No /etc/kernel/cmdline found - falling back to /proc/cmdline"
43 CMDLINE
="$(cat /proc/cmdline)"
47 lsblk
--list -o PATH
,UUID
,FSTYPE
,PARTTYPE
,MOUNTPOINT |
48 awk '$3 == "vfat" && $4 == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && $5 == "" {print $1,$2}'
52 if [ ! -f "${ESP_LIST}" ]; then
53 warn
"No ${ESP_LIST} found cannot update installed kernels - exiting"
54 esps
="$(potential_esps)"
55 warn
"add the UUIDs of one of the following devices to ${ESP_LIST}:"
59 cat "${ESP_LIST}" |
while IFS
= read -r uuid
; do
60 if ! (echo "${uuid}" |
grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}'); then
61 warn
"WARN: ${uuid} read from ${ESP_LIST} does not look like a VFAT-UUID - skipping"
65 path
="/dev/disk/by-uuid/$uuid"
66 if [ ! -e "${path}" ]; then
67 warn
"WARN: ${path} does not exist - clean ${ESP_LIST}! - skipping"
71 mountpoint
="${MOUNTROOT}/${uuid}"
72 mkdir
-p "${mountpoint}"
73 mount
"${path}" "${mountpoint}" || \
74 { warn
"mount of ${path} failed - skipping"; continue; }
75 if [ ! -f "${mountpoint}/loader/loader.conf" ]; then
76 warn
"${path} contains no loader.conf - skipping"
79 if [ ! -d "${mountpoint}/EFI/proxmox" ]; then
80 warn
"${path} contains no EFI/proxmox - skipping"
84 warn
"Copying and configuring kernels on ${path}"
85 copy_and_config_kernels
"${mountpoint}"
86 remove_old_kernels
"${mountpoint}"
88 umount
"${mountpoint}" || \
89 { warn
"umount of ${path} failed - failure"; exit 2; }
96 copy_and_config_kernels
() {
100 for kver
in ${BOOT_KVERS}; do
102 linux_image
="/boot/vmlinuz-${kver}"
103 initrd
="/boot/initrd.img-${kver}"
105 if [ ! -f "${linux_image}" ]; then
106 warn
"No linux-image ${linux_image} found - skipping"
109 if [ ! -f "${initrd}" ]; then
110 warn
"No initrd-image ${initrd} found - skipping"
114 warn
" Copying kernel and creating boot-entry for ${kver}"
115 KERNEL_ESP_DIR
="${PMX_ESP_DIR}/${kver}"
116 KERNEL_LIVE_DIR
="${esp}/${KERNEL_ESP_DIR}"
117 mkdir
-p "${KERNEL_LIVE_DIR}"
118 cp -u --preserve=timestamps
"${linux_image}" "${KERNEL_LIVE_DIR}/"
119 cp -u --preserve=timestamps
"${initrd}" "${KERNEL_LIVE_DIR}/"
121 # create loader entry
122 cat > "${esp}/loader/entries/proxmox-${kver}.conf" <<- EOF
126 linux /${KERNEL_ESP_DIR}/vmlinuz-${kver}
127 initrd /${KERNEL_ESP_DIR}/initrd.img-${kver}
133 remove_old_kernels
() {
136 for kerneldir
in "${esp}/${PMX_ESP_DIR}"/*; do
137 if [ ! -d "${kerneldir}" ]; then
138 warn
" ${kerneldir} is not a directory - skipping"
142 kver
="$(echo "${kerneldir}" | sed -r "s#^${esp}/${PMX_ESP_DIR}/(.
+)\
$#\\1#")"
144 echo "${BOOT_KVERS}" |
grep -q "${kver}" && continue;
145 warn
" Removing old version ${kver}"
146 rm -rf "${kerneldir}"
147 rm -f "${esp}/loader/entries/proxmox-${kver}.conf"
152 set -- $DEB_MAINT_PARAMS
156 # Only run on postinst configure and postrm remove, to avoid wasting
157 # time by calling update-grub multiple times on upgrade and removal.
158 # Also run if we have no DEB_MAINT_PARAMS, in order to work with old
160 */postinst.d
/*:|
*/postinst.d
/*:configure|
*/postrm.d
/*:|
*/postrm.d
/*:remove
)