3 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # Functions related to disk operations using gpart
30 # See if device is a full disk or partition/slice
33 for _dsk in `sysctl -n kern.disks`
35 [ "$_dsk" = "${1}" ] && return 0
41 # Get a MBR partitions sysid
42 get_partition_sysid_mbr()
46 PARTNUM=`echo ${2} | sed "s|${DISK}s||g"`
47 fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
50 echo "$i" | grep -q "The data for partition" 2>/dev/null
51 if [ $? -eq 0 ] ; then
53 PART="`echo ${i} | cut -d ' ' -f 5`"
54 if [ "$PART" = "$PARTNUM" ] ; then
59 # In the partition section
60 if [ "$INPART" = "1" ] ; then
61 echo "$i" | grep -q "^sysid" 2>/dev/null
62 if [ $? -eq 0 ] ; then
63 SYSID="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2`"
69 done < ${TMPDIR}/disk-${DISK}
70 rm ${TMPDIR}/disk-${DISK}
75 # Get the partitions MBR label
76 get_partition_label_mbr()
80 PARTNUM=`echo ${2} | sed "s|${DISK}s||g"`
81 fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
84 echo "$i" | grep -q "The data for partition" 2>/dev/null
85 if [ $? -eq 0 ] ; then
87 PART="`echo ${i} | cut -d ' ' -f 5`"
88 if [ "$PART" = "$PARTNUM" ] ; then
93 # In the partition section
94 if [ "$INPART" = "1" ] ; then
95 echo "$i" | grep -q "^sysid" 2>/dev/null
96 if [ $? -eq 0 ] ; then
97 LABEL="`echo ${i} | tr -s '\t' ' ' | cut -d ',' -f 2-10`"
103 done < ${TMPDIR}/disk-${DISK}
104 rm ${TMPDIR}/disk-${DISK}
106 export VAL="${LABEL}"
109 # Get a GPT partitions label
110 get_partition_label_gpt()
113 PARTNUM=`echo ${2} | sed "s|${DISK}p||g"`
115 gpart show ${DISK} >${TMPDIR}/disk-${DISK}
118 SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
119 if [ "${SLICE}" = "${PARTNUM}" ] ; then
120 LABEL="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4`"
123 done <${TMPDIR}/disk-${DISK}
124 rm ${TMPDIR}/disk-${DISK}
126 export VAL="${LABEL}"
129 # Get a partitions startblock
130 get_partition_startblock()
133 PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"`
135 gpart show ${DISK} >${TMPDIR}/disk-${DISK}
138 SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
139 if [ "$SLICE" = "${PARTNUM}" ] ; then
140 SB="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 1`"
143 done <${TMPDIR}/disk-${DISK}
144 rm ${TMPDIR}/disk-${DISK}
149 # Get a partitions blocksize
150 get_partition_blocksize()
153 PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"`
155 gpart show ${DISK} >${TMPDIR}/disk-${DISK}
158 SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
159 if [ "$SLICE" = "${PARTNUM}" ] ; then
160 BS="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 2`"
163 done <${TMPDIR}/disk-${DISK}
164 rm ${TMPDIR}/disk-${DISK}
169 # Function which returns the partitions on a target disk
170 get_disk_partitions()
172 gpart show ${1} >/dev/null 2>/dev/null
173 if [ $? -ne 0 ] ; then
178 type=`gpart show ${1} | awk '/^=>/ { printf("%s",$5); }'`
180 SLICES="`gpart show ${1} | grep -v ${1} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4 | sed '/^$/d'`"
184 MBR) name="${1}s${i}" ;;
185 GPT) name="${1}p${i}";;
186 *) name="${1}s${i}";;
188 if [ -z "${RSLICES}" ]
192 RSLICES="${RSLICES} ${name}"
196 export VAL="${RSLICES}"
199 # Function which returns a target disks cylinders
202 cyl=`diskinfo -v ${1} | grep "# Cylinders" | tr -s ' ' | cut -f 2`
206 # Function which returns a target disks sectors
209 sec=`diskinfo -v ${1} | grep "# Sectors" | tr -s ' ' | cut -f 2`
213 # Function which returns a target disks heads
216 head=`diskinfo -v ${1} | grep "# Heads" | tr -s ' ' | cut -f 2`
220 # Function which returns a target disks mediasize in sectors
223 mediasize=`diskinfo -v ${1} | grep "# mediasize in sectors" | tr -s ' ' | cut -f 2`
224 export VAL="${mediasize}"
227 # Function to delete all gparts before starting an install
230 echo_log "Deleting all gparts"
233 # Check for any swaps to stop
234 for i in `swapctl -l | grep "$DISK" | awk '{print $1}'`
236 swapoff ${i} >/dev/null 2>/dev/null
239 # Delete the gparts now
240 for i in `gpart show ${DISK} 2>/dev/null | tr -s ' ' | cut -d ' ' -f 4`
242 if [ "/dev/${i}" != "${DISK}" -a "${i}" != "-" ] ; then
243 rc_nohalt "gpart delete -i ${i} ${DISK}"
247 # Destroy the disk geom
248 rc_nohalt "gpart destroy ${DISK}"
250 # Make sure we clear any hidden gpt tables
251 clear_backup_gpt_table "${DISK}"
253 # Wipe out front of disk
254 rc_nohalt "dd if=/dev/zero of=${DISK} count=3000"
258 # Function to export all zpools before starting an install
261 local DISK="`echo ${1} | sed 's|/dev/||g'`"
263 # Export any zpools using this device so we can overwrite
264 for i in `zpool list -H -o name`
266 ztst=`zpool status ${i} | grep "ONLINE" | awk '{print $1}' | grep -q ${DISK}`
267 if [ "$ztst" = "$DISK" ] ; then
273 # Function which stops all gmirrors before doing any disk manipulation
276 local DISK="`echo ${1} | sed 's|/dev/||g'`"
277 GPROV="`gmirror list | grep ". Name: mirror/" | cut -d '/' -f 2`"
280 gmirror list | grep -q "Name: ${DISK}" 2>/dev/null
283 echo_log "Stopping mirror $gprov $DISK"
284 rc_nohalt "gmirror remove $gprov $DISK"
285 rc_nohalt "dd if=/dev/zero of=/dev/${DISK} count=4096"
290 # Make sure we don't have any geli providers active on this disk
293 local _geld="`echo ${1} | sed 's|/dev/||g'`"
296 for i in `ls ${_geld}*`
298 echo $i | grep -q '.eli' 2>/dev/null
301 echo_log "Detaching GELI on ${i}"
302 rc_halt "geli detach ${i}"
308 # Function which reads in the disk slice config, and performs it
312 # Cleanup any slice / mirror dirs
313 rm -rf ${SLICECFGDIR} >/dev/null 2>/dev/null
315 rm -rf ${MIRRORCFGDIR} >/dev/null 2>/dev/null
316 mkdir ${MIRRORCFGDIR}
318 # Start with disk0 and gm0
322 # We are ready to start setting up the disks, lets read the config and do the actions
325 echo $line | grep -q "^disk${disknum}=" 2>/dev/null
329 # Found a disk= entry, lets get the disk we are working on
330 get_value_from_string "${line}"
331 strip_white_space "$VAL"
334 echo "${DISK}" | grep -q '^/dev/'
335 if [ $? -ne 0 ] ; then DISK="/dev/$DISK" ; fi
337 # Before we go further, lets confirm this disk really exists
338 if [ ! -e "${DISK}" ] ; then
339 exit_err "ERROR: The disk ${DISK} does not exist!"
342 # Make sure we stop any gmirrors on this disk
343 stop_all_gmirror ${DISK}
345 # Make sure we stop any geli stuff on this disk
346 stop_all_geli ${DISK}
348 # Make sure we don't have any zpools loaded
353 # Lets look if this device will be mirrored on another disk
354 echo $line | grep -q "^mirror=" 2>/dev/null
358 # Found a disk= entry, lets get the disk we are working on
359 get_value_from_string "${line}"
360 strip_white_space "$VAL"
362 echo "${MIRRORDISK}" | grep -q '^/dev/'
363 if [ $? -ne 0 ] ; then MIRRORDISK="/dev/$MIRRORDISK" ; fi
365 # Before we go further, lets confirm this disk really exists
366 if [ ! -e "${MIRRORDISK}" ]
368 exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!"
371 # Make sure we stop any gmirrors on this mirror disk
372 stop_all_gmirror ${MIRRORDISK}
374 # Make sure we stop any geli stuff on this mirror disk
375 stop_all_geli ${MIRRORDISK}
377 # Make sure we don't have any zpools mirror loaded
378 stop_all_zfs ${MIRRORDISK}
382 # Lets see if we have been given a mirror balance choice
383 echo $line | grep -q "^mirrorbal=" 2>/dev/null
387 # Found a disk= entry, lets get the disk we are working on
388 get_value_from_string "${line}"
389 strip_white_space "$VAL"
393 echo $line | grep -q "^partition=" 2>/dev/null
396 # Found a partition= entry, lets read / set it
397 get_value_from_string "${line}"
398 strip_white_space "$VAL"
399 PTYPE=`echo $VAL|tr A-Z a-z`
401 # We are using free space, figure out the slice number
402 if [ "${PTYPE}" = "free" ]
404 # Lets figure out what number this slice will be
405 LASTSLICE="`gpart show ${DISK} \
413 if [ -z "${LASTSLICE}" ]
417 LASTSLICE=$((LASTSLICE+1))
420 if [ $LASTSLICE -gt 4 ]
422 exit_err "ERROR: BSD only supports primary partitions, and there are none availble on $DISK"
428 # Check if we have an image file defined
429 echo $line | grep -q "^image=" 2>/dev/null
430 if [ $? -eq 0 ] ; then
431 # Found an image= entry, lets read / set it
432 get_value_from_string "${line}"
433 strip_white_space "$VAL"
435 if [ ! -f "$IMAGE" ] ; then
436 exit_err "$IMAGE file does not exist"
440 # Check if we have a partscheme specified
441 echo $line | grep -q "^partscheme=" 2>/dev/null
442 if [ $? -eq 0 ] ; then
443 # Found a partscheme= entry, lets read / set it
444 get_value_from_string "${line}"
445 strip_white_space "$VAL"
447 if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
448 exit_err "Unknown partition scheme: $PSCHEME"
452 echo $line | grep -q "^bootManager=" 2>/dev/null
455 # Found a bootManager= entry, lets read /set it
456 get_value_from_string "${line}"
457 strip_white_space "$VAL"
461 echo $line | grep -q "^commitDiskPart" 2>/dev/null
464 # Found our flag to commit this disk setup / lets do sanity check and do it
465 if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
467 # Make sure we are only installing ppc to full disk
468 if [ `uname -m` = "powerpc" -o `uname -m` = "powerpc64" ]; then
469 if [ "$PTYPE" != "all" ] ; then
470 exit_err "powerpc can only be installed to a full disk"
476 # If we have a gmirror, lets set it up
477 if [ -n "$MIRRORDISK" ]; then
478 # Default to round-robin if the user didn't specify
479 if [ -z "$MIRRORBAL" ]; then MIRRORBAL="round-robin" ; fi
481 _mFile=`echo $DISK | sed 's|/|%|g'`
482 echo "$MIRRORDISK:$MIRRORBAL:gm${gmnum}" >${MIRRORCFGDIR}/$_mFile
483 init_gmirror "$gmnum" "$MIRRORBAL" "$DISK" "$MIRRORDISK"
485 # Reset DISK to the gmirror device
486 DISK="/dev/mirror/gm${gmnum}"
490 if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
497 if [ `uname -m` = "powerpc" -o `uname -m` = "powerpc64" ]
503 run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}"
507 tmpSLICE="${DISK}${PTYPE}"
508 # Get the number of the slice we are working on
509 s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`"
510 run_gpart_slice "${DISK}" "${BMANAGER}" "${s}"
513 p1|p2|p3|p4|p5|p6|p7|p8|p9|p10|p11|p12|p13|p14|p15|p16|p17|p18|p19|p20)
514 tmpSLICE="${DISK}${PTYPE}"
515 # Get the number of the gpt partition we are working on
516 s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`"
517 run_gpart_gpt_part "${DISK}" "${BMANAGER}" "${s}"
521 tmpSLICE="${DISK}s${LASTSLICE}"
522 run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}"
528 exit_err "ERROR: partition type image specified with no image!"
532 *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;;
540 if [ -n "${tmpSLICE}" ]
547 write_image "${IMAGE}" "${DEST}"
548 check_disk_layout "${DEST}"
551 # Now save which disk<num> this is, so we can parse it later during slice partition setup
554 _sFile=`echo $tmpSLICE | sed 's|/|-|g'`
555 echo "disk${disknum}" >${SLICECFGDIR}/$_sFile
558 # Increment our disk counter to look for next disk and unset
559 unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE
560 disknum=$((disknum+1))
562 exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!"
571 # Init the gmirror device
578 # Create this mirror device
579 rc_halt "gmirror label -vb ${_mBal} gm${_mNum} ${_mDisk}"
585 # Stop all gjournals on disk / slice
588 _gdsk="`echo $1 | sed 's|/dev/||g'`"
589 # Check if we need to shutdown any journals on this drive
590 ls /dev/${_gdsk}*.journal >/dev/null 2>/dev/null
594 for i in `ls ${_gdsk}*.journal`
596 rawjournal="`echo ${i} | cut -d '.' -f 1`"
597 gjournal stop -f ${rawjournal} >>${LOGOUT} 2>>${LOGOUT}
598 gjournal clear ${rawjournal} >>${LOGOUT} 2>>${LOGOUT}
604 # Function to wipe the potential backup gpt table from a disk
605 clear_backup_gpt_table()
607 echo_log "Clearing gpt backup table location on disk"
608 rc_nohalt "dd if=/dev/zero of=${1} bs=1m count=1"
609 rc_nohalt "dd if=/dev/zero of=${1} bs=1m oseek=`diskinfo ${1} | awk '{print int($3 / (1024*1024)) - 4;}'`"
612 # Function which runs gpart and creates a single large APM partition scheme
617 # Set our sysctl so we can overwrite any geom using drives
618 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
620 # Stop any journaling
621 stop_gjournal "${_intDISK}"
623 # Remove any existing partitions
624 delete_all_gpart "${_intDISK}"
628 echo_log "Running gpart on ${_intDISK}"
629 rc_halt "gpart create -s APM ${_intDISK}"
630 rc_halt "gpart add -s 800k -t freebsd-boot ${_intDISK}"
632 echo_log "Stamping boot sector on ${_intDISK}"
633 rc_halt "gpart bootcode -p /boot/boot1.hfs -i 1 ${_intDISK}"
637 # Function which runs gpart and creates a single large GPT partition scheme
642 # Set our sysctl so we can overwrite any geom using drives
643 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
645 # Stop any journaling
646 stop_gjournal "${_intDISK}"
648 # Remove any existing partitions
649 delete_all_gpart "${_intDISK}"
653 echo_log "Running gpart on ${_intDISK}"
654 rc_halt "gpart create -s GPT ${_intDISK}"
655 rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}"
657 echo_log "Stamping boot sector on ${_intDISK}"
658 rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}"
662 # Function which runs gpart and creates a single large MBR partition scheme
670 # Set our sysctl so we can overwrite any geom using drives
671 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
673 # Stop any journaling
674 stop_gjournal "${_intDISK}"
676 # Remove any existing partitions
677 delete_all_gpart "${_intDISK}"
681 echo_log "Running gpart on ${_intDISK}"
682 rc_halt "gpart create -s mbr -f active ${_intDISK}"
684 # Install new partition setup
685 echo_log "Running gpart add on ${_intDISK}"
686 rc_halt "gpart add -a 4k -t freebsd -i 1 ${_intDISK}"
689 echo_log "Cleaning up ${_intDISK}s1"
690 rc_halt "dd if=/dev/zero of=${_intDISK}s1 count=1024"
692 # Make the partition active
693 rc_halt "gpart set -a active -i 1 ${_intDISK}"
695 if [ "$_intBOOT" = "bsd" ] ; then
696 echo_log "Stamping boot0 on ${_intDISK}"
697 rc_halt "gpart bootcode -b /boot/boot0 ${_intDISK}"
699 echo_log "Stamping boot1 on ${_intDISK}"
700 rc_halt "gpart bootcode -b /boot/boot1 ${_intDISK}"
705 # Function which runs gpart and creates a single large slice
712 if [ "$SCHEME" = "APM" ] ; then
713 init_apm_full_disk "$DISK"
714 slice=`echo "${DISK}:1:apm" | sed 's|/|-|g'`
715 elif [ "$SCHEME" = "MBR" ] ; then
716 init_mbr_full_disk "$DISK" "$BOOT"
717 slice=`echo "${DISK}:1:mbr" | sed 's|/|-|g'`
719 init_gpt_full_disk "$DISK"
720 slice=`echo "${DISK}:1:gpt" | sed 's|/|-|g'`
723 # Lets save our slice, so we know what to look for in the config file later on
724 if [ -z "$WORKINGSLICES" ]
726 WORKINGSLICES="${slice}"
729 WORKINGSLICES="${WORKINGSLICES} ${slice}"
734 # Function which runs gpart on a specified gpt partition
739 # Set the slice we will use later
742 # Set our sysctl so we can overwrite any geom using drives
743 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
745 # Get the number of the slice we are working on
748 # Stop any journaling
749 stop_gjournal "${slice}"
751 # Make sure we have disabled swap on this drive
752 if [ -e "${slice}b" ]
754 swapoff ${slice}b >/dev/null 2>/dev/null
755 swapoff ${slice}b.eli >/dev/null 2>/dev/null
758 # Modify partition type
759 echo_log "Running gpart modify on ${DISK}"
760 rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}"
763 # Clean up old partition
764 echo_log "Cleaning up $slice"
765 rc_halt "dd if=/dev/zero of=${DISK}p${slicenum} count=1024"
769 # Init the MBR partition
770 rc_halt "gpart create -s BSD ${DISK}p${slicenum}"
772 # Stamp the bootloader
774 rc_halt "gpart bootcode -b /boot/boot ${DISK}p${slicenum}"
776 # Set the slice to the format we'll be using for gpart later
777 slice=`echo "${1}:${3}:gptslice" | sed 's|/|-|g'`
779 # Lets save our slice, so we know what to look for in the config file later on
780 if [ -z "$WORKINGSLICES" ]
782 WORKINGSLICES="${slice}"
785 WORKINGSLICES="${WORKINGSLICES} ${slice}"
790 # Function which runs gpart on a specified s1-4 slice
799 # Set the slice we will use later
802 # Set our sysctl so we can overwrite any geom using drives
803 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
805 # Get the number of the slice we are working on
808 # Stop any journaling
809 stop_gjournal "${slice}"
811 # Make sure we have disabled swap on this drive
812 if [ -e "${slice}b" ]
814 swapoff ${slice}b >/dev/null 2>/dev/null
815 swapoff ${slice}b.eli >/dev/null 2>/dev/null
818 # Modify partition type
819 echo_log "Running gpart modify on ${DISK}"
820 rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}"
823 # Clean up old partition
824 echo_log "Cleaning up $slice"
825 rc_halt "dd if=/dev/zero of=${DISK}s${slicenum} count=1024"
829 if [ "${BMANAGER}" = "bsd" ]
831 echo_log "Stamping boot sector on ${DISK}"
832 rc_halt "gpart bootcode -b /boot/boot0 ${DISK}"
835 # Set the slice to the format we'll be using for gpart later
836 slice=`echo "${1}:${3}:mbr" | sed 's|/|-|g'`
838 # Lets save our slice, so we know what to look for in the config file later on
839 if [ -z "$WORKINGSLICES" ]
841 WORKINGSLICES="${slice}"
844 WORKINGSLICES="${WORKINGSLICES} ${slice}"
849 # Function which runs gpart and creates a new slice from free disk space
859 # Set our sysctl so we can overwrite any geom using drives
860 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
862 slice="${DISK}s${SLICENUM}"
863 slicenum="${SLICENUM}"
865 # Working on the first slice, make sure we have MBR setup
866 gpart show ${DISK} >/dev/null 2>/dev/null
867 if [ $? -ne 0 -a "$SLICENUM" = "1" ] ; then
868 echo_log "Initializing disk, no existing MBR setup"
869 rc_halt "gpart create -s mbr ${DISK}"
872 # Install new partition setup
873 echo_log "Running gpart on ${DISK}"
874 rc_halt "gpart add -a 4k -t freebsd -i ${slicenum} ${DISK}"
877 echo_log "Cleaning up $slice"
878 rc_halt "dd if=/dev/zero of=${slice} count=1024"
882 if [ "${BMANAGER}" = "bsd" ]
884 echo_log "Stamping boot sector on ${DISK}"
885 rc_halt "gpart bootcode -b /boot/boot0 ${DISK}"
888 slice=`echo "${DISK}:${SLICENUM}:mbr" | sed 's|/|-|g'`
889 # Lets save our slice, so we know what to look for in the config file later on
890 if [ -z "$WORKINGSLICES" ]
892 WORKINGSLICES="${slice}"
895 WORKINGSLICES="${WORKINGSLICES} ${slice}"