NetBSD Problem Report #54430

From martin@aprisoft.de  Fri Aug  2 10:55:19 2019
Return-Path: <martin@aprisoft.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 244397A1AC
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  2 Aug 2019 10:55:19 +0000 (UTC)
Message-Id: <20190802105509.605E85CC853@emmas.aprisoft.de>
Date: Fri,  2 Aug 2019 12:55:09 +0200 (CEST)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: installboot(8) fails with GPT PMBR
X-Send-Pr-Version: 3.95

>Number:         54430
>Category:       port-amd64
>Synopsis:       installboot(8) fails with GPT PMBR
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    martin
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 02 11:00:00 +0000 2019
>Closed-Date:    Sun Oct 11 13:10:32 +0000 2020
>Last-Modified:  Sun Oct 11 13:10:32 +0000 2020
>Originator:     Martin Husemann
>Release:        NetBSD 9.99.2
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD seven-days-to-the-wolves.aprisoft.de 9.99.2 NetBSD 9.99.2 (GENERIC) #293: Thu Aug 1 08:25:48 CEST 2019 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:

I have a setup where installing bootblocks fails. This is a BIOS and GPT
install:

# /usr/sbin/installboot -o console=pc,speed=38400 /dev/rdk0 /usr/mdec/bootxx_ffsv2
installboot: Insufficient reserved space before FAT (512 bytes available), use -f (may invalidate filesystem)
installboot: Set bootstrap operation failed

and gpt show says:

      start       size  index  contents
          0          1         PMBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34         30         Unused
         64    8388608      1  GPT part - NetBSD FFSv1/FFSv2
    8388672         64         Unused
    8388736   33552384      2  GPT part - NetBSD swap
   41941120         64         Unused
   41941184   82831293      3  GPT part - NetBSD FFSv1/FFSv2
  124772477          3         Unused
  124772480   31457119      4  GPT part - NetBSD FFSv1/FFSv2
  156229599         32         Sec GPT table
  156229631          1         Sec GPT header


Of course there is no FAT involved anywhere.

>How-To-Repeat:

Not sure, ran into this accidently and am not sure how to replicate it yet.

>Fix:
n/a (will look, but feel free to beat me to it)

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-amd64/54430: installboot(8) fails with GPT PMBR
Date: Fri, 2 Aug 2019 13:03:08 +0200

 Ooops, likely my fault, dk0 is not configured at this point

From: Martin Husemann <martin@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-amd64/54430: installboot(8) fails with GPT PMBR
Date: Sat, 3 Aug 2019 11:41:20 +0000

 Ok, not my fault directly - dk0 was configured at the point of failure,
 and installboot does it's thing:

 (gdb) 
 416             if (!(params->flags & IB_FORCE)) {
 (gdb) 
 423                     if (bootstrap.b[0] != 0xeb || bootstrap.b[2] != 0x90) {
 (gdb) p bootstrap.b[0]
 $2 = 235 '\353'
 (gdb) p/x bootstrap.b[0]
 $3 = 0xeb
 (gdb) p/x bootstrap.b[2]
 $4 = 0x90
 (gdb) n
 439                     if (disk_buf.b[0] == 0xeb && disk_buf.b[1] >= 9 &&
 (gdb) p/x disk_buf.b[0]
 $5 = 0xeb
 (gdb) p/x disk_buf.b[1]
 $6 = 0x3c
 (gdb) n
 441                         !is_zero(disk_buf.b + 3 + 8, disk_buf.b[1] - 1 - 8)) {
 (gdb) 
 440                         disk_buf.b[2] == 0x90 &&
 (gdb) 
 444                             u = le16toh(bpb->bpbBytesPerSec)
 (gdb) 
 445                                 * le16toh(bpb->bpbResSectors);
 (gdb) 
 446                             if (u != 0 && u < params->s1stat.st_size) {
 (gdb) p u
 $7 = 512
 (gdb) p params->s1stat.st_size
 $8 = 6656
 (gdb) n
 447                                     warnx("Insufficient reserved space before FAT "


 (in usr.sbin/installboot/arch/i386.c)

 Doing

  # dd if=/dev/zero of=/dev/rdk0 bs=1m count=10

 before the installboot makes it work. I guess there could be better checks
 for more magic values (apparently this is random stuff on the disk midway
 inside some old partition that got removed and the new added).

 I will make sysinst do something like that on all partitions it requires for
 booting (and also the whole disk, when we are creating partitions from
 scratch).

 Martin

Responsible-Changed-From-To: port-amd64-maintainer->martin
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Sun, 11 Oct 2020 13:10:32 +0000
Responsible-Changed-Why:
I'm dealing with sysinst


State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Sun, 11 Oct 2020 13:10:32 +0000
State-Changed-Why:
Sysinst now uses installboot -f


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.