3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Functions related to disk operations using gpart
32 # See if device is a full disk or partition/slice
35 for _dsk in `sysctl -n kern.disks`
37 [ "$_dsk" = "${1}" ] && return 0
38 [ "/dev/$_dsk" = "${1}" ] && return 0
44 # Get a MBR partitions sysid
45 get_partition_sysid_mbr()
49 PARTNUM=`echo ${2} | sed "s|${DISK}s||g"`
50 fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
53 echo "$i" | grep -q "The data for partition" 2>/dev/null
54 if [ $? -eq 0 ] ; then
56 PART="`echo ${i} | cut -d ' ' -f 5`"
57 if [ "$PART" = "$PARTNUM" ] ; then
62 # In the partition section
63 if [ "$INPART" = "1" ] ; then
64 echo "$i" | grep -q "^sysid" 2>/dev/null
65 if [ $? -eq 0 ] ; then
66 SYSID="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2`"
72 done < ${TMPDIR}/disk-${DISK}
73 rm ${TMPDIR}/disk-${DISK}
78 # Get the partitions MBR label
79 get_partition_label_mbr()
83 PARTNUM=`echo ${2} | sed "s|${DISK}s||g"`
84 fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
87 echo "$i" | grep -q "The data for partition" 2>/dev/null
88 if [ $? -eq 0 ] ; then
90 PART="`echo ${i} | cut -d ' ' -f 5`"
91 if [ "$PART" = "$PARTNUM" ] ; then
96 # In the partition section
97 if [ "$INPART" = "1" ] ; then
98 echo "$i" | grep -q "^sysid" 2>/dev/null
99 if [ $? -eq 0 ] ; then
100 LABEL="`echo ${i} | tr -s '\t' ' ' | cut -d ',' -f 2-10`"
106 done < ${TMPDIR}/disk-${DISK}
107 rm ${TMPDIR}/disk-${DISK}
109 export VAL="${LABEL}"
112 # Get a GPT partitions label
113 get_partition_label_gpt()
116 PARTNUM=`echo ${2} | sed "s|${DISK}p||g"`
118 gpart show ${DISK} >${TMPDIR}/disk-${DISK}
121 SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
122 if [ "${SLICE}" = "${PARTNUM}" ] ; then
123 LABEL="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4`"
126 done <${TMPDIR}/disk-${DISK}
127 rm ${TMPDIR}/disk-${DISK}
129 export VAL="${LABEL}"
132 # Get a partitions startblock
133 get_partition_startblock()
136 PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"`
138 gpart show ${DISK} >${TMPDIR}/disk-${DISK}
141 SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
142 if [ "$SLICE" = "${PARTNUM}" ] ; then
143 SB="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 1`"
146 done <${TMPDIR}/disk-${DISK}
147 rm ${TMPDIR}/disk-${DISK}
152 # Get a partitions blocksize
153 get_partition_blocksize()
156 PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"`
158 gpart show ${DISK} >${TMPDIR}/disk-${DISK}
161 SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
162 if [ "$SLICE" = "${PARTNUM}" ] ; then
163 BS="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 2`"
166 done <${TMPDIR}/disk-${DISK}
167 rm ${TMPDIR}/disk-${DISK}
172 # Function which returns the partitions on a target disk
173 get_disk_partitions()
175 gpart show ${1} >/dev/null 2>/dev/null
176 if [ $? -ne 0 ] ; then
181 type=`gpart show ${1} | awk '/^=>/ { printf("%s",$5); }'`
183 SLICES="`gpart show ${1} | grep -v ${1} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4 | sed '/^$/d'`"
187 MBR) name="${1}s${i}" ;;
188 GPT) name="${1}p${i}";;
189 *) name="${1}s${i}";;
191 if [ -z "${RSLICES}" ]
195 RSLICES="${RSLICES} ${name}"
199 export VAL="${RSLICES}"
202 # Function which returns a target disks cylinders
205 cyl=`diskinfo -v ${1} | grep "# Cylinders" | tr -s ' ' | cut -f 2`
209 # Function which returns a target disks sectors
212 sec=`diskinfo -v ${1} | grep "# Sectors" | tr -s ' ' | cut -f 2`
216 # Function which returns a target disks heads
219 head=`diskinfo -v ${1} | grep "# Heads" | tr -s ' ' | cut -f 2`
223 # Function which returns a target disks mediasize in sectors
226 mediasize=`diskinfo -v ${1} | grep "# mediasize in sectors" | tr -s ' ' | cut -f 2`
227 export VAL="${mediasize}"
230 # Function which returns a target disks mediasize in megabytes
231 get_disk_mediasize_mb()
233 mediasize=`diskinfo -v ${1} | grep "# mediasize in bytes" | tr -s ' ' | cut -f 2`
234 mediasize=`expr $mediasize / 1024`
235 mediasize=`expr $mediasize / 1024`
236 export VAL="${mediasize}"
239 # Function to delete all gparts before starting an install
242 echo_log "Deleting all gparts"
245 # Check for any swaps to stop
246 for i in `swapctl -l | grep "$DISK" | awk '{print $1}'`
248 swapoff ${i} >/dev/null 2>/dev/null
251 # Delete the gparts now
252 for i in `gpart show ${DISK} 2>/dev/null | tr -s ' ' | cut -d ' ' -f 4`
254 if [ "/dev/${i}" != "${DISK}" -a "${i}" != "-" ] ; then
255 rc_nohalt "gpart delete -i ${i} ${DISK}"
259 # Destroy the disk geom
260 rc_nohalt "gpart destroy ${DISK}"
262 wipe_metadata "${DISK}"
265 # Function to export all zpools before starting an install
268 if [ ! -c /dev/zfs ]; then
271 local DISK="`echo ${1} | sed 's|/dev/||g'`"
273 # Export any zpools using this device so we can overwrite
274 for i in `zpool list -H -o name`
276 ztst=`zpool status ${i} | grep "ONLINE" | awk '{print $1}' | grep -q ${DISK}`
277 if [ "$ztst" = "$DISK" ] ; then
283 # Function which stops all gmirrors before doing any disk manipulation
286 if [ ! -d /dev/mirror ]; then
289 local DISK="`echo ${1} | sed 's|/dev/||g'`"
290 GPROV="`gmirror list | grep ". Name: mirror/" | cut -d '/' -f 2`"
293 gmirror list | grep -q "Name: ${DISK}" 2>/dev/null
296 echo_log "Stopping mirror $gprov $DISK"
297 rc_nohalt "gmirror remove $gprov $DISK"
298 wipe_metadata "${DISK}"
303 # Make sure we don't have any geli providers active on this disk
306 local _geld="`echo ${1} | sed 's|/dev/||g'`"
309 for i in `ls ${_geld}*`
311 echo $i | grep -q '.eli' 2>/dev/null
314 echo_log "Detaching GELI on ${i}"
315 rc_halt "geli detach ${i}"
321 # Function which reads in the disk slice config, and performs it
325 # Cleanup any slice / mirror dirs
326 rm -rf ${SLICECFGDIR} >/dev/null 2>/dev/null
328 rm -rf ${MIRRORCFGDIR} >/dev/null 2>/dev/null
329 mkdir ${MIRRORCFGDIR}
331 # Start with disk0 and gm0
335 # We are ready to start setting up the disks, lets read the config and do the actions
338 echo $line | grep -q "^disk${disknum}=" 2>/dev/null
342 # Found a disk= entry, lets get the disk we are working on
343 get_value_from_string "${line}"
344 strip_white_space "$VAL"
347 echo "${DISK}" | grep -q '^/dev/'
348 if [ $? -ne 0 ] ; then DISK="/dev/$DISK" ; fi
350 # Before we go further, lets confirm this disk really exists
351 if [ ! -e "${DISK}" ] ; then
352 exit_err "ERROR: The disk ${DISK} does not exist!"
355 # Make sure we stop any gmirrors on this disk
356 stop_all_gmirror ${DISK}
358 # Make sure we stop any geli stuff on this disk
359 stop_all_geli ${DISK}
361 # Make sure we don't have any zpools loaded
366 # Lets look if this device will be mirrored on another disk
367 echo $line | grep -q "^mirror=" 2>/dev/null
371 # Found a disk= entry, lets get the disk we are working on
372 get_value_from_string "${line}"
373 strip_white_space "$VAL"
375 echo "${MIRRORDISK}" | grep -q '^/dev/'
376 if [ $? -ne 0 ] ; then MIRRORDISK="/dev/$MIRRORDISK" ; fi
378 # Before we go further, lets confirm this disk really exists
379 if [ ! -e "${MIRRORDISK}" ]
381 exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!"
384 # Make sure we stop any gmirrors on this mirror disk
385 stop_all_gmirror ${MIRRORDISK}
387 # Make sure we stop any geli stuff on this mirror disk
388 stop_all_geli ${MIRRORDISK}
390 # Make sure we don't have any zpools mirror loaded
391 stop_all_zfs ${MIRRORDISK}
395 # Lets see if we have been given a mirror balance choice
396 echo $line | grep -q "^mirrorbal=" 2>/dev/null
400 # Found a disk= entry, lets get the disk we are working on
401 get_value_from_string "${line}"
402 strip_white_space "$VAL"
406 echo $line | grep -q "^partition=" 2>/dev/null
409 # Found a partition= entry, lets read / set it
410 get_value_from_string "${line}"
411 strip_white_space "$VAL"
412 PTYPE=`echo $VAL|tr A-Z a-z`
414 # We are using free space, figure out the slice number
415 if [ "${PTYPE}" = "free" ]
417 # Lets figure out what number this slice will be
418 LASTSLICE="`gpart show ${DISK} \
426 if [ -z "${LASTSLICE}" ]
430 LASTSLICE=$((LASTSLICE+1))
433 if [ $LASTSLICE -gt 4 ]
435 exit_err "ERROR: BSD only supports primary partitions, and there are none available on $DISK"
441 # Check if we have an image file defined
442 echo $line | grep -q "^image=" 2>/dev/null
443 if [ $? -eq 0 ] ; then
444 # Found an image= entry, lets read / set it
445 get_value_from_string "${line}"
446 strip_white_space "$VAL"
448 if [ ! -f "$IMAGE" ] ; then
449 exit_err "$IMAGE file does not exist"
453 # Check if we have a partscheme specified
454 echo $line | grep -q "^partscheme=" 2>/dev/null
455 if [ $? -eq 0 ] ; then
456 # Found a partscheme= entry, lets read / set it
457 get_value_from_string "${line}"
458 strip_white_space "$VAL"
460 if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
461 exit_err "Unknown partition scheme: $PSCHEME"
465 echo $line | grep -q "^bootManager=" 2>/dev/null
468 # Found a bootManager= entry, lets read /set it
469 get_value_from_string "${line}"
470 strip_white_space "$VAL"
474 echo $line | grep -q "^commitDiskPart" 2>/dev/null
477 # Found our flag to commit this disk setup / lets do sanity check and do it
478 if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
480 # Make sure we are only installing ppc to full disk
481 if [ `uname -m` = "powerpc" -o `uname -m` = "powerpc64" ]; then
482 if [ "$PTYPE" != "all" ] ; then
483 exit_err "powerpc can only be installed to a full disk"
489 # If we have a gmirror, lets set it up
490 if [ -n "$MIRRORDISK" ]; then
491 # Default to round-robin if the user didn't specify
492 if [ -z "$MIRRORBAL" ]; then MIRRORBAL="round-robin" ; fi
494 _mFile=`echo $DISK | sed 's|/|%|g'`
495 echo "$MIRRORDISK:$MIRRORBAL:gm${gmnum}" >${MIRRORCFGDIR}/$_mFile
496 init_gmirror "$gmnum" "$MIRRORBAL" "$DISK" "$MIRRORDISK"
498 # Reset DISK to the gmirror device
499 DISK="/dev/mirror/gm${gmnum}"
503 if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
510 if [ `uname -m` = "powerpc" -o `uname -m` = "powerpc64" ]
516 run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}"
520 tmpSLICE="${DISK}${PTYPE}"
521 # Get the number of the slice we are working on
522 s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`"
523 run_gpart_slice "${DISK}" "${BMANAGER}" "${s}"
526 p1|p2|p3|p4|p5|p6|p7|p8|p9|p10|p11|p12|p13|p14|p15|p16|p17|p18|p19|p20)
527 tmpSLICE="${DISK}${PTYPE}"
528 # Get the number of the gpt partition we are working on
529 s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`"
530 run_gpart_gpt_part "${DISK}" "${BMANAGER}" "${s}"
534 tmpSLICE="${DISK}s${LASTSLICE}"
535 run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}"
541 exit_err "ERROR: partition type image specified with no image!"
545 *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;;
553 if [ -n "${tmpSLICE}" ]
560 write_image "${IMAGE}" "${DEST}"
561 check_disk_layout "${DEST}"
564 # Now save which disk<num> this is, so we can parse it later during slice partition setup
567 _sFile=`echo $tmpSLICE | sed 's|/|-|g'`
568 echo "disk${disknum}" >${SLICECFGDIR}/$_sFile
571 # Increment our disk counter to look for next disk and unset
572 unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE
573 disknum=$((disknum+1))
575 exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!"
584 # Init the gmirror device
591 # Create this mirror device
592 rc_halt "gmirror label -vb ${_mBal} gm${_mNum} ${_mDisk}"
598 # Stop all gjournals on disk / slice
601 _gdsk="`echo $1 | sed 's|/dev/||g'`"
602 # Check if we need to shutdown any journals on this drive
603 ls /dev/${_gdsk}*.journal >/dev/null 2>/dev/null
607 for i in `ls ${_gdsk}*.journal`
609 rawjournal="`echo ${i} | cut -d '.' -f 1`"
610 gjournal stop -f ${rawjournal} >>${LOGOUT} 2>>${LOGOUT}
611 gjournal clear ${rawjournal} >>${LOGOUT} 2>>${LOGOUT}
617 # Function to wipe the potential metadata from a disk
620 echo_log "Wiping possible metadata on ${1}"
621 local SIZE="`diskinfo ${1} | awk '{print int($3/(1024*1024)) }'`"
622 if [ "$SIZE" -gt "5" ] ; then
623 rc_halt "dd if=/dev/zero of=${1} bs=1m count=1"
624 rc_nohalt "dd if=/dev/zero of=${1} bs=1m oseek=$((SIZE-4))"
626 rc_nohalt "dd if=/dev/zero of=${1} bs=128k"
630 # Function which runs gpart and creates a single large APM partition scheme
635 # Set our sysctl so we can overwrite any geom using drives
636 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
638 # Stop any journaling
639 stop_gjournal "${_intDISK}"
641 # Remove any existing partitions
642 delete_all_gpart "${_intDISK}"
646 echo_log "Running gpart on ${_intDISK}"
647 rc_halt "gpart create -s APM ${_intDISK}"
648 rc_halt "gpart add -s 800k -t freebsd-boot ${_intDISK}"
650 echo_log "Stamping boot sector on ${_intDISK}"
651 rc_halt "gpart bootcode -p /boot/boot1.hfs -i 1 ${_intDISK}"
655 # Function which runs gpart and creates a single large GPT partition scheme
660 # Set our sysctl so we can overwrite any geom using drives
661 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
663 # Stop any journaling
664 stop_gjournal "${_intDISK}"
666 # Remove any existing partitions
667 delete_all_gpart "${_intDISK}"
671 echo_log "Running gpart on ${_intDISK}"
672 rc_halt "gpart create -s GPT ${_intDISK}"
673 rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}"
675 echo_log "Stamping boot sector on ${_intDISK}"
676 rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}"
680 # Function which runs gpart and creates a single large MBR partition scheme
688 # Set our sysctl so we can overwrite any geom using drives
689 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
691 # Stop any journaling
692 stop_gjournal "${_intDISK}"
694 # Remove any existing partitions
695 delete_all_gpart "${_intDISK}"
699 echo_log "Running gpart on ${_intDISK}"
700 rc_halt "gpart create -s mbr -f active ${_intDISK}"
702 # Install new partition setup
703 echo_log "Running gpart add on ${_intDISK}"
704 rc_halt "gpart add -a 4k -t freebsd -i 1 ${_intDISK}"
707 wipe_metadata "${_intDISK}s1"
709 # Make the partition active
710 rc_halt "gpart set -a active -i 1 ${_intDISK}"
712 if [ "$_intBOOT" = "bsd" ] ; then
713 echo_log "Stamping boot0 on ${_intDISK}"
714 rc_halt "gpart bootcode -b /boot/boot0 ${_intDISK}"
716 echo_log "Stamping boot1 on ${_intDISK}"
717 rc_halt "gpart bootcode -b /boot/boot1 ${_intDISK}"
722 # Function which runs gpart and creates a single large slice
729 if [ "$SCHEME" = "APM" ] ; then
730 init_apm_full_disk "$DISK"
731 slice=`echo "${DISK}:1:apm" | sed 's|/|-|g'`
732 elif [ "$SCHEME" = "MBR" ] ; then
733 init_mbr_full_disk "$DISK" "$BOOT"
734 slice=`echo "${DISK}:1:mbr" | sed 's|/|-|g'`
736 init_gpt_full_disk "$DISK"
737 slice=`echo "${DISK}:1:gpt" | sed 's|/|-|g'`
740 # Lets save our slice, so we know what to look for in the config file later on
741 if [ -z "$WORKINGSLICES" ]
743 WORKINGSLICES="${slice}"
746 WORKINGSLICES="${WORKINGSLICES} ${slice}"
751 # Function which runs gpart on a specified gpt partition
756 # Set the slice we will use later
759 # Set our sysctl so we can overwrite any geom using drives
760 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
762 # Get the number of the slice we are working on
765 # Stop any journaling
766 stop_gjournal "${slice}"
768 # Make sure we have disabled swap on this drive
769 if [ -e "${slice}b" ]
771 swapoff ${slice}b >/dev/null 2>/dev/null
772 swapoff ${slice}b.eli >/dev/null 2>/dev/null
775 # Modify partition type
776 echo_log "Running gpart modify on ${DISK}"
777 rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}"
780 wipe_metadata "${slice}"
784 # Init the MBR partition
785 rc_halt "gpart create -s BSD ${DISK}p${slicenum}"
787 # Stamp the bootloader
789 rc_halt "gpart bootcode -b /boot/boot ${DISK}p${slicenum}"
791 # Set the slice to the format we'll be using for gpart later
792 slice=`echo "${1}:${3}:gptslice" | sed 's|/|-|g'`
794 # Lets save our slice, so we know what to look for in the config file later on
795 if [ -z "$WORKINGSLICES" ]
797 WORKINGSLICES="${slice}"
800 WORKINGSLICES="${WORKINGSLICES} ${slice}"
805 # Function which runs gpart on a specified s1-4 slice
814 # Set the slice we will use later
817 # Set our sysctl so we can overwrite any geom using drives
818 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
820 # Get the number of the slice we are working on
823 # Stop any journaling
824 stop_gjournal "${slice}"
826 # Make sure we have disabled swap on this drive
827 if [ -e "${slice}b" ]
829 swapoff ${slice}b >/dev/null 2>/dev/null
830 swapoff ${slice}b.eli >/dev/null 2>/dev/null
833 # Modify partition type
834 echo_log "Running gpart modify on ${DISK}"
835 rc_halt "gpart modify -t freebsd -i ${slicenum} ${DISK}"
838 wipe_metadata "${slice}"
842 if [ "${BMANAGER}" = "bsd" ]
844 echo_log "Stamping boot sector on ${DISK}"
845 rc_halt "gpart bootcode -b /boot/boot0 ${DISK}"
848 # Set the slice to the format we'll be using for gpart later
849 slice=`echo "${1}:${3}:mbr" | sed 's|/|-|g'`
851 # Lets save our slice, so we know what to look for in the config file later on
852 if [ -z "$WORKINGSLICES" ]
854 WORKINGSLICES="${slice}"
857 WORKINGSLICES="${WORKINGSLICES} ${slice}"
862 # Function which runs gpart and creates a new slice from free disk space
872 # Set our sysctl so we can overwrite any geom using drives
873 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
875 slice="${DISK}s${SLICENUM}"
876 slicenum="${SLICENUM}"
878 # Working on the first slice, make sure we have MBR setup
879 gpart show ${DISK} >/dev/null 2>/dev/null
880 if [ $? -ne 0 -a "$SLICENUM" = "1" ] ; then
881 echo_log "Initializing disk, no existing MBR setup"
882 rc_halt "gpart create -s mbr ${DISK}"
885 # Install new partition setup
886 echo_log "Running gpart on ${DISK}"
887 rc_halt "gpart add -a 4k -t freebsd -i ${slicenum} ${DISK}"
890 wipe_metadata "${slice}"
894 if [ "${BMANAGER}" = "bsd" ]
896 echo_log "Stamping boot sector on ${DISK}"
897 rc_halt "gpart bootcode -b /boot/boot0 ${DISK}"
900 slice=`echo "${DISK}:${SLICENUM}:mbr" | sed 's|/|-|g'`
901 # Lets save our slice, so we know what to look for in the config file later on
902 if [ -z "$WORKINGSLICES" ]
904 WORKINGSLICES="${slice}"
907 WORKINGSLICES="${WORKINGSLICES} ${slice}"