From nobody@FreeBSD.org  Fri Nov  5 16:28:19 2010
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 8BEF41065672
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  5 Nov 2010 16:28:19 +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 5F6838FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  5 Nov 2010 16:28:19 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id oA5GSJiV079859
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 5 Nov 2010 16:28:19 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id oA5GSJuF079858;
	Fri, 5 Nov 2010 16:28:19 GMT
	(envelope-from nobody)
Message-Id: <201011051628.oA5GSJuF079858@www.freebsd.org>
Date: Fri, 5 Nov 2010 16:28:19 GMT
From: Kris Moore <kmoore@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: src: usr.sbin/pc-sysinstall - Add support 4k partition alignment
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         151967
>Category:       bin
>Synopsis:       [patch] pc-sysinstall(8) - Add support 4k partition alignment
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 05 16:30:09 UTC 2010
>Closed-Date:    Mon Jan 10 19:12:05 UTC 2011
>Last-Modified:  Mon Jan 10 19:20:09 UTC 2011
>Originator:     Kris Moore
>Release:        9.0-Current
>Organization:
PC-BSD / iXsystems
>Environment:
9.0-Current
>Description:
After talking to pjd@, jpaetzel@ and a few others at MeetBSD, the fix to getting proper alignment on 4K drives seems to be changing our starting block to "64" when doing a full-disk installation or creating the first partition. The attached patch fixes this. 
>How-To-Repeat:

>Fix:
Attached patch fixes the issue in pc-sysinstall

Patch attached with submission follows:

diff -ruN src.o/usr.sbin/pc-sysinstall/backend/functions-disk.sh src/usr.sbin/pc-sysinstall/backend/functions-disk.sh
--- src.o/usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-11-05 12:05:57.066860900 -0400
+++ src/usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-11-05 12:11:43.416538580 -0400
@@ -562,6 +562,8 @@
 init_gpt_full_disk()
 {
   _intDISK=$1
+
+  startblock="64"
  
   # Set our sysctl so we can overwrite any geom using drives
   sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
@@ -580,7 +582,7 @@
 
   echo_log "Running gpart on ${_intDISK}"
   rc_halt "gpart create -s GPT ${_intDISK}"
-  rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}"
+  rc_halt "gpart add -b ${startblock} -s 128 -t freebsd-boot ${_intDISK}"
   
   echo_log "Stamping boot sector on ${_intDISK}"
   rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}"
@@ -593,7 +595,7 @@
   _intDISK=$1
   _intBOOT=$2
  
-  startblock="63"
+  startblock="64"
 
   # Set our sysctl so we can overwrite any geom using drives
   sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
@@ -763,7 +765,7 @@
   # Lets get the starting block first
   if [ "${slicenum}" = "1" ]
   then
-     startblock="63"
+     startblock="64"
   else
      # Lets figure out where the prior slice ends
      checkslice="`expr ${slicenum} - 1`"
diff -ruN src.o/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh src/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh
--- src.o/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	2010-11-05 12:05:56.876842879 -0400
+++ src/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	2010-11-05 12:25:50.192031927 -0400
@@ -69,7 +69,7 @@
 
 # Lets get the starting block
 if [ "${SLICENUM}" = "1" ] ; then
-  STARTBLOCK="63"
+  STARTBLOCK="64"
 else
   # Lets figure out where the prior slice ends
   checkslice="`expr ${SLICENUM} - 1`"


>Release-Note:
>Audit-Trail:

From: Bruce Cran <bruce@cran.org.uk>
To: Kris Moore <kmoore@FreeBSD.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/151967: src: usr.sbin/pc-sysinstall - Add support 4k
 partition alignment
Date: Fri, 5 Nov 2010 16:37:57 +0000

 On Fri, 5 Nov 2010 16:28:19 GMT
 Kris Moore <kmoore@FreeBSD.org> wrote:
 
 > After talking to pjd@, jpaetzel@ and a few others at MeetBSD, the fix
 > to getting proper alignment on 4K drives seems to be changing our
 > starting block to "64" when doing a full-disk installation or
 > creating the first partition. The attached patch fixes this. 
 > >How-To-Repeat:
 
 See
 http://lists.freebsd.org/pipermail/freebsd-geom/2010-November/004456.html
 for why using a starting block of 64 won't (currently) work.
 
 -- 
 Bruce Cran
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Nov 5 16:53:12 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer.  Note, however, brucec's pointer to the thread 
where it was discussed whether or not we can actually do this. 

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

From: Kris Moore <kris@pcbsd.org>
To: Bruce Cran <bruce@cran.org.uk>
Cc: Kris Moore <kmoore@FreeBSD.org>, freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/151967: src: usr.sbin/pc-sysinstall - Add support 4k
 partition alignment
Date: Tue, 16 Nov 2010 11:21:02 -0500

 On Fri, Nov 05, 2010 at 04:37:57PM +0000, Bruce Cran wrote:
 > On Fri, 5 Nov 2010 16:28:19 GMT
 > Kris Moore <kmoore@FreeBSD.org> wrote:
 > 
 > > After talking to pjd@, jpaetzel@ and a few others at MeetBSD, the fix
 > > to getting proper alignment on 4K drives seems to be changing our
 > > starting block to "64" when doing a full-disk installation or
 > > creating the first partition. The attached patch fixes this. 
 > > >How-To-Repeat:
 > 
 > See
 > http://lists.freebsd.org/pipermail/freebsd-geom/2010-November/004456.html
 > for why using a starting block of 64 won't (currently) work.
 > 
 > -- 
 > Bruce Cran
 
 If my math is correct, using a starting block of 2016 (63*32) = 1008KB should work,
 which is evenly divisible by 4 (1008/4) = 252. I've been testing this offset here
 in virtualbox, and gpart accepts it without trying to auto-adjust anything. 
 
 The attached patch has this fix, along with a cleanup of the legacy bsdlabel calls
 to use gpart now, so we are consistent across the board. 
 
 Does this seem like a suitable offset? 
 
 -- 
 Kris Moore
 PC-BSD Software

From: Kris Moore <kris@pcbsd.org>
To: Bruce Cran <bruce@cran.org.uk>
Cc: Kris Moore <kmoore@FreeBSD.org>, freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/151967: src: usr.sbin/pc-sysinstall - Add support 4k
 partition alignment
Date: Tue, 16 Nov 2010 11:21:44 -0500

 --y0ulUmNC+osPPQO6
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 On Fri, Nov 05, 2010 at 04:37:57PM +0000, Bruce Cran wrote:
 > On Fri, 5 Nov 2010 16:28:19 GMT
 > Kris Moore <kmoore@FreeBSD.org> wrote:
 > 
 > > After talking to pjd@, jpaetzel@ and a few others at MeetBSD, the fix
 > > to getting proper alignment on 4K drives seems to be changing our
 > > starting block to "64" when doing a full-disk installation or
 > > creating the first partition. The attached patch fixes this. 
 > > >How-To-Repeat:
 > 
 > See
 > http://lists.freebsd.org/pipermail/freebsd-geom/2010-November/004456.html
 > for why using a starting block of 64 won't (currently) work.
 > 
 > -- 
 > Bruce Cran
 
 Of course I forgot to attach the patch :P
 
 -- 
 Kris Moore
 PC-BSD Software
 
 --y0ulUmNC+osPPQO6
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="patch-pcsysinstall-4k-bsdlabel.txt"
 
 diff -ruN usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh.o usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
 --- usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh.o	2010-11-15 15:18:24.629391537 -0500
 +++ usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	2010-11-16 10:31:20.623658464 -0500
 @@ -158,227 +158,29 @@
    export VAL
  };
  
 -# Function to setup / stamp a legacy MBR bsdlabel
 -setup_mbr_partitions()
 +# Function to setup partitions using gpart
 +setup_gpart_partitions()
  {
 -  DISKTAG="$1"
 -  WRKSLICE="$2"
 +  local _dTag="$1"
 +  local _pDisk="$2"
 +  local _wSlice="$3"
 +  local _sNum="$4"
 +  local _pType="$5"
    FOUNDPARTS="1"
  
 -  # Lets setup the BSDLABEL
 -  BSDLABEL="${TMPDIR}/bsdLabel-${WRKSLICE}"
 -  export BSDLABEL
 -  rm $BSDLABEL >/dev/null 2>/dev/null
 -  echo "# /dev/${WRKSLICE}" >>$BSDLABEL
 -  echo "8 partitions:" >>$BSDLABEL
 -  echo "#	size	offset	fstype	bsize	bps/cpg" >>$BSDLABEL
 -   
 -  PARTLETTER="a"
 -
 -  # Lets read in the config file now and populate this
 -  while read line
 -  do
 -    # Check for data on this slice
 -    echo $line | grep "^${DISKTAG}-part=" >/dev/null 2>/dev/null
 -    if [ "$?" = "0" ]
 -    then
 -      # Found a slice- entry, lets get the slice info
 -      get_value_from_string "${line}"
 -      STRING="$VAL"
 -      FOUNDPARTS="0"
 -
 -      # We need to split up the string now, and pick out the variables
 -      FS=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 1` 
 -      SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2` 
 -      MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3` 
 -
 -      if echo $STRING | grep -E '^/.+' >/dev/null 2>&1
 -      then
 -        IMAGE=`echo ${STRING} | cut -f1 -d' '`
 -      fi
 -
 -      # Check if we have a .eli extension on this FS
 -      echo ${FS} | grep ".eli" >/dev/null 2>/dev/null
 -      if [ "$?" = "0" ]
 -      then
 -        FS="`echo ${FS} | cut -d '.' -f 1`"
 -        ENC="ON"
 -        check_for_enc_pass "${line}"
 -        if [ "${VAL}" != "" ] ; then
 -          # We have a user supplied password, save it for later
 -          ENCPASS="${VAL}" 
 -        fi
 -      else
 -        ENC="OFF"
 -      fi
 -
 -      # Check if the user tried to setup / as an encrypted partition
 -      check_for_mount "${MNT}" "/"
 -      if [ "${?}" = "0" -a "${ENC}" = "ON" ]
 -      then
 -        USINGENCROOT="0" ; export USINGENCROOT
 -      fi
 -          
 -      if [ -n "${IMAGE}" ]
 -      then
 -        FS="IMAGE"
 -        SIZE=`ls -l "${IMAGE}" | awk '{ print $5 }'`
 -        MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2`
 -		SIZE=`convert_byte_to_megabyte $SIZE`
 -      fi
 -
 -      # Now check that these values are sane
 -      case $FS in
 -        UFS|UFS+S|UFS+J|UFS+SUJ|ZFS|SWAP|IMAGE) ;;
 -       *) exit_err "ERROR: Invalid file system specified on $line" ;;
 -      esac
 -
 -      # Check that we have a valid size number
 -      expr $SIZE + 1 >/dev/null 2>/dev/null
 -      if [ "$?" != "0" ]; then
 -        exit_err "ERROR: The size specified on $line is invalid"
 -      fi
 -
 -      # Check that the mount-point starts with /
 -      echo "$MNT" | grep -e "^/" -e "^none" >/dev/null 2>/dev/null
 -      if [ "$?" != "0" ]; then
 -        exit_err "ERROR: The mount-point specified on $line is invalid"
 -      fi
 -
 -      if [ "$SIZE" = "0" ]
 -      then
 -        SOUT="*"
 -      else
 -        SOUT="${SIZE}M"
 -      fi
 -
 -      # OK, we passed all tests, now lets put these values into a config
 -      # If the part
 -      if [ "${PARTLETTER}" = "a" ]
 -      then
 -        if [ "$FS" = "SWAP" ]
 -        then
 -          echo "a:	${SOUT}	*	swap	0	0" >>${BSDLABEL}
 -        else
 -          echo "a:	${SOUT}	0	4.2BSD	0	0" >>${BSDLABEL}
 -        fi
 -
 -        # Check if we found a valid root partition
 -        check_for_mount "${MNT}" "/"
 -        if [ "$?" = "0" ] ; then
 -          FOUNDROOT="0" ; export FOUNDROOT
 -        fi
 -
 -        # Check if we have a "/boot" instead
 -        check_for_mount "${MNT}" "/boot"
 -        if [ "${?}" = "0" ] ; then
 -          USINGBOOTPART="0" ; export USINGBOOTPART
 -          if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ]
 -          then
 -            exit_err "/boot partition must be formatted with UFS"
 -          fi
 -        fi
 -
 -       else
 -        # Done with the a: partitions
 -
 -        # Check if we found a valid root partition not on a:
 -        check_for_mount "${MNT}" "/"
 -        if [ "${?}" = "0" ] ; then
 -          FOUNDROOT="1" ; export FOUNDROOT
 -        fi
 -
 -        # Check if we have a /boot partition, and fail since its not first
 -        check_for_mount "${MNT}" "/boot"
 -        if [ "${?}" = "0" ] ; then
 -          exit_err "/boot partition must be first partition"
 -        fi
 -
 -
 -        if [ "$FS" = "SWAP" ]
 -        then
 -          echo "${PARTLETTER}:	${SOUT}	*	swap" >>${BSDLABEL}
 -        else
 -          echo "${PARTLETTER}:	${SOUT}	*	4.2BSD" >>${BSDLABEL}
 -        fi
 -      fi
 -
 -      # Generate a unique label name for this mount
 -      gen_glabel_name "${MNT}" "${FS}"
 -      PLABEL="${VAL}"
 -      
 -      # Get any extra options for this fs / line
 -      get_fs_line_xvars "${WRKSLICE}${PARTLETTER}" "${STRING}"
 -      XTRAOPTS="${VAR}"
 -
 -      # Check if using zfs mirror
 -      echo ${XTRAOPTS} | grep "mirror" >/dev/null 2>/dev/null
 -      if [ "$?" = "0" ] ; then
 -       	XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${WRKSLICE}${PARTLETTER}")
 -      fi
 -
 -      # Save this data to our partition config dir
 -      echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${WRKSLICE}${PARTLETTER}
 -
 -      # If we have a enc password, save it as well
 -      if [ ! -z "${ENCPASS}" ] ; then
 -        echo "${ENCPASS}" >${PARTDIR}-enc/${WRKSLICE}${PARTLETTER}-encpass
 -      fi
 -
 -      # This partition letter is used, get the next one
 -      case ${PARTLETTER} in
 -        a) PARTLETTER="b" ;;
 -        b) # When we hit b, add the special c: setup for bsdlabel 
 -           echo "c:	*	*	unused" >>${BSDLABEL}
 -           PARTLETTER="d" ;;
 -        d) PARTLETTER="e" ;;
 -        e) PARTLETTER="f" ;;
 -        f) PARTLETTER="g" ;;
 -        g) PARTLETTER="h" ;;
 -        h) PARTLETTER="ERR" ;;
 -        *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;;
 -      esac
 -
 -      unset IMAGE
 -
 -    fi # End of subsection locating a slice in config
 -
 -    echo $line | grep "^commitDiskLabel" >/dev/null 2>/dev/null
 -    if [ "$?" = "0" -a "${FOUNDPARTS}" = "0" ]
 -    then
 -      # Found our flag to commit this label setup, check that we found at least 1 partition and do it
 -      if [ "${PARTLETTER}" != "a" ]
 -      then
 -        # Check if we only had 1 partition, and make sure we add "c:" section to label
 -        if [ "${PARTLETTER}" = "b" ]
 -        then
 -             echo "c:	*	*	unused" >>${BSDLABEL}
 -        fi
 -
 -        echo "bsdlabel -R -B /dev/${WRKSLICE} ${BSDLABEL}"
 -        bsdlabel -R -B ${WRKSLICE} ${BSDLABEL}
 -
 -        break
 -      else
 -        exit_err "ERROR: commitDiskLabel was called without any partition entries for it!"
 -      fi
 -    fi
 -  done <${CFGF}
 -};
 -
 -# Function to setup partitions using gpt
 -setup_gpt_partitions()
 -{
 -  DISKTAG="$1"
 -  DISK="$2"
 -  FOUNDPARTS="1"
 +  # Lets read in the config file now and setup our partitions
 +  if [ "${_pType}" = "gpt" ] ; then
 +    CURPART="2"
 +  else
 +    PARTLETTER="a"
 +    CURPART="1"
 +    rc_halt "gpart create -s BSD ${_wSlice}"
 +  fi
  
 -  # Lets read in the config file now and setup our GPT partitions
 -  CURPART="2"
    while read line
    do
      # Check for data on this slice
 -    echo $line | grep "^${DISKTAG}-part=" >/dev/null 2>/dev/null
 +    echo $line | grep "^${_dTag}-part=" >/dev/null 2>/dev/null
      if [ "$?" = "0" ]
      then
        FOUNDPARTS="0"
 @@ -441,24 +243,28 @@
        # Check if we found a valid root partition
        check_for_mount "${MNT}" "/"
        if [ "${?}" = "0" ] ; then
 -        if [ "${CURPART}" = "2" ] ; then
 +        FOUNDROOT="1" ; export FOUNDROOT
 +        if [ "${CURPART}" = "2" -a "$_pType" = "gpt" ] ; then
 +          FOUNDROOT="0" ; export FOUNDROOT
 +        fi
 +        if [ "${CURPART}" = "1" -a "$_pType" = "mbr" ] ; then
            FOUNDROOT="0" ; export FOUNDROOT
 -        else
 -          FOUNDROOT="1" ; export FOUNDROOT
          fi
        fi
  
        check_for_mount "${MNT}" "/boot"
        if [ "${?}" = "0" ] ; then
 -        if [ "${CURPART}" = "2" ] ; then
 -          USINGBOOTPART="0" ; export USINGBOOTPART
 -          if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ]
 -          then
 -            exit_err "/boot partition must be formatted with UFS"
 -          fi
 -        else
 +        USINGBOOTPART="0" ; export USINGBOOTPART
 +        if [ "${CURPART}" != "2" -a "${_pType}" = "gpt" ] ; then
 +            exit_err "/boot partition must be first partition"
 +        fi
 +        if [ "${CURPART}" != "1" -a "${_pType}" = "mbr" ] ; then
              exit_err "/boot partition must be first partition"
          fi
 +
 +        if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ] ; then
 +          exit_err "/boot partition must be formatted with UFS"
 +        fi
        fi
  
        # Generate a unique label name for this mount
 @@ -466,13 +272,21 @@
        PLABEL="${VAL}"
  
        # Get any extra options for this fs / line
 -      get_fs_line_xvars "${DISK}p${CURPART}" "${STRING}"
 +      if [ "${_pType}" = "gpt" ] ; then
 +        get_fs_line_xvars "${_pDisk}p${CURPART}" "${STRING}"
 +      else
 +        get_fs_line_xvars "${_wSlice}" "${STRING}"
 +      fi
        XTRAOPTS="${VAR}"
  
        # Check if using zfs mirror
        echo ${XTRAOPTS} | grep "mirror" >/dev/null 2>/dev/null
        if [ "$?" = "0" ] ; then
 -       	XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${DISK}p${CURPART}")
 +        if [ "${_pType}" = "gpt" ] ; then
 +       	  XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}p${CURPART}")
 +        else
 +       	  XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_wSlice}")
 +        fi
        fi
  
        # Figure out the gpart type to use
 @@ -483,7 +297,11 @@
        esac
  
        # Create the partition
 -      rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${DISK}"
 +      if [ "${_pType}" = "gpt" ] ; then
 +        rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}"
 +      else
 +        rc_halt "gpart add ${SOUT} -t ${PARTYPE} -i ${CURPART} ${_wSlice}"
 +      fi
  
        # Check if this is a root / boot partition, and stamp the right loader
        for TESTMNT in `echo ${MNT} | sed 's|,| |g'`
 @@ -497,19 +315,53 @@
        done 
  
        # Save this data to our partition config dir
 -      echo "${FS}:${MNT}:${ENC}:${PLABEL}:GPT:${XTRAOPTS}" >${PARTDIR}/${DISK}p${CURPART}
 +      if [ "${_pType}" = "gpt" ] ; then
 +        echo "${FS}:${MNT}:${ENC}:${PLABEL}:GPT:${XTRAOPTS}" >${PARTDIR}/${_pDisk}p${CURPART}
  
 -      # Clear out any headers
 -      sleep 2
 -      dd if=/dev/zero of=${DISK}p${CURPART} count=2048 >/dev/null 2>/dev/null
 -
 -      # If we have a enc password, save it as well
 -      if [ ! -z "${ENCPASS}" ] ; then
 -        echo "${ENCPASS}" >${PARTDIR}-enc/${DISK}p${CURPART}-encpass
 +        # Clear out any headers
 +        sleep 2
 +        dd if=/dev/zero of=${_pDisk}p${CURPART} count=2048 >/dev/null 2>/dev/null
 +
 +        # If we have a enc password, save it as well
 +        if [ ! -z "${ENCPASS}" ] ; then
 +          echo "${ENCPASS}" >${PARTDIR}-enc/${_pDisk}p${CURPART}-encpass
 +        fi
 +      else
 +	# MBR Partition
 +        echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${_wSlice}${PARTLETTER}
 +        # Clear out any headers
 +        sleep 2
 +        dd if=/dev/zero of=${_wSlice}${PARTLETTER} count=2048 >/dev/null 2>/dev/null
 +
 +        # If we have a enc password, save it as well
 +        if [ ! -z "${ENCPASS}" ] ; then
 +          echo "${ENCPASS}" >${PARTDIR}-enc/${_wSlice}${PARTLETTER}-encpass
 +        fi
        fi
  
 +
        # Increment our parts counter
 -      CURPART="`expr ${CURPART} + 1`"
 +      if [ "$_pType" = "gpt" ] ; then 
 +        CURPART="`expr ${CURPART} + 1`"
 +        # If this is a gpt partition, we can continue and skip the MBR part letter stuff
 +        continue
 +      else
 +        CURPART="`expr ${CURPART} + 1`"
 +        if [ "$CURPART" = "3" ] ; then CURPART="4" ; fi
 +      fi
 +
 +
 +      # This partition letter is used, get the next one
 +      case ${PARTLETTER} in
 +        a) PARTLETTER="b" ;;
 +        b) PARTLETTER="d" ;;
 +        d) PARTLETTER="e" ;;
 +        e) PARTLETTER="f" ;;
 +        f) PARTLETTER="g" ;;
 +        g) PARTLETTER="h" ;;
 +        h) PARTLETTER="ERR" ;;
 +        *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;;
 +      esac
  
      fi # End of subsection locating a slice in config
  
 @@ -518,13 +370,17 @@
      then
  
        # If this is the boot disk, stamp the right gptboot
 -      if [ ! -z "${BOOTTYPE}" ] ; then
 +      if [ ! -z "${BOOTTYPE}" -a "$_pType" = "gpt" ] ; then
          case ${BOOTTYPE} in
 -          freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${DISK}" ;;
 -          freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${DISK}" ;;
 +          freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${_pDisk}" ;;
 +          freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${_pDisk}" ;;
          esac 
        fi
  
 +      # Make sure to stamp the MBR loader
 +      if [ "$_pType" = "mbr" ] ; then
 +	rc_halt "gpart bootcode -b /boot/boot ${_wSlice}"
 +      fi
  
        # Found our flag to commit this label setup, check that we found at least 1 partition
        if [ "${CURPART}" = "2" ] ; then
 @@ -564,15 +420,9 @@
      exit_err "ERROR: Missing SLICETAG data. This shouldn't happen - please let the developers know"
    fi
  
 -  # Using Traditional MBR for dual-booting
 -  if [ "$type" = "mbr" ] ; then
 -    setup_mbr_partitions "${disktag}" "${wrkslice}"
 -  fi
  
 -  # Using entire disk mode, use GPT for this
 -  if [ "$type" = "gpt" ] ; then
 -    setup_gpt_partitions "${disktag}" "${disk}"
 -  fi
 +  # Setup the partitions with gpart
 +  setup_gpart_partitions "${disktag}" "${disk}" "${wrkslice}" "${slicenum}" "${type}"
  
  };
  
 diff -ruN usr.sbin/pc-sysinstall/backend/functions-disk.sh.o usr.sbin/pc-sysinstall/backend/functions-disk.sh
 --- usr.sbin/pc-sysinstall/backend/functions-disk.sh.o	2010-11-15 15:18:24.622397324 -0500
 +++ usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-11-16 11:14:11.012131353 -0500
 @@ -580,7 +580,7 @@
  
    echo_log "Running gpart on ${_intDISK}"
    rc_halt "gpart create -s GPT ${_intDISK}"
 -  rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}"
 +  rc_halt "gpart add -b 34 -s 1982 -t freebsd-boot ${_intDISK}"
    
    echo_log "Stamping boot sector on ${_intDISK}"
    rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}"
 @@ -593,7 +593,7 @@
    _intDISK=$1
    _intBOOT=$2
   
 -  startblock="63"
 +  startblock="2016"
  
    # Set our sysctl so we can overwrite any geom using drives
    sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
 
 --y0ulUmNC+osPPQO6--

From: Kris Moore <kris@pcbsd.org>
To: bug-followup@FreeBSD.org, kmoore@FreeBSD.org
Cc:  
Subject: Re: bin/151967: [patch] pc-sysinstall(8) - Add support 4k partition
 alignment
Date: Tue, 07 Dec 2010 17:36:27 -0500

 This is a multi-part message in MIME format.
 --------------010806020207050905020108
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 Attached is an update to the last patch, which makes entire disk
 setups using both GPT/MBR 4k aligned, and boots each properly.
 It also fixes an issue with gpt backup tables not getting cleared out
 when switching back to MBR.
 
 I've tested this a number of times now, with different layouts /
 file-systems, partitions
 start at 1008KB on the disk and later partitions still maintain 4k
 alignment.
 
 - -- 
 Kris Moore
 PC-BSD Software
 iXsystems
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.15 (FreeBSD)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iQEcBAEBAgAGBQJM/rbrAAoJEDv6T4U6J2HSR68H+QFDLePlGtOiDSbJcx5IZRaJ
 mqjGm8PtHzNYDGRAYVAuWCi8cL0D/c+F9vSbuaN3XdFNm+r/5qvXK/uhMluQqto8
 hHj3gtKqxvOb0OOIVFxUIw1/PrrQIpsSPmBfn9CSzLetAJuKY4M5+jT7T1xlU2qZ
 IzdBOh1sWuW+O4l1/b5e18emmwds/hvXLPBQkAPHlznb96M0OC1+DYoNiNyZHutX
 mWKkvYE1CZZcJ970WbzlRyyAf89IMdf+ZZNX7MFLy/7CX4HI6oZuPWcGvFS6T5lF
 7m/MvS6T12gIwEj4Ho53O+R8aGwiAsxYb8/4U2aun3ZMHqoRLTD0o3OQNqR02Xc=
 =Ue8m
 -----END PGP SIGNATURE-----
 
 
 --------------010806020207050905020108
 Content-Type: text/plain;
  name="patch-pcsysinstall-4k-bsdlabel.txt"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="patch-pcsysinstall-4k-bsdlabel.txt"
 
 diff -ruN usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
 --- usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	2010-12-07 13:14:06.809482201 -0500
 +++ usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	2010-12-07 16:25:32.516591385 -0500
 @@ -158,227 +158,29 @@
    export VAL
  };
  
 -# Function to setup / stamp a legacy MBR bsdlabel
 -setup_mbr_partitions()
 +# Function to setup partitions using gpart
 +setup_gpart_partitions()
  {
 -  DISKTAG="$1"
 -  WRKSLICE="$2"
 +  local _dTag="$1"
 +  local _pDisk="$2"
 +  local _wSlice="$3"
 +  local _sNum="$4"
 +  local _pType="$5"
    FOUNDPARTS="1"
  
 -  # Lets setup the BSDLABEL
 -  BSDLABEL="${TMPDIR}/bsdLabel-${WRKSLICE}"
 -  export BSDLABEL
 -  rm $BSDLABEL >/dev/null 2>/dev/null
 -  echo "# /dev/${WRKSLICE}" >>$BSDLABEL
 -  echo "8 partitions:" >>$BSDLABEL
 -  echo "#	size	offset	fstype	bsize	bps/cpg" >>$BSDLABEL
 -   
 -  PARTLETTER="a"
 -
 -  # Lets read in the config file now and populate this
 -  while read line
 -  do
 -    # Check for data on this slice
 -    echo $line | grep "^${DISKTAG}-part=" >/dev/null 2>/dev/null
 -    if [ "$?" = "0" ]
 -    then
 -      # Found a slice- entry, lets get the slice info
 -      get_value_from_string "${line}"
 -      STRING="$VAL"
 -      FOUNDPARTS="0"
 -
 -      # We need to split up the string now, and pick out the variables
 -      FS=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 1` 
 -      SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2` 
 -      MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3` 
 -
 -      if echo $STRING | grep -E '^/.+' >/dev/null 2>&1
 -      then
 -        IMAGE=`echo ${STRING} | cut -f1 -d' '`
 -      fi
 -
 -      # Check if we have a .eli extension on this FS
 -      echo ${FS} | grep ".eli" >/dev/null 2>/dev/null
 -      if [ "$?" = "0" ]
 -      then
 -        FS="`echo ${FS} | cut -d '.' -f 1`"
 -        ENC="ON"
 -        check_for_enc_pass "${line}"
 -        if [ "${VAL}" != "" ] ; then
 -          # We have a user supplied password, save it for later
 -          ENCPASS="${VAL}" 
 -        fi
 -      else
 -        ENC="OFF"
 -      fi
 -
 -      # Check if the user tried to setup / as an encrypted partition
 -      check_for_mount "${MNT}" "/"
 -      if [ "${?}" = "0" -a "${ENC}" = "ON" ]
 -      then
 -        USINGENCROOT="0" ; export USINGENCROOT
 -      fi
 -          
 -      if [ -n "${IMAGE}" ]
 -      then
 -        FS="IMAGE"
 -        SIZE=`ls -l "${IMAGE}" | awk '{ print $5 }'`
 -        MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2`
 -		SIZE=`convert_byte_to_megabyte $SIZE`
 -      fi
 -
 -      # Now check that these values are sane
 -      case $FS in
 -        UFS|UFS+S|UFS+J|UFS+SUJ|ZFS|SWAP|IMAGE) ;;
 -       *) exit_err "ERROR: Invalid file system specified on $line" ;;
 -      esac
 -
 -      # Check that we have a valid size number
 -      expr $SIZE + 1 >/dev/null 2>/dev/null
 -      if [ "$?" != "0" ]; then
 -        exit_err "ERROR: The size specified on $line is invalid"
 -      fi
 -
 -      # Check that the mount-point starts with /
 -      echo "$MNT" | grep -e "^/" -e "^none" >/dev/null 2>/dev/null
 -      if [ "$?" != "0" ]; then
 -        exit_err "ERROR: The mount-point specified on $line is invalid"
 -      fi
 -
 -      if [ "$SIZE" = "0" ]
 -      then
 -        SOUT="*"
 -      else
 -        SOUT="${SIZE}M"
 -      fi
 -
 -      # OK, we passed all tests, now lets put these values into a config
 -      # If the part
 -      if [ "${PARTLETTER}" = "a" ]
 -      then
 -        if [ "$FS" = "SWAP" ]
 -        then
 -          echo "a:	${SOUT}	*	swap	0	0" >>${BSDLABEL}
 -        else
 -          echo "a:	${SOUT}	0	4.2BSD	0	0" >>${BSDLABEL}
 -        fi
 -
 -        # Check if we found a valid root partition
 -        check_for_mount "${MNT}" "/"
 -        if [ "$?" = "0" ] ; then
 -          FOUNDROOT="0" ; export FOUNDROOT
 -        fi
 -
 -        # Check if we have a "/boot" instead
 -        check_for_mount "${MNT}" "/boot"
 -        if [ "${?}" = "0" ] ; then
 -          USINGBOOTPART="0" ; export USINGBOOTPART
 -          if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ]
 -          then
 -            exit_err "/boot partition must be formatted with UFS"
 -          fi
 -        fi
 -
 -       else
 -        # Done with the a: partitions
 -
 -        # Check if we found a valid root partition not on a:
 -        check_for_mount "${MNT}" "/"
 -        if [ "${?}" = "0" ] ; then
 -          FOUNDROOT="1" ; export FOUNDROOT
 -        fi
 -
 -        # Check if we have a /boot partition, and fail since its not first
 -        check_for_mount "${MNT}" "/boot"
 -        if [ "${?}" = "0" ] ; then
 -          exit_err "/boot partition must be first partition"
 -        fi
 -
 -
 -        if [ "$FS" = "SWAP" ]
 -        then
 -          echo "${PARTLETTER}:	${SOUT}	*	swap" >>${BSDLABEL}
 -        else
 -          echo "${PARTLETTER}:	${SOUT}	*	4.2BSD" >>${BSDLABEL}
 -        fi
 -      fi
 -
 -      # Generate a unique label name for this mount
 -      gen_glabel_name "${MNT}" "${FS}"
 -      PLABEL="${VAL}"
 -      
 -      # Get any extra options for this fs / line
 -      get_fs_line_xvars "${WRKSLICE}${PARTLETTER}" "${STRING}"
 -      XTRAOPTS="${VAR}"
 -
 -      # Check if using zfs mirror
 -      echo ${XTRAOPTS} | grep "mirror" >/dev/null 2>/dev/null
 -      if [ "$?" = "0" ] ; then
 -       	XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${WRKSLICE}${PARTLETTER}")
 -      fi
 -
 -      # Save this data to our partition config dir
 -      echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${WRKSLICE}${PARTLETTER}
 -
 -      # If we have a enc password, save it as well
 -      if [ ! -z "${ENCPASS}" ] ; then
 -        echo "${ENCPASS}" >${PARTDIR}-enc/${WRKSLICE}${PARTLETTER}-encpass
 -      fi
 -
 -      # This partition letter is used, get the next one
 -      case ${PARTLETTER} in
 -        a) PARTLETTER="b" ;;
 -        b) # When we hit b, add the special c: setup for bsdlabel 
 -           echo "c:	*	*	unused" >>${BSDLABEL}
 -           PARTLETTER="d" ;;
 -        d) PARTLETTER="e" ;;
 -        e) PARTLETTER="f" ;;
 -        f) PARTLETTER="g" ;;
 -        g) PARTLETTER="h" ;;
 -        h) PARTLETTER="ERR" ;;
 -        *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;;
 -      esac
 -
 -      unset IMAGE
 -
 -    fi # End of subsection locating a slice in config
 -
 -    echo $line | grep "^commitDiskLabel" >/dev/null 2>/dev/null
 -    if [ "$?" = "0" -a "${FOUNDPARTS}" = "0" ]
 -    then
 -      # Found our flag to commit this label setup, check that we found at least 1 partition and do it
 -      if [ "${PARTLETTER}" != "a" ]
 -      then
 -        # Check if we only had 1 partition, and make sure we add "c:" section to label
 -        if [ "${PARTLETTER}" = "b" ]
 -        then
 -             echo "c:	*	*	unused" >>${BSDLABEL}
 -        fi
 -
 -        echo "bsdlabel -R -B /dev/${WRKSLICE} ${BSDLABEL}"
 -        bsdlabel -R -B ${WRKSLICE} ${BSDLABEL}
 -
 -        break
 -      else
 -        exit_err "ERROR: commitDiskLabel was called without any partition entries for it!"
 -      fi
 -    fi
 -  done <${CFGF}
 -};
 -
 -# Function to setup partitions using gpt
 -setup_gpt_partitions()
 -{
 -  DISKTAG="$1"
 -  DISK="$2"
 -  FOUNDPARTS="1"
 +  # Lets read in the config file now and setup our partitions
 +  if [ "${_pType}" = "gpt" ] ; then
 +    CURPART="2"
 +  else
 +    PARTLETTER="a"
 +    CURPART="1"
 +    rc_halt "gpart create -s BSD ${_wSlice}"
 +  fi
  
 -  # Lets read in the config file now and setup our GPT partitions
 -  CURPART="2"
    while read line
    do
      # Check for data on this slice
 -    echo $line | grep "^${DISKTAG}-part=" >/dev/null 2>/dev/null
 +    echo $line | grep "^${_dTag}-part=" >/dev/null 2>/dev/null
      if [ "$?" = "0" ]
      then
        FOUNDPARTS="0"
 @@ -441,24 +243,28 @@
        # Check if we found a valid root partition
        check_for_mount "${MNT}" "/"
        if [ "${?}" = "0" ] ; then
 -        if [ "${CURPART}" = "2" ] ; then
 +        FOUNDROOT="1" ; export FOUNDROOT
 +        if [ "${CURPART}" = "2" -a "$_pType" = "gpt" ] ; then
 +          FOUNDROOT="0" ; export FOUNDROOT
 +        fi
 +        if [ "${CURPART}" = "1" -a "$_pType" = "mbr" ] ; then
            FOUNDROOT="0" ; export FOUNDROOT
 -        else
 -          FOUNDROOT="1" ; export FOUNDROOT
          fi
        fi
  
        check_for_mount "${MNT}" "/boot"
        if [ "${?}" = "0" ] ; then
 -        if [ "${CURPART}" = "2" ] ; then
 -          USINGBOOTPART="0" ; export USINGBOOTPART
 -          if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ]
 -          then
 -            exit_err "/boot partition must be formatted with UFS"
 -          fi
 -        else
 +        USINGBOOTPART="0" ; export USINGBOOTPART
 +        if [ "${CURPART}" != "2" -a "${_pType}" = "gpt" ] ; then
 +            exit_err "/boot partition must be first partition"
 +        fi
 +        if [ "${CURPART}" != "1" -a "${_pType}" = "mbr" ] ; then
              exit_err "/boot partition must be first partition"
          fi
 +
 +        if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ] ; then
 +          exit_err "/boot partition must be formatted with UFS"
 +        fi
        fi
  
        # Generate a unique label name for this mount
 @@ -466,13 +272,21 @@
        PLABEL="${VAL}"
  
        # Get any extra options for this fs / line
 -      get_fs_line_xvars "${DISK}p${CURPART}" "${STRING}"
 +      if [ "${_pType}" = "gpt" ] ; then
 +        get_fs_line_xvars "${_pDisk}p${CURPART}" "${STRING}"
 +      else
 +        get_fs_line_xvars "${_wSlice}" "${STRING}"
 +      fi
        XTRAOPTS="${VAR}"
  
        # Check if using zfs mirror
        echo ${XTRAOPTS} | grep "mirror" >/dev/null 2>/dev/null
        if [ "$?" = "0" ] ; then
 -       	XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${DISK}p${CURPART}")
 +        if [ "${_pType}" = "gpt" ] ; then
 +       	  XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}p${CURPART}")
 +        else
 +       	  XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_wSlice}")
 +        fi
        fi
  
        # Figure out the gpart type to use
 @@ -483,7 +297,16 @@
        esac
  
        # Create the partition
 -      rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${DISK}"
 +      if [ "${_pType}" = "gpt" ] ; then
 +	if [ "$CURPART" = "2" ] ; then
 +	  # If this is GPT, make sure first partition is aligned to 4k
 +          rc_halt "gpart add -b 2016 ${SOUT} -t ${PARTYPE} ${_pDisk}"
 +	else
 +          rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}"
 +	fi
 +      else
 +        rc_halt "gpart add ${SOUT} -t ${PARTYPE} -i ${CURPART} ${_wSlice}"
 +      fi
  
        # Check if this is a root / boot partition, and stamp the right loader
        for TESTMNT in `echo ${MNT} | sed 's|,| |g'`
 @@ -497,19 +320,53 @@
        done 
  
        # Save this data to our partition config dir
 -      echo "${FS}:${MNT}:${ENC}:${PLABEL}:GPT:${XTRAOPTS}" >${PARTDIR}/${DISK}p${CURPART}
 +      if [ "${_pType}" = "gpt" ] ; then
 +        echo "${FS}:${MNT}:${ENC}:${PLABEL}:GPT:${XTRAOPTS}" >${PARTDIR}/${_pDisk}p${CURPART}
  
 -      # Clear out any headers
 -      sleep 2
 -      dd if=/dev/zero of=${DISK}p${CURPART} count=2048 >/dev/null 2>/dev/null
 -
 -      # If we have a enc password, save it as well
 -      if [ ! -z "${ENCPASS}" ] ; then
 -        echo "${ENCPASS}" >${PARTDIR}-enc/${DISK}p${CURPART}-encpass
 +        # Clear out any headers
 +        sleep 2
 +        dd if=/dev/zero of=${_pDisk}p${CURPART} count=2048 >/dev/null 2>/dev/null
 +
 +        # If we have a enc password, save it as well
 +        if [ ! -z "${ENCPASS}" ] ; then
 +          echo "${ENCPASS}" >${PARTDIR}-enc/${_pDisk}p${CURPART}-encpass
 +        fi
 +      else
 +	# MBR Partition
 +        echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${_wSlice}${PARTLETTER}
 +        # Clear out any headers
 +        sleep 2
 +        dd if=/dev/zero of=${_wSlice}${PARTLETTER} count=2048 >/dev/null 2>/dev/null
 +
 +        # If we have a enc password, save it as well
 +        if [ ! -z "${ENCPASS}" ] ; then
 +          echo "${ENCPASS}" >${PARTDIR}-enc/${_wSlice}${PARTLETTER}-encpass
 +        fi
        fi
  
 +
        # Increment our parts counter
 -      CURPART="`expr ${CURPART} + 1`"
 +      if [ "$_pType" = "gpt" ] ; then 
 +        CURPART="`expr ${CURPART} + 1`"
 +        # If this is a gpt partition, we can continue and skip the MBR part letter stuff
 +        continue
 +      else
 +        CURPART="`expr ${CURPART} + 1`"
 +        if [ "$CURPART" = "3" ] ; then CURPART="4" ; fi
 +      fi
 +
 +
 +      # This partition letter is used, get the next one
 +      case ${PARTLETTER} in
 +        a) PARTLETTER="b" ;;
 +        b) PARTLETTER="d" ;;
 +        d) PARTLETTER="e" ;;
 +        e) PARTLETTER="f" ;;
 +        f) PARTLETTER="g" ;;
 +        g) PARTLETTER="h" ;;
 +        h) PARTLETTER="ERR" ;;
 +        *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;;
 +      esac
  
      fi # End of subsection locating a slice in config
  
 @@ -518,13 +375,17 @@
      then
  
        # If this is the boot disk, stamp the right gptboot
 -      if [ ! -z "${BOOTTYPE}" ] ; then
 +      if [ ! -z "${BOOTTYPE}" -a "$_pType" = "gpt" ] ; then
          case ${BOOTTYPE} in
 -          freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${DISK}" ;;
 -          freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${DISK}" ;;
 +          freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${_pDisk}" ;;
 +          freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${_pDisk}" ;;
          esac 
        fi
  
 +      # Make sure to stamp the MBR loader
 +      if [ "$_pType" = "mbr" ] ; then
 +	rc_halt "gpart bootcode -b /boot/boot ${_wSlice}"
 +      fi
  
        # Found our flag to commit this label setup, check that we found at least 1 partition
        if [ "${CURPART}" = "2" ] ; then
 @@ -564,15 +425,9 @@
      exit_err "ERROR: Missing SLICETAG data. This shouldn't happen - please let the developers know"
    fi
  
 -  # Using Traditional MBR for dual-booting
 -  if [ "$type" = "mbr" ] ; then
 -    setup_mbr_partitions "${disktag}" "${wrkslice}"
 -  fi
  
 -  # Using entire disk mode, use GPT for this
 -  if [ "$type" = "gpt" ] ; then
 -    setup_gpt_partitions "${disktag}" "${disk}"
 -  fi
 +  # Setup the partitions with gpart
 +  setup_gpart_partitions "${disktag}" "${disk}" "${wrkslice}" "${slicenum}" "${type}"
  
  };
  
 diff -ruN usr.sbin/pc-sysinstall/backend/functions-disk.sh usr.sbin/pc-sysinstall/backend/functions-disk.sh
 --- usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-12-07 13:14:06.809482201 -0500
 +++ usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-12-07 16:25:29.544320674 -0500
 @@ -248,7 +248,7 @@
  delete_all_gpart()
  {
    echo_log "Deleting all gparts"
 -  DISK="$1"
 +  local DISK="$1"
  
    # Check for any swaps to stop
    for i in `gpart show ${DISK} 2>/dev/null | grep 'freebsd-swap' | tr -s ' ' | cut -d ' ' -f 4`
 @@ -265,6 +265,13 @@
     fi
    done
  
 +  # Destroy the disk geom
 +  rc_nohalt "gpart destroy ${DISK}"
 +
 +  # Make sure we clear any hidden gpt tables
 +  clear_backup_gpt_table "${DISK}"
 +
 +  # Wipe out front of disk
    rc_nohalt "dd if=/dev/zero of=/dev/${DISK} count=3000"
  
  };
 @@ -558,6 +565,24 @@
    fi
  } ;
  
 +
 +# Function to wipe the potential backup gpt table from a disk
 +clear_backup_gpt_table()
 +{
 +  # Get the disk block size
 +  local dSize="`gpart show $1 | grep $1 | tr -s ' ' | cut -d ' ' -f 3`"
 +
 +  # Make sure this is a valid number
 +  is_num "${dSize}" >/dev/null 2>/dev/null
 +  if [ "$?" != "0" ] ; then return ; fi
 +
 +  # Die backup label, DIE
 +  echo_log "Clearing gpt backup table location on disk"
 +  rc_nohalt "dd if=/dev/zero of=${1} bs=512 seek=${dSize}"
 +
 +} ;
 +
 +
  # Function which runs gpart and creates a single large GPT partition scheme
  init_gpt_full_disk()
  {
 @@ -572,15 +597,11 @@
    # Remove any existing partitions
    delete_all_gpart "${_intDISK}"
  
 -  #Erase any existing bootloader
 -  echo_log "Cleaning up ${_intDISK}"
 -  rc_halt "dd if=/dev/zero of=/dev/${_intDISK} count=2048"
 -
    sleep 2
  
    echo_log "Running gpart on ${_intDISK}"
    rc_halt "gpart create -s GPT ${_intDISK}"
 -  rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}"
 +  rc_halt "gpart add -b 34 -s 64 -t freebsd-boot ${_intDISK}"
    
    echo_log "Stamping boot sector on ${_intDISK}"
    rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}"
 @@ -593,7 +614,7 @@
    _intDISK=$1
    _intBOOT=$2
   
 -  startblock="63"
 +  startblock="2016"
  
    # Set our sysctl so we can overwrite any geom using drives
    sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
 @@ -604,10 +625,6 @@
    # Remove any existing partitions
    delete_all_gpart "${_intDISK}"
  
 -  #Erase any existing bootloader
 -  echo_log "Cleaning up ${_intDISK}"
 -  rc_halt "dd if=/dev/zero of=/dev/${_intDISK} count=2048"
 -
    sleep 2
  
    echo_log "Running gpart on ${_intDISK}"
 
 --------------010806020207050905020108--
State-Changed-From-To: open->closed 
State-Changed-By: jpaetzel 
State-Changed-When: Mon Jan 10 19:11:45 UTC 2011 
State-Changed-Why:  
Committed, thanks. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/151967: commit references a PR
Date: Mon, 10 Jan 2011 19:11:31 +0000 (UTC)

 Author: jpaetzel (ports committer)
 Date: Mon Jan 10 19:11:25 2011
 New Revision: 217229
 URL: http://svn.freebsd.org/changeset/base/217229
 
 Log:
   Patch pc-sysinstall to deal with 4k sector size drives
   
   PR:	bin/151967
   Submitted by:	kmoore
   Approved by:	imp
 
 Modified:
   head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
   head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	Mon Jan 10 18:15:34 2011	(r217228)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	Mon Jan 10 19:11:25 2011	(r217229)
 @@ -158,227 +158,29 @@ gen_glabel_name()
    export VAL
  };
  
 -# Function to setup / stamp a legacy MBR bsdlabel
 -setup_mbr_partitions()
 +# Function to setup partitions using gpart
 +setup_gpart_partitions()
  {
 -  DISKTAG="$1"
 -  WRKSLICE="$2"
 +  local _dTag="$1"
 +  local _pDisk="$2"
 +  local _wSlice="$3"
 +  local _sNum="$4"
 +  local _pType="$5"
    FOUNDPARTS="1"
  
 -  # Lets setup the BSDLABEL
 -  BSDLABEL="${TMPDIR}/bsdLabel-${WRKSLICE}"
 -  export BSDLABEL
 -  rm $BSDLABEL >/dev/null 2>/dev/null
 -  echo "# /dev/${WRKSLICE}" >>$BSDLABEL
 -  echo "8 partitions:" >>$BSDLABEL
 -  echo "#	size	offset	fstype	bsize	bps/cpg" >>$BSDLABEL
 -   
 -  PARTLETTER="a"
 -
 -  # Lets read in the config file now and populate this
 -  while read line
 -  do
 -    # Check for data on this slice
 -    echo $line | grep "^${DISKTAG}-part=" >/dev/null 2>/dev/null
 -    if [ "$?" = "0" ]
 -    then
 -      # Found a slice- entry, lets get the slice info
 -      get_value_from_string "${line}"
 -      STRING="$VAL"
 -      FOUNDPARTS="0"
 -
 -      # We need to split up the string now, and pick out the variables
 -      FS=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 1` 
 -      SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2` 
 -      MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3` 
 -
 -      if echo $STRING | grep -E '^/.+' >/dev/null 2>&1
 -      then
 -        IMAGE=`echo ${STRING} | cut -f1 -d' '`
 -      fi
 -
 -      # Check if we have a .eli extension on this FS
 -      echo ${FS} | grep ".eli" >/dev/null 2>/dev/null
 -      if [ "$?" = "0" ]
 -      then
 -        FS="`echo ${FS} | cut -d '.' -f 1`"
 -        ENC="ON"
 -        check_for_enc_pass "${line}"
 -        if [ "${VAL}" != "" ] ; then
 -          # We have a user supplied password, save it for later
 -          ENCPASS="${VAL}" 
 -        fi
 -      else
 -        ENC="OFF"
 -      fi
 -
 -      # Check if the user tried to setup / as an encrypted partition
 -      check_for_mount "${MNT}" "/"
 -      if [ "${?}" = "0" -a "${ENC}" = "ON" ]
 -      then
 -        USINGENCROOT="0" ; export USINGENCROOT
 -      fi
 -          
 -      if [ -n "${IMAGE}" ]
 -      then
 -        FS="IMAGE"
 -        SIZE=`ls -l "${IMAGE}" | awk '{ print $5 }'`
 -        MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2`
 -		SIZE=`convert_byte_to_megabyte $SIZE`
 -      fi
 -
 -      # Now check that these values are sane
 -      case $FS in
 -        UFS|UFS+S|UFS+J|UFS+SUJ|ZFS|SWAP|IMAGE) ;;
 -       *) exit_err "ERROR: Invalid file system specified on $line" ;;
 -      esac
 -
 -      # Check that we have a valid size number
 -      expr $SIZE + 1 >/dev/null 2>/dev/null
 -      if [ "$?" != "0" ]; then
 -        exit_err "ERROR: The size specified on $line is invalid"
 -      fi
 -
 -      # Check that the mount-point starts with /
 -      echo "$MNT" | grep -e "^/" -e "^none" >/dev/null 2>/dev/null
 -      if [ "$?" != "0" ]; then
 -        exit_err "ERROR: The mount-point specified on $line is invalid"
 -      fi
 -
 -      if [ "$SIZE" = "0" ]
 -      then
 -        SOUT="*"
 -      else
 -        SOUT="${SIZE}M"
 -      fi
 -
 -      # OK, we passed all tests, now lets put these values into a config
 -      # If the part
 -      if [ "${PARTLETTER}" = "a" ]
 -      then
 -        if [ "$FS" = "SWAP" ]
 -        then
 -          echo "a:	${SOUT}	*	swap	0	0" >>${BSDLABEL}
 -        else
 -          echo "a:	${SOUT}	0	4.2BSD	0	0" >>${BSDLABEL}
 -        fi
 -
 -        # Check if we found a valid root partition
 -        check_for_mount "${MNT}" "/"
 -        if [ "$?" = "0" ] ; then
 -          FOUNDROOT="0" ; export FOUNDROOT
 -        fi
 -
 -        # Check if we have a "/boot" instead
 -        check_for_mount "${MNT}" "/boot"
 -        if [ "${?}" = "0" ] ; then
 -          USINGBOOTPART="0" ; export USINGBOOTPART
 -          if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ]
 -          then
 -            exit_err "/boot partition must be formatted with UFS"
 -          fi
 -        fi
 -
 -       else
 -        # Done with the a: partitions
 -
 -        # Check if we found a valid root partition not on a:
 -        check_for_mount "${MNT}" "/"
 -        if [ "${?}" = "0" ] ; then
 -          FOUNDROOT="1" ; export FOUNDROOT
 -        fi
 -
 -        # Check if we have a /boot partition, and fail since its not first
 -        check_for_mount "${MNT}" "/boot"
 -        if [ "${?}" = "0" ] ; then
 -          exit_err "/boot partition must be first partition"
 -        fi
 -
 -
 -        if [ "$FS" = "SWAP" ]
 -        then
 -          echo "${PARTLETTER}:	${SOUT}	*	swap" >>${BSDLABEL}
 -        else
 -          echo "${PARTLETTER}:	${SOUT}	*	4.2BSD" >>${BSDLABEL}
 -        fi
 -      fi
 -
 -      # Generate a unique label name for this mount
 -      gen_glabel_name "${MNT}" "${FS}"
 -      PLABEL="${VAL}"
 -      
 -      # Get any extra options for this fs / line
 -      get_fs_line_xvars "${WRKSLICE}${PARTLETTER}" "${STRING}"
 -      XTRAOPTS="${VAR}"
 -
 -      # Check if using zfs mirror
 -      echo ${XTRAOPTS} | grep "mirror" >/dev/null 2>/dev/null
 -      if [ "$?" = "0" ] ; then
 -       	XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${WRKSLICE}${PARTLETTER}")
 -      fi
 -
 -      # Save this data to our partition config dir
 -      echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${WRKSLICE}${PARTLETTER}
 -
 -      # If we have a enc password, save it as well
 -      if [ ! -z "${ENCPASS}" ] ; then
 -        echo "${ENCPASS}" >${PARTDIR}-enc/${WRKSLICE}${PARTLETTER}-encpass
 -      fi
 -
 -      # This partition letter is used, get the next one
 -      case ${PARTLETTER} in
 -        a) PARTLETTER="b" ;;
 -        b) # When we hit b, add the special c: setup for bsdlabel 
 -           echo "c:	*	*	unused" >>${BSDLABEL}
 -           PARTLETTER="d" ;;
 -        d) PARTLETTER="e" ;;
 -        e) PARTLETTER="f" ;;
 -        f) PARTLETTER="g" ;;
 -        g) PARTLETTER="h" ;;
 -        h) PARTLETTER="ERR" ;;
 -        *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;;
 -      esac
 -
 -      unset IMAGE
 -
 -    fi # End of subsection locating a slice in config
 -
 -    echo $line | grep "^commitDiskLabel" >/dev/null 2>/dev/null
 -    if [ "$?" = "0" -a "${FOUNDPARTS}" = "0" ]
 -    then
 -      # Found our flag to commit this label setup, check that we found at least 1 partition and do it
 -      if [ "${PARTLETTER}" != "a" ]
 -      then
 -        # Check if we only had 1 partition, and make sure we add "c:" section to label
 -        if [ "${PARTLETTER}" = "b" ]
 -        then
 -             echo "c:	*	*	unused" >>${BSDLABEL}
 -        fi
 -
 -        echo "bsdlabel -R -B /dev/${WRKSLICE} ${BSDLABEL}"
 -        bsdlabel -R -B ${WRKSLICE} ${BSDLABEL}
 -
 -        break
 -      else
 -        exit_err "ERROR: commitDiskLabel was called without any partition entries for it!"
 -      fi
 -    fi
 -  done <${CFGF}
 -};
 -
 -# Function to setup partitions using gpt
 -setup_gpt_partitions()
 -{
 -  DISKTAG="$1"
 -  DISK="$2"
 -  FOUNDPARTS="1"
 +  # Lets read in the config file now and setup our partitions
 +  if [ "${_pType}" = "gpt" ] ; then
 +    CURPART="2"
 +  else
 +    PARTLETTER="a"
 +    CURPART="1"
 +    rc_halt "gpart create -s BSD ${_wSlice}"
 +  fi
  
 -  # Lets read in the config file now and setup our GPT partitions
 -  CURPART="2"
    while read line
    do
      # Check for data on this slice
 -    echo $line | grep "^${DISKTAG}-part=" >/dev/null 2>/dev/null
 +    echo $line | grep "^${_dTag}-part=" >/dev/null 2>/dev/null
      if [ "$?" = "0" ]
      then
        FOUNDPARTS="0"
 @@ -441,24 +243,28 @@ setup_gpt_partitions()
        # Check if we found a valid root partition
        check_for_mount "${MNT}" "/"
        if [ "${?}" = "0" ] ; then
 -        if [ "${CURPART}" = "2" ] ; then
 +        FOUNDROOT="1" ; export FOUNDROOT
 +        if [ "${CURPART}" = "2" -a "$_pType" = "gpt" ] ; then
 +          FOUNDROOT="0" ; export FOUNDROOT
 +        fi
 +        if [ "${CURPART}" = "1" -a "$_pType" = "mbr" ] ; then
            FOUNDROOT="0" ; export FOUNDROOT
 -        else
 -          FOUNDROOT="1" ; export FOUNDROOT
          fi
        fi
  
        check_for_mount "${MNT}" "/boot"
        if [ "${?}" = "0" ] ; then
 -        if [ "${CURPART}" = "2" ] ; then
 -          USINGBOOTPART="0" ; export USINGBOOTPART
 -          if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ]
 -          then
 -            exit_err "/boot partition must be formatted with UFS"
 -          fi
 -        else
 +        USINGBOOTPART="0" ; export USINGBOOTPART
 +        if [ "${CURPART}" != "2" -a "${_pType}" = "gpt" ] ; then
 +            exit_err "/boot partition must be first partition"
 +        fi
 +        if [ "${CURPART}" != "1" -a "${_pType}" = "mbr" ] ; then
              exit_err "/boot partition must be first partition"
          fi
 +
 +        if [ "${FS}" != "UFS" -a "${FS}" != "UFS+S" -a "${FS}" != "UFS+J" -a "${FS}" != "UFS+SUJ" ] ; then
 +          exit_err "/boot partition must be formatted with UFS"
 +        fi
        fi
  
        # Generate a unique label name for this mount
 @@ -466,13 +272,21 @@ setup_gpt_partitions()
        PLABEL="${VAL}"
  
        # Get any extra options for this fs / line
 -      get_fs_line_xvars "${DISK}p${CURPART}" "${STRING}"
 +      if [ "${_pType}" = "gpt" ] ; then
 +        get_fs_line_xvars "${_pDisk}p${CURPART}" "${STRING}"
 +      else
 +        get_fs_line_xvars "${_wSlice}" "${STRING}"
 +      fi
        XTRAOPTS="${VAR}"
  
        # Check if using zfs mirror
        echo ${XTRAOPTS} | grep "mirror" >/dev/null 2>/dev/null
        if [ "$?" = "0" ] ; then
 -       	XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${DISK}p${CURPART}")
 +        if [ "${_pType}" = "gpt" ] ; then
 +       	  XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_pDisk}p${CURPART}")
 +        else
 +       	  XTRAOPTS=$(setup_zfs_mirror_parts "$XTRAOPTS" "${_wSlice}")
 +        fi
        fi
  
        # Figure out the gpart type to use
 @@ -483,7 +297,16 @@ setup_gpt_partitions()
        esac
  
        # Create the partition
 -      rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${DISK}"
 +      if [ "${_pType}" = "gpt" ] ; then
 +	if [ "$CURPART" = "2" ] ; then
 +	  # If this is GPT, make sure first partition is aligned to 4k
 +          rc_halt "gpart add -b 2016 ${SOUT} -t ${PARTYPE} ${_pDisk}"
 +	else
 +          rc_halt "gpart add ${SOUT} -t ${PARTYPE} ${_pDisk}"
 +	fi
 +      else
 +        rc_halt "gpart add ${SOUT} -t ${PARTYPE} -i ${CURPART} ${_wSlice}"
 +      fi
  
        # Check if this is a root / boot partition, and stamp the right loader
        for TESTMNT in `echo ${MNT} | sed 's|,| |g'`
 @@ -497,19 +320,53 @@ setup_gpt_partitions()
        done 
  
        # Save this data to our partition config dir
 -      echo "${FS}:${MNT}:${ENC}:${PLABEL}:GPT:${XTRAOPTS}" >${PARTDIR}/${DISK}p${CURPART}
 +      if [ "${_pType}" = "gpt" ] ; then
 +        echo "${FS}:${MNT}:${ENC}:${PLABEL}:GPT:${XTRAOPTS}" >${PARTDIR}/${_pDisk}p${CURPART}
  
 -      # Clear out any headers
 -      sleep 2
 -      dd if=/dev/zero of=${DISK}p${CURPART} count=2048 >/dev/null 2>/dev/null
 -
 -      # If we have a enc password, save it as well
 -      if [ ! -z "${ENCPASS}" ] ; then
 -        echo "${ENCPASS}" >${PARTDIR}-enc/${DISK}p${CURPART}-encpass
 +        # Clear out any headers
 +        sleep 2
 +        dd if=/dev/zero of=${_pDisk}p${CURPART} count=2048 >/dev/null 2>/dev/null
 +
 +        # If we have a enc password, save it as well
 +        if [ ! -z "${ENCPASS}" ] ; then
 +          echo "${ENCPASS}" >${PARTDIR}-enc/${_pDisk}p${CURPART}-encpass
 +        fi
 +      else
 +	# MBR Partition
 +        echo "${FS}:${MNT}:${ENC}:${PLABEL}:MBR:${XTRAOPTS}:${IMAGE}" >${PARTDIR}/${_wSlice}${PARTLETTER}
 +        # Clear out any headers
 +        sleep 2
 +        dd if=/dev/zero of=${_wSlice}${PARTLETTER} count=2048 >/dev/null 2>/dev/null
 +
 +        # If we have a enc password, save it as well
 +        if [ ! -z "${ENCPASS}" ] ; then
 +          echo "${ENCPASS}" >${PARTDIR}-enc/${_wSlice}${PARTLETTER}-encpass
 +        fi
        fi
  
 +
        # Increment our parts counter
 -      CURPART="`expr ${CURPART} + 1`"
 +      if [ "$_pType" = "gpt" ] ; then 
 +        CURPART="`expr ${CURPART} + 1`"
 +        # If this is a gpt partition, we can continue and skip the MBR part letter stuff
 +        continue
 +      else
 +        CURPART="`expr ${CURPART} + 1`"
 +        if [ "$CURPART" = "3" ] ; then CURPART="4" ; fi
 +      fi
 +
 +
 +      # This partition letter is used, get the next one
 +      case ${PARTLETTER} in
 +        a) PARTLETTER="b" ;;
 +        b) PARTLETTER="d" ;;
 +        d) PARTLETTER="e" ;;
 +        e) PARTLETTER="f" ;;
 +        f) PARTLETTER="g" ;;
 +        g) PARTLETTER="h" ;;
 +        h) PARTLETTER="ERR" ;;
 +        *) exit_err "ERROR: bsdlabel only supports up to letter h for partitions." ;;
 +      esac
  
      fi # End of subsection locating a slice in config
  
 @@ -518,13 +375,17 @@ setup_gpt_partitions()
      then
  
        # If this is the boot disk, stamp the right gptboot
 -      if [ ! -z "${BOOTTYPE}" ] ; then
 +      if [ ! -z "${BOOTTYPE}" -a "$_pType" = "gpt" ] ; then
          case ${BOOTTYPE} in
 -          freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${DISK}" ;;
 -          freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${DISK}" ;;
 +          freebsd-ufs) rc_halt "gpart bootcode -p /boot/gptboot -i 1 ${_pDisk}" ;;
 +          freebsd-zfs) rc_halt "gpart bootcode -p /boot/gptzfsboot -i 1 ${_pDisk}" ;;
          esac 
        fi
  
 +      # Make sure to stamp the MBR loader
 +      if [ "$_pType" = "mbr" ] ; then
 +	rc_halt "gpart bootcode -b /boot/boot ${_wSlice}"
 +      fi
  
        # Found our flag to commit this label setup, check that we found at least 1 partition
        if [ "${CURPART}" = "2" ] ; then
 @@ -564,15 +425,9 @@ populate_disk_label()
      exit_err "ERROR: Missing SLICETAG data. This shouldn't happen - please let the developers know"
    fi
  
 -  # Using Traditional MBR for dual-booting
 -  if [ "$type" = "mbr" ] ; then
 -    setup_mbr_partitions "${disktag}" "${wrkslice}"
 -  fi
  
 -  # Using entire disk mode, use GPT for this
 -  if [ "$type" = "gpt" ] ; then
 -    setup_gpt_partitions "${disktag}" "${disk}"
 -  fi
 +  # Setup the partitions with gpart
 +  setup_gpart_partitions "${disktag}" "${disk}" "${wrkslice}" "${slicenum}" "${type}"
  
  };
  
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Mon Jan 10 18:15:34 2011	(r217228)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Mon Jan 10 19:11:25 2011	(r217229)
 @@ -243,7 +243,7 @@ export_all_zpools()
  delete_all_gpart()
  {
    echo_log "Deleting all gparts"
 -  DISK="$1"
 +  local DISK="$1"
  
    # Check for any swaps to stop
    for i in `gpart show ${DISK} 2>/dev/null | grep 'freebsd-swap' | tr -s ' ' | cut -d ' ' -f 4`
 @@ -260,6 +260,13 @@ delete_all_gpart()
     fi
    done
  
 +  # Destroy the disk geom
 +  rc_nohalt "gpart destroy ${DISK}"
 +
 +  # Make sure we clear any hidden gpt tables
 +  clear_backup_gpt_table "${DISK}"
 +
 +  # Wipe out front of disk
    rc_nohalt "dd if=/dev/zero of=/dev/${DISK} count=3000"
  
  };
 @@ -553,6 +560,24 @@ stop_gjournal()
    fi
  } ;
  
 +
 +# Function to wipe the potential backup gpt table from a disk
 +clear_backup_gpt_table()
 +{
 +  # Get the disk block size
 +  local dSize="`gpart show $1 | grep $1 | tr -s ' ' | cut -d ' ' -f 3`"
 +
 +  # Make sure this is a valid number
 +  is_num "${dSize}" >/dev/null 2>/dev/null
 +  if [ "$?" != "0" ] ; then return ; fi
 +
 +  # Die backup label, DIE
 +  echo_log "Clearing gpt backup table location on disk"
 +  rc_nohalt "dd if=/dev/zero of=${1} bs=512 seek=${dSize}"
 +
 +} ;
 +
 +
  # Function which runs gpart and creates a single large GPT partition scheme
  init_gpt_full_disk()
  {
 @@ -567,15 +592,11 @@ init_gpt_full_disk()
    # Remove any existing partitions
    delete_all_gpart "${_intDISK}"
  
 -  #Erase any existing bootloader
 -  echo_log "Cleaning up ${_intDISK}"
 -  rc_halt "dd if=/dev/zero of=/dev/${_intDISK} count=2048"
 -
    sleep 2
  
    echo_log "Running gpart on ${_intDISK}"
    rc_halt "gpart create -s GPT ${_intDISK}"
 -  rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}"
 +  rc_halt "gpart add -b 34 -s 64 -t freebsd-boot ${_intDISK}"
    
    echo_log "Stamping boot sector on ${_intDISK}"
    rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}"
 @@ -588,7 +609,7 @@ init_mbr_full_disk()
    _intDISK=$1
    _intBOOT=$2
   
 -  startblock="63"
 +  startblock="2016"
  
    # Set our sysctl so we can overwrite any geom using drives
    sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
 @@ -599,10 +620,6 @@ init_mbr_full_disk()
    # Remove any existing partitions
    delete_all_gpart "${_intDISK}"
  
 -  #Erase any existing bootloader
 -  echo_log "Cleaning up ${_intDISK}"
 -  rc_halt "dd if=/dev/zero of=/dev/${_intDISK} count=2048"
 -
    sleep 2
  
    echo_log "Running gpart on ${_intDISK}"
 _______________________________________________
 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:
