From 0956bd22cb7eeb46e9ec213213d66d9170fb7a8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Fri, 12 Jul 2019 15:16:45 +0200 Subject: [PATCH] pve-efiboot-tool: add clean command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit to remove outdated entries from the ESP list Signed-off-by: Fabian Grünbichler --- bin/pve-efiboot-tool | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/bin/pve-efiboot-tool b/bin/pve-efiboot-tool index 31ba9c1..1000bde 100755 --- a/bin/pve-efiboot-tool +++ b/bin/pve-efiboot-tool @@ -165,6 +165,35 @@ init() { refresh } +_clean_impl() { + if [ ! -e "/dev/disk/by-uuid/" ]; then + warn 'E: /dev/disk/by-uuid does not exist, aborting!' + exit 1 + fi + echo -n "Checking whether ESP '$curr_uuid' exists.. " + if [ -e "/dev/disk/by-uuid/$curr_uuid" ]; then + echo "Found!" + else + echo "Not found!" + if [ -z "$dry_run" ] || [ "$dry_run" != '--dry-run' ]; then + _remove_entry_from_list_file "$ESP_LIST" "$curr_uuid" + fi + fi +} + +clean() { + dry_run="$1" + rm -f "$ESP_LIST".tmp + loop_esp_list _clean_impl + if [ "$?" -eq 2 ]; then + warn "E: $ESP_LIST does not exist." + exit 1 + fi + if [ -e "$ESP_LIST".tmp ]; then + mv "$ESP_LIST".tmp "$ESP_LIST" + fi +} + refresh() { hookscript='/etc/kernel/postinst.d/zz-pve-efiboot' echo "Running hook script '$hookscript'.." @@ -176,6 +205,7 @@ usage() { warn "" warn " $0 format [--force]" warn " $0 init " + warn " $0 clean [--dry-run]" warn " $0 refresh" warn " $0 help" } @@ -189,6 +219,10 @@ help() { echo "" echo " initialize EFI system partition at for automatic synchronization of pve-kernels and their associated initrds." echo "" + echo "USAGE: $0 clean [--dry-run]" + echo "" + echo " remove no longer existing EFI system partition UUIDs from $ESP_LIST. Use --dry-run to only print outdated entries instead of removing them." + echo "" echo "USAGE: $0 refresh" echo "" echo " refresh all configured EFI system partitions." @@ -224,6 +258,11 @@ case "$1" in init "$@" exit 0 ;; + 'clean') + shift + clean "$@" + exit 0 + ;; 'refresh') shift refresh -- 2.39.2