From owner-freebsd-current@FreeBSD.ORG  Sun Aug 24 23:31:52 2014
Return-Path: <owner-freebsd-current@FreeBSD.ORG>
Delivered-To: freebsd-current@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id 079F1A8B;
 Sun, 24 Aug 2014 23:31:52 +0000 (UTC)
Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18])
 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
 (Client CN "funkthat.com", Issuer "funkthat.com" (not verified))
 by mx1.freebsd.org (Postfix) with ESMTPS id CDA333076;
 Sun, 24 Aug 2014 23:31:51 +0000 (UTC)
Received: from h2.funkthat.com (localhost [127.0.0.1])
 by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id s7ONVibc087487
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
 Sun, 24 Aug 2014 16:31:44 -0700 (PDT)
 (envelope-from jmg@h2.funkthat.com)
Received: (from jmg@localhost)
 by h2.funkthat.com (8.14.3/8.14.3/Submit) id s7ONVhdX087486;
 Sun, 24 Aug 2014 16:31:43 -0700 (PDT) (envelope-from jmg)
Date: Sun, 24 Aug 2014 16:31:43 -0700
From: John-Mark Gurney <jmg@funkthat.com>
To: Craig Rodrigues <rodrigc@freebsd.org>
Subject: Re: mkimg used to create gpt image, problem booting
Message-ID: <20140824233143.GQ71691@funkthat.com>
Mail-Followup-To: Craig Rodrigues <rodrigc@freebsd.org>,
 Marcel Moolenaar <marcel@xcllnt.net>,
 "Andrey V. Elsukov" <bu7cher@yandex.ru>,
 freebsd-current Current <freebsd-current@freebsd.org>
References: <CAG=rPVeucq+sMxe_NPe3Og939o=Sg4WGfYL7PjA1uXGU8uL=8g@mail.gmail.com>
 <853B0396-2C19-49DF-A8E8-8EB43D107597@xcllnt.net>
 <CAG=rPVes3Eq87hOE6W135yGvzRiAzHTbCGSxiyd0JBAs2ufqmA@mail.gmail.com>
 <7CE168C1-6AF3-4AD2-80DB-192AEC49FD2B@xcllnt.net>
 <CAG=rPVfe6pP08WWaYQ6enk7A6AkT3dBXVxNfK0JgJPaN_rJ_Uw@mail.gmail.com>
 <CAG=rPVe8Lh=P2MUdycM7+2mpSBPhe+kTvxR_bjnZfB1EkvK92Q@mail.gmail.com>
 <53F9AC50.1000000@yandex.ru>
 <CAG=rPVctN4-UBxRzWhEoEt5e_4d8UXCa0O40LZUHnS5Qj9hFeA@mail.gmail.com>
 <82000B55-10E5-4348-9F35-38962965A63C@xcllnt.net>
 <CAG=rPVeLgOGXx8=S18u03JuNGB9PzYk3uYZS8r=sgu3b_UHOmQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAG=rPVeLgOGXx8=S18u03JuNGB9PzYk3uYZS8r=sgu3b_UHOmQ@mail.gmail.com>
User-Agent: Mutt/1.4.2.3i
X-Operating-System: FreeBSD 7.2-RELEASE i386
X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88  9322 9CB1 8F74 6D3F A396
X-Files: The truth is out there
X-URL: http://resnet.uoregon.edu/~gurney_j/
X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html
X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE
X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger?
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.2
 (h2.funkthat.com [127.0.0.1]); Sun, 24 Aug 2014 16:31:44 -0700 (PDT)
Cc: "Andrey V. Elsukov" <bu7cher@yandex.ru>,
 freebsd-current Current <freebsd-current@freebsd.org>,
 Marcel Moolenaar <marcel@xcllnt.net>
X-BeenThere: freebsd-current@freebsd.org
X-Mailman-Version: 2.1.18-1
Precedence: list
List-Id: Discussions about the use of FreeBSD-current
 <freebsd-current.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/freebsd-current>, 
 <mailto:freebsd-current-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-current/>
List-Post: <mailto:freebsd-current@freebsd.org>
List-Help: <mailto:freebsd-current-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-current>,
 <mailto:freebsd-current-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sun, 24 Aug 2014 23:31:52 -0000

Craig Rodrigues wrote this message on Sun, Aug 24, 2014 at 15:37 -0700:
> On Sun, Aug 24, 2014 at 12:05 PM, Marcel Moolenaar <marcel@xcllnt.net> wrote:
> >
> > On Aug 24, 2014, at 9:59 AM, Craig Rodrigues <rodrigc@freebsd.org> wrote:
> >
> >> On Sun, Aug 24, 2014 at 2:11 AM, Andrey V. Elsukov <bu7cher@yandex.ru> wrote:
> >>>
> >>> Yes, the problem is in the ptable_gptread() function. I'll commit the fix.
> >>
> >
> >> Should mkimg be changed to create a partition table with 128 entries
> >> by default, to match older versions of FreeBSD which do not have this fix?
> >
> > Maybe. 128 is the suggested default. It's not a hard lower
> > limit. Technically speaking, it's perfectly fine to create
> > just enough entries to fill a single sector. Then again,
> > code makes all kinds of assumptions or has all kinds of
> > bugs -- just like the logic in the loader apparently.
> >
> > By having mkimg create a large table, even if it's knows
> > up front that it doesn't have to may prevent broken code
> > from tripping over, bit it surely bloats the image for
> > no reason.
> 
> I see what you are saying.  If you have a new device
> and do "gpart create -s GPT", then this value in sys/geom/part/g_part_gpt.c:
> 
>      .gps_minent = 128,
> 
> causes the logic in the g_part_ctl_create() function in sys/geom/part/g_part.c
> to set the number of partitions to 128, and then it calls g_part_ctl_create()
> which creates the partition table with 128 empty entries.
> 
> "gpart create" doesn't know how many partitions you want, so it
> needs to allocate some space up front for the partition table,
> and then you can do "gpart add" to add the partitions later.
> 
> With mkimg, you know exactly how many partitions you are creating
> , so you don't need to specify 128 as the number of partitions.

Though, w/ people dd'ing images onto disks, and using growfs to grow
as necessary, we might want to allocate a few more more than the
minimum...  I do agree that we want to keep sizes to a minimum...

> Since only gpart was available for creating GPT partitions, the side-effect
> of always having 128 partitions hid the bug in the loader.
> 
> Hopefully Andrey's fix can be backported to at least stable/9, because
> the loader bug seems to have been there since at least 2012.

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."