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 217229 2011-01-10 19:11:25Z 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 local 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 # Destroy the disk geom 264 rc_nohalt "gpart destroy ${DISK}" 265 266 # Make sure we clear any hidden gpt tables 267 clear_backup_gpt_table "${DISK}" 268 269 # Wipe out front of disk |
270 rc_nohalt "dd if=/dev/zero of=/dev/${DISK} count=3000" 271 272}; 273 274# Function to export all zpools before starting an install 275stop_all_zfs() 276{ 277 # Export all zpools again, so that we can overwrite these partitions potentially --- 277 unchanged lines hidden (view full) --- 555 do 556 rawjournal="`echo ${i} | cut -d '.' -f 1`" 557 gjournal stop -f ${rawjournal} >>${LOGOUT} 2>>${LOGOUT} 558 gjournal clear ${rawjournal} >>${LOGOUT} 2>>${LOGOUT} 559 done 560 fi 561} ; 562 |
563 564# Function to wipe the potential backup gpt table from a disk 565clear_backup_gpt_table() 566{ 567 # Get the disk block size 568 local dSize="`gpart show $1 | grep $1 | tr -s ' ' | cut -d ' ' -f 3`" 569 570 # Make sure this is a valid number 571 is_num "${dSize}" >/dev/null 2>/dev/null 572 if [ "$?" != "0" ] ; then return ; fi 573 574 # Die backup label, DIE 575 echo_log "Clearing gpt backup table location on disk" 576 rc_nohalt "dd if=/dev/zero of=${1} bs=512 seek=${dSize}" 577 578} ; 579 580 |
581# Function which runs gpart and creates a single large GPT partition scheme 582init_gpt_full_disk() 583{ 584 _intDISK=$1 585 586 # Set our sysctl so we can overwrite any geom using drives 587 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} 588 589 # Stop any journaling 590 stop_gjournal "${_intDISK}" 591 592 # Remove any existing partitions 593 delete_all_gpart "${_intDISK}" 594 |
595 sleep 2 596 597 echo_log "Running gpart on ${_intDISK}" 598 rc_halt "gpart create -s GPT ${_intDISK}" |
599 rc_halt "gpart add -b 34 -s 64 -t freebsd-boot ${_intDISK}" |
600 601 echo_log "Stamping boot sector on ${_intDISK}" 602 rc_halt "gpart bootcode -b /boot/pmbr ${_intDISK}" 603 604} 605 606# Function which runs gpart and creates a single large MBR partition scheme 607init_mbr_full_disk() 608{ 609 _intDISK=$1 610 _intBOOT=$2 611 |
612 startblock="2016" |
613 614 # Set our sysctl so we can overwrite any geom using drives 615 sysctl kern.geom.debugflags=16 >>${LOGOUT} 2>>${LOGOUT} 616 617 # Stop any journaling 618 stop_gjournal "${_intDISK}" 619 620 # Remove any existing partitions 621 delete_all_gpart "${_intDISK}" 622 |
623 sleep 2 624 625 echo_log "Running gpart on ${_intDISK}" 626 rc_halt "gpart create -s mbr ${_intDISK}" 627 628 # Lets figure out disk size in blocks 629 # Get the cyl of this disk 630 get_disk_cyl "${_intDISK}" --- 209 unchanged lines hidden --- |