]> git.proxmox.com Git - pve-kernel-meta.git/blobdiff - efiboot/zz-pve-efiboot
zz-pve-efiboot: remove unmount warning
[pve-kernel-meta.git] / efiboot / zz-pve-efiboot
index f3c0aee8425e9bcec16c6eee441d274055cb59ba..8d5d62593f3067769c1592a7e2c8bcbab6cd7b75 100755 (executable)
@@ -6,20 +6,13 @@ set -e
 # https://kernel-team.pages.debian.net/kernel-handbook/ch-update-hooks.html
 
 # relative to the ESP mountpoint
+ESP_LIST="/etc/kernel/pve-efiboot-uuids"
 PMX_ESP_DIR="EFI/proxmox"
 
 MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts"
 
-# TODO:
-# - no mount on /boot/efi - mount all available esps on /var/tmp/esp-UUID
-#   and copy the stuff for all of them (or copy onto first and sync for the
-#   others - or don't copy if unchanged
-# - trap error-conditions and make sure stuff gets unmounted
 # - cleanup - gently delete all kernels not in kernel-keep-list
 
-#[ -f "${LOADERDIR}/loader.conf" ] || exit 0
-#[ -d "${ESPMOUNT}/${PMX_ESP_DIR}" ] || exit 0
-
 if command -V systemd-detect-virt >/dev/null 2>&1 &&
        systemd-detect-virt --quiet --container; then
        exit 0
@@ -27,7 +20,6 @@ fi
 
 cleanup() {
 
-       warn "unmounting ESPs"
        for mount in "${MOUNTROOT}"/* ; do
                if echo "${mount}" | grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}' && \
                        mountpoint -q "${mount}"; then
@@ -39,7 +31,7 @@ cleanup() {
 
 trap cleanup EXIT INT TERM QUIT
 
-. /usr/share/proxmox-ve/scripts/functions
+. /usr/share/pve-kernel-helper/scripts/functions
 
 BOOT_KVERS="$(boot_kernel_list "$@")"
 
@@ -50,19 +42,35 @@ else
        CMDLINE="$(cat /proc/cmdline)"
 fi
 
+potential_esps(){
+       lsblk --list -o PATH,UUID,FSTYPE,PARTTYPE,MOUNTPOINT |
+       awk '$3 == "vfat" && $4 == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && $5 == "" {print $1,$2}'
+}
 
 update_esps() {
-       esps="$(lsblk --list -o PATH,UUID,FSTYPE,PARTTYPE,MOUNTPOINT |
-               awk -v OFS=';' '$3 == "vfat" && $4 == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && $5 == "" {print $1,$2}')"
+       if [ ! -f "${ESP_LIST}" ]; then
+           warn "No ${ESP_LIST} found cannot update installed kernels - exiting"
+           esps="$(potential_esps)"
+           warn "add the UUIDs of one of the following devices to ${ESP_LIST}:"
+           warn "${esps}"
+           exit 1
+       fi
+       cat "${ESP_LIST}" | while IFS= read -r uuid; do
+               if ! (echo "${uuid}" | grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}'); then
+                       warn "WARN: ${uuid} read from ${ESP_LIST} does not look like a VFAT-UUID - skipping"
+                       continue
+               fi
 
-       for esp in ${esps}; do
-               path="$(echo "${esp}" | cut -d ';' -f1)"
-               uuid="$(echo "${esp}" | cut -d ';' -f2)"
-               mountpoint="${MOUNTROOT}/${uuid}"
+               path="/dev/disk/by-uuid/$uuid"
+               if [ ! -e "${path}" ]; then
+                       warn "WARN: ${path} does not exist - clean ${ESP_LIST}! - skipping"
+                       continue
+               fi
 
+               mountpoint="${MOUNTROOT}/${uuid}"
                mkdir -p "${mountpoint}"
                mount "${path}" "${mountpoint}" || \
-                       { warn "mount of ${esp} failed - skipping"; continue; }
+                       { warn "mount of ${path} failed - skipping"; continue; }
                if [ ! -f "${mountpoint}/loader/loader.conf" ]; then
                        warn "${path} contains no loader.conf - skipping"
                        continue
@@ -77,7 +85,7 @@ update_esps() {
                remove_old_kernels "${mountpoint}"
 
                umount "${mountpoint}" || \
-                       { warn "umount of ${esp} failed - failure"; exit 2; }
+                       { warn "umount of ${path} failed - failure"; exit 2; }
 
                rmdir "${mountpoint}"
        done