[pve-devel] [PATCH kernel-meta 04/10] pve-efiboot-tool: add clean command

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jul 12 15:16:45 CEST 2019


to remove outdated entries from the ESP list

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 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 <partition> [--force]"
 	warn "       $0 init <partition>"
+	warn "       $0 clean [--dry-run]"
 	warn "       $0 refresh"
 	warn "       $0 help"
 }
@@ -189,6 +219,10 @@ help() {
 	echo ""
 	echo "    initialize EFI system partition at <partition> 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.20.1





More information about the pve-devel mailing list