all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-kernel-meta v2 2/8] proxmox-boot-tool: add status command
Date: Fri, 23 Apr 2021 11:04:44 +0200	[thread overview]
Message-ID: <20210423090451.2279-3-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20210423090451.2279-1-s.ivanov@proxmox.com>

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@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





  parent reply	other threads:[~2021-04-23  9:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23  9:04 [pve-devel] [PATCH pve-kernel-meta/pve-installer v2] boot ZFS on legacy BIOS systems from vfat Stoiko Ivanov
2021-04-23  9:04 ` [pve-devel] [PATCH pve-kernel-meta v2 1/8] proxmox-boot-tool: rename from pve-efiboot-tool Stoiko Ivanov
2021-04-23  9:04 ` Stoiko Ivanov [this message]
2021-04-23  9:04 ` [pve-devel] [PATCH pve-kernel-meta v2 3/8] proxmox-boot-tool: sort and remove duplicates on clean Stoiko Ivanov
2021-04-23  9:04 ` [pve-devel] [PATCH pve-kernel-meta v2 4/8] proxmox-boot: rename uuid list file Stoiko Ivanov
2021-04-23  9:04 ` [pve-devel] [PATCH pve-kernel-meta v2 5/8] proxmox-boot-tool: handle legacy boot zfs installs Stoiko Ivanov
2021-04-23  9:04 ` [pve-devel] [PATCH pve-kernel-meta v2 6/8] proxmox-boot: add grub.cfg header snippet Stoiko Ivanov
2021-04-23  9:04 ` [pve-devel] [PATCH pve-kernel-meta v2 7/8] proxmox-boot: add grub-install wrapper Stoiko Ivanov
2021-04-23  9:04 ` [pve-devel] [PATCH pve-kernel-meta v2 8/8] proxmox-boot: run p-b-t refresh on update-grub Stoiko Ivanov
2021-04-23  9:04 ` [pve-devel] [PATCH installer v2 1/1] always boot zfs with proxmox-boot-tool Stoiko Ivanov
2021-04-23 11:30 ` [pve-devel] applied: [PATCH pve-kernel-meta/pve-installer v2] boot ZFS on legacy BIOS systems from vfat Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210423090451.2279-3-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal