proxmox-boot-tool: add status command

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>
This commit is contained in:
Stoiko Ivanov 2021-04-23 11:04:44 +02:00 committed by Thomas Lamprecht
parent b3c980626d
commit 182bfa3a0f
3 changed files with 72 additions and 1 deletions

View File

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

View File

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

View File

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