From nobody@FreeBSD.org  Fri Feb 11 15:06:56 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 9993C1065673
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Feb 2011 15:06:56 +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 7CDA98FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Feb 2011 15:06:56 +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 p1BF6ujR037565
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Feb 2011 15:06:56 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p1BF6uWl037564;
	Fri, 11 Feb 2011 15:06:56 GMT
	(envelope-from nobody)
Message-Id: <201102111506.p1BF6uWl037564@red.freebsd.org>
Date: Fri, 11 Feb 2011 15:06:56 GMT
From: Kris Moore <kmoore@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: bin: usr.sbin/pc-sysinstall - Improvements for pc-sysinstall to create GPT and other types of partitions
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         154684
>Category:       bin
>Synopsis:       bin: usr.sbin/pc-sysinstall - Improvements for pc-sysinstall to create GPT and other types of partitions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jpaetzel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 11 15:10:09 UTC 2011
>Closed-Date:    Fri Feb 18 15:01:15 UTC 2011
>Last-Modified:  Fri Feb 18 15:10:11 UTC 2011
>Originator:     Kris Moore
>Release:        9.0-Current
>Organization:
PC-BSD / iXsystems
>Environment:
FreeBSD 9.0-CURRENT
>Description:
The included patch adds support to pc-sysinstall's create-part feature, to create non MBR type partitions, such as GPT and others. 
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -ruN usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh
--- usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	2011-01-27 10:26:03.659375118 -0500
+++ usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	2011-01-27 11:48:40.178393624 -0500
@@ -25,7 +25,7 @@
 #
 # $FreeBSD$
 
-# Query a disk for partitions and display them
+# Create partitions on a target disk
 #############################
 
 . ${PROGDIR}/backend/functions.sh
@@ -47,46 +47,40 @@
 
 DISK="${1}"
 MB="${2}"
+TYPE="${3}"
+STARTBLOCK="${4}"
 
 TOTALBLOCKS="`expr $MB \* 2048`"
 
+# If no TYPE specified, default to MBR
+if [ -z "$TYPE" ] ; then TYPE="mbr" ; fi
 
-# Lets figure out what number this slice will be
-LASTSLICE="`fdisk -s /dev/${DISK} 2>/dev/null | grep -v ${DISK} | grep ':' | tail -n 1 | cut -d ':' -f 1 | tr -s '\t' ' ' | tr -d ' '`"
+# Lets figure out what number this partition will be
+LASTSLICE="`gpart show $DISK | grep -v -e $DISK -e '\- free \-' -e '^$' | tail -1 | tr -s ' ' | cut -d ' ' -f 4`"
 if [ -z "${LASTSLICE}" ] ; then
   LASTSLICE="1"
 else
   LASTSLICE="`expr $LASTSLICE + 1`"
 fi
 
-if [ ${LASTSLICE} -gt "4" ] ; then
-  echo "Error: FreeBSD MBR setups can only have a max of 4 slices"
-  exit 1
-fi
-
-
 SLICENUM="${LASTSLICE}"
 
-# Lets get the starting block
-if [ "${SLICENUM}" = "1" ] ; then
-  STARTBLOCK="63"
-else
-  # Lets figure out where the prior slice ends
-  checkslice="`expr ${SLICENUM} - 1`"
-
-  # Get starting block of this slice
-  fdisk -s /dev/${DISK} | grep -v "${DISK}:" | grep "${checkslice}:" | tr -s " " >${TMPDIR}/pfdisk
-  pstartblock="`cat ${TMPDIR}/pfdisk | cut -d ' ' -f 3`"
-  psize="`cat ${TMPDIR}/pfdisk | cut -d ' ' -f 4`"
-  STARTBLOCK="`expr ${pstartblock} + ${psize}`"
+# Set a 4k Aligned start block if none specified
+if [ "${SLICENUM}" = "1" -a -z "$STARTBLOCK" ] ; then
+  STARTBLOCK="2016"
 fi
 
 
-# If this is an empty disk, see if we need to create a new MBR scheme for it
+# If this is an empty disk, see if we need to create a new scheme for it
 gpart show ${DISK} >/dev/null 2>/dev/null
 if [ "$?" != "0" -a "${SLICENUM}" = "1" ] ; then
- gpart create -s mbr ${DISK}
+ gpart create -s ${TYPE} ${DISK}
+fi
+
+# If we have a starting block, use it
+if [ -z "$STARTBLOCK" ] ; then
+  sBLOCK="-b $STARTBLOCK"
 fi
 
-gpart add -b ${STARTBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK}
+gpart add ${sBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK}
 exit "$?"
diff -ruN usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
--- usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	2011-01-27 10:26:03.709380520 -0500
+++ usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	2011-01-27 11:49:10.371138733 -0500
@@ -125,7 +125,7 @@
   ;;
 
   # The user is wanting to create a new partition
-  create-part) ${PARTMANAGERDIR}/create-part.sh "${2}" "${3}"
+  create-part) ${PARTMANAGERDIR}/create-part.sh "${2}" "${3}" "${4}" "${5}"
   ;;
 
   # The user is wanting to delete an existing partition


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jpaetzel 
Responsible-Changed-By: jpaetzel 
Responsible-Changed-When: Fri Feb 11 15:43:44 UTC 2011 
Responsible-Changed-Why:  
I'll take it. 

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

From: Kris Moore <kris@pcbsd.org>
To: bug-followup@FreeBSD.org, kmoore@FreeBSD.org
Cc:  
Subject: Re: bin/154684: bin: usr.sbin/pc-sysinstall - Improvements for pc-sysinstall
 to create GPT and other types of partitions
Date: Mon, 14 Feb 2011 15:29:29 -0500

 This is a multi-part message in MIME format.
 --------------030106040808000900020108
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 
 Attached is a cleaned up version of the above patch, with sanity
 checking for the part scheme, and a simplified command to grab the
 last slice.
 
 - -- 
 Kris Moore
 PC-BSD Software
 iXsystems
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.16 (FreeBSD)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iQEcBAEBAgAGBQJNWZCpAAoJEDv6T4U6J2HSb60H/iEcyrWDmrFCuaiNeglY6+N4
 eSMJCicSOq3ixkLtAqcu1i1EUOQN1+2MkqrrHn48ChjaYQXROCqmcLORspbaMqSl
 H5JDRN0FjesYR75nbWbpteCxtsI6+PjUNLmBvLFKWt0dBNV24N28xtDxxLaOSv9w
 N8I2EsrolgYnan369TUI7ORnmNSQXRWgbcJIaQJtz6pEQcwciXQMBAvFBLSbrtXX
 sQOO4LBKMMtoLZjJzlTtk3wRYoXCIG9xq3WVL2bl6LAhD05KKmXhA6NNFWMweHkJ
 E/oKelpVlPxw/ik9FBTEnMzOX1Wyrspy4wVERKVR+lGQ9vGzc4K3wkOF32OT37A=
 =QBlq
 -----END PGP SIGNATURE-----
 
 
 --------------030106040808000900020108
 Content-Type: text/plain;
  name="pc-sysinstall-createpart-patch.txt"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="pc-sysinstall-createpart-patch.txt"
 
 diff -ruN usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh
 --- usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	2011-02-14 15:06:34.234336063 -0500
 +++ usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	2011-02-14 15:25:07.041306325 -0500
 @@ -25,7 +25,7 @@
  #
  # $FreeBSD$
  
 -# Query a disk for partitions and display them
 +# Create partitions on a target disk
  #############################
  
  . ${PROGDIR}/backend/functions.sh
 @@ -47,46 +47,52 @@
  
  DISK="${1}"
  MB="${2}"
 +TYPE="${3}"
 +STARTBLOCK="${4}"
  
  TOTALBLOCKS="`expr $MB \* 2048`"
  
 +# If no TYPE specified, default to MBR
 +if [ -z "$TYPE" ] ; then TYPE="mbr" ; fi
  
 -# Lets figure out what number this slice will be
 -LASTSLICE="`fdisk -s /dev/${DISK} 2>/dev/null | grep -v ${DISK} | grep ':' | tail -n 1 | cut -d ':' -f 1 | tr -s '\t' ' ' | tr -d ' '`"
 +# Sanity check the gpart type
 +case $TYPE in
 +	apm|APM) ;;
 +	bsd|BSD) ;;
 +	ebr|EBR) ;;
 +      pc98|pc98) ;;
 +	gpt|GPT) ;;
 +	mbr|MBR) ;;
 +    vtoc8|VTOC8) ;;
 +	*) echo "Error: Unknown gpart type: $TYPE" ; exit 1 ;;
 +esac
 +
 +# Lets figure out what number this partition will be
 +LASTSLICE="`gpart show $DISK | grep -v -e $DISK -e '\- free \-' -e '^$' | awk 'END {print $3}'`"
  if [ -z "${LASTSLICE}" ] ; then
    LASTSLICE="1"
  else
    LASTSLICE="`expr $LASTSLICE + 1`"
  fi
  
 -if [ ${LASTSLICE} -gt "4" ] ; then
 -  echo "Error: FreeBSD MBR setups can only have a max of 4 slices"
 -  exit 1
 -fi
 -
 -
  SLICENUM="${LASTSLICE}"
  
 -# Lets get the starting block
 -if [ "${SLICENUM}" = "1" ] ; then
 -  STARTBLOCK="63"
 -else
 -  # Lets figure out where the prior slice ends
 -  checkslice="`expr ${SLICENUM} - 1`"
 -
 -  # Get starting block of this slice
 -  fdisk -s /dev/${DISK} | grep -v "${DISK}:" | grep "${checkslice}:" | tr -s " " >${TMPDIR}/pfdisk
 -  pstartblock="`cat ${TMPDIR}/pfdisk | cut -d ' ' -f 3`"
 -  psize="`cat ${TMPDIR}/pfdisk | cut -d ' ' -f 4`"
 -  STARTBLOCK="`expr ${pstartblock} + ${psize}`"
 +# Set a 4k Aligned start block if none specified
 +if [ "${SLICENUM}" = "1" -a -z "$STARTBLOCK" ] ; then
 +  STARTBLOCK="2016"
  fi
  
  
 -# If this is an empty disk, see if we need to create a new MBR scheme for it
 +# If this is an empty disk, see if we need to create a new scheme for it
  gpart show ${DISK} >/dev/null 2>/dev/null
  if [ "$?" != "0" -a "${SLICENUM}" = "1" ] ; then
 - gpart create -s mbr ${DISK}
 + gpart create -s ${TYPE} ${DISK}
 +fi
 +
 +# If we have a starting block, use it
 +if [ -z "$STARTBLOCK" ] ; then
 +  sBLOCK="-b $STARTBLOCK"
  fi
  
 -gpart add -b ${STARTBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK}
 +gpart add ${sBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK}
  exit "$?"
 diff -ruN usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
 --- usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	2011-02-14 15:06:34.272349060 -0500
 +++ usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	2011-02-14 15:08:49.105694915 -0500
 @@ -125,7 +125,7 @@
    ;;
  
    # The user is wanting to create a new partition
 -  create-part) ${PARTMANAGERDIR}/create-part.sh "${2}" "${3}"
 +  create-part) ${PARTMANAGERDIR}/create-part.sh "${2}" "${3}" "${4}" "${5}"
    ;;
  
    # The user is wanting to delete an existing partition
 
 --------------030106040808000900020108--
State-Changed-From-To: open->closed 
State-Changed-By: jpaetzel 
State-Changed-When: Fri Feb 18 15:00:52 UTC 2011 
State-Changed-Why:  
Committed, thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/154684: commit references a PR
Date: Fri, 18 Feb 2011 15:00:33 +0000 (UTC)

 Author: jpaetzel
 Date: Fri Feb 18 15:00:25 2011
 New Revision: 218800
 URL: http://svn.freebsd.org/changeset/base/218800
 
 Log:
   Add support to pc-sysinstall's create-part feature, to create non MBR type partitions,
   such as GPT and others.
   
   PR:	bin/154684
   Submitted by:	kmoore
   Approved by:	kib (mentor, implicit)
 
 Modified:
   head/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh
   head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
 
 Modified: head/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	Fri Feb 18 14:54:34 2011	(r218799)
 +++ head/usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh	Fri Feb 18 15:00:25 2011	(r218800)
 @@ -25,7 +25,7 @@
  #
  # $FreeBSD$
  
 -# Query a disk for partitions and display them
 +# Create partitions on a target disk
  #############################
  
  . ${PROGDIR}/backend/functions.sh
 @@ -47,46 +47,52 @@ fi
  
  DISK="${1}"
  MB="${2}"
 +TYPE="${3}"
 +STARTBLOCK="${4}"
  
  TOTALBLOCKS="`expr $MB \* 2048`"
  
 +# If no TYPE specified, default to MBR
 +if [ -z "$TYPE" ] ; then TYPE="mbr" ; fi
  
 -# Lets figure out what number this slice will be
 -LASTSLICE="`fdisk -s /dev/${DISK} 2>/dev/null | grep -v ${DISK} | grep ':' | tail -n 1 | cut -d ':' -f 1 | tr -s '\t' ' ' | tr -d ' '`"
 +# Sanity check the gpart type
 +case $TYPE in
 +	apm|APM) ;;
 +	bsd|BSD) ;;
 +	ebr|EBR) ;;
 +      pc98|pc98) ;;
 +	gpt|GPT) ;;
 +	mbr|MBR) ;;
 +    vtoc8|VTOC8) ;;
 +	*) echo "Error: Unknown gpart type: $TYPE" ; exit 1 ;;
 +esac
 +
 +# Lets figure out what number this partition will be
 +LASTSLICE="`gpart show $DISK | grep -v -e $DISK -e '\- free \-' -e '^$' | awk 'END {print $3}'`"
  if [ -z "${LASTSLICE}" ] ; then
    LASTSLICE="1"
  else
    LASTSLICE="`expr $LASTSLICE + 1`"
  fi
  
 -if [ ${LASTSLICE} -gt "4" ] ; then
 -  echo "Error: FreeBSD MBR setups can only have a max of 4 slices"
 -  exit 1
 -fi
 -
 -
  SLICENUM="${LASTSLICE}"
  
 -# Lets get the starting block
 -if [ "${SLICENUM}" = "1" ] ; then
 -  STARTBLOCK="63"
 -else
 -  # Lets figure out where the prior slice ends
 -  checkslice="`expr ${SLICENUM} - 1`"
 -
 -  # Get starting block of this slice
 -  fdisk -s /dev/${DISK} | grep -v "${DISK}:" | grep "${checkslice}:" | tr -s " " >${TMPDIR}/pfdisk
 -  pstartblock="`cat ${TMPDIR}/pfdisk | cut -d ' ' -f 3`"
 -  psize="`cat ${TMPDIR}/pfdisk | cut -d ' ' -f 4`"
 -  STARTBLOCK="`expr ${pstartblock} + ${psize}`"
 +# Set a 4k Aligned start block if none specified
 +if [ "${SLICENUM}" = "1" -a -z "$STARTBLOCK" ] ; then
 +  STARTBLOCK="2016"
  fi
  
  
 -# If this is an empty disk, see if we need to create a new MBR scheme for it
 +# If this is an empty disk, see if we need to create a new scheme for it
  gpart show ${DISK} >/dev/null 2>/dev/null
  if [ "$?" != "0" -a "${SLICENUM}" = "1" ] ; then
 - gpart create -s mbr ${DISK}
 + gpart create -s ${TYPE} ${DISK}
 +fi
 +
 +# If we have a starting block, use it
 +if [ -z "$STARTBLOCK" ] ; then
 +  sBLOCK="-b $STARTBLOCK"
  fi
  
 -gpart add -b ${STARTBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK}
 +gpart add ${sBLOCK} -s ${TOTALBLOCKS} -t freebsd -i ${SLICENUM} ${DISK}
  exit "$?"
 
 Modified: head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	Fri Feb 18 14:54:34 2011	(r218799)
 +++ head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	Fri Feb 18 15:00:25 2011	(r218800)
 @@ -125,7 +125,7 @@ case $1 in
    ;;
  
    # The user is wanting to create a new partition
 -  create-part) ${PARTMANAGERDIR}/create-part.sh "${2}" "${3}"
 +  create-part) ${PARTMANAGERDIR}/create-part.sh "${2}" "${3}" "${4}" "${5}"
    ;;
  
    # The user is wanting to delete an existing partition
 _______________________________________________
 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:
