zfsboot (297713) | zfsboot (298243) |
---|---|
1#!/bin/sh 2#- 3# Copyright (c) 2013-2015 Allan Jude 4# Copyright (c) 2013-2015 Devin Teske 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 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 26# SUCH DAMAGE. 27# | 1#!/bin/sh 2#- 3# Copyright (c) 2013-2015 Allan Jude 4# Copyright (c) 2013-2015 Devin Teske 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions --- 11 unchanged lines hidden (view full) --- 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 26# SUCH DAMAGE. 27# |
28# $FreeBSD: head/usr.sbin/bsdinstall/scripts/zfsboot 297713 2016-04-08 15:08:22Z allanjude $ | 28# $FreeBSD: head/usr.sbin/bsdinstall/scripts/zfsboot 298243 2016-04-19 03:25:36Z allanjude $ |
29# 30############################################################ INCLUDES 31 32BSDCFG_SHARE="/usr/share/bsdconfig" 33. $BSDCFG_SHARE/common.subr || exit 1 34f_dprintf "%s: loading includes..." "$0" 35f_include $BSDCFG_SHARE/device.subr 36f_include $BSDCFG_SHARE/dialog.subr --- 70 unchanged lines hidden (view full) --- 107: ${ZFSBOOT_DISKS:=} 108 109# 110# Default partitioning scheme to use on disks 111# 112: ${ZFSBOOT_PARTITION_SCHEME:=} 113 114# | 29# 30############################################################ INCLUDES 31 32BSDCFG_SHARE="/usr/share/bsdconfig" 33. $BSDCFG_SHARE/common.subr || exit 1 34f_dprintf "%s: loading includes..." "$0" 35f_include $BSDCFG_SHARE/device.subr 36f_include $BSDCFG_SHARE/dialog.subr --- 70 unchanged lines hidden (view full) --- 107: ${ZFSBOOT_DISKS:=} 108 109# 110# Default partitioning scheme to use on disks 111# 112: ${ZFSBOOT_PARTITION_SCHEME:=} 113 114# |
115# Default partitioning scheme to use on disks | 115# Default boot type to use on disks |
116# 117: ${ZFSBOOT_BOOT_TYPE:=} 118 119# 120# How much swap to put on each block device in the boot zpool 121# NOTE: Value passed to gpart(8); which supports SI unit suffixes. 122# 123: ${ZFSBOOT_SWAP_SIZE:=2g} --- 626 unchanged lines hidden (view full) --- 750 "$ZFSBOOT_PARTITION_SCHEME" 751 msg_error="$msg_error: $funcname" f_show_err \ 752 "$msg_unsupported_partition_scheme" \ 753 "$ZFSBOOT_PARTITION_SCHEME" 754 return $FAILURE 755 esac 756 757 # | 116# 117: ${ZFSBOOT_BOOT_TYPE:=} 118 119# 120# How much swap to put on each block device in the boot zpool 121# NOTE: Value passed to gpart(8); which supports SI unit suffixes. 122# 123: ${ZFSBOOT_SWAP_SIZE:=2g} --- 626 unchanged lines hidden (view full) --- 750 "$ZFSBOOT_PARTITION_SCHEME" 751 msg_error="$msg_error: $funcname" f_show_err \ 752 "$msg_unsupported_partition_scheme" \ 753 "$ZFSBOOT_PARTITION_SCHEME" 754 return $FAILURE 755 esac 756 757 # |
758 # Enable boot pool if encryption is desired 759 # 760 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 761 762 # 763 # ZFSBOOT_BOOT_POOL and BIOS+UEFI boot type are incompatible 764 # 765 if [ "$ZFSBOOT_BOOT_POOL" -a "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 766 f_dprintf "$funcname: ZFSBOOT_BOOT_POOL is incompatible with BIOS+UEFI boot type" 767 msg_error="$msg_error: $funcname" f_show_err \ 768 "ZFSBOOT_BOOT_POOL is incompatible with BIOS+UEFI boot type" 769 return $FAILURE 770 fi 771 772 # |
|
758 # Destroy whatever partition layout is currently on disk. 759 # NOTE: `-F' required to destroy if partitions still exist. 760 # NOTE: Failure is ok here, blank disk will have nothing to destroy. 761 # 762 f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" 763 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 764 f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk 765 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk 766 767 # Make doubly-sure backup GPT is destroyed 768 f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk 769 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 770 771 # | 773 # Destroy whatever partition layout is currently on disk. 774 # NOTE: `-F' required to destroy if partitions still exist. 775 # NOTE: Failure is ok here, blank disk will have nothing to destroy. 776 # 777 f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" 778 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 779 f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk 780 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk 781 782 # Make doubly-sure backup GPT is destroyed 783 f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk 784 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 785 786 # |
772 # Enable boot pool if encryption is desired 773 # 774 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 775 776 # | |
777 # Lay down the desired type of partition scheme 778 # 779 local setsize mbrindex align_small align_big 780 # 781 # If user has requested 4 K alignment, add these params to the 782 # gpart add calls. With GPT, we align large partitions to 1 M for 783 # improved performance on SSDs. MBR does not always play well with gaps 784 # between partitions, so all alignment is only 4k for that case. --- 23 unchanged lines hidden (view full) --- 808 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 809 f_eval_catch $funcname gpart "$GPART_SET_PMBR_ACTIVE" \ 810 $disk || return $FAILURE 811 fi 812 813 # 814 # 2. Add small freebsd-boot or efi partition 815 # | 787 # Lay down the desired type of partition scheme 788 # 789 local setsize mbrindex align_small align_big 790 # 791 # If user has requested 4 K alignment, add these params to the 792 # gpart add calls. With GPT, we align large partitions to 1 M for 793 # improved performance on SSDs. MBR does not always play well with gaps 794 # between partitions, so all alignment is only 4k for that case. --- 23 unchanged lines hidden (view full) --- 818 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 819 f_eval_catch $funcname gpart "$GPART_SET_PMBR_ACTIVE" \ 820 $disk || return $FAILURE 821 fi 822 823 # 824 # 2. Add small freebsd-boot or efi partition 825 # |
816 if [ "$ZFSBOOT_BOOT_TYPE" = "UEFI" ]; then | 826 if [ "$ZFSBOOT_BOOT_TYPE" = "UEFI" -o "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then |
817 f_eval_catch $funcname gpart \ 818 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 819 "$align_small" efiboot$index efi 800k $disk || 820 return $FAILURE 821 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PARTONLY" \ 822 /boot/boot1.efifat 1 $disk || 823 return $FAILURE | 827 f_eval_catch $funcname gpart \ 828 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 829 "$align_small" efiboot$index efi 800k $disk || 830 return $FAILURE 831 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PARTONLY" \ 832 /boot/boot1.efifat 1 $disk || 833 return $FAILURE |
824 else | 834 fi 835 836 if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" -o "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then |
825 f_eval_catch $funcname gpart \ 826 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 827 "$align_small" gptboot$index freebsd-boot \ 828 512k $disk || return $FAILURE | 837 f_eval_catch $funcname gpart \ 838 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 839 "$align_small" gptboot$index freebsd-boot \ 840 512k $disk || return $FAILURE |
829 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 830 /boot/pmbr /boot/gptzfsboot 1 $disk || 831 return $FAILURE | 841 if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then 842 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 843 /boot/pmbr /boot/gptzfsboot 1 $disk || 844 return $FAILURE 845 else 846 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 847 /boot/pmbr /boot/gptzfsboot 2 $disk || 848 return $FAILURE 849 fi |
832 fi 833 834 # NB: zpool will use the `zfs#' GPT labels | 850 fi 851 852 # NB: zpool will use the `zfs#' GPT labels |
835 bootpart=p2 swappart=p2 targetpart=p2 836 [ ${swapsize:-0} -gt 0 ] && targetpart=p3 | 853 if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 854 if [ "$ZFSBOOT_BOOT_POOL" ]; then 855 bootpart=p3 swappart=p4 targetpart=p4 856 [ ${swapsize:-0} -gt 0 ] && targetpart=p5 857 else 858 # Bootpart unused 859 bootpart=p3 swappart=p3 targetpart=p3 860 [ ${swapsize:-0} -gt 0 ] && targetpart=p4 861 fi 862 else 863 if [ "$ZFSBOOT_BOOT_POOL" ]; then 864 bootpart=p2 swappart=p3 targetpart=p3 865 [ ${swapsize:-0} -gt 0 ] && targetpart=p4 866 else 867 # Bootpart unused 868 bootpart=p2 swappart=p2 targetpart=p2 869 [ ${swapsize:-0} -gt 0 ] && targetpart=p3 870 fi 871 fi |
837 838 # 839 # Prepare boot pool if enabled (e.g., for geli(8)) 840 # 841 if [ "$ZFSBOOT_BOOT_POOL" ]; then | 872 873 # 874 # Prepare boot pool if enabled (e.g., for geli(8)) 875 # 876 if [ "$ZFSBOOT_BOOT_POOL" ]; then |
842 bootpart=p2 swappart=p3 targetpart=p3 843 [ ${swapsize:-0} -gt 0 ] && targetpart=p4 | |
844 f_eval_catch $funcname gpart \ 845 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 846 "$align_big" boot$index freebsd-zfs \ 847 ${bootsize}b $disk || 848 return $FAILURE 849 # Pedantically nuke any old labels 850 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 851 /dev/$disk$bootpart --- 587 unchanged lines hidden (view full) --- 1439f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" 1440 1441# 1442# If the system was booted with UEFI, set the default boot type to UEFI 1443# 1444bootmethod=$( sysctl -n machdep.bootmethod ) 1445f_dprintf "machdep.bootmethod=[%s]" "$bootmethod" 1446if [ "$bootmethod" = "UEFI" ]; then | 877 f_eval_catch $funcname gpart \ 878 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 879 "$align_big" boot$index freebsd-zfs \ 880 ${bootsize}b $disk || 881 return $FAILURE 882 # Pedantically nuke any old labels 883 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 884 /dev/$disk$bootpart --- 587 unchanged lines hidden (view full) --- 1472f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" 1473 1474# 1475# If the system was booted with UEFI, set the default boot type to UEFI 1476# 1477bootmethod=$( sysctl -n machdep.bootmethod ) 1478f_dprintf "machdep.bootmethod=[%s]" "$bootmethod" 1479if [ "$bootmethod" = "UEFI" ]; then |
1447 : ${ZFSBOOT_BOOT_TYPE:=UEFI} | 1480 : ${ZFSBOOT_BOOT_TYPE:=BIOS+UEFI} |
1448 : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 1449else 1450 : ${ZFSBOOT_BOOT_TYPE:=BIOS} 1451 : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 1452fi 1453 1454# 1455# Loop over the main menu until we've accomplished what we came here to do --- 113 unchanged lines hidden (view full) --- 1569 ZFSBOOT_GELI_ENCRYPTION=1 1570 fi 1571 ;; 1572 ?" $msg_partition_scheme") 1573 # Toggle between GPT (BIOS), GPT (UEFI) and MBR 1574 if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then 1575 ZFSBOOT_PARTITION_SCHEME="GPT" 1576 ZFSBOOT_BOOT_TYPE="UEFI" | 1481 : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 1482else 1483 : ${ZFSBOOT_BOOT_TYPE:=BIOS} 1484 : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 1485fi 1486 1487# 1488# Loop over the main menu until we've accomplished what we came here to do --- 113 unchanged lines hidden (view full) --- 1602 ZFSBOOT_GELI_ENCRYPTION=1 1603 fi 1604 ;; 1605 ?" $msg_partition_scheme") 1606 # Toggle between GPT (BIOS), GPT (UEFI) and MBR 1607 if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then 1608 ZFSBOOT_PARTITION_SCHEME="GPT" 1609 ZFSBOOT_BOOT_TYPE="UEFI" |
1610 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a "$ZFSBOOT_BOOT_TYPE" = "UEFI" ]; then 1611 ZFSBOOT_PARTITION_SCHEME="GPT" 1612 ZFSBOOT_BOOT_TYPE="BIOS+UEFI" |
|
1577 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" ]; then 1578 ZFSBOOT_PARTITION_SCHEME="MBR" 1579 ZFSBOOT_BOOT_TYPE="BIOS" 1580 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1581 ZFSBOOT_PARTITION_SCHEME="GPT + Active" 1582 ZFSBOOT_BOOT_TYPE="BIOS" 1583 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 1584 ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" --- 53 unchanged lines hidden --- | 1613 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" ]; then 1614 ZFSBOOT_PARTITION_SCHEME="MBR" 1615 ZFSBOOT_BOOT_TYPE="BIOS" 1616 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1617 ZFSBOOT_PARTITION_SCHEME="GPT + Active" 1618 ZFSBOOT_BOOT_TYPE="BIOS" 1619 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 1620 ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" --- 53 unchanged lines hidden --- |