[PC-BSD Commits] r3034 - in pcbsd: branches/7.0/installcd-overlay/usr/local/pcbsd/scripts trunk/installcd-overlay/usr/local/pcbsd/scripts

svn at pcbsd.org svn at pcbsd.org
Wed Dec 3 11:51:35 PST 2008


Author: kris
Date: 2008-12-03 11:51:35 -0800 (Wed, 03 Dec 2008)
New Revision: 3034

Modified:
   pcbsd/branches/7.0/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh
   pcbsd/trunk/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh
Log:

Fixed a major installation bug, when trying to install PC-BSD to free space, and not an existing primary partition (slice). 

Now the install script, will detect if the slice is non-existant, and figure out the starting block and size of the new slice, and set it up with fdisk properly




Modified: pcbsd/branches/7.0/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh
===================================================================
--- pcbsd/branches/7.0/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh	2008-12-03 14:40:52 UTC (rev 3033)
+++ pcbsd/branches/7.0/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh	2008-12-03 19:51:35 UTC (rev 3034)
@@ -39,16 +39,76 @@
   swapoff ${slice}b
 fi
 
-# Get the fdisk -s output of this device
-fdisk -s /dev/${device} | grep -v "${device}:" | grep "${slicenum}:" | tr -s " " > /tmp/fdiskblk
-startblock="`cat /tmp/fdiskblk | cut -d ' ' -f 3`"
-endblock="`cat /tmp/fdiskblk | cut -d ' ' -f 4`"
+# Lets check if we are using a new slice, which needs to be initialized
+fdisk -s /dev/${device} | grep -v "${device}:" | grep "${slicenum}:" >/dev/null 2>/dev/null
+if [ "$?" != "0" ]
+then
+  # This slice isn't on the disk, lets create it now
 
-# Create the new fdiskconfig file now to set this partition to type 165
-echo "p	${slicenum}	165	${startblock}	${endblock}" > /tmp/fdiskconfig
+  # Lets get the starting block first
+  if [ "${slicenum}" = "1" ]
+  then
+     startblock="1"
+  else 
+     # Lets figure out where the prior slice ends
+     checkslice="`expr ${slicenum} - 1`"
+     
+     # Get starting block of this slice
+     fdisk -s /dev/${device} | grep -v "${device}:" | grep "${checkslice}:" | tr -s " " >/tmp/pfdisk
+     pstartblock="`cat /tmp/pfdisk | cut -d ' ' -f 3`"
+     psize="`cat /tmp/pfdisk | cut -d ' ' -f 4`"
+     startblock="`expr ${pstartblock} + ${psize}`"   
+  fi
 
+  # Now lets figure out the ending block for this slice
+  nextslice="`expr ${slicenum} + 1`"
+
+  # Check if we have a slice after where our free space one will go
+  fdisk -s /dev/${device} | grep -v "${device}:" | grep "${nextslice}:" >/dev/null 2>/dev/null
+  if [ "$?" != "0" ]
+  then
+    # No slice after the new slice, lets figure out the free space remaining and use it
+    
+    # Get the cyl of this disk
+    cyl=`fdisk -s /dev/${device} | grep "${device}:" | tr -s ' ' | cut -d ' ' -f 2`
+ 
+    # Get the heads of this disk 
+    head=`fdisk -s /dev/${device} | grep "${device}:" | tr -s ' ' | cut -d ' ' -f 4`
+
+    # Get the tracks/sectors of this disk
+    sec=`fdisk -s /dev/${device} | grep "${device}:" | tr -s ' ' | cut -d ' ' -f 6`
+
+    # 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}`"
+
+  else
+    # Figure out the start block of the next slice, and subtract one to get our new ending block
+    fdisk -s /dev/${device} | grep -v "${device}:" | grep "${nextslice}:" | tr -s " " >/tmp/nfdisk
+    nstartblock="`cat /tmp/nfdisk | cut -d ' ' -f 3`"
+    sizeblock="`expr ${nstartblock} - ${startblock}`"
+  fi
+  
+  # Create the new fdiskconfig file now to set this partition to type 165
+  echo "p	${slicenum}	165	${startblock}	${sizeblock}" > /tmp/fdiskconfig
+
+else
+  # Slice already exists, lets mark it as 165 for FreeBSD
+  # Get the fdisk -s output of this device
+  fdisk -s /dev/${device} | grep -v "${device}:" | grep "${slicenum}:" | tr -s " " > /tmp/fdiskblk
+  startblock="`cat /tmp/fdiskblk | cut -d ' ' -f 3`"
+  sizeblock="`cat /tmp/fdiskblk | cut -d ' ' -f 4`"
+
+  # Create the new fdiskconfig file now to set this partition to type 165
+  echo "p	${slicenum}	165	${startblock}	${sizeblock}" > /tmp/fdiskconfig
+fi
+
 sleep 4
 
+
 # Install new partition setup
 fdisk -f /tmp/fdiskconfig /dev/${device}
 

Modified: pcbsd/trunk/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh
===================================================================
--- pcbsd/trunk/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh	2008-12-03 14:40:52 UTC (rev 3033)
+++ pcbsd/trunk/installcd-overlay/usr/local/pcbsd/scripts/PCBSD.FormatPartition.sh	2008-12-03 19:51:35 UTC (rev 3034)
@@ -39,16 +39,76 @@
   swapoff ${slice}b
 fi
 
-# Get the fdisk -s output of this device
-fdisk -s /dev/${device} | grep -v "${device}:" | grep "${slicenum}:" | tr -s " " > /tmp/fdiskblk
-startblock="`cat /tmp/fdiskblk | cut -d ' ' -f 3`"
-endblock="`cat /tmp/fdiskblk | cut -d ' ' -f 4`"
+# Lets check if we are using a new slice, which needs to be initialized
+fdisk -s /dev/${device} | grep -v "${device}:" | grep "${slicenum}:" >/dev/null 2>/dev/null
+if [ "$?" != "0" ]
+then
+  # This slice isn't on the disk, lets create it now
 
-# Create the new fdiskconfig file now to set this partition to type 165
-echo "p	${slicenum}	165	${startblock}	${endblock}" > /tmp/fdiskconfig
+  # Lets get the starting block first
+  if [ "${slicenum}" = "1" ]
+  then
+     startblock="1"
+  else 
+     # Lets figure out where the prior slice ends
+     checkslice="`expr ${slicenum} - 1`"
+     
+     # Get starting block of this slice
+     fdisk -s /dev/${device} | grep -v "${device}:" | grep "${checkslice}:" | tr -s " " >/tmp/pfdisk
+     pstartblock="`cat /tmp/pfdisk | cut -d ' ' -f 3`"
+     psize="`cat /tmp/pfdisk | cut -d ' ' -f 4`"
+     startblock="`expr ${pstartblock} + ${psize}`"   
+  fi
 
+  # Now lets figure out the ending block for this slice
+  nextslice="`expr ${slicenum} + 1`"
+
+  # Check if we have a slice after where our free space one will go
+  fdisk -s /dev/${device} | grep -v "${device}:" | grep "${nextslice}:" >/dev/null 2>/dev/null
+  if [ "$?" != "0" ]
+  then
+    # No slice after the new slice, lets figure out the free space remaining and use it
+    
+    # Get the cyl of this disk
+    cyl=`fdisk -s /dev/${device} | grep "${device}:" | tr -s ' ' | cut -d ' ' -f 2`
+ 
+    # Get the heads of this disk 
+    head=`fdisk -s /dev/${device} | grep "${device}:" | tr -s ' ' | cut -d ' ' -f 4`
+
+    # Get the tracks/sectors of this disk
+    sec=`fdisk -s /dev/${device} | grep "${device}:" | tr -s ' ' | cut -d ' ' -f 6`
+
+    # 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}`"
+
+  else
+    # Figure out the start block of the next slice, and subtract one to get our new ending block
+    fdisk -s /dev/${device} | grep -v "${device}:" | grep "${nextslice}:" | tr -s " " >/tmp/nfdisk
+    nstartblock="`cat /tmp/nfdisk | cut -d ' ' -f 3`"
+    sizeblock="`expr ${nstartblock} - ${startblock}`"
+  fi
+  
+  # Create the new fdiskconfig file now to set this partition to type 165
+  echo "p	${slicenum}	165	${startblock}	${sizeblock}" > /tmp/fdiskconfig
+
+else
+  # Slice already exists, lets mark it as 165 for FreeBSD
+  # Get the fdisk -s output of this device
+  fdisk -s /dev/${device} | grep -v "${device}:" | grep "${slicenum}:" | tr -s " " > /tmp/fdiskblk
+  startblock="`cat /tmp/fdiskblk | cut -d ' ' -f 3`"
+  sizeblock="`cat /tmp/fdiskblk | cut -d ' ' -f 4`"
+
+  # Create the new fdiskconfig file now to set this partition to type 165
+  echo "p	${slicenum}	165	${startblock}	${sizeblock}" > /tmp/fdiskconfig
+fi
+
 sleep 4
 
+
 # Install new partition setup
 fdisk -f /tmp/fdiskconfig /dev/${device}
 



More information about the Commits mailing list