From nobody@FreeBSD.org  Sat May 16 20:03:34 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 4FEBB106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 May 2009 20:03:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 24D178FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 May 2009 20:03:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n4GK3XoA093545
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 May 2009 20:03:33 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n4GK3XVW093544;
	Sat, 16 May 2009 20:03:33 GMT
	(envelope-from nobody)
Message-Id: <200905162003.n4GK3XVW093544@www.freebsd.org>
Date: Sat, 16 May 2009 20:03:33 GMT
From: Christoph Langguth <christoph@rosenkeller.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [request][patch] Bootloader support for hybrid MBR/GPT partitioning
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         134590
>Category:       kern
>Synopsis:       [libi386] [gpt] [patch] Bootloader support for hybrid MBR/GPT partitioning
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rpaulo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 16 20:10:04 UTC 2009
>Closed-Date:    Fri Feb 05 06:26:33 UTC 2010
>Last-Modified:  Fri Feb 05 06:26:33 UTC 2010
>Originator:     Christoph Langguth
>Release:        7.2-RELEASE, 8.0-CURRENT
>Organization:
>Environment:
FreeBSD marvin 8.0-CURRENT FreeBSD 8.0-CURRENT #12: Sat May 16 18:33:46 UTC 2009     root@marvin:/usr/obj/usr/src/sys/MARVIN  amd64
>Description:
When FreeBSD is installed on a GPT partition on a Multi-Boot Computer (Macbook Pro in this case), loader refuses to read the GPT table (and thus, to boot) if MBR partitions other than the protective EFI one are installed.

I have a quadruple-boot setup here, with MacOS, Windows, Linux, FreeBSD. The way that Bootcamp traditionally partitions the disk is not entirely compliant with the GPT scheme (I know...), because it allows additional entries in the MBR.

I have actually used this setup productively and not experienced any problems (as long as the MBR and GPT are "in sync" for the 4 first partitions, of course): MBR-only OSs such as Windows happily work with the limited information that they have, while GPT-aware ones ignore the MBR and use the GPT. This also goes for FreeBSD, with the only exception being the boot loader, actually: If unpatched, it fails to recognize the GPT partition (resorting to the MBR instead), and therefore fails to find the boot (and root) partitions.
>How-To-Repeat:
Partition drive using GPT, and have the first 4 partitions of the GPT and MBR be in sync. (in sync meaning: have an EE partition as first MBR partition, but other ones as well). Install FreeBSD on a partition exclusively available in the GPT (i.e., partition number > 4)

>Fix:
let loader ignore any additional MBR partitions while scanning for the GPT table. The attached patch does this with a (IMO) minimal impact:
- it will still (correctly) fail to see the GPT if anything is logically wrong with it
- it will still fail if there is no, or more than one, EE partition
- it will still fail if the EE partition is not the first
- the only change is that it will silently accept other partitions being present in the MBR, yet still be able to recognize a GPT.

Patch attached with submission follows:

--- sys/boot/i386/libi386/biosdisk.c.org	2009-05-16 19:36:22.000000000 +0000
+++ sys/boot/i386/libi386/biosdisk.c	2009-05-16 19:38:36.000000000 +0000
@@ -879,7 +879,7 @@
     for (i = 0; i < NDOSPART; i++) {
 	if (dp[i].dp_typ == 0xee)
 	    part++;
-	else if (dp[i].dp_typ != 0x00)
+	else if ((part != 1) && (dp[i].dp_typ != 0x00))
 	    return (EINVAL);
     }
     if (part != 1)


>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/134590: commit references a PR
Date: Fri, 26 Jun 2009 09:32:46 +0000 (UTC)

 Author: rpaulo
 Date: Fri Jun 26 09:32:31 2009
 New Revision: 195045
 URL: http://svn.freebsd.org/changeset/base/195045
 
 Log:
   On special systems where the MBR and the GPT are in sync (up to the 4th
   slicei, Apple EFI hardware), the bootloader will fail to recognize the GPT
   if it finds anything else but the EFI partition. Change the check to continue
   detecting the GPT by looking at the EFI partition on the MBR but
   stopping successfuly after finding it.
   
   PR:		kern/134590
   Submitted by:	Christoph Langguth <christoph at rosenkeller.org>
   Reviewed by:	jhb
   MFC after:	2 weeks
   Approved by:	re (kib)
 
 Modified:
   head/sys/boot/i386/libi386/biosdisk.c
 
 Modified: head/sys/boot/i386/libi386/biosdisk.c
 ==============================================================================
 --- head/sys/boot/i386/libi386/biosdisk.c	Fri Jun 26 07:11:14 2009	(r195044)
 +++ head/sys/boot/i386/libi386/biosdisk.c	Fri Jun 26 09:32:31 2009	(r195045)
 @@ -880,7 +880,7 @@ bd_open_gpt(struct open_disk *od, struct
      for (i = 0; i < NDOSPART; i++) {
  	if (dp[i].dp_typ == 0xee)
  	    part++;
 -	else if (dp[i].dp_typ != 0x00)
 +	else if ((part != 1) && (dp[i].dp_typ != 0x00))
  	    return (EINVAL);
      }
      if (part != 1)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/134590: commit references a PR
Date: Mon, 13 Jul 2009 16:36:18 +0000 (UTC)

 Author: rpaulo
 Date: Mon Jul 13 16:36:04 2009
 New Revision: 195657
 URL: http://svn.freebsd.org/changeset/base/195657
 
 Log:
   MFC r195045:
    On special systems where the MBR and the GPT are in sync (up to the 4th
    slicei, Apple EFI hardware), the bootloader will fail to recognize the GPT
    if it finds anything else but the EFI partition. Change the check to continue
    detecting the GPT by looking at the EFI partition on the MBR but
    stopping successfuly after finding it.
   
    PR:		kern/134590
    Submitted by:	Christoph Langguth <christoph at rosenkeller.org>
    Reviewed by:	jhb
 
 Modified:
   stable/7/sys/   (props changed)
   stable/7/sys/boot/i386/libi386/biosdisk.c
   stable/7/sys/contrib/pf/   (props changed)
   stable/7/sys/geom/label/   (props changed)
   stable/7/sys/geom/label/g_label.c   (props changed)
 
 Modified: stable/7/sys/boot/i386/libi386/biosdisk.c
 ==============================================================================
 --- stable/7/sys/boot/i386/libi386/biosdisk.c	Mon Jul 13 12:53:43 2009	(r195656)
 +++ stable/7/sys/boot/i386/libi386/biosdisk.c	Mon Jul 13 16:36:04 2009	(r195657)
 @@ -888,7 +888,7 @@ bd_open_gpt(struct open_disk *od, struct
      for (i = 0; i < NDOSPART; i++) {
  	if (dp[i].dp_typ == 0xee)
  	    part++;
 -	else if (dp[i].dp_typ != 0x00)
 +	else if ((part != 1) && (dp[i].dp_typ != 0x00))
  	    return (EINVAL);
      }
      if (part != 1)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Fri Feb 5 06:25:28 UTC 2010 
State-Changed-Why:  
already committed; unlikely to be merged to 6. 


Responsible-Changed-From-To: freebsd-bugs->rpaulo 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Feb 5 06:25:28 UTC 2010 
Responsible-Changed-Why:  
Assign to committer just in case. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=134590 
>Unformatted:
