[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#763127: UEFI corner case - installer booted in UEFI mode, existing system in BIOS mode - PLEASE REVIEW



Current patches attached here.

I was totally thrown in testing by #768788 - some of my tests on
installed EFI systems were failing, due to the broken GUID on the
ESP. Yay!

I've merged things forward and I'm ready to push these changes. Please
review one last time?

-- 
Steve McIntyre, Cambridge, UK.                                steve@einval.com
"I've only once written 'SQL is my bitch' in a comment. But that code 
 is in use on a military site..." -- Simon Booth
>From 3d16e8491d1ddc0a8903d173af989906de1b7d43 Mon Sep 17 00:00:00 2001
From: Steve McIntyre <steve@einval.com>
Date: Wed, 1 Oct 2014 23:58:10 +0100
Subject: [PATCH] Recognise the new ignore_uefi flag from partman-efi

---
 debian/changelog |    7 +++++++
 grub-installer   |    6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 4baf893..ff8fa14 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+grub-installer (1.99) unstable; urgency=medium
+
+  [ Steve McIntyre ]
+  * Recognise the new ignore_uefi flag from partman-efi.
+
+ -- Steve McIntyre <93sam@debian.org>  Wed, 01 Oct 2014 01:42:22 +0100
+
 grub-installer (1.98) unstable; urgency=medium
 
   [ Philip Hands ]
diff --git a/grub-installer b/grub-installer
index bff4174..ad5d688 100755
--- a/grub-installer
+++ b/grub-installer
@@ -329,7 +329,11 @@ case $ARCH in
 	fi
 	;;
     i386/efi|amd64/efi)
-	grub_package="grub-efi"
+	if [ -f /var/lib/partman/ignore_uefi ]; then
+		grub_package="grub-pc"
+	else
+		grub_package="grub-efi"
+	fi
 	;;
     i386/*|amd64/*)
 	grub_package="grub-pc"
-- 
1.7.10.4

>From f8633afbcbae7f8c9b0a588b62de8c7f490d7638 Mon Sep 17 00:00:00 2001
From: Steve McIntyre <steve@einval.com>
Date: Wed, 12 Nov 2014 01:08:55 +0000
Subject: [PATCH] Recognise the new ignore_uefi flag from partman-efi

---
 debian/changelog |    7 +++++++
 src/system/efi.c |    9 ++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index d10bc4d..f637394 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+libdebian-installer (0.98) unstable; urgency=low
+
+  [ Steve McIntyre ]
+  * Recognise the new ignore_uefi flag from partman-efi.
+
+ -- Steve McIntyre <93sam@debian.org>  Wed, 01 Oct 2014 01:42:22 +0100
+
 libdebian-installer (0.97) unstable; urgency=low
 
   [ Jérémy Bobbio ]
diff --git a/src/system/efi.c b/src/system/efi.c
index 41af731..84659ef 100644
--- a/src/system/efi.c
+++ b/src/system/efi.c
@@ -28,7 +28,14 @@ int di_system_is_efi(void)
 {
 	int ret = access("/sys/firmware/efi", R_OK);
 	if (ret == 0)
-		return 1;
+	{
+		/* Have we been told to ignore EFI in partman-efi? */
+		ret = access("/var/lib/partman/ignore_uefi", R_OK);
+		if (ret == 0)
+			return 0;
+		else
+			return 1;
+	}
 	else
 		return 0;
 }
-- 
1.7.10.4

>From e5870c91bdf678208a28806370af3b16a09e5e74 Mon Sep 17 00:00:00 2001
From: Steve McIntyre <steve@einval.com>
Date: Thu, 2 Oct 2014 00:03:25 +0100
Subject: [PATCH] Recognise the new ignore_uefi flag from partman-efi

---
 debian/changelog     |    7 +++++++
 debian/isinstallable |    2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index 61ac47e..615acee 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+lilo-installer (1.47) unstable; urgency=low
+
+  [ Steve McIntyre ]
+  * Recognise the new ignore_uefi flag from partman-efi.
+
+ -- Steve McIntyre <93sam@debian.org>  Wed, 01 Oct 2014 01:42:22 +0100
+
 lilo-installer (1.46) unstable; urgency=low
 
   [ Updated translations ]
diff --git a/debian/isinstallable b/debian/isinstallable
index e3f9708..80a7939 100755
--- a/debian/isinstallable
+++ b/debian/isinstallable
@@ -11,7 +11,7 @@ case $ARCH in
 	# LILO stands a better chance of working in BIOS compatibility mode,
 	# where /sys/firmware/efi doesn't exist.
 	# Note: depends on partman-efi to load the efivars module!
-	if [ -d /sys/firmware/efi ]; then
+	if [ -d /sys/firmware/efi ] && [ ! -f /var/lib/partman/ignore_uefi ]; then
 		log "LILO not usable on EFI PCs without BIOS compatibility; use grub-efi"
 		exit 1
 	fi
-- 
1.7.10.4

>From d4199b453834801538d0f41b5b18f0a71850425a Mon Sep 17 00:00:00 2001
From: Steve McIntyre <steve@einval.com>
Date: Thu, 2 Oct 2014 00:05:15 +0100
Subject: [PATCH] Recognise the new ignore_uefi flag from partman-efi

---
 debian/changelog                  |    7 +++++++
 os-probes/mounted/x86/05efi       |    2 +-
 os-probes/mounted/x86/20microsoft |    2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 1499695..84a81e4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+os-prober (1.65) unstable; urgency=medium
+
+  [ Steve McIntyre ]
+  * Recognise the new ignore_uefi flag from partman-efi.
+
+ -- Steve McIntyre <93sam@debian.org>  Wed, 01 Oct 2014 01:42:22 +0100
+
 os-prober (1.64) unstable; urgency=medium
 
   [ Frederic Bonnard ]
diff --git a/os-probes/mounted/x86/05efi b/os-probes/mounted/x86/05efi
index e77ca6d..93309ce 100755
--- a/os-probes/mounted/x86/05efi
+++ b/os-probes/mounted/x86/05efi
@@ -8,7 +8,7 @@ mpoint="$2"
 type="$3"
 
 # This file is for UEFI platform only
-if [ ! -d /sys/firmware/efi ]; then
+if [ ! -d /sys/firmware/efi ] || [ -f /var/lib/partman/ignore_uefi ]; then
 	debug "Not on UEFI platform"
 	exit 1
 fi
diff --git a/os-probes/mounted/x86/20microsoft b/os-probes/mounted/x86/20microsoft
index bf829d9..6fb3cc5 100755
--- a/os-probes/mounted/x86/20microsoft
+++ b/os-probes/mounted/x86/20microsoft
@@ -8,7 +8,7 @@ mpoint="$2"
 type="$3"
 
 # This script looks for legacy BIOS bootloaders only. Skip if running UEFI
-if [ -d /sys/firmware/efi ]; then
+if [ -d /sys/firmware/efi ] && [ ! -f /var/lib/partman/ignore_uefi ]; then
 	debug "Skipping legacy bootloaders on UEFI system"
 	exit 1
 fi
-- 
1.7.10.4

>From 7e80794efb8d1b717eafa951a9d70fc30ffe6804 Mon Sep 17 00:00:00 2001
From: Steve McIntyre <steve@einval.com>
Date: Wed, 12 Nov 2014 00:40:37 +0000
Subject: [PATCH] Better handle mixed UEFI and non-UEFI booting

Warn the user if we've booted in UEFI mode but we seem to have only
non-UEFI existing OS installations - give them the option to switch
the installer to non-UEFI mode from this point forwards so they don't
break potential dual-boot setup. Closes: #763127

Check for EFI System Partitions on the target disks - if we have none
but have other filesystems then that suggests there is a BIOS-mode OS
already installed. If so, ask the user what they want to do.

Add a flag file /var/lib/partman/ignore_uefi that other bits of d-i
can look for to know that although the installer is running in UEFI
mode we should stick to installing for BIOS-mode boot instead.
---
 check.d/efi                  |    4 ++++
 choose_method/efi/choices    |    4 ++++
 debian/changelog             |   10 ++++++++++
 debian/partman-efi.templates |   16 ++++++++++++++++
 debian/po/templates.pot      |   15 +++++++++++++++
 init.d/efi                   |   25 +++++++++++++++++++++++++
 update.d/efi_visuals         |    4 ++++
 7 files changed, 78 insertions(+)

diff --git a/check.d/efi b/check.d/efi
index 395688d..9d74bd3 100755
--- a/check.d/efi
+++ b/check.d/efi
@@ -4,6 +4,10 @@ if [ ! -d /proc/efi ] && [ ! -d /sys/firmware/efi ]; then
 	exit 0
 fi
 
+if [ -f /var/lib/partman/ignore_uefi ]; then
+	exit 0
+fi
+
 . /lib/partman/lib/base.sh
 
 have_efi=no
diff --git a/choose_method/efi/choices b/choose_method/efi/choices
index 160a565..b4af018 100755
--- a/choose_method/efi/choices
+++ b/choose_method/efi/choices
@@ -9,6 +9,10 @@ if [ ! -d /proc/efi ] && [ ! -d /sys/firmware/efi ]; then
 	exit 0
 fi
 
+if [ -f /var/lib/partman/ignore_uefi ]; then
+	exit 0
+fi
+
 db_metaget partman-efi/text/efi description
 
 printf "efi\t${RET}\n"
diff --git a/debian/changelog b/debian/changelog
index cc9897f..d69a4ac 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+partman-efi (53) UNRELEASED; urgency=medium
+
+  [ Steve McIntyre ]
+  * Warn the user if we've booted in UEFI mode but we seem to have only
+    non-UEFI existing OS installations - give them the option to switch
+    the installer to non-UEFI mode from this point forwards so they don't
+    break potential dual-boot setup. Closes: #763127
+
+ -- Steve McIntyre <93sam@debian.org>  Wed, 12 Nov 2014 00:37:44 +0000
+
 partman-efi (52) unstable; urgency=medium
 
   [ Steve McIntyre ]
diff --git a/debian/partman-efi.templates b/debian/partman-efi.templates
index 6fb2f7d..c03f8de 100644
--- a/debian/partman-efi.templates
+++ b/debian/partman-efi.templates
@@ -41,3 +41,19 @@ Type: error
 _Description: EFI partition too small
  EFI System Partitions on this architecture cannot be created with a size
  less than 35 MB. Please make the EFI System Partition larger.
+
+Template: partman-efi/non_efi_system
+Type: boolean
+# :sl5:
+_Description: Force UEFI installation?
+ Your computer's firmware has started the installer in UEFI mode but
+ it looks like there may be existing operating systems already
+ installed on your computer using 'BIOS compatibility mode'. If you
+ continue to install Debian in UEFI mode, it might be difficult to
+ reboot your computer into any BIOS-mode operating systems later.
+ .
+ If you wish to install Debian in UEFI mode and don't care about
+ keeping the ability to boot one of the existing systems, you have the
+ option to force that here. If you wish to keep the option to boot an
+ existing operating system, you should choose NOT to force UEFI
+ installation here.
diff --git a/debian/po/templates.pot b/debian/po/templates.pot
index 1a1a857..0fbf475 100644
--- a/debian/po/templates.pot
+++ b/debian/po/templates.pot
@@ -85,3 +85,18 @@ msgid ""
 "EFI System Partitions on this architecture cannot be created with a size "
 "less than 35 MB. Please make the EFI System Partition larger."
 msgstr ""
+
+#. Type: boolean
+#. Description
+#. :sl5:
+#: ../partman-efi.templates:9001
+msgid "Force EFI installation?"
+msgstr ""
+
+#. Type: boolean
+#. Description
+#. :sl5:
+#: ../partman-efi.templates:9001
+msgid "EFI boot, but no ESP found and other filesystems in use"
+msgstr ""
+
diff --git a/init.d/efi b/init.d/efi
index 8955718..9418971 100755
--- a/init.d/efi
+++ b/init.d/efi
@@ -30,6 +30,9 @@ fi
 gpt_efi_type=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
 msdos_efi_type=0xef
 
+NUM_ESP=0
+NUM_NO=0
+
 for dev in /var/lib/partman/devices/*; do
 	[ -d "$dev" ] || continue
 	cd $dev
@@ -52,6 +55,10 @@ for dev in /var/lib/partman/devices/*; do
 		elif [ "$label_type" = gpt ] && \
 		     [ "$(blkid -o value -s PART_ENTRY_TYPE -p "$path" 2>/dev/null)" = "$gpt_efi_type" ]; then
 			partitions="$partitions $id"
+		else
+			if [ "$fs" != "free" ]; then
+				NUM_NO=$(($NUM_NO + 1))
+			fi
 		fi
 	done
 	close_dialog
@@ -62,7 +69,10 @@ for dev in /var/lib/partman/devices/*; do
 	while { read_line flag; [ "$flag" ]; }; do
 		if [ "$flag" = boot ]; then
 			efi=yes
+			NUM_ESP=$(($NUM_ESP + 1))
 			# cannot break here
+		else
+			NUM_NO=$(($NUM_NO + 1))
 		fi
 	done
 	close_dialog
@@ -72,3 +82,18 @@ for dev in /var/lib/partman/devices/*; do
 	fi
 	done
 done
+
+log "Found $NUM_ESP ESPs, $NUM_NO non-ESPs"
+
+if [ $NUM_ESP = 0 ] && [ $NUM_NO -gt 0 ]; then
+	db_input critical partman-efi/non_efi_system || true
+	db_go || exit 1
+	db_fset partman-efi/non_efi_system seen true
+	db_get partman-efi/non_efi_system
+	if [ "$RET" = false ]; then
+		log "User chose to ignore UEFI"
+		touch /var/lib/partman/ignore_uefi
+	else
+		log "User chose to continue in UEFI mode"
+	fi
+fi
diff --git a/update.d/efi_visuals b/update.d/efi_visuals
index eed5412..ac47af5 100755
--- a/update.d/efi_visuals
+++ b/update.d/efi_visuals
@@ -6,6 +6,10 @@ if [ ! -d /proc/efi ] && [ ! -d /sys/firmware/efi ]; then
 	exit 0
 fi
 
+if [ -f /var/lib/partman/ignore_uefi ]; then
+	exit 0
+fi
+
 dev=$1
 num=$2
 id=$3
-- 
1.7.10.4


Reply to: