Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Mar 2016 09:35:29 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r297345 - stable/10/usr.sbin/pc-sysinstall/backend
Message-ID:  <201603280935.u2S9ZTll005407@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Mar 28 09:35:29 2016
New Revision: 297345
URL: https://svnweb.freebsd.org/changeset/base/297345

Log:
  MFC r296655, r296673, r296776: Unify and improve metadata wiping.

Modified:
  stable/10/usr.sbin/pc-sysinstall/backend/functions-disk.sh
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/pc-sysinstall/backend/functions-disk.sh
==============================================================================
--- stable/10/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Mon Mar 28 09:34:14 2016	(r297344)
+++ stable/10/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Mon Mar 28 09:35:29 2016	(r297345)
@@ -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_nohalt "dd if=/dev/zero of=${1} bs=1m oseek=$((SIZE-4))"
+  else
+    rc_nohalt "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?201603280935.u2S9ZTll005407>