Accepting request 843382 from Base:System

OBS-URL: https://build.opensuse.org/request/show/843382
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/grub2?expand=0&rev=230
This commit is contained in:
Dominique Leuenberger 2020-10-26 15:11:47 +00:00 committed by Git OBS Bridge
parent 83ace30e23
commit f56927348b
5 changed files with 340 additions and 7 deletions

View File

@ -0,0 +1,233 @@
From 53e9a353dbc5110039bc229e271ea60f7bc5bd69 Mon Sep 17 00:00:00 2001
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date: Mon, 27 Apr 2020 17:51:34 +0200
Subject: [PATCH 1/2] Warn if MBR gap is small and user uses advanced modules
We don't want to support small MBR gap in pair with anything but
the simplest config of biosdisk+part_msdos+simple filesystem. In this
path "simple filesystems" are all current filesystems except zfs and
btrfs.
---
grub-core/partmap/gpt.c | 9 ++++++++-
grub-core/partmap/msdos.c | 7 ++++++-
include/grub/partition.h | 4 +++-
include/grub/util/install.h | 7 +++++--
util/grub-install-common.c | 25 +++++++++++++++++++++++++
util/grub-install.c | 13 +++++++++----
util/grub-setup.c | 2 +-
util/setup.c | 5 +++--
8 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c
index 72a2e37cd..20cbcc7ff 100644
--- a/grub-core/partmap/gpt.c
+++ b/grub-core/partmap/gpt.c
@@ -25,6 +25,9 @@
#include <grub/msdos_partition.h>
#include <grub/gpt_partition.h>
#include <grub/i18n.h>
+#ifdef GRUB_UTIL
+#include <grub/emu/misc.h>
+#endif
GRUB_MOD_LICENSE ("GPLv3+");
@@ -169,7 +172,8 @@ static grub_err_t
gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
unsigned int max_nsectors,
grub_embed_type_t embed_type,
- grub_disk_addr_t **sectors)
+ grub_disk_addr_t **sectors,
+ int warn_short)
{
struct gpt_partition_map_embed_ctx ctx = {
.start = 0,
@@ -191,6 +195,9 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
N_("this GPT partition label contains no BIOS Boot Partition;"
" embedding won't be possible"));
+ if (ctx.len < GRUB_MIN_RECOMMENDED_MBRGAP) {
+ grub_util_warn("Your BIOS Boot Partition is under 1 MiB, please increase its size.");
+ }
if (ctx.len < *nsectors)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
N_("your BIOS Boot Partition is too small;"
diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c
index 508f0ff76..fb452d5fc 100644
--- a/grub-core/partmap/msdos.c
+++ b/grub-core/partmap/msdos.c
@@ -243,7 +243,8 @@ static grub_err_t
pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
unsigned int max_nsectors,
grub_embed_type_t embed_type,
- grub_disk_addr_t **sectors)
+ grub_disk_addr_t **sectors,
+ int warn_short)
{
grub_disk_addr_t end = ~0ULL;
struct grub_msdos_partition_mbr mbr;
@@ -397,6 +398,10 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
return GRUB_ERR_NONE;
}
+ if (end < GRUB_MIN_RECOMMENDED_MBRGAP && warn_short) {
+ grub_util_warn("You have a short MBR gap and use advanced config. Please increase post-MBR gap");
+ }
+
if (end <= 1)
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
N_("this msdos-style partition label has no "
diff --git a/include/grub/partition.h b/include/grub/partition.h
index 7adb7ec6e..adc50d680 100644
--- a/include/grub/partition.h
+++ b/include/grub/partition.h
@@ -52,10 +52,12 @@ struct grub_partition_map
grub_partition_iterate_hook_t hook, void *hook_data);
#ifdef GRUB_UTIL
/* Determine sectors available for embedding. */
+#define GRUB_MIN_RECOMMENDED_MBRGAP 1900
grub_err_t (*embed) (struct grub_disk *disk, unsigned int *nsectors,
unsigned int max_nsectors,
grub_embed_type_t embed_type,
- grub_disk_addr_t **sectors);
+ grub_disk_addr_t **sectors,
+ int warn_short);
#endif
};
typedef struct grub_partition_map *grub_partition_map_t;
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
index f56058111..1541ee233 100644
--- a/include/grub/util/install.h
+++ b/include/grub/util/install.h
@@ -194,13 +194,13 @@ grub_util_bios_setup (const char *dir,
const char *boot_file, const char *core_file,
const char *dest, int force,
int fs_probe, int allow_floppy,
- int add_rs_codes);
+ int add_rs_codes, int warn_short_mbr_gap);
void
grub_util_sparc_setup (const char *dir,
const char *boot_file, const char *core_file,
const char *dest, int force,
int fs_probe, int allow_floppy,
- int add_rs_codes);
+ int add_rs_codes, int warn_short_mbr_gap);
char *
grub_install_get_image_targets_string (void);
@@ -269,6 +269,9 @@ grub_util_get_target_name (const struct grub_install_image_target_desc *t);
extern char *grub_install_copy_buffer;
#define GRUB_INSTALL_COPY_BUFFER_SIZE 1048576
+int
+grub_install_is_short_mbrgap_supported(void);
+
int
grub_install_sync_fs_journal (const char *path);
#endif
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
index 9cc217d70..4c04b1bce 100644
--- a/util/grub-install-common.c
+++ b/util/grub-install-common.c
@@ -234,6 +234,31 @@ char *grub_install_source_directory = NULL;
char *grub_install_locale_directory = NULL;
char *grub_install_themes_directory = NULL;
+int
+grub_install_is_short_mbrgap_supported()
+{
+ int i, j;
+ static const char *whitelist[] =
+ {
+ "part_msdos", "biosdisk", "affs", "afs", "bfs", "archelp",
+ "cpio", "cpio_be", "newc", "odc", "ext2", "fat", "exfat",
+ "f2fs", "fshelp", "hfs", "hfsplus", "hfspluscomp",
+ "iso9660", "jfs", "minix", "minix2", "minix3", "minix_be",
+ "minix2_be", "minix2_be", "nilfs2", "ntfs", "ntfscomp",
+ "reiserfs", "romfs", "sfs", "squash4", "tar", "udf",
+ "ufs1", "ufs1_be", "ufs2", "xfs"
+ };
+ for (i = 0; i < modules.n_entries; i++)
+ {
+ for (j = 0; j < ARRAY_SIZE (whitelist); j++)
+ if (strcmp(modules.entries[i], whitelist[j]) == 0)
+ break;
+ if (j == ARRAY_SIZE (whitelist))
+ return 0;
+ }
+ return 1;
+}
+
void
grub_install_push_module (const char *val)
{
diff --git a/util/grub-install.c b/util/grub-install.c
index 8d18f2530..ac8f98552 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -1956,9 +1956,14 @@ main (int argc, char *argv[])
/* Now perform the installation. */
if (install_bootsector)
- grub_util_bios_setup (platdir, "boot.img", "core.img",
- install_drive, force,
- fs_probe, allow_floppy, add_rs_codes);
+ {
+ int warn_short_mbr_gap = !grub_install_is_short_mbrgap_supported();
+
+ grub_util_bios_setup (platdir, "boot.img", "core.img",
+ install_drive, force,
+ fs_probe, allow_floppy, add_rs_codes,
+ warn_short_mbr_gap);
+ }
break;
}
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
@@ -1985,7 +1990,7 @@ main (int argc, char *argv[])
grub_util_sparc_setup (platdir, "boot.img", "core.img",
install_drive, force,
fs_probe, allow_floppy,
- 0 /* unused */ );
+ 0 /* unused */, 0 /* unused */ );
break;
}
diff --git a/util/grub-setup.c b/util/grub-setup.c
index 42b98ad3c..1783224dd 100644
--- a/util/grub-setup.c
+++ b/util/grub-setup.c
@@ -315,7 +315,7 @@ main (int argc, char *argv[])
arguments.core_file ? : DEFAULT_CORE_FILE,
dest_dev, arguments.force,
arguments.fs_probe, arguments.allow_floppy,
- arguments.add_rs_codes);
+ arguments.add_rs_codes, 0);
/* Free resources. */
grub_fini_all ();
diff --git a/util/setup.c b/util/setup.c
index 59b2b4b85..f34dcb0fe 100644
--- a/util/setup.c
+++ b/util/setup.c
@@ -254,7 +254,8 @@ SETUP (const char *dir,
const char *boot_file, const char *core_file,
const char *dest, int force,
int fs_probe, int allow_floppy,
- int add_rs_codes __attribute__ ((unused))) /* unused on sparc64 */
+ int add_rs_codes __attribute__ ((unused)), /* unused on sparc64 */
+ int warn_small)
{
char *core_path;
char *boot_img, *core_img, *boot_path;
@@ -528,7 +529,7 @@ SETUP (const char *dir,
else if (ctx.dest_partmap)
{
err = ctx.dest_partmap->embed (dest_dev->disk, &nsec, maxsec,
- GRUB_EMBED_PCBIOS, &sectors);
+ GRUB_EMBED_PCBIOS, &sectors, warn_small);
#ifdef GRUB_SETUP_BIOS
if ((err == GRUB_ERR_OUT_OF_RANGE || err == GRUB_ERR_FILE_NOT_FOUND)
&& dest_dev->disk->id == root_dev->disk->id
--
2.26.2

View File

@ -33,6 +33,11 @@ V5:
* Use grub_calloc for overflow check and return NULL when it would
occur.
V6:
* Don't force grub_print_error if no best route found as boot process
could be interrupted by logged error. The default interface will be
used as fallback in this case
---
grub-core/Makefile.core.def | 18 +
grub-core/io/bufio.c | 2 +-
@ -1990,7 +1995,7 @@ Index: grub-2.04/grub-core/net/efi/net.c
===================================================================
--- /dev/null
+++ grub-2.04/grub-core/net/efi/net.c
@@ -0,0 +1,1437 @@
@@ -0,0 +1,1440 @@
+#include <grub/net.h>
+#include <grub/env.h>
+#include <grub/mm.h>
@ -2792,13 +2797,16 @@ Index: grub-2.04/grub-core/net/efi/net.c
+ grub_efi_net_interface_t *inf;
+ int is_ip6 = 0;
+
+ grub_error_push ();
+ err = grub_efi_net_parse_address (server, &ip4, &ip6, &is_ip6, 0);
+
+ if (err)
+ {
+ grub_print_error ();
+ grub_dprintf ("efinetfs", "error in matching route : %s\n", grub_errmsg);
+ grub_error_pop ();
+ return NULL;
+ }
+ grub_error_pop ();
+
+ if (is_ip6)
+ {

View File

@ -0,0 +1,58 @@
From 4cf2e774557c782aa7156b2261d603212b24a64c Mon Sep 17 00:00:00 2001
From: Michael Chang <mchang@suse.com>
Date: Sat, 26 Sep 2020 20:29:40 +0800
Subject: [PATCH 2/2] grub-install: Avoid incompleted install on i386-pc
If any error happens between grub_install_copy_files() and
grub_util_bios_setup(), the system would become unbootable with error
like undefined symbol as a result of incompleted install that leaves
behind images on disk from different build to the modules on /boot.
This patch makes grub_install_copy_files() an adjecent call to
grub_util_bios_setup() to minimize the risk of running into any error in
between that would abort the process.
V1:
* Create platform directory, /boot/grub2/i386-pc, which is required to
have existed in the process of setting up prefix for the core.img.
This fixed "failed to get canonical path of `/boot/grub2/i386-pc`"
error during grub-install.
Signed-off-by: Michael Chang <mchang@suse.com>
---
util/grub-install.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Index: grub-2.04/util/grub-install.c
===================================================================
--- grub-2.04.orig/util/grub-install.c
+++ grub-2.04/util/grub-install.c
@@ -1340,8 +1340,9 @@ main (int argc, char *argv[])
}
}
- grub_install_copy_files (grub_install_source_directory,
- grubdir, platform);
+ if (platform != GRUB_INSTALL_PLATFORM_I386_PC)
+ grub_install_copy_files (grub_install_source_directory,
+ grubdir, platform);
char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
if (!grub_util_is_regular (envfile))
@@ -1430,6 +1431,7 @@ main (int argc, char *argv[])
{
char *t = grub_util_path_concat (2, grubdir,
platname);
+ grub_install_mkdir_p (t);
platdir = grub_canonicalize_file_name (t);
if (!platdir)
grub_util_error (_("failed to get canonical path of `%s'"),
@@ -1964,6 +1966,8 @@ main (int argc, char *argv[])
fs_probe, allow_floppy, add_rs_codes,
warn_short_mbr_gap);
}
+ grub_install_copy_files (grub_install_source_directory,
+ grubdir, platform);
break;
}
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:

View File

@ -1,3 +1,31 @@
-------------------------------------------------------------------
Thu Oct 22 06:19:13 UTC 2020 - Michael Chang <mchang@suse.com>
- Fix grub2-install error with "failed to get canonical path of
`/boot/grub2/i386-pc'." (bsc#1177957)
* Modified 0002-grub-install-Avoid-incompleted-install-on-i386-pc.patch
-------------------------------------------------------------------
Wed Oct 14 08:46:46 UTC 2020 - Michael Chang <mchang@suse.com>
- Fix https boot interrupted by unrecognised network address error message
(bsc#1172952)
* 0001-add-support-for-UEFI-network-protocols.patch
-------------------------------------------------------------------
Tue Oct 13 08:54:10 UTC 2020 - Michael Chang <mchang@suse.com>
- grub2.spec: Fix bare words used as string in expression which is no longer
allowed in rpm 4.16
-------------------------------------------------------------------
Fri Sep 25 07:13:27 UTC 2020 - Michael Chang <mchang@suse.com>
- Improve the error handling when grub2-install fails with short mbr gap
(bsc#1176062)
* 0001-Warn-if-MBR-gap-is-small-and-user-uses-advanced-modu.patch
* 0002-grub-install-Avoid-incompleted-install-on-i386-pc.patch
-------------------------------------------------------------------
Wed Sep 9 08:10:45 UTC 2020 - Michael Chang <mchang@suse.com>

View File

@ -138,7 +138,7 @@ BuildRequires: update-bootloader-rpm-macros
%define grubxenarch x86_64-xen
%endif
%if %{platform} == emu
%if "%{platform}" == "emu"
# force %%{emu} to 1, e.g. for s390
%define emu 1
%endif
@ -332,6 +332,10 @@ Patch718: 0002-ieee1275-powerpc-enables-device-mapper-discovery.patch
Patch719: 0001-Unify-the-check-to-enable-btrfs-relative-path.patch
Patch720: 0001-shim_lock-Disable-GRUB_VERIFY_FLAGS_DEFER_AUTH-if-se.patch
Patch721: 0001-efi-linux-provide-linux-command.patch
# Improve the error handling when grub2-install fails with short mbr gap
# (bsc#1176062)
Patch722: 0001-Warn-if-MBR-gap-is-small-and-user-uses-advanced-modu.patch
Patch723: 0002-grub-install-Avoid-incompleted-install-on-i386-pc.patch
Requires: gettext-runtime
%if 0%{?suse_version} >= 1140
@ -399,7 +403,7 @@ Upstream branding for GRUB2's graphical console
Summary: Bootloader with support for Linux, Multiboot and more
Group: System/Boot
%if %{platform} != emu
%if "%{platform}" != "emu"
BuildArch: noarch
%endif
Requires: %{name} = %{version}
@ -420,7 +424,7 @@ provides support for %{platform} systems.
%package %{grubarch}-debug
Summary: Debug symbols for %{grubarch}
Group: System/Boot
%if %{platform} != emu
%if "%{platform}" != "emu"
BuildArch: noarch
%endif
Requires: %{name}-%{grubarch} = %{version}
@ -464,7 +468,7 @@ provides support for EFI systems.
%package %{grubefiarch}-debug
Summary: Debug symbols for %{grubefiarch}
Group: System/Boot
%if %{platform} != emu
%if "%{platform}" != "emu"
BuildArch: noarch
%endif
Requires: %{name}-%{grubefiarch} = %{version}
@ -655,6 +659,8 @@ swap partition while in resuming
%patch719 -p1
%patch720 -p1
%patch721 -p1
%patch722 -p1
%patch723 -p1
%build
# collect evidence to debug spurious build failure on SLE15
@ -811,7 +817,7 @@ cd build
%define _target_platform i386-%{_vendor}-%{_target_os}%{?_gnu}
%endif
%if %{platform} != "emu"
%if "%{platform}" != "emu"
%define arch_specific --enable-device-mapper
TLFLAGS="-static"