[pve-devel] [PATCH pve-kernel-meta v2 2/8] proxmox-boot-tool: add status command
Stoiko Ivanov
s.ivanov at proxmox.com
Fri Apr 23 11:04:44 CEST 2021
currently simply checking if $ESP_LIST exists, and indicating via
the exit status if proxmox-boot-tool is used for booting the system.
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
v1->v2:
* add sensible output
* replace verbose by quiet (with inverted meaning)
bin/proxmox-boot-tool | 71 ++++++++++++++++++++++++++++++++++++
proxmox-boot/functions | 1 +
proxmox-boot/zz-proxmox-boot | 1 -
3 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/bin/proxmox-boot-tool b/bin/proxmox-boot-tool
index 2d625a6..a60fc0c 100755
--- a/bin/proxmox-boot-tool
+++ b/bin/proxmox-boot-tool
@@ -283,6 +283,7 @@ usage() {
warn " $0 refresh [--hook <name>]"
warn " $0 kernel <add|remove> <kernel-version>"
warn " $0 kernel list"
+ warn " $0 status [--quiet]"
warn " $0 help"
}
@@ -312,6 +313,62 @@ help() {
echo ""
echo " list kernel versions currently selected for inclusion on ESPs."
echo ""
+ echo "USAGE: $0 status [--quiet]"
+ echo ""
+ echo " Print details about the ESPs configuration. Exits with 0 if any ESP is configured, else with 2."
+ echo ""
+}
+
+_status_detail() {
+ if ! (echo "${curr_uuid}" | grep -qE '[0-9a-fA-F]{4}-[0-9a-fA-F]{4}'); then
+ warn "WARN: ${curr_uuid} read from ${ESP_LIST} does not look like a VFAT-UUID - skipping"
+ return
+ fi
+
+ path="/dev/disk/by-uuid/$curr_uuid"
+ if [ ! -e "${path}" ]; then
+ warn "WARN: ${path} does not exist - clean '${ESP_LIST}'! - skipping"
+ return
+ fi
+
+ mountpoint="${MOUNTROOT}/${curr_uuid}"
+ mkdir -p "${mountpoint}" || \
+ { warn "creation of mountpoint ${mountpoint} failed - skipping"; return; }
+ mount "${path}" "${mountpoint}" || \
+ { warn "mount of ${path} failed - skipping"; return; }
+
+ result=""
+ if [ -f "${mountpoint}/$PMX_LOADER_CONF" ]; then
+ result="uefi"
+ if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then
+ warn "${path}/$PMX_ESP_DIR does not exist"
+ fi
+ fi
+ if [ -d "${mountpoint}/grub" ]; then
+ if [ -n "$result" ]; then
+ result="${result},grub"
+ else
+ result="grub"
+ fi
+ fi
+ echo "$curr_uuid is configured with: $result"
+ umount "${mountpoint}" || \
+ { warn "umount of ${path} failed - failure"; exit 0; }
+
+ rmdir "${mountpoint}" || true
+}
+
+status() {
+ quiet="$1"
+ if [ ! -e "${ESP_LIST}" ]; then
+ if [ -z "$quiet" ]; then
+ warn "E: $ESP_LIST does not exist."
+ fi
+ exit 2
+ fi
+ if [ -z "$quiet" ]; then
+ loop_esp_list _status_detail
+ fi
}
if [ -z "$1" ]; then
@@ -390,6 +447,20 @@ case "$1" in
;;
esac
;;
+ 'status')
+ if [ "$#" -eq 2 ] && [ "$2" = '--quiet' ]; then
+ shift
+ status "$1"
+ elif [ "$#" -eq 1 ]; then
+ reexec_in_mountns "$@"
+ shift
+ status
+ else
+ usage
+ exit 1
+ fi
+ exit 0
+ ;;
'help')
shift
help
diff --git a/proxmox-boot/functions b/proxmox-boot/functions
index 72fe15d..4b0b9c2 100755
--- a/proxmox-boot/functions
+++ b/proxmox-boot/functions
@@ -6,6 +6,7 @@ ESPTYPE='c12a7328-f81f-11d2-ba4b-00a0c93ec93b'
MANUAL_KERNEL_LIST="/etc/kernel/pve-efiboot-manual-kernels"
+MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts"
# relative to the ESP mountpoint
PMX_ESP_DIR="EFI/proxmox"
PMX_LOADER_CONF="loader/loader.conf"
diff --git a/proxmox-boot/zz-proxmox-boot b/proxmox-boot/zz-proxmox-boot
index 1c4ad73..b2469d2 100755
--- a/proxmox-boot/zz-proxmox-boot
+++ b/proxmox-boot/zz-proxmox-boot
@@ -6,7 +6,6 @@ set -e
# https://kernel-team.pages.debian.net/kernel-handbook/ch-update-hooks.html
-MOUNTROOT="${TMPDIR:-/var/tmp}/espmounts"
# - cleanup - gently delete all kernels not in kernel-keep-list
--
2.20.1
More information about the pve-devel
mailing list