functions-disk.sh (217164) | functions-disk.sh (217229) |
---|---|
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# | 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 $ | 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" | 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" | 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 | 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 |
|
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 | 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 |
|
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 | 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 |
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}" | 595 sleep 2 596 597 echo_log "Running gpart on ${_intDISK}" 598 rc_halt "gpart create -s GPT ${_intDISK}" |
578 rc_halt "gpart add -b 34 -s 128 -t freebsd-boot ${_intDISK}" | 599 rc_halt "gpart add -b 34 -s 64 -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 | 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 |
591 startblock="63" | 612 startblock="2016" |
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 | 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 |
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 --- | 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 --- |