sysinst: the simple mode no longer writes to the disk before "last chance"; wipe_disk_ends() clears the real end

- arch/i386/md.c md_get_info(): the simple mode freed the partitioning it
  had read with destroy_part_scheme(), which writes at once (gpt destroy,
  a zeroed MBR, disklabel -D) -- before MSG_lastchance in install.c, so a
  "no" there left a disk without a partition table (review 2026-11-13,
  tasksd t0064).  Now ->free(), the copy in memory only, as disks.c and
  partman.c do.
- install.c wipe_disk_ends(), which runs after that question: counted in
  sectors.  In whole MB it cleared [mb-4, mb-1) and left the last MB with
  the backup GPT, and gpt create refuses a disk that still has one (t0066).
  The stray "see defs.h" comment is gone.

Not tested yet: needs a release (another session is running make userland).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Opus 5.5 committed 2026-11-13 22:33:25 +00:00
1 parent fafd1d1d6b
commit 8826ffa456
2 files changed
+31 -14

No files matched your search

+7 -3
View File
@@ -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;
+24 -11
View File
@@ -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);
}