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
9 MOUNTROOT
="${TMPDIR:-/var/tmp}/espmounts"
11 # - cleanup - gently delete all kernels not in kernel-keep-list
13 if command -V systemd-detect-virt
>/dev
/null
2>&1 &&
14 systemd-detect-virt
--quiet --container; then
20 for mount
in "${MOUNTROOT}"/* ; do
21 if echo "${mount}" |
grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}' && \
22 mountpoint
-q "${mount}"; then
23 umount
"${mount}" || \
24 { warn
"umount of ${mount} failed - failure"; exit 0; }
30 trap cleanup EXIT INT TERM QUIT
32 .
/usr
/share
/pve-kernel-helper
/scripts
/functions
34 BOOT_KVERS
="$(boot_kernel_list "$@
")"
37 lsblk
--list -o PATH
,UUID
,FSTYPE
,PARTTYPE
,MOUNTPOINT |
38 awk '$3 == "vfat" && $4 == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && $5 == "" {print $1,$2}'
42 if [ ! -f "${ESP_LIST}" ]; then
43 warn
"No ${ESP_LIST} found, skipping ESP sync."
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)"
53 cat "${ESP_LIST}" |
while IFS
= read -r uuid
; do
54 if ! (echo "${uuid}" |
grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}'); then
55 warn
"WARN: ${uuid} read from ${ESP_LIST} does not look like a VFAT-UUID - skipping"
59 path
="/dev/disk/by-uuid/$uuid"
60 if [ ! -e "${path}" ]; then
61 warn
"WARN: ${path} does not exist - clean ${ESP_LIST}! - skipping"
65 mountpoint
="${MOUNTROOT}/${uuid}"
66 mkdir
-p "${mountpoint}" || \
67 { warn
"creation of mountpoint ${mountpoint} failed - skipping"; continue; }
68 mount
"${path}" "${mountpoint}" || \
69 { warn
"mount of ${path} failed - skipping"; continue; }
70 if [ ! -f "${mountpoint}/$PMX_LOADER_CONF" ]; then
71 warn
"${path} contains no loader.conf - skipping"
74 if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then
75 warn
"${path}/$PMX_ESP_DIR does not exist- skipping"
79 warn
"Copying and configuring kernels on ${path}"
80 copy_and_config_kernels
"${mountpoint}"
81 remove_old_kernels
"${mountpoint}"
83 umount
"${mountpoint}" || \
84 { warn
"umount of ${path} failed - failure"; exit 0; }
86 rmdir "${mountpoint}" || true
91 copy_and_config_kernels
() {
95 for kver
in ${BOOT_KVERS}; do
97 linux_image
="/boot/vmlinuz-${kver}"
98 initrd
="/boot/initrd.img-${kver}"
100 if [ ! -f "${linux_image}" ]; then
101 warn
"No linux-image ${linux_image} found - skipping"
104 if [ ! -f "${initrd}" ]; then
105 warn
"No initrd-image ${initrd} found - skipping"
109 warn
" Copying kernel and creating boot-entry for ${kver}"
110 KERNEL_ESP_DIR
="${PMX_ESP_DIR}/${kver}"
111 KERNEL_LIVE_DIR
="${esp}/${KERNEL_ESP_DIR}"
112 mkdir
-p "${KERNEL_LIVE_DIR}"
113 cp -u --preserve=timestamps
"${linux_image}" "${KERNEL_LIVE_DIR}/"
114 cp -u --preserve=timestamps
"${initrd}" "${KERNEL_LIVE_DIR}/"
116 # create loader entry
117 cat > "${esp}/loader/entries/proxmox-${kver}.conf" <<- EOF
121 linux /${KERNEL_ESP_DIR}/vmlinuz-${kver}
122 initrd /${KERNEL_ESP_DIR}/initrd.img-${kver}
128 remove_old_kernels
() {
131 for kerneldir
in "${esp}/${PMX_ESP_DIR}"/*; do
132 if [ ! -d "${kerneldir}" ]; then
133 warn
" ${kerneldir} is not a directory - skipping"
137 kver
="$(echo "${kerneldir}" | sed -r "s#^${esp}/${PMX_ESP_DIR}/(.
+)\
$#\\1#")"
139 echo "${BOOT_KVERS}" |
grep -q "${kver}" && continue;
140 warn
" Removing old version ${kver}"
141 rm -rf "${kerneldir}"
142 rm -f "${esp}/loader/entries/proxmox-${kver}.conf"
147 set -- $DEB_MAINT_PARAMS
151 # Only run on postinst configure and postrm remove, to avoid wasting
152 # time by calling update-grub multiple times on upgrade and removal.
153 # Also run if we have no DEB_MAINT_PARAMS, in order to work with old
155 */postinst.d
/*:|
*/postinst.d
/*:configure|
*/postrm.d
/*:|
*/postrm.d
/*:remove
)