Deleted Added
sdiff udiff text old ( 217164 ) new ( 217229 )
full compact
1#!/bin/sh
2#-
3# Copyright (c) 2010 iXsystems, Inc. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

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
24# SUCH DAMAGE.
25#
26# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-disk.sh 217164 2011-01-08 20:25:00Z jpaetzel $
27
28# Functions related to disk operations using gpart
29
30# See if device is a full disk or partition/slice
31is_disk()
32{
33 for _dsk in `sysctl -n kern.disks`
34 do

--- 203 unchanged lines hidden (view full) ---

238 zpool export -f ${i}
239 done
240};
241
242# Function to delete all gparts before starting an install
243delete_all_gpart()
244{
245 echo_log "Deleting all gparts"
246 DISK="$1"
247
248 # Check for any swaps to stop
249 for i in `gpart show ${DISK} 2>/dev/null | grep 'freebsd-swap' | tr -s ' ' | cut -d ' ' -f 4`
250 do
251 swapoff /dev/${DISK}s${i}b >/dev/null 2>/dev/null
252 swapoff /dev/${DISK}p${i} >/dev/null 2>/dev/null
253 done
254
255 # Delete the gparts now
256 for i in `gpart show ${DISK} 2>/dev/null | tr -s ' ' | cut -d ' ' -f 4`
257 do
258 if [ "${i}" != "${DISK}" -a "${i}" != "-" ] ; then
259 rc_nohalt "gpart delete -i ${i} ${DISK}"
260 fi
261 done
262
263 rc_nohalt "dd if=/dev/zero of=/dev/${DISK} count=3000"
264
265};
266
267# Function to export all zpools before starting an install
268stop_all_zfs()
269{
270 # Export all zpools again, so that we can overwrite these partitions potentially

--- 277 unchanged lines hidden (view full) ---

548 do
549 rawjournal="`echo ${i} | cut -d '.' -f 1`"
550 gjournal stop -f ${rawjournal} >>${LOGOUT} 2>>${LOGOUT}
551 gjournal clear ${rawjournal} >>${LOGOUT} 2>>${LOGOUT}
552 done
553 fi
554} ;
555
556# Function which runs gpart and creates a single large GPT partition scheme
557init_gpt_full_disk()
558{
559 _intDISK=$1
560
561 # Set our sysctl so we can overwrite any geom using drives
562 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
563
564 # Stop any journaling
565 stop_gjournal "${_intDISK}"
566
567 # Remove any existing partitions
568 delete_all_gpart "${_intDISK}"
569
570 #Erase any existing bootloader
571 echo_log "Cleaning up ${_intDISK}"
572 rc_halt "dd if=/dev/zero of=/dev/${_intDISK} count=2048"
573
574 sleep 2
575
576 echo_log "Running gpart on ${_intDISK}"
577 rc_halt "gpart create -s GPT ${_intDISK}"
578 rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}"
579
580 echo_log "Stamping boot sector on ${_intDISK}"
581 rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}"
582
583}
584
585# Function which runs gpart and creates a single large MBR partition scheme
586init_mbr_full_disk()
587{
588 _intDISK=$1
589 _intBOOT=$2
590
591 startblock="63"
592
593 # Set our sysctl so we can overwrite any geom using drives
594 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT}
595
596 # Stop any journaling
597 stop_gjournal "${_intDISK}"
598
599 # Remove any existing partitions
600 delete_all_gpart "${_intDISK}"
601
602 #Erase any existing bootloader
603 echo_log "Cleaning up ${_intDISK}"
604 rc_halt "dd if=/dev/zero of=/dev/${_intDISK} count=2048"
605
606 sleep 2
607
608 echo_log "Running gpart on ${_intDISK}"
609 rc_halt "gpart create -s mbr ${_intDISK}"
610
611 # Lets figure out disk size in blocks
612 # Get the cyl of this disk
613 get_disk_cyl "${_intDISK}"

--- 209 unchanged lines hidden ---