functions-bsdlabel.sh (211730) | functions-bsdlabel.sh (212337) |
---|---|
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-bsdlabel.sh 211730 2010-08-24 06:11:46Z imp $ | 26# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh 212337 2010-09-08 20:10:24Z imp $ |
27 28# Functions related to disk operations using bsdlabel 29 30# Check if we are are provided a geli password on the nextline of the config 31check_for_enc_pass() 32{ 33 CURLINE="${1}" 34 --- 526 unchanged lines hidden (view full) --- 561 fi 562 563}; 564 565# Function which reads in the disk slice config, and performs it 566setup_disk_label() 567{ 568 # We are ready to start setting up the label, lets read the config and do the actions | 27 28# Functions related to disk operations using bsdlabel 29 30# Check if we are are provided a geli password on the nextline of the config 31check_for_enc_pass() 32{ 33 CURLINE="${1}" 34 --- 526 unchanged lines hidden (view full) --- 561 fi 562 563}; 564 565# Function which reads in the disk slice config, and performs it 566setup_disk_label() 567{ 568 # We are ready to start setting up the label, lets read the config and do the actions |
569 | |
570 # First confirm that we have a valid WORKINGSLICES | 569 # First confirm that we have a valid WORKINGSLICES |
571 if [ -z "${WORKINGSLICES}" ]; then | 570 if [ -z "${WORKINGSLICES}" -a -z "${WORKINGIMAGES}" ]; then |
572 exit_err "ERROR: No slices were setup! Please report this to the maintainers" 573 fi 574 575 # Check that the slices we have did indeed get setup and gpart worked 576 for i in $WORKINGSLICES 577 do 578 disk="`echo $i | cut -d '-' -f 1`" 579 pnum="`echo $i | cut -d '-' -f 2`" --- 28 unchanged lines hidden (view full) --- 608 rm -rf ${PARTDIR}-enc >/dev/null 2>/dev/null 609 mkdir -p ${PARTDIR}-enc >/dev/null 2>/dev/null 610 611 for i in $WORKINGSLICES 612 do 613 populate_disk_label "${i}" 614 done 615 | 571 exit_err "ERROR: No slices were setup! Please report this to the maintainers" 572 fi 573 574 # Check that the slices we have did indeed get setup and gpart worked 575 for i in $WORKINGSLICES 576 do 577 disk="`echo $i | cut -d '-' -f 1`" 578 pnum="`echo $i | cut -d '-' -f 2`" --- 28 unchanged lines hidden (view full) --- 607 rm -rf ${PARTDIR}-enc >/dev/null 2>/dev/null 608 mkdir -p ${PARTDIR}-enc >/dev/null 2>/dev/null 609 610 for i in $WORKINGSLICES 611 do 612 populate_disk_label "${i}" 613 done 614 |
615 for i in $WORKINGIMAGES 616 do 617 image=`echo "${i}"|cut -f2 -d:` 618 check_image_layout "${image}" 619 done 620 |
|
616 # Check if we made a root partition 617 if [ "$FOUNDROOT" = "-1" ] 618 then 619 exit_err "ERROR: No root (/) partition specified!!" 620 fi 621 622 # Check if we made a root partition 623 if [ "$FOUNDROOT" = "1" -a "${USINGBOOTPART}" != "0" ] 624 then 625 exit_err "ERROR: (/) partition isn't first partition on disk!" 626 fi 627 628 if [ "${USINGENCROOT}" = "0" -a "${USINGBOOTPART}" != "0" ] 629 then 630 exit_err "ERROR: Can't encrypt (/) with no (/boot) partition!" 631 fi 632}; 633 | 621 # Check if we made a root partition 622 if [ "$FOUNDROOT" = "-1" ] 623 then 624 exit_err "ERROR: No root (/) partition specified!!" 625 fi 626 627 # Check if we made a root partition 628 if [ "$FOUNDROOT" = "1" -a "${USINGBOOTPART}" != "0" ] 629 then 630 exit_err "ERROR: (/) partition isn't first partition on disk!" 631 fi 632 633 if [ "${USINGENCROOT}" = "0" -a "${USINGBOOTPART}" != "0" ] 634 then 635 exit_err "ERROR: Can't encrypt (/) with no (/boot) partition!" 636 fi 637}; 638 |
639check_fstab_mbr() 640{ 641 local SLICE 642 local FSTAB 643 644 if [ -z "$2" ] 645 then 646 return 1 647 fi 648 649 SLICE="$1" 650 FSTAB="$2/etc/fstab" 651 652 if [ -f "${FSTAB}" ] 653 then 654 PARTLETTER=`echo "$SLICE" | sed -E 's|^.+([a-h])$|\1|'` 655 656 grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1 657 if [ "$?" = "0" ] 658 then 659 if [ "${PARTLETTER}" = "a" ] 660 then 661 FOUNDROOT="0" 662 else 663 FOUNDROOT="1" 664 fi 665 export FOUNDROOT 666 fi 667 668 grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1 669 if [ "$?" = "0" ] 670 then 671 if [ "${PARTLETTER}" = "a" ] 672 then 673 USINGBOOTPART="0" 674 else 675 exit_err "/boot partition must be first partition" 676 fi 677 export USINGBOOTPART 678 fi 679 680 return 0 681 fi 682 683 return 1 684}; 685 686check_fstab_gpt() 687{ 688 local SLICE 689 local FSTAB 690 691 if [ -z "$2" ] 692 then 693 return 1 694 fi 695 696 SLICE="$1" 697 FSTAB="$2/etc/fstab" 698 699 if [ -f "${FSTAB}" ] 700 then 701 PARTNUMBER=`echo "${SLICE}" | sed -E 's|^.+p([0-9]*)$|\1|'` 702 703 grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1 704 if [ "$?" = "0" ] 705 then 706 if [ "${PARTNUMBER}" = "2" ] 707 then 708 FOUNDROOT="0" 709 else 710 FOUNDROOT="1" 711 fi 712 export FOUNDROOT 713 fi 714 715 grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1 716 if [ "$?" = "0" ] 717 then 718 if [ "${PARTNUMBER}" = "2" ] 719 then 720 USINGBOOTPART="0" 721 else 722 exit_err "/boot partition must be first partition" 723 fi 724 export USINGBOOTPART 725 fi 726 727 return 0 728 fi 729 730 731 return 1 732}; 733 734check_image_layout() 735{ 736 local SLICES 737 local IMAGE 738 local TYPE 739 local RES 740 local MD 741 local F 742 743 IMAGE="$1" 744 TYPE="MBR" 745 746 if [ -z "${IMAGE}" ] 747 then 748 return 1 749 fi 750 751 MD=`mdconfig -af "${IMAGE}"` 752 if [ "$?" != "0" ] 753 then 754 return 1 755 fi 756 757 SLICES=`ls /dev/${MD}s[1-4]*[a-h]* 2>/dev/null` 758 if [ "$?" != "0" ] 759 then 760 SLICES=`ls /dev/${MD}p[0-9]* 2>/dev/null` 761 if [ -n "${SLICES}" ] 762 then 763 TYPE="GPT" 764 RES=0 765 fi 766 else 767 RES=0 768 fi 769 770 for slice in ${SLICES} 771 do 772 F=1 773 mount ${slice} /mnt 2>/dev/null 774 if [ "$?" != "0" ] 775 then 776 continue 777 fi 778 779 if [ "${TYPE}" = "MBR" ] 780 then 781 check_fstab_mbr "${slice}" "/mnt" 782 F="$?" 783 784 elif [ "${TYPE}" = "GPT" ] 785 then 786 check_fstab_gpt "${slice}" "/mnt" 787 F="$?" 788 fi 789 790 if [ "${F}" = "0" ] 791 then 792 umount /mnt 793 break 794 fi 795 796 umount /mnt 797 done 798 799 mdconfig -d -u "${MD}" 800 return ${RES} 801}; |
|