From nobody@FreeBSD.org  Mon Jun 13 07:22:35 2011
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 71ED11065670
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 13 Jun 2011 07:22:35 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 62CE18FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 13 Jun 2011 07:22:35 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p5D7MZVa062967
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 13 Jun 2011 07:22:35 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p5D7MZ9L062962;
	Mon, 13 Jun 2011 07:22:35 GMT
	(envelope-from nobody)
Message-Id: <201106130722.p5D7MZ9L062962@red.freebsd.org>
Date: Mon, 13 Jun 2011 07:22:35 GMT
From: Eir Nym <eirnym@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [geom] gpart(8): drop serial from MBR
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         157819
>Category:       kern
>Synopsis:       [geom] gpart(8): drop serial from MBR
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-geom
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 13 07:30:11 UTC 2011
>Closed-Date:    Wed Jul 27 04:11:24 UTC 2011
>Last-Modified:  Wed Jul 27 04:20:08 UTC 2011
>Originator:     Eir Nym
>Release:        FreeBSD-Current r222913
>Organization:
Private Person
>Environment:
>Description:
boot0cfg is aware about "serial number" field in MBR code, gpart(8) is not. If this field is broken, Windows Vista/7 (XP?) doesn't want to boot.
>How-To-Repeat:
Install Windows with MBR partition scheme, 

install FreeBSD without installer like this:

# gpart add -t freebsd ada0
# gpart create -s MBR ada0s3
# bsdlabel -wB ada0s3
# newfs ada0s3a
# mount ada0s3a /mnt
// here unpack FreeBSD distro into /mnt and do initial configuration.
# dd if=/dev/ada0 of=orig.mbr 
# gpart bootcode -b /mnt/boot/boot0 ada0
# boot0cfg -v ada0

if you do `boot0cfg -Bvb /mnt/boot/boot0` instead of `gpart bootcode` MBR serial will be preserved and windows vista/7 (xp?) will boot correctly.
>Fix:
be aware about MBR serial on MBR partition scheme

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-geom 
Responsible-Changed-By: ae 
Responsible-Changed-When: Tue Jun 14 06:35:25 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=157819 

From: "Andrey V. Elsukov" <ae@FreeBSD.org>
To: bug-followup@FreeBSD.org, eirnym@gmail.com, 
 Marcel Moolenaar <marcel@FreeBSD.org>
Cc:  
Subject: Re: kern/157819: [geom] gpart(8): drop serial from MBR
Date: Wed, 15 Jun 2011 13:21:59 +0400

 Hi,
 
 Yes, you are right. `gpart bootcode` does not keep disk signature.
 It just overwrites the whole sector and fills partition table area.
 
 I see three ways how this can be fixed:
 1. Do not change anything :)
 2. Always keep disk signature for each boot code.
 3. Introduce new option for `gpart bootcode` command, i.e:
 # gpart bootcode -b /boot/boot0 -o some,boot,options ada0
 
 where 'some,boot,options' string, that contains separated by comma
 options which are handled with a scheme specific code.
 
 -- 
 WBR, Andrey V. Elsukov

From: Marcel Moolenaar <marcel@xcllnt.net>
To: "Andrey V. Elsukov" <ae@FreeBSD.org>
Cc: bug-followup@FreeBSD.org, eirnym@gmail.com,
        Marcel Moolenaar <marcel@FreeBSD.org>
Subject: Re: kern/157819: [geom] gpart(8): drop serial from MBR
Date: Wed, 15 Jun 2011 08:43:02 -0700

 On Jun 15, 2011, at 2:21 AM, Andrey V. Elsukov wrote:
 
 > Hi,
 > 
 > Yes, you are right. `gpart bootcode` does not keep disk signature.
 > It just overwrites the whole sector and fills partition table area.
 > 
 > I see three ways how this can be fixed:
 > 1. Do not change anything :)
 > 2. Always keep disk signature for each boot code.
 > 3. Introduce new option for `gpart bootcode` command, i.e:
 > # gpart bootcode -b /boot/boot0 -o some,boot,options ada0
 
 I would advise against adding options. That never scales and
 in this case is even the wrong thing to do.
 
 The fundamental question we need to answer is this:
 Is the serial number a well-defined field in the MBR that is
 independent and unrelated to the bootcode, or not?
 
 If those are entirely independent, then writing the bootcode
 should not have the side effect of clobbering the serial
 number and the MBR scheme should "merge" contents.
 
 If they are related then what we do is right and no change
 is to be made.
 
 Since the MBR is one of those legacy structures that have
 grown warts over time, I can see that different definitions
 would tell us different things. Let's take the definition
 that is most applicable in today's world.
 
 My off the cuff response would be this:
 If we instructions in our bootcode that occupies the space
 of the serial number, then we cannot change anything, other-
 wise we should probably preserve the serial number.
 
 HTH,
 
 -- 
 Marcel Moolenaar
 marcel@xcllnt.net
 
 

From: Eir Nym <eirnym@gmail.com>
To: Marcel Moolenaar <marcel@xcllnt.net>
Cc: "Andrey V. Elsukov" <ae@freebsd.org>, bug-followup@freebsd.org, 
	Marcel Moolenaar <marcel@freebsd.org>
Subject: Re: kern/157819: [geom] gpart(8): drop serial from MBR
Date: Wed, 15 Jun 2011 20:10:41 +0400

 On 15 June 2011 19:43, Marcel Moolenaar <marcel@xcllnt.net> wrote:
 >
 > [....]
 >
 > The fundamental question we need to answer is this:
 > Is the serial number a well-defined field in the MBR that is
 > independent and unrelated to the bootcode, or not?
 
 Yes, this field is defined in several documentation sources.
 It has 6 bytes and used Windows OS as disk identifier in registry to
 specify mount point.
 
 http://technet.microsoft.com/en-us/library/cc978525.aspx
 
 > [....]
State-Changed-From-To: open->patched 
State-Changed-By: ae 
State-Changed-When: Mon Jun 27 10:43:56 UTC 2011 
State-Changed-Why:  
Patched in head/. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=157819 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/157819: commit references a PR
Date: Mon, 27 Jun 2011 10:42:20 +0000 (UTC)

 Author: ae
 Date: Mon Jun 27 10:42:06 2011
 New Revision: 223587
 URL: http://svn.freebsd.org/changeset/base/223587
 
 Log:
   MS Windows NT+ uses 4 bytes at offset 0x1b8 in the MBR to identify
   disk drive. The boot0cfg(8) utility preserves these 4 bytes when is
   writing bootcode to keep a multiboot ability.
   Change gpart's bootcode method to keep DSN if it is not zero. Also
   do not allow writing bootcode with size not equal to MBRSIZE.
   
   PR:		kern/157819
   Tested by:	Eir Nym
   MFC after:	1 month
 
 Modified:
   head/sys/geom/part/g_part_mbr.c
   head/sys/sys/diskmbr.h
 
 Modified: head/sys/geom/part/g_part_mbr.c
 ==============================================================================
 --- head/sys/geom/part/g_part_mbr.c	Mon Jun 27 09:15:41 2011	(r223586)
 +++ head/sys/geom/part/g_part_mbr.c	Mon Jun 27 10:42:06 2011	(r223587)
 @@ -237,14 +237,16 @@ static int
  g_part_mbr_bootcode(struct g_part_table *basetable, struct g_part_parms *gpp)
  {
  	struct g_part_mbr_table *table;
 -	size_t codesz;
 +	uint32_t dsn;
 +
 +	if (gpp->gpp_codesize != MBRSIZE)
 +		return (ENODEV);
  
 -	codesz = DOSPARTOFF;
  	table = (struct g_part_mbr_table *)basetable;
 -	bzero(table->mbr, codesz);
 -	codesz = MIN(codesz,  gpp->gpp_codesize);
 -	if (codesz > 0)
 -		bcopy(gpp->gpp_codeptr, table->mbr, codesz);
 +	dsn = *(uint32_t *)(table->mbr + DOSDSNOFF);
 +	bcopy(gpp->gpp_codeptr, table->mbr, DOSPARTOFF);
 +	if (dsn != 0)
 +		*(uint32_t *)(table->mbr + DOSDSNOFF) = dsn;
  	return (0);
  }
  
 
 Modified: head/sys/sys/diskmbr.h
 ==============================================================================
 --- head/sys/sys/diskmbr.h	Mon Jun 27 09:15:41 2011	(r223586)
 +++ head/sys/sys/diskmbr.h	Mon Jun 27 10:42:06 2011	(r223587)
 @@ -36,6 +36,7 @@
  #include <sys/ioccom.h>
  
  #define	DOSBBSECTOR	0	/* DOS boot block relative sector number */
 +#define	DOSDSNOFF	440	/* WinNT/2K/XP Drive Serial Number offset */
  #define	DOSPARTOFF	446
  #define	DOSPARTSIZE	16
  #define	NDOSPART	4
 _______________________________________________
 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: patched->closed 
State-Changed-By: ae 
State-Changed-When: Wed Jul 27 04:10:58 UTC 2011 
State-Changed-Why:  
Merged to stable/8. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=157819 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/157819: commit references a PR
Date: Wed, 27 Jul 2011 04:10:47 +0000 (UTC)

 Author: ae
 Date: Wed Jul 27 04:10:32 2011
 New Revision: 224464
 URL: http://svn.freebsd.org/changeset/base/224464
 
 Log:
   MFC r223587:
     MS Windows NT+ uses 4 bytes at offset 0x1b8 in the MBR to identify
     disk drive. The boot0cfg(8) utility preserves these 4 bytes when it is
     writing bootcode to keep a multiboot ability.
     Change gpart's bootcode method to keep DSN if it is not zero. Also
     do not allow writing bootcode with size not equal to MBRSIZE.
   
     PR:		kern/157819
 
 Modified:
   stable/8/sys/geom/part/g_part_mbr.c
   stable/8/sys/sys/diskmbr.h
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
   stable/8/sys/geom/label/   (props changed)
 
 Modified: stable/8/sys/geom/part/g_part_mbr.c
 ==============================================================================
 --- stable/8/sys/geom/part/g_part_mbr.c	Wed Jul 27 01:57:24 2011	(r224463)
 +++ stable/8/sys/geom/part/g_part_mbr.c	Wed Jul 27 04:10:32 2011	(r224464)
 @@ -234,14 +234,16 @@ static int
  g_part_mbr_bootcode(struct g_part_table *basetable, struct g_part_parms *gpp)
  {
  	struct g_part_mbr_table *table;
 -	size_t codesz;
 +	uint32_t dsn;
 +
 +	if (gpp->gpp_codesize != MBRSIZE)
 +		return (ENODEV);
  
 -	codesz = DOSPARTOFF;
  	table = (struct g_part_mbr_table *)basetable;
 -	bzero(table->mbr, codesz);
 -	codesz = MIN(codesz,  gpp->gpp_codesize);
 -	if (codesz > 0)
 -		bcopy(gpp->gpp_codeptr, table->mbr, codesz);
 +	dsn = *(uint32_t *)(table->mbr + DOSDSNOFF);
 +	bcopy(gpp->gpp_codeptr, table->mbr, DOSPARTOFF);
 +	if (dsn != 0)
 +		*(uint32_t *)(table->mbr + DOSDSNOFF) = dsn;
  	return (0);
  }
  
 
 Modified: stable/8/sys/sys/diskmbr.h
 ==============================================================================
 --- stable/8/sys/sys/diskmbr.h	Wed Jul 27 01:57:24 2011	(r224463)
 +++ stable/8/sys/sys/diskmbr.h	Wed Jul 27 04:10:32 2011	(r224464)
 @@ -36,6 +36,7 @@
  #include <sys/ioccom.h>
  
  #define	DOSBBSECTOR	0	/* DOS boot block relative sector number */
 +#define	DOSDSNOFF	440	/* WinNT/2K/XP Drive Serial Number offset */
  #define	DOSPARTOFF	446
  #define	DOSPARTSIZE	16
  #define	NDOSPART	4
 _______________________________________________
 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"
 
>Unformatted:
