Add a heuristic to detect and properly mark EFI system partitions

when re-using pre-existing partitions.
This commit is contained in:
martin 2020-10-05 12:28:45 +00:00
parent 7f481043e4
commit 325b99962d
5 changed files with 67 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: README.md_defs,v 1.5 2020/09/28 18:40:23 martin Exp $ */
/* $NetBSD: README.md_defs,v 1.6 2020/10/05 12:28:45 martin Exp $ */
The following is trying to document the most important machine dependent
defines used in the sysinst code.
@ -112,5 +112,8 @@ partitions this way).
HAVE_GPT_BOOT defined if the architecture can boot from GPT
HAVE_EFI_BOOT defined if the architecture may be able
to boot from an EFI partition
NO_DISKLABEL_BOOT defined if the architecture can NOT boot
from a disklabel partitioned disk

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.h,v 1.8 2019/11/16 21:25:14 martin Exp $ */
/* $NetBSD: md.h,v 1.9 2020/10/05 12:28:45 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -128,3 +128,6 @@ bool x86_md_need_bootblock(struct install_partition_desc *install);
/* post-process boot.cfg for KASLR if that kernel has been selected */
void amd64_md_boot_cfg_finalize(const char*);
#define MD_BOOT_CFG_FINALIZE(P) amd64_md_boot_cfg_finalize(P)
#define HAVE_EFI_BOOT 1 /* we support EFI boot partitions */

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.h,v 1.6 2020/05/04 18:19:34 joerg Exp $ */
/* $NetBSD: md.h,v 1.7 2020/10/05 12:28:45 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -118,3 +118,5 @@ void evbarm_part_defaults(struct pm_devs*, struct part_usage_info*,
#define MD_PART_DEFAULTS(A,B,C) evbarm_part_defaults(A,B,C)
#define HAVE_EFI_BOOT 1 /* we support EFI boot partitions */

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.h,v 1.7 2019/10/02 11:16:02 maya Exp $ */
/* $NetBSD: md.h,v 1.8 2020/10/05 12:28:45 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -123,3 +123,5 @@ void x86_md_part_defaults(struct pm_devs*, struct part_usage_info**,
/* no need to install bootblock if installing for UEFI */
bool x86_md_need_bootblock(struct install_partition_desc *install);
#define MD_NEED_BOOTBLOCK(A) x86_md_need_bootblock(A)
#define HAVE_EFI_BOOT 1 /* we support EFI boot partitions */

View File

@ -1,4 +1,4 @@
/* $NetBSD: bsddisklabel.c,v 1.48 2020/10/04 19:05:47 martin Exp $ */
/* $NetBSD: bsddisklabel.c,v 1.49 2020/10/05 12:28:45 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -1776,12 +1776,19 @@ make_bsd_partitions(struct install_partition_desc *install)
}
/*
* Make sure the target root partition is properly marked
* Make sure the target root partition is properly marked,
* check for existing EFI boot partition.
*/
bool have_inst_target = false;
#ifdef HAVE_EFI_BOOT
daddr_t target_start = -1;
#endif
for (size_t i = 0; i < wanted.num; i++) {
if (wanted.infos[i].cur_flags & PTI_INSTALL_TARGET) {
have_inst_target = true;
#ifdef HAVE_EFI_BOOT
target_start = wanted.infos[i].cur_start;
#endif
break;
}
}
@ -1800,9 +1807,53 @@ make_bsd_partitions(struct install_partition_desc *install)
info.flags |= PTI_INSTALL_TARGET;
wanted.parts->pscheme->set_part_info(wanted.parts,
wanted.infos[i].cur_part_id, &info, NULL);
#ifdef HAVE_EFI_BOOT
target_start = wanted.infos[i].cur_start;
#endif
break;
}
}
#ifdef HAVE_EFI_BOOT
size_t boot_part = ~0U;
for (part_id i = 0; i < wanted.num; i++) {
if ((wanted.infos[i].cur_flags & PTI_BOOT) != 0 ||
wanted.infos[i].type == PT_EFI_SYSTEM) {
boot_part = i;
break;
}
}
if (boot_part == ~0U) {
for (part_id i = 0; i < wanted.num; i++) {
/*
* heuristic to recognize existing MBR FAT
* partitions as EFI without looking for
* details
*/
if ((wanted.infos[i].type != PT_FAT &&
wanted.infos[i].type != PT_EFI_SYSTEM) ||
wanted.infos[i].fs_type != FS_MSDOS)
continue;
daddr_t ps = wanted.infos[i].cur_start;
daddr_t pe = ps + wanted.infos[i].size;
if (target_start >= 0 &&
(ps >= target_start || pe >= target_start))
continue;
boot_part = i;
break;
}
}
if (boot_part != ~0U) {
struct disk_part_info info;
if (wanted.parts->pscheme->get_part_info(wanted.parts,
wanted.infos[boot_part].cur_part_id, &info)) {
info.flags |= PTI_BOOT;
wanted.parts->pscheme->set_part_info(wanted.parts,
wanted.infos[boot_part].cur_part_id, &info, NULL);
}
wanted.infos[boot_part].instflags |= PUIINST_BOOT;
}
#endif
/*
* OK, we have a partition table. Give the user the chance to