From owner-freebsd-current@FreeBSD.ORG Sun Aug 24 16:59:13 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 92499AE2 for ; Sun, 24 Aug 2014 16:59:13 +0000 (UTC) Received: from mail-la0-x22b.google.com (mail-la0-x22b.google.com [IPv6:2a00:1450:4010:c03::22b]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 165C73F5A for ; Sun, 24 Aug 2014 16:59:12 +0000 (UTC) Received: by mail-la0-f43.google.com with SMTP id gi9so9198276lab.2 for ; Sun, 24 Aug 2014 09:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=Y1mEJhft7+E8ISVsMg3TsgPm2W/M12vkjlCxPNa7dLE=; b=D42UaAGQ7pmdofeeMzkp8l/OgSmF4nq/OxaFn6FMWryqtrhnv+Sc9uK01IWHG+l3D6 jaK8fVlPXnhY8HWwre9SmDYBjnQdTADttyYhGDIcUlNhAiZLp0lgw0sIe7OCZwqQBkIt zAB2K8uGEPALa8eT0gxd9bAP3xjkh6SZpNJWgPD1sfbZ34s2otTIgh5B5kF13wODKuZC CaQ7dJUt1S0vE35/uXDqyBlPdEGHZTAwsh9Ry+Ofn7sLe+2mAl/XiTltK7NRxtwEyMOM F8mVn4KM5/Dqms+Ka+TYaxFCiQqSmvXwH7+jMwcHr7QqpsbbfeRD27NkZpHoeyKWWZMX BrSQ== MIME-Version: 1.0 X-Received: by 10.112.163.103 with SMTP id yh7mr8140787lbb.73.1408899550808; Sun, 24 Aug 2014 09:59:10 -0700 (PDT) Sender: crodr001@gmail.com Received: by 10.112.197.107 with HTTP; Sun, 24 Aug 2014 09:59:10 -0700 (PDT) In-Reply-To: <53F9AC50.1000000@yandex.ru> References: <853B0396-2C19-49DF-A8E8-8EB43D107597@xcllnt.net> <7CE168C1-6AF3-4AD2-80DB-192AEC49FD2B@xcllnt.net> <53F9AC50.1000000@yandex.ru> Date: Sun, 24 Aug 2014 09:59:10 -0700 X-Google-Sender-Auth: qK0-V2khIohpDe58l-E5aClSFsw Message-ID: Subject: Re: mkimg used to create gpt image, problem booting From: Craig Rodrigues To: "Andrey V. Elsukov" Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-current Current , Marcel Moolenaar X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Aug 2014 16:59:13 -0000 On Sun, Aug 24, 2014 at 2:11 AM, Andrey V. Elsukov wrote: > > Yes, the problem is in the ptable_gptread() function. I'll commit the fix. Index: head/sys/boot/common/part.c =================================================================== --- head/sys/boot/common/part.c (revision 270444) +++ head/sys/boot/common/part.c (revision 270445) @@ -254,8 +254,8 @@ table->sectorsize); if (phdr != NULL) { /* Read the primary GPT table. */ - size = MIN(MAXTBLSZ, - phdr->hdr_entries * phdr->hdr_entsz / table->sectorsize); + size = MIN(MAXTBLSZ, (phdr->hdr_entries * phdr->hdr_entsz + + table->sectorsize - 1) / table->sectorsize); if (dread(dev, tbl, size, phdr->hdr_lba_table) == 0 && gpt_checktbl(phdr, tbl, size * table->sectorsize, table->sectors - 1) == 0) { I can confirm that r270445 fixes the problem for me, where I can now QEMU boot a GPT partitioned image created with mkimg. I put some more debugging in the code, and found this: (1) GPT IMAGE CREATED WITH MKIMG =============================== phdr->hdr_entries = 2, phdr->hdr_entsz = 128, table->sectorsize = 512 (2) GPT IMAGE CREATED WITH BSDINSTALL =================================== phdr->hdr_entries = 128, phdr->hdr_entsz = 128, table->sectorsize = 512 Does gpart create a fixed partition table with 128 entries? That would explain a lot. Also, in the gptboot man page, it mentions that gptboot can only boot on systems with 128 partitions or less. This seems like an artificial restriction. Does the gptboot code really enforce this? Not that I have a system with more than 128 partitions. :) 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? Thanks for the fix! -- Craig