From nobody@FreeBSD.org  Wed Aug 18 15:44:11 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 72FF810656B9
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 18 Aug 2010 15:44:11 +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 58B428FC23
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 18 Aug 2010 15:44:11 +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 o7IFiBCa094237
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 18 Aug 2010 15:44:11 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o7IFiBK2094236;
	Wed, 18 Aug 2010 15:44:11 GMT
	(envelope-from nobody)
Message-Id: <201008181544.o7IFiBK2094236@www.freebsd.org>
Date: Wed, 18 Aug 2010 15:44:11 GMT
From: Kris Moore <kmoore@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] pc-sysinstall(8) update to support selecting  MBR/GPT partitioning
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         149772
>Category:       bin
>Synopsis:       [patch] pc-sysinstall(8) update to support selecting  MBR/GPT partitioning
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 18 15:50:02 UTC 2010
>Closed-Date:    Thu Aug 19 00:11:22 MDT 2010
>Last-Modified:  Thu Aug 19 06:20:03 UTC 2010
>Originator:     Kris Moore
>Release:        8.1-Release
>Organization:
iXsystems
>Environment:
FreeBSD pcbsd-7550 8.1-Release FreeBSD 8.1-Release #0: Tue Jul 18 09:54:49 PDT 2010     root@build8x64.pcbsd.org:/usr/obj/usr/pcbsd-build81/fbsd-source/8.1/sys/PCBSD  amd64

>Description:
This patch to pc-sysinstall allows the setting of a new config variable for installation, which lets the user/front-end select between MBR or GPT partitioning schemes when doing a dedicated disk installation. 
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -ruN usr.sbin/pc-sysinstall.o/backend/functions-disk.sh usr.sbin/pc-sysinstall/backend/functions-disk.sh
--- usr.sbin/pc-sysinstall.o/backend/functions-disk.sh	2010-08-18 10:54:38.962114783 -0400
+++ usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-08-18 11:29:30.503947499 -0400
@@ -406,6 +406,18 @@
        fi
      fi
 
+     # Check if we have a partscheme specified
+     echo $line | grep "^partscheme=" >/dev/null 2>/dev/null
+     if [ "$?" = "0" ] ; then
+       # Found a partscheme= entry, lets read / set it 
+       get_value_from_string "${line}"
+       strip_white_space "$VAL"
+       PSCHEME="$VAL"
+       if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
+	 exit_err "Unknown partition scheme: $PSCHEME" 
+       fi
+     fi
+
      echo $line | grep "^bootManager=" >/dev/null 2>/dev/null
      if [ "$?" = "0" ]
      then
@@ -422,8 +434,13 @@
        if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
        then
          case ${PTYPE} in
-                   all|ALL) tmpSLICE="${DISK}p1"  
-                        run_gpart_full "${DISK}" "${BMANAGER}" ;;
+               all|ALL) if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
+			  PSCHEME="MBR"
+			  tmpSLICE="${DISK}s1"  
+			else
+			  tmpSLICE="${DISK}p1"  
+			fi
+                        run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}" ;;
            s1|s2|s3|s4) tmpSLICE="${DISK}${PTYPE}" 
                         # Get the number of the slice we are working on
                         s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" 
@@ -449,7 +466,7 @@
 
 
          # Increment our disk counter to look for next disk and unset
-         unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL
+         unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME
          disknum="`expr $disknum + 1`"
        else
          exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!" 
@@ -477,7 +494,7 @@
   fi
 } ;
 
-# Function which runs gpart and creates a single large slice
+# Function which runs gpart and creates a single large GPT partition scheme
 init_gpt_full_disk()
 {
   _intDISK=$1
@@ -506,14 +523,82 @@
 
 }
 
+# Function which runs gpart and creates a single large MBR partition scheme
+init_mbr_full_disk()
+{
+  _intDISK=$1
+  _intBOOT=$2
+ 
+  startblock="63"
+
+  # Set our sysctl so we can overwrite any geom using drives
+  sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
+
+  # Stop any journaling
+  stop_gjournal "${_intDISK}"
+
+  # 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 mbr ${_intDISK}"
+
+  # Lets figure out disk size in blocks
+  # Get the cyl of this disk
+  get_disk_cyl "${_intDISK}"
+  cyl="${VAL}"
+
+  # Get the heads of this disk
+  get_disk_heads "${_intDISK}"
+  head="${VAL}"
+
+  # Get the tracks/sectors of this disk
+  get_disk_sectors "${_intDISK}"
+  sec="${VAL}"
+
+  # Multiply them all together to get our total blocks
+  totalblocks="`expr ${cyl} \* ${head}`"
+  totalblocks="`expr ${totalblocks} \* ${sec}`"
+
+
+  # Now set the ending block to the total disk block size
+  sizeblock="`expr ${totalblocks} - ${startblock}`"
+
+  # Install new partition setup
+  echo_log "Running gpart add on ${_intDISK}"
+  rc_halt "gpart add -b ${startblock} -s ${sizeblock} -t freebsd -i 1 ${_intDISK}"
+  sleep 2
+  
+  echo_log "Cleaning up ${_intDISK}s1"
+  rc_halt "dd if=/dev/zero of=/dev/${_intDISK}s1 count=1024"
+  
+  if [ "$_intBOOT" = "bsd" ] ; then
+    echo_log "Stamping boot sector on ${_intDISK}"
+    rc_halt "gpart bootcode -b /boot/boot0 ${_intDISK}"
+  fi
+
+}
+
 # Function which runs gpart and creates a single large slice
 run_gpart_full()
 {
   DISK=$1
+  BOOT=$2
+  SCHEME=$3
 
-  init_gpt_full_disk "$DISK"
-
-  slice="${DISK}-1-gpt"
+  if [ "$SCHEME" = "MBR" ] ; then
+    init_mbr_full_disk "$DISK" "$BOOT"
+    slice="${DISK}-1-mbr"
+  else
+    init_gpt_full_disk "$DISK"
+    slice="${DISK}-1-gpt"
+  fi
 
   # Lets save our slice, so we know what to look for in the config file later on
   if [ -z "$WORKINGSLICES" ]
diff -ruN usr.sbin/pc-sysinstall.o/examples/README usr.sbin/pc-sysinstall/examples/README
--- usr.sbin/pc-sysinstall.o/examples/README	2010-08-18 10:54:39.080115720 -0400
+++ usr.sbin/pc-sysinstall/examples/README	2010-08-18 11:28:12.717924490 -0400
@@ -128,6 +128,11 @@
 
 (This tag is unused for upgrades)
 
+# partscheme=(MBR/GPT)
+
+When performing a "full" disk (partition=all), the partscheme= variable is used
+to determine the partition scheme type gpart will be using on the disk. Valid
+choices are MBR or GPT. 
 
 # mirror=(disk device such as ad1)
 


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Thu Aug 19 00:11:15 MDT 2010 
State-Changed-Why:  
Committed. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/149772: commit references a PR
Date: Thu, 19 Aug 2010 06:16:02 +0000 (UTC)

 Author: imp
 Date: Thu Aug 19 06:11:06 2010
 New Revision: 211490
 URL: http://svn.freebsd.org/changeset/base/211490
 
 Log:
   This patch to pc-sysinstall allows the setting of a new config
   variable for installation, which lets the user/front-end select
   between MBR or GPT partitioning schemes when doing a dedicated disk
   installation.
   
   PR:		149772
   Submitted by:	Kris Moore
 
 Modified:
   head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
   head/usr.sbin/pc-sysinstall/examples/README
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Thu Aug 19 06:07:49 2010	(r211489)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Thu Aug 19 06:11:06 2010	(r211490)
 @@ -406,6 +406,18 @@ setup_disk_slice()
         fi
       fi
  
 +     # Check if we have a partscheme specified
 +     echo $line | grep "^partscheme=" >/dev/null 2>/dev/null
 +     if [ "$?" = "0" ] ; then
 +       # Found a partscheme= entry, lets read / set it 
 +       get_value_from_string "${line}"
 +       strip_white_space "$VAL"
 +       PSCHEME="$VAL"
 +       if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
 +	 exit_err "Unknown partition scheme: $PSCHEME" 
 +       fi
 +     fi
 +
       echo $line | grep "^bootManager=" >/dev/null 2>/dev/null
       if [ "$?" = "0" ]
       then
 @@ -422,8 +434,13 @@ setup_disk_slice()
         if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
         then
           case ${PTYPE} in
 -                   all|ALL) tmpSLICE="${DISK}p1"  
 -                        run_gpart_full "${DISK}" "${BMANAGER}" ;;
 +               all|ALL) if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
 +			  PSCHEME="MBR"
 +			  tmpSLICE="${DISK}s1"  
 +			else
 +			  tmpSLICE="${DISK}p1"  
 +			fi
 +                        run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}" ;;
             s1|s2|s3|s4) tmpSLICE="${DISK}${PTYPE}" 
                          # Get the number of the slice we are working on
                          s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" 
 @@ -449,7 +466,7 @@ setup_disk_slice()
  
  
           # Increment our disk counter to look for next disk and unset
 -         unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL
 +         unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME
           disknum="`expr $disknum + 1`"
         else
           exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!" 
 @@ -477,7 +494,7 @@ stop_gjournal() {
    fi
  } ;
  
 -# Function which runs gpart and creates a single large slice
 +# Function which runs gpart and creates a single large GPT partition scheme
  init_gpt_full_disk()
  {
    _intDISK=$1
 @@ -506,14 +523,82 @@ init_gpt_full_disk()
  
  }
  
 +# Function which runs gpart and creates a single large MBR partition scheme
 +init_mbr_full_disk()
 +{
 +  _intDISK=$1
 +  _intBOOT=$2
 + 
 +  startblock="63"
 +
 +  # Set our sysctl so we can overwrite any geom using drives
 +  sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
 +
 +  # Stop any journaling
 +  stop_gjournal "${_intDISK}"
 +
 +  # 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 mbr ${_intDISK}"
 +
 +  # Lets figure out disk size in blocks
 +  # Get the cyl of this disk
 +  get_disk_cyl "${_intDISK}"
 +  cyl="${VAL}"
 +
 +  # Get the heads of this disk
 +  get_disk_heads "${_intDISK}"
 +  head="${VAL}"
 +
 +  # Get the tracks/sectors of this disk
 +  get_disk_sectors "${_intDISK}"
 +  sec="${VAL}"
 +
 +  # Multiply them all together to get our total blocks
 +  totalblocks="`expr ${cyl} \* ${head}`"
 +  totalblocks="`expr ${totalblocks} \* ${sec}`"
 +
 +
 +  # Now set the ending block to the total disk block size
 +  sizeblock="`expr ${totalblocks} - ${startblock}`"
 +
 +  # Install new partition setup
 +  echo_log "Running gpart add on ${_intDISK}"
 +  rc_halt "gpart add -b ${startblock} -s ${sizeblock} -t freebsd -i 1 ${_intDISK}"
 +  sleep 2
 +  
 +  echo_log "Cleaning up ${_intDISK}s1"
 +  rc_halt "dd if=/dev/zero of=/dev/${_intDISK}s1 count=1024"
 +  
 +  if [ "$_intBOOT" = "bsd" ] ; then
 +    echo_log "Stamping boot sector on ${_intDISK}"
 +    rc_halt "gpart bootcode -b /boot/boot0 ${_intDISK}"
 +  fi
 +
 +}
 +
  # Function which runs gpart and creates a single large slice
  run_gpart_full()
  {
    DISK=$1
 +  BOOT=$2
 +  SCHEME=$3
  
 -  init_gpt_full_disk "$DISK"
 -
 -  slice="${DISK}-1-gpt"
 +  if [ "$SCHEME" = "MBR" ] ; then
 +    init_mbr_full_disk "$DISK" "$BOOT"
 +    slice="${DISK}-1-mbr"
 +  else
 +    init_gpt_full_disk "$DISK"
 +    slice="${DISK}-1-gpt"
 +  fi
  
    # Lets save our slice, so we know what to look for in the config file later on
    if [ -z "$WORKINGSLICES" ]
 
 Modified: head/usr.sbin/pc-sysinstall/examples/README
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/examples/README	Thu Aug 19 06:07:49 2010	(r211489)
 +++ head/usr.sbin/pc-sysinstall/examples/README	Thu Aug 19 06:11:06 2010	(r211490)
 @@ -128,6 +128,11 @@ Setting this to "s1, s2, s3 or s4" will 
  
  (This tag is unused for upgrades)
  
 +# partscheme=(MBR/GPT)
 +
 +When performing a "full" disk (partition=all), the partscheme= variable is used
 +to determine the partition scheme type gpart will be using on the disk. Valid
 +choices are MBR or GPT. 
  
  # mirror=(disk device such as ad1)
  
 _______________________________________________
 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:
