From 691f7f3c38101ede6b294499deb92a9a1604a291 Mon Sep 17 00:00:00 2001
From: Ian Jackson <ijackson@chiark.greenend.org.uk>
Date: Fri, 16 Jul 2021 16:54:00 +0100
Subject: [PATCH] mountkernfs: Mount /sys/firmware/efi/efivars if necessary

I have checked that on my buster systemn, running this script by hand
mounts the directory iff it isn't already mounted.

I have also tested, by running a deliberately sabotaged version, that
the error handling is correct: if the mount call fails, a message is
printed to stderr but (i) the script continues executing (ii) it exits
with a zero status.

Closes: 783990
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
---
 debian/src/initscripts/etc/init.d/mountkernfs.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/debian/src/initscripts/etc/init.d/mountkernfs.sh b/debian/src/initscripts/etc/init.d/mountkernfs.sh
index f9a2677d..353ef048 100755
--- a/debian/src/initscripts/etc/init.d/mountkernfs.sh
+++ b/debian/src/initscripts/etc/init.d/mountkernfs.sh
@@ -52,6 +52,14 @@ mount_filesystems () {
 		domount "$MNTMODE" pstore "" /sys/fs/pstore pstore ""
 	fi
 
+	#
+	# Mount efivarfs on /sys/firmware/efi/efivars if necessary
+	#
+	efivarsmnt=/sys/firmware/efi/efivars
+	if test -d $efivarsmnt; then
+		# domount is a no-op if already mounted
+		domount "$MNTMODE" efivarfs "" $efivarsmnt none ""
+	fi
 }
 
 case "$1" in
-- 
2.20.1

