From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.ivanov@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 253DD75AB1
 for <pve-devel@lists.proxmox.com>; Thu, 22 Apr 2021 13:18:43 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 8ABAC1AF24
 for <pve-devel@lists.proxmox.com>; Thu, 22 Apr 2021 13:18:12 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 00E721AEAE
 for <pve-devel@lists.proxmox.com>; Thu, 22 Apr 2021 13:18:09 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CFD9141E06
 for <pve-devel@lists.proxmox.com>; Thu, 22 Apr 2021 13:18:08 +0200 (CEST)
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 22 Apr 2021 13:17:59 +0200
Message-Id: <20210422111801.4193-7-s.ivanov@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210422111801.4193-1-s.ivanov@proxmox.com>
References: <20210422111801.4193-1-s.ivanov@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH pve-kernel-meta 6/7] proxmox-boot: add grub.cfg
 header snippet
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 22 Apr 2021 11:18:43 -0000

If the system seems to be booted using proxmox-boot, write a header at
the beginning of the grub.cfg generated when running `update-grub`

Additionally print a warning in case the script is run interactively.
This is determined by checking for DPKG_VERSION, which is set when
running as post-inst task (after a kernel install/removal)
and for PVE_EFIBOOT_UNSHARED, which is set by proxmox-boot-tool when
running `proxmox-boot-tool refresh.`

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 proxmox-boot/000_proxmox_boot_header | 22 ++++++++++++++++++++++
 proxmox-boot/Makefile                |  4 ++++
 2 files changed, 26 insertions(+)
 create mode 100755 proxmox-boot/000_proxmox_boot_header

diff --git a/proxmox-boot/000_proxmox_boot_header b/proxmox-boot/000_proxmox_boot_header
new file mode 100755
index 0000000..57dae2c
--- /dev/null
+++ b/proxmox-boot/000_proxmox_boot_header
@@ -0,0 +1,22 @@
+#! /bin/sh
+set -e
+
+. /usr/share/pve-kernel-helper/scripts/functions
+
+if proxmox-boot-tool status; then
+	cat <<- EOF
+	#
+	# This system is booted via proxmox-boot-tool! The grub-config used when
+	# booting from the disks configured with proxmox-boot-tool resides on the vfat
+	# partitions with UUIDs listed in ${ESP_LIST}.
+	# /boot/grub/grub.cfg is NOT read when booting from those disk!
+	EOF
+
+	if [ -z "$DPKG_VERSION" ] && [ -z "$PVE_EFIBOOT_UNSHARED" ]; then
+		warn "W: This system is booted via proxmox-boot-tool:"
+		warn "W: Running update-grub does not update the correct config!"
+		warn "W: Run 'proxmox-boot-tool refresh' instead."
+		warn ""
+	fi
+fi
+
diff --git a/proxmox-boot/Makefile b/proxmox-boot/Makefile
index 3a36cb7..effd726 100644
--- a/proxmox-boot/Makefile
+++ b/proxmox-boot/Makefile
@@ -1,11 +1,13 @@
 KERNEL_HOOKSCRIPTS = proxmox-auto-removal zz-proxmox-boot
 INITRAMFS_HOOKSCRIPTS = proxmox-boot-sync
 SHARE_FILES = functions
+GRUB_CFG_SNIPPET = 000_proxmox_boot_header
 
 POSTINSTHOOKDIR = ${DESTDIR}/etc/kernel/postinst.d
 POSTRMHOOKDIR = ${DESTDIR}/etc/kernel/postrm.d
 POSTINITRAMFSHOOKDIR = ${DESTDIR}/etc/initramfs/post-update.d
 SHARE_SCRIPTDIR = ${DESTDIR}/usr/share/pve-kernel-helper/scripts
+GRUB_CFG_DIR = ${DESTDIR}/etc/grub.d
 
 .PHONY: all
 all:
@@ -19,6 +21,8 @@ install:
 	install -m 0755 ${INITRAMFS_HOOKSCRIPTS} ${POSTINITRAMFSHOOKDIR}
 	install -d ${SHARE_SCRIPTDIR}
 	install -m 0755 ${SHARE_FILES} ${SHARE_SCRIPTDIR}
+	install -d ${GRUB_CFG_DIR}
+	install -m 0755 ${GRUB_CFG_SNIPPET} ${GRUB_CFG_DIR}
 
 .PHONY: clean distclean
 distclean:
-- 
2.20.1