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
10 # - cleanup - gently delete all kernels not in kernel-keep-list
12 if command -V systemd-detect-virt
>/dev
/null
2>&1 &&
13 systemd-detect-virt
--quiet --container; then
19 for mount
in "${MOUNTROOT}"/* ; do
20 if echo "${mount}" |
grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}' && \
21 mountpoint
-q "${mount}"; then
22 umount
"${mount}" || \
23 { warn
"umount of ${mount} failed - failure"; exit 0; }
29 trap cleanup EXIT INT TERM QUIT
31 .
/usr
/share
/pve-kernel-helper
/scripts
/functions
33 LOADER_TITLE
="Proxmox Virtual Environment"
34 if [ -d /etc
/pve
/ ]; then
35 LOADER_TITLE
="Proxmox Virtual Environment"
36 elif [ -d /usr
/share
/doc
/proxmox-mailgateway
/ ]; then
37 LOADER_TITLE
="Proxmox Mailgateway"
38 elif [ -d /usr
/share
/doc
/proxmox-backup
/ ]; then
39 LOADER_TITLE
="Proxmox Backup Server"
43 if [ ! -f "${ESP_LIST}" ]; then
44 warn
"No ${ESP_LIST} found, skipping ESP sync."
47 if [ -f /etc
/kernel
/cmdline
]; then
48 # we can have cmdline files with multiple or no new line at all, handle both!
49 while IFS
= read -r CMDLINE ||
[ -n "$CMDLINE" ]; do
51 done < /etc
/kernel
/cmdline
52 echo ${CMDLINE} |
grep -q 'root=' || \
53 { warn
"No root= parameter in /etc/kernel/cmdline found!"; exit 1; }
55 warn
"No /etc/kernel/cmdline found - falling back to /proc/cmdline"
56 # remove initrd entries
57 CMDLINE
="$(perl -pe 's/\binitrd=([0-9a-zA-Z\\\/.-])*\s*//g;' /proc/cmdline)"
60 loop_esp_list update_esp_func
64 if ! (echo "${curr_uuid}" |
grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}'); then
65 warn
"WARN: ${curr_uuid} read from ${ESP_LIST} does not look like a VFAT-UUID - skipping"
69 path
="/dev/disk/by-uuid/$curr_uuid"
70 if [ ! -e "${path}" ]; then
71 warn
"WARN: ${path} does not exist - clean '${ESP_LIST}'! - skipping"
75 mountpoint
="${MOUNTROOT}/${curr_uuid}"
76 mkdir
-p "${mountpoint}" || \
77 { warn
"creation of mountpoint ${mountpoint} failed - skipping"; return; }
78 mount
"${path}" "${mountpoint}" || \
79 { warn
"mount of ${path} failed - skipping"; return; }
80 if [ -d /sys
/firmware
/efi
]; then
81 if [ ! -f "${mountpoint}/$PMX_LOADER_CONF" ]; then
82 warn
"${path} contains no loader.conf - skipping"
85 if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then
86 warn
"${path}/$PMX_ESP_DIR does not exist- skipping"
89 elif [ ! -d "${mountpoint}/grub" ]; then
90 warn
"${path} contains no grub directory - skipping"
93 warn
"Copying and configuring kernels on ${path}"
94 copy_and_config_kernels
"${mountpoint}"
95 if [ -d /sys
/firmware
/efi
]; then
96 remove_old_kernels_efi
"${mountpoint}"
98 remove_old_kernels_legacy
"${mountpoint}"
99 mount
--bind "${mountpoint}" "/boot"
105 umount
"${mountpoint}" || \
106 { warn
"umount of ${path} failed - failure"; exit 0; }
108 rmdir "${mountpoint}" || true
111 copy_and_config_kernels
() {
115 for kver
in ${BOOT_KVERS}; do
117 linux_image
="/boot/vmlinuz-${kver}"
118 initrd
="/boot/initrd.img-${kver}"
120 if [ ! -f "${linux_image}" ]; then
121 warn
"No linux-image ${linux_image} found - skipping"
124 if [ ! -f "${initrd}" ]; then
125 warn
"No initrd-image ${initrd} found - skipping"
129 if [ -d /sys
/firmware
/efi
]; then
131 warn
" Copying kernel and creating boot-entry for ${kver}"
132 KERNEL_ESP_DIR
="${PMX_ESP_DIR}/${kver}"
133 KERNEL_LIVE_DIR
="${esp}/${KERNEL_ESP_DIR}"
134 mkdir
-p "${KERNEL_LIVE_DIR}"
135 cp --preserve=timestamps
"${linux_image}" "${KERNEL_LIVE_DIR}/"
136 cp --preserve=timestamps
"${initrd}" "${KERNEL_LIVE_DIR}/"
138 # create loader entry
139 cat > "${esp}/loader/entries/proxmox-${kver}.conf" <<- EOF
140 title ${LOADER_TITLE}
143 linux /${KERNEL_ESP_DIR}/vmlinuz-${kver}
144 initrd /${KERNEL_ESP_DIR}/initrd.img-${kver}
147 warn
" Copying kernel ${kver}"
148 cp --preserve=timestamps
"${linux_image}" "${esp}/"
149 cp --preserve=timestamps
"${initrd}" "${esp}/"
155 remove_old_kernels_efi
() {
158 for kerneldir
in "${esp}/${PMX_ESP_DIR}"/*; do
159 if [ ! -d "${kerneldir}" ]; then
160 warn
" ${kerneldir} is not a directory - skipping"
164 kver
="$(echo "${kerneldir}" | sed -r "s#^${esp}/${PMX_ESP_DIR}/(.
+)\
$#\\1#")"
166 echo "${BOOT_KVERS}" |
grep -q "${kver}" && continue;
167 warn
" Removing old version ${kver}"
168 rm -rf "${kerneldir}"
169 rm -f "${esp}/loader/entries/proxmox-${kver}.conf"
174 remove_old_kernels_legacy
() {
177 for kernel
in "${esp}/"vmlinuz-
*; do
178 kver
="$(echo "${kernel}" | sed -r "s
#^${esp}/vmlinuz-(.+)\$#\\1#")"
180 echo "${BOOT_KVERS}" |
grep -q "${kver}" && continue;
181 warn
" Removing old version ${kver}"
182 rm -rf "${esp}/vmlinuz-${kver}"
183 rm -rf "${esp}/initrd.img-${kver}"
188 set -- $DEB_MAINT_PARAMS
192 # Only run on postinst configure and postrm remove, to avoid wasting
193 # time by calling update-grub multiple times on upgrade and removal.
194 # Also run if we have no DEB_MAINT_PARAMS, in order to work with old
196 */postinst.d
/*:|
*/postinst.d
/*:configure
)
197 reexec_in_mountns
"$@"
198 BOOT_KVERS
="$(boot_kernel_list "$@
")"
201 */postrm.d
/*:|
*/postrm.d
/*:remove
)
202 reexec_in_mountns
"$@"
203 # no newly installed kernel
204 BOOT_KVERS
="$(boot_kernel_list)"