From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC pve-kernel-meta 2/2] proxmox-boot-tool: handle legacy boot zfs installs
Date: Tue, 20 Apr 2021 20:25:40 +0200 [thread overview]
Message-ID: <20210420182540.25204-3-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20210420182540.25204-1-s.ivanov@proxmox.com>
This patch adds support for booting non-uefi/legacy/bios-boot ZFS
installs, by using proxmox-boot-tool to copy the kernels to the ESP
and then generate a fitting grub config for booting from the vfat ESP:
* grub is installed onto the ESP and the MBR points to the ESP
* after copying/deleting the kernels proxmox-boot-tool bindmounts the
ESP on /boot (inside the new mount namespace)
* grub-update then manages to generate a fitting config.
Some paths/sanity-checks needed adaptation (to differentiate between
EFI boot and not (based on the existence of /sys/firmware/efi)
The approach is inspired by @avw in our community-forum [0].
[0] https://forum.proxmox.com/threads/zfs-error-no-such-device-error-unknown-filesystem-entering-rescue-mode.75122/post-374799
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
best viewed with `git show -w`
bin/proxmox-boot-tool | 21 ++++++----
proxmox-boot/zz-pve-efiboot | 81 ++++++++++++++++++++++++++-----------
2 files changed, 70 insertions(+), 32 deletions(-)
diff --git a/bin/proxmox-boot-tool b/bin/proxmox-boot-tool
index f57a752..dd23231 100755
--- a/bin/proxmox-boot-tool
+++ b/bin/proxmox-boot-tool
@@ -150,14 +150,19 @@ init() {
echo "Mounting '$part' on '$esp_mp'."
mount -t vfat "$part" "$esp_mp"
- echo "Installing systemd-boot.."
- mkdir -p "$esp_mp/$PMX_ESP_DIR"
- bootctl --path "$esp_mp" install
-
- echo "Configuring systemd-boot.."
- echo "timeout 3" > "$esp_mp/$PMX_LOADER_CONF.tmp"
- echo "default proxmox-*" >> "$esp_mp/$PMX_LOADER_CONF.tmp"
- mv "$esp_mp/$PMX_LOADER_CONF.tmp" "$esp_mp/$PMX_LOADER_CONF"
+ if [ -d /sys/firmware/efi ]; then
+ echo "Installing systemd-boot.."
+ mkdir -p "$esp_mp/$PMX_ESP_DIR"
+ bootctl --path "$esp_mp" install
+
+ echo "Configuring systemd-boot.."
+ echo "timeout 3" > "$esp_mp/$PMX_LOADER_CONF.tmp"
+ echo "default proxmox-*" >> "$esp_mp/$PMX_LOADER_CONF.tmp"
+ mv "$esp_mp/$PMX_LOADER_CONF.tmp" "$esp_mp/$PMX_LOADER_CONF"
+ else
+ echo "Installing grub i386-pc target.."
+ grub-install --boot-directory $esp_mp --target i386-pc "/dev/$PKNAME"
+ fi
echo "Unmounting '$part'."
umount "$part"
diff --git a/proxmox-boot/zz-pve-efiboot b/proxmox-boot/zz-pve-efiboot
index 1c4ad73..1ce89f7 100755
--- a/proxmox-boot/zz-pve-efiboot
+++ b/proxmox-boot/zz-pve-efiboot
@@ -76,18 +76,30 @@ update_esp_func() {
{ warn "creation of mountpoint ${mountpoint} failed - skipping"; return; }
mount "${path}" "${mountpoint}" || \
{ warn "mount of ${path} failed - skipping"; return; }
- if [ ! -f "${mountpoint}/$PMX_LOADER_CONF" ]; then
- warn "${path} contains no loader.conf - skipping"
- return
- fi
- if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then
- warn "${path}/$PMX_ESP_DIR does not exist- skipping"
+ if [ -d /sys/firmware/efi ]; then
+ if [ ! -f "${mountpoint}/$PMX_LOADER_CONF" ]; then
+ warn "${path} contains no loader.conf - skipping"
+ return
+ fi
+ if [ ! -d "${mountpoint}/$PMX_ESP_DIR" ]; then
+ warn "${path}/$PMX_ESP_DIR does not exist- skipping"
+ return
+ fi
+ elif [ ! -d "${mountpoint}/grub" ]; then
+ warn "${path} contains no grub directory - skipping"
return
fi
-
warn "Copying and configuring kernels on ${path}"
copy_and_config_kernels "${mountpoint}"
- remove_old_kernels "${mountpoint}"
+ if [ -d /sys/firmware/efi ]; then
+ remove_old_kernels_efi "${mountpoint}"
+ else
+ remove_old_kernels_legacy "${mountpoint}"
+ mount --bind "${mountpoint}" "/boot"
+ update-grub
+ umount /boot
+
+ fi
umount "${mountpoint}" || \
{ warn "umount of ${path} failed - failure"; exit 0; }
@@ -113,26 +125,33 @@ copy_and_config_kernels() {
continue
fi
- warn " Copying kernel and creating boot-entry for ${kver}"
- KERNEL_ESP_DIR="${PMX_ESP_DIR}/${kver}"
- KERNEL_LIVE_DIR="${esp}/${KERNEL_ESP_DIR}"
- mkdir -p "${KERNEL_LIVE_DIR}"
- cp -u --preserve=timestamps "${linux_image}" "${KERNEL_LIVE_DIR}/"
- cp -u --preserve=timestamps "${initrd}" "${KERNEL_LIVE_DIR}/"
-
- # create loader entry
- cat > "${esp}/loader/entries/proxmox-${kver}.conf" <<- EOF
- title ${LOADER_TITLE}
- version ${kver}
- options ${CMDLINE}
- linux /${KERNEL_ESP_DIR}/vmlinuz-${kver}
- initrd /${KERNEL_ESP_DIR}/initrd.img-${kver}
- EOF
+ if [ -d /sys/firmware/efi ]; then
+
+ warn " Copying kernel and creating boot-entry for ${kver}"
+ KERNEL_ESP_DIR="${PMX_ESP_DIR}/${kver}"
+ KERNEL_LIVE_DIR="${esp}/${KERNEL_ESP_DIR}"
+ mkdir -p "${KERNEL_LIVE_DIR}"
+ cp -u --preserve=timestamps "${linux_image}" "${KERNEL_LIVE_DIR}/"
+ cp -u --preserve=timestamps "${initrd}" "${KERNEL_LIVE_DIR}/"
+
+ # create loader entry
+ cat > "${esp}/loader/entries/proxmox-${kver}.conf" <<- EOF
+ title ${LOADER_TITLE}
+ version ${kver}
+ options ${CMDLINE}
+ linux /${KERNEL_ESP_DIR}/vmlinuz-${kver}
+ initrd /${KERNEL_ESP_DIR}/initrd.img-${kver}
+ EOF
+ else
+ warn " Copying kernel ${kver}"
+ cp -u --preserve=timestamps "${linux_image}" "${esp}/"
+ cp -u --preserve=timestamps "${initrd}" "${esp}/"
+ fi
done
}
-remove_old_kernels() {
+remove_old_kernels_efi() {
esp="$1"
for kerneldir in "${esp}/${PMX_ESP_DIR}"/*; do
@@ -151,6 +170,20 @@ remove_old_kernels() {
}
+remove_old_kernels_legacy() {
+ esp="$1"
+
+ for kernel in "${esp}/"vmlinuz-*; do
+ kver="$(echo "${kernel}" | sed -r "s#^${esp}/vmlinuz-(.+)\$#\\1#")"
+
+ echo "${BOOT_KVERS}" | grep -q "${kver}" && continue;
+ warn " Removing old version ${kver}"
+ rm -rf "vmlinux-${kerneldir}"
+ rm -rf "initrd.img-${kerneldir}"
+ done
+
+}
+
set -- $DEB_MAINT_PARAMS
mode="${1#\'}"
mode="${mode%\'}"
--
2.20.1
prev parent reply other threads:[~2021-04-20 18:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-20 18:25 [pve-devel] [RFC pve-kernel-meta 0/2] boot ZFS on legacy BIOS systems from vfat Stoiko Ivanov
2021-04-20 18:25 ` [pve-devel] [RFC pve-kernel-meta 1/2] proxmox-boot-tool: rename from pve-efiboot-tool Stoiko Ivanov
2021-04-20 18:25 ` Stoiko Ivanov [this message]
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=20210420182540.25204-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.