diff --git a/src/usr.sbin/sysinst/arch/i386/md.c b/src/usr.sbin/sysinst/arch/i386/md.c index dabae8e60b..6082da423b 100644 --- a/src/usr.sbin/sysinst/arch/i386/md.c +++ b/src/usr.sbin/sysinst/arch/i386/md.c @@ -114,11 +114,15 @@ md_get_info(struct install_partition_desc *install) /* * Makronix simple installation: the disk is partitioned from scratch, - * so drop the partitioning that is on it (the same call as at the end - * of this function) and let the scheme be chosen again. + * so forget the partitioning read from it and let the scheme be chosen + * again. Only the copy in memory is freed (->free, as disks.c and + * partman.c do): destroy_part_scheme() would write to the disk now + * (gpt destroy, a zeroed MBR), before the "last chance" question in + * install.c, and a "no" there would leave a disk without a partition + * table. The old maps go after that question: wipe_disk_ends(). */ if (simple_install && pm->parts != NULL) { - pm->parts->pscheme->destroy_part_scheme(pm->parts); + pm->parts->pscheme->free(pm->parts); pm->parts = NULL; pm->ptstart = 0; pm->ptsize = 0; diff --git a/src/usr.sbin/sysinst/install.c b/src/usr.sbin/sysinst/install.c index c7e287a088..57550418d6 100644 --- a/src/usr.sbin/sysinst/install.c +++ b/src/usr.sbin/sysinst/install.c @@ -1,4 +1,10 @@ -/* $NetBSD: install.c,v 1.26 2026/06/25 16:46:56 martin Exp $ */ + intmax_t n; + + if (p->sectorsize == 0) + return; + n = (intmax_t)4 * MEG / p->sectorsize; /* 4 MB in sectors */ + if ((intmax_t)p->dlsize <= 4 * n) + return;/* $NetBSD: install.c,v 1.26 2026/06/25 16:46:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -147,27 +153,34 @@ out: return res; } -/* Makronix: see defs.h */ /* * Makronix: the simple mode takes the whole disk, so it first clears the marks * the disk carries: the first and the last 4 MB (partition maps, the GPT and - * its copy at the end, LVM or LUKS headers, an Apple partition map). What an - * earlier system left there can make the new partition table fail. Errors here - * do not stop the installation: partitioning says what is wrong. + * its copy in the last sector, LVM or LUKS headers, an Apple partition map). + * What an earlier system left there makes the new partition table fail ("gpt + * create" refuses a disk that still has a GPT, src/sbin/gpt/gpt.c). Runs after + * the "last chance" question; md_get_info() does not touch the disk before. + * Counted in sectors, so the tail really is the end of the disk (in whole MB + * the last MB and the backup GPT in it were left). Errors here do not stop + * the installation: partitioning says what is wrong. */ static void wipe_disk_ends(struct pm_devs *p) { - intmax_t mb = (intmax_t)p->dlsize * p->sectorsize / MEG; + intmax_t n; - if (mb <= 16) + if (p->sectorsize == 0) + return; + n = (intmax_t)(4 * MEG / p->sectorsize); /* 4 MB in sectors */ + if ((intmax_t)p->dlsize <= 4 * n) return; run_program(RUN_SILENT | RUN_ERROR_OK, - "dd if=/dev/zero of=/dev/r%s%c bs=1m count=4", - p->diskdev, 'a' + RAW_PART); + "dd if=/dev/zero of=/dev/r%s%c bs=%u count=%jd", + p->diskdev, 'a' + RAW_PART, p->sectorsize, n); run_program(RUN_SILENT | RUN_ERROR_OK, - "dd if=/dev/zero of=/dev/r%s%c bs=1m seek=%jd count=3", - p->diskdev, 'a' + RAW_PART, mb - 4); + "dd if=/dev/zero of=/dev/r%s%c bs=%u seek=%jd count=%jd", + p->diskdev, 'a' + RAW_PART, p->sectorsize, + (intmax_t)p->dlsize - n, n); }