Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Mar 2016 14:14:15 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r296655 - head/usr.sbin/pc-sysinstall/backend
Message-ID:  <201603111414.u2BEEFMs036615@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Fri Mar 11 14:14:15 2016
New Revision: 296655
URL: https://svnweb.freebsd.org/changeset/base/296655

Log:
  Unify and improve metadata wiping.
  
  MFC after:	2 weeks

Modified:
  head/usr.sbin/pc-sysinstall/backend/functions-disk.sh

Modified: head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Fri Mar 11 13:06:11 2016	(r296654)
+++ head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Fri Mar 11 14:14:15 2016	(r296655)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -x
 #-
 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
 #
@@ -257,12 +257,7 @@ delete_all_gpart()
   # 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=${DISK} count=3000"
-
+  wipe_metadata "${DISK}"
 };
 
 # Function to export all zpools before starting an install
@@ -292,7 +287,7 @@ stop_all_gmirror()
     then
       echo_log "Stopping mirror $gprov $DISK"
       rc_nohalt "gmirror remove $gprov $DISK"
-      rc_nohalt "dd if=/dev/zero of=/dev/${DISK} count=4096"
+      wipe_metadata "${DISK}"
     fi
   done
 };
@@ -611,12 +606,17 @@ stop_gjournal()
 } ;
 
 
-# Function to wipe the potential backup gpt table from a disk
-clear_backup_gpt_table()
+# Function to wipe the potential metadata from a disk
+wipe_metadata()
 {
-  echo_log "Clearing gpt backup table location on disk"
-  rc_nohalt "dd if=/dev/zero of=${1} bs=1m count=1"
-  rc_nohalt "dd if=/dev/zero of=${1} bs=1m oseek=`diskinfo ${1} | awk '{print int($3 / (1024*1024)) - 4;}'`"
+  echo_log "Wiping possible metadata on ${1}"
+  local SIZE="`diskinfo ${1} | awk '{print int($3/(1024*1024)) }'`"
+  if [ "$SIZE" -gt "5" ]  ; then
+    rc_halt "dd if=/dev/zero of=${1} bs=1m count=1"
+    rc_halt "dd if=/dev/zero of=${1} bs=1m oseek=$((SIZE-4))"
+  else
+    rc_halt "dd if=/dev/zero of=${1} bs=128k"
+  fi
 } ;
 
 # Function which runs gpart and creates a single large APM partition scheme
@@ -696,8 +696,7 @@ init_mbr_full_disk()
   rc_halt "gpart add -a 4k -t freebsd -i 1 ${_intDISK}"
   sleep 2
   
-  echo_log "Cleaning up ${_intDISK}s1"
-  rc_halt "dd if=/dev/zero of=${_intDISK}s1 count=1024"
+  wipe_metadata "${_intDISK}s1"
   
   # Make the partition active
   rc_halt "gpart set -a active -i 1 ${_intDISK}"
@@ -770,9 +769,7 @@ run_gpart_gpt_part()
   rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}"
   sleep 2
 
-  # Clean up old partition
-  echo_log "Cleaning up $slice"
-  rc_halt "dd if=/dev/zero of=${DISK}p${slicenum} count=1024"
+  wipe_metadata "${slice}"
 
   sleep 4
 
@@ -830,9 +827,7 @@ run_gpart_slice()
   rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}"
   sleep 2
 
-  # Clean up old partition
-  echo_log "Cleaning up $slice"
-  rc_halt "dd if=/dev/zero of=${DISK}s${slicenum} count=1024"
+  wipe_metadata "${slice}"
 
   sleep 1
 
@@ -883,9 +878,8 @@ run_gpart_free()
   echo_log "Running gpart on ${DISK}"
   rc_halt "gpart add -a 4k -t freebsd -i ${slicenum} ${DISK}"
   sleep 2
-  
-  echo_log "Cleaning up $slice"
-  rc_halt "dd if=/dev/zero of=${slice} count=1024"
+
+  wipe_metadata "${slice}"
 
   sleep 1
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603111414.u2BEEFMs036615>