1#!/bin/sh 2#- 3# Copyright (c) 2013 Allan Jude 4# Copyright (c) 2013 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: stable/10/usr.sbin/bsdinstall/scripts/zfsboot 259621 2013-12-19 18:52:41Z dteske $ |
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 --- 24 unchanged lines hidden (view full) --- 61 62# 63# Should we use gnop(8) to configure a transparent mapping to 4K sectors? 64# 65: ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:=1} 66 67# 68# Should we use geli(8) to encrypt the drives? |
69# NB: Automatically enables ZFSBOOT_BOOT_POOL |
70# 71: ${ZFSBOOT_GELI_ENCRYPTION=} 72 73# |
74# Default path to the geli(8) keyfile used in drive encryption |
75# |
76: ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key} |
77 78# |
79# Create a separate boot pool? 80# NB: Automatically set when using geli(8) or MBR |
81# |
82: ${ZFSBOOT_BOOT_POOL=} |
83 84# |
85# Default name for boot pool when enabled (e.g., geli(8) or MBR) |
86# |
87: ${ZFSBOOT_BOOT_POOL_NAME:=bootpool} |
88 89# |
90# Default size for boot pool when enabled (e.g., geli(8) or MBR) 91# 92: ${ZFSBOOT_BOOT_POOL_SIZE:=2g} 93 94# |
95# Default disks to use (always empty unless being scripted) 96# 97: ${ZFSBOOT_DISKS:=} 98 99# 100# Default partitioning scheme to use on disks 101# 102: ${ZFSBOOT_PARTITION_SCHEME:=GPT} --- 31 unchanged lines hidden (view full) --- 134 135 # Source tree (compressed) 136 /usr/src compression=lz4,exec=off,setuid=off 137 138 # Create /var and friends 139 /var mountpoint=/var 140 /var/crash compression=lz4,exec=off,setuid=off 141 /var/log compression=lz4,exec=off,setuid=off |
142 /var/mail compression=lz4,atime=on |
143 /var/tmp compression=lz4,exec=on,setuid=off 144" # END-QUOTE 145 146# 147# If interactive and the user has not explicitly chosen a vdev type or disks, 148# make the user confirm scripted/default choices when proceeding to install. 149# 150: ${ZFSBOOT_CONFIRM_LAYOUT:=1} --- 7 unchanged lines hidden (view full) --- 158 159# 160# Command strings for various tasks 161# 162CHMOD_MODE='chmod %s "%s"' 163DD_WITH_OPTIONS='dd if="%s" of="%s" %s' 164ECHO_APPEND='echo "%s" >> "%s"' 165GELI_ATTACH='geli attach -j - -k "%s" "%s"' |
166GELI_DETACH_F='geli detach -f "%s"' |
167GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"' 168GNOP_CREATE='gnop create -S 4096 "%s"' |
169GNOP_DESTROY='gnop destroy "%s"' |
170GPART_ADD='gpart add -t %s "%s"' 171GPART_ADD_INDEX='gpart add -i %s -t %s "%s"' 172GPART_ADD_INDEX_WITH_SIZE='gpart add -i %s -t %s -s %s "%s"' 173GPART_ADD_LABEL='gpart add -l %s -t %s "%s"' 174GPART_ADD_LABEL_WITH_SIZE='gpart add -l %s -t %s -s %s "%s"' 175GPART_BOOTCODE='gpart bootcode -b "%s" "%s"' 176GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"' 177GPART_CREATE='gpart create -s %s "%s"' |
178GPART_DESTROY_F='gpart destroy -F "%s"' |
179GPART_SET_ACTIVE='gpart set -a active -i %s "%s"' |
180GRAID_DELETE='graid delete "%s"' |
181LN_SF='ln -sf "%s" "%s"' 182MKDIR_P='mkdir -p "%s"' 183MOUNT_TYPE='mount -t %s "%s" "%s"' 184PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\"" 185PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"' 186SHELL_TRUNCATE=':> "%s"' |
187UMOUNT='umount "%s"' |
188ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"' 189ZFS_SET='zfs set "%s" "%s"' 190ZFS_UNMOUNT='zfs unmount "%s"' 191ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s' 192ZPOOL_EXPORT='zpool export "%s"' 193ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"' |
194ZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"' |
195ZPOOL_SET='zpool set %s "%s"' 196 197# 198# Strings that should be moved to an i18n file and loaded with f_include_lang() 199# 200hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER" 201hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" 202hline_arrows_tab_enter="Press arrows, TAB or ENTER" --- 7 unchanged lines hidden (view full) --- 210msg_disk_info_help="Get detailed information on disk device(s)" 211msg_encrypt_disks="Encrypt Disks?" 212msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions" 213msg_error="Error" 214msg_force_4k_sectors="Force 4K Sectors?" 215msg_force_4k_sectors_help="Use gnop(8) to configure forced 4K sector alignment" 216msg_freebsd_installer="FreeBSD Installer" 217msg_geli_password="Enter a strong passphrase, used to protect your encryption keys. You will be required to enter this passphrase each time the system is booted" |
218msg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk" |
219msg_install="Install" 220msg_install_desc="Proceed with Installation" 221msg_install_help="Create ZFS boot pool with displayed options" |
222msg_invalid_boot_pool_size="Invalid boot pool size \`%s'" |
223msg_invalid_disk_argument="Invalid disk argument \`%s'" |
224msg_invalid_index_argument="Invalid index argument \`%s'" 225msg_invalid_swap_size="Invalid swap size \`%s'" 226msg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'" 227msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s" 228msg_last_chance_are_you_sure_color='\\ZrLast Chance!\\ZR Are you \\Z1sure\\Zn you want to \\Zr\\Z1destroy\\Zn\nthe current contents of the following disks:\n\n %s' 229msg_mirror_desc="Mirror - n-Way Mirroring" 230msg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage" 231msg_missing_disk_arguments="missing disk arguments" --- 387 unchanged lines hidden (view full) --- 619 620# zfs_create_diskpart $disk $index 621# 622# For each block device to be used in the zpool, rather than just create the 623# zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions 624# so we can have some real swap. This also provides wiggle room incase your 625# replacement drivers do not have the exact same sector counts. 626# |
627# NOTE: $swapsize and $bootsize should be defined by the calling function. 628# NOTE: Sets $bootpart and $targetpart for the calling function. |
629# 630zfs_create_diskpart() 631{ 632 local funcname=zfs_create_diskpart 633 local disk="$1" index="$2" |
634 635 # Check arguments 636 if [ ! "$disk" ]; then 637 f_dprintf "$funcname: NULL disk argument" 638 msg_error="$msg_error: $funcname" \ 639 f_show_err "$msg_null_disk_argument" 640 return $FAILURE 641 fi --- 30 unchanged lines hidden (view full) --- 672 esac 673 674 # 675 # Destroy whatever partition layout is currently on disk. 676 # NOTE: `-F' required to destroy if partitions still exist. 677 # NOTE: Failure is ok here, blank disk will have nothing to destroy. 678 # 679 f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" |
680 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 681 f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk 682 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk |
683 684 # Make doubly-sure backup GPT is destroyed |
685 f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk 686 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk |
687 |
688 # 689 # Enable boot pool if encryption is desired 690 # 691 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 |
692 693 # 694 # Lay down the desired type of partition scheme 695 # 696 local setsize mbrindex 697 case "$ZFSBOOT_PARTITION_SCHEME" in 698 ""|GPT) f_dprintf "$funcname: Creating GPT layout..." 699 # 700 # 1. Create GPT layout using labels 701 # |
702 f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk || |
703 return $FAILURE 704 705 # 706 # 2. Add small freebsd-boot partition labeled `boot#' 707 # 708 f_eval_catch $funcname gpart "$GPART_ADD_LABEL_WITH_SIZE" \ |
709 gptboot$index freebsd-boot 512k $disk || |
710 return $FAILURE 711 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ |
712 /boot/pmbr /boot/gptzfsboot 1 $disk || |
713 return $FAILURE 714 |
715 # NB: zpool will use the `zfs#' GPT labels |
716 bootpart=p2 targetpart=p2 |
717 [ ${swapsize:-0} -gt 0 ] && targetpart=p3 |
718 |
719 # 720 # Prepare boot pool if enabled (e.g., for geli(8)) 721 # 722 if [ "$ZFSBOOT_BOOT_POOL" ]; then |
723 bootpart=p2 targetpart=p3 |
724 [ ${swapsize:-0} -gt 0 ] && targetpart=p4 |
725 f_eval_catch $funcname gpart \ |
726 "$GPART_ADD_LABEL_WITH_SIZE" boot$index \ 727 freebsd-zfs ${bootsize}b $disk || |
728 return $FAILURE |
729 # Pedantically nuke any old labels 730 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 731 /dev/$disk$bootpart 732 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 733 # Pedantically detach targetpart for later 734 f_eval_catch -d $funcname geli \ 735 "$GELI_DETACH_F" \ 736 /dev/$disk$targetpart 737 fi |
738 fi 739 740 # |
741 # 3. Add freebsd-swap partition labeled `swap#' |
742 # 743 if [ ${swapsize:-0} -gt 0 ]; then |
744 f_eval_catch $funcname gpart \ |
745 "$GPART_ADD_LABEL_WITH_SIZE" swap$index \ 746 freebsd-swap ${swapsize}b $disk || |
747 return $FAILURE |
748 # Pedantically nuke any old labels on the swap 749 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 750 /dev/gpt/swap$index 751 # Update fstab(5) 752 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 753 /dev/gpt/swap$index none swap sw 0 0 \ 754 $BSDINSTALL_TMPETC/fstab || |
755 return $FAILURE 756 fi |
757 758 # |
759 # 4. Add freebsd-zfs partition labeled `zfs#' for zroot |
760 # |
761 f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \ 762 zfs$index freebsd-zfs $disk || return $FAILURE 763 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 764 /dev/$disk$targetpart |
765 ;; 766 767 MBR) f_dprintf "$funcname: Creating MBR layout..." 768 # 769 # 1. Create MBR layout (no labels) 770 # |
771 f_eval_catch $funcname gpart "$GPART_CREATE" mbr $disk || |
772 return $FAILURE 773 f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \ |
774 $disk || return $FAILURE |
775 776 # 777 # 2. Add freebsd slice with all available space 778 # |
779 f_eval_catch $funcname gpart "$GPART_ADD" freebsd $disk || |
780 return $FAILURE |
781 f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 $disk || |
782 return $FAILURE |
783 # Pedantically nuke any old labels 784 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 785 /dev/${disk}s1 786 # Pedantically nuke any old scheme 787 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" ${disk}s1 |
788 789 # 790 # 3. Write BSD scheme to the freebsd slice 791 # |
792 f_eval_catch $funcname gpart "$GPART_CREATE" BSD ${disk}s1 || |
793 return $FAILURE 794 |
795 # NB: zpool will use s1a (no labels) 796 bootpart=s1a targetpart=s1d mbrindex=4 |
797 |
798 # 799 # Always prepare a boot pool on MBR 800 # 801 ZFSBOOT_BOOT_POOL=1 802 f_eval_catch $funcname gpart \ 803 "$GPART_ADD_INDEX_WITH_SIZE" \ 804 1 freebsd-zfs ${bootsize}b ${disk}s1 || 805 return $FAILURE 806 # Pedantically nuke any old labels 807 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 808 /dev/$disk$bootpart |
809 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then |
810 # Pedantically detach targetpart for later 811 f_eval_catch -d $funcname geli \ 812 "$GELI_DETACH_F" \ 813 /dev/$disk$targetpart |
814 fi 815 816 # |
817 # 4. Add freebsd-swap partition |
818 # 819 if [ ${swapsize:-0} -gt 0 ]; then |
820 f_eval_catch $funcname gpart \ |
821 "$GPART_ADD_INDEX_WITH_SIZE" 2 \ 822 freebsd-swap ${swapsize}b ${disk}s1 || |
823 return $FAILURE |
824 # Pedantically nuke any old labels on the swap 825 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 826 /dev/${disk}s1b |
827 # Update fstab(5) 828 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ |
829 /dev/${disk}s1b none swap sw 0 0 \ 830 $BSDINSTALL_TMPETC/fstab || |
831 return $FAILURE 832 fi |
833 834 # 835 # 5. Add freebsd-zfs partition for zroot 836 # 837 f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \ 838 $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE 839 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 840 /dev/$disk$targetpart # Pedantic 841 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 842 /boot/zfsboot /dev/${disk}s1 count=1 || 843 return $FAILURE |
844 ;; 845 846 esac # $ZFSBOOT_PARTITION_SCHEME 847 848 return $SUCCESS 849} 850 851# zfs_create_boot $poolname $vdev_type $disks ... 852# 853# Creates boot pool and dataset layout. Returns error if something goes wrong. 854# Errors are printed to stderr for collection and display. 855# 856zfs_create_boot() 857{ 858 local funcname=zfs_create_boot |
859 local zroot_name="$1" 860 local zroot_vdevtype="$2" 861 local zroot_vdevs= # Calculated below 862 local boot_vdevs= # Used for geli(8) and/or MBR layouts 863 shift 2 # poolname vdev_type 864 local disks="$*" disk 865 local bootpart targetpart # Set by zfs_create_diskpart() below |
866 |
867 # |
868 # Pedantic checks; should never be seen |
869 # 870 if [ ! "$zroot_name" ]; then |
871 f_dprintf "$funcname: NULL poolname" 872 msg_error="$msg_error: $funcname" \ 873 f_show_err "$msg_null_poolname" 874 return $FAILURE 875 fi 876 if [ $# -lt 1 ]; then 877 f_dprintf "$funcname: missing disk arguments" 878 msg_error="$msg_error: $funcname" \ 879 f_show_err "$msg_missing_disk_arguments" 880 return $FAILURE 881 fi 882 f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \ |
883 "$zroot_name" "$zroot_vdevtype" |
884 |
885 # |
886 # Initialize fstab(5) |
887 # |
888 f_dprintf "$funcname: Initializing temporary fstab(5) file..." |
889 f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab || |
890 return $FAILURE 891 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 892 "# Device" Mountpoint FStype Options Dump "Pass#" \ |
893 $BSDINSTALL_TMPETC/fstab || return $FAILURE |
894 |
895 # |
896 # Expand SI units in desired sizes |
897 # 898 f_dprintf "$funcname: Expanding supplied size values..." 899 local swapsize bootsize |
900 if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then 901 f_dprintf "$funcname: Invalid swap size \`%s'" \ 902 "$ZFSBOOT_SWAP_SIZE" 903 f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE" 904 return $FAILURE 905 fi |
906 if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then 907 f_dprintf "$funcname: Invalid boot pool size \`%s'" \ 908 "$ZFSBOOT_BOOT_POOL_SIZE" 909 f_show_err "$msg_invalid_boot_pool_size" \ 910 "$ZFSBOOT_BOOT_POOL_SIZE" |
911 return $FAILURE 912 fi 913 f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \ 914 "$ZFSBOOT_SWAP_SIZE" "$swapsize" |
915 f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \ 916 "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize" |
917 |
918 # 919 # Prepare the disks and build pool device list(s) 920 # |
921 f_dprintf "$funcname: Preparing disk partitions for ZFS pool..." |
922 [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ] && 923 f_dprintf "$funcname: With 4k alignment using gnop(8)..." |
924 local n=0 |
925 for disk in $disks; do |
926 zfs_create_diskpart $disk $n || return $FAILURE |
927 # Now $bootpart and $targetpart are set (suffix for $disk) 928 929 # Forced 4k alignment support using Geom NOP (see gnop(8)) 930 if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then 931 if [ "$ZFSBOOT_BOOT_POOL" ]; then 932 boot_vdevs="$boot_vdevs $disk$bootpart.nop" 933 f_eval_catch $funcname gnop "$GNOP_CREATE" \ 934 $disk$bootpart || return $FAILURE 935 fi 936 # Don't gnop encrypted partition |
937 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then |
938 zroot_vdevs="$zroot_vdevs $disk$targetpart.eli" |
939 else |
940 zroot_vdevs="$zroot_vdevs $disk$targetpart.nop" 941 f_eval_catch $funcname gnop "$GNOP_CREATE" \ 942 $disk$targetpart || 943 return $FAILURE |
944 fi |
945 else 946 if [ "$ZFSBOOT_BOOT_POOL" ]; then 947 boot_vdevs="$boot_vdevs $disk$bootpart" 948 fi 949 zroot_vdevs="$zroot_vdevs $disk$targetpart" 950 fi |
951 |
952 n=$(( $n + 1 )) 953 done # disks 954 |
955 # |
956 # If we need/want a boot pool, create it |
957 # |
958 if [ "$ZFSBOOT_BOOT_POOL" ]; then 959 local bootpool_vdevtype= # Calculated below 960 local bootpool_options= # Calculated below 961 local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME" 962 local bootpool="$BSDINSTALL_CHROOT/$bootpool_name" 963 local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}" |
964 |
965 f_dprintf "$funcname: Setting up boot pool..." 966 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && 967 f_dprintf "$funcname: For encrypted root disk..." |
968 |
969 # Create parent directory for boot pool 970 f_eval_catch -d $funcname umount "$UMOUNT" /mnt |
971 f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \ |
972 $BSDINSTALL_CHROOT || return $FAILURE |
973 |
974 # Create mirror across the boot partition on all disks 975 [ $( set -- $boot_vdevs; echo $# ) -gt 1 ] && 976 bootpool_vdevtype=mirror |
977 |
978 bootpool_options="-o altroot=$BSDINSTALL_CHROOT" 979 bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f" |
980 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ |
981 "$bootpool_options" "$bootpool_name" \ 982 "$bootpool_vdevtype" "$boot_vdevs" || |
983 return $FAILURE 984 |
985 f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" || |
986 return $FAILURE 987 |
988 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 989 # Generate an encryption key using random(4) 990 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 991 /dev/random "$bootpool/$zroot_key" \ 992 "bs=4096 count=1" || return $FAILURE 993 else 994 # Clean up 995 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \ 996 "$bootpool_name" || return $FAILURE 997 f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 998 fi 999 1000 fi 1001 1002 # 1003 # Create the geli(8) GEOMS 1004 # 1005 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1006 # Prompt user for password (twice) |
1007 if ! msg_enter_new_password="$msg_geli_password" \ 1008 f_dialog_input_password 1009 then 1010 f_dprintf "$funcname: User cancelled" 1011 f_show_err "$msg_user_cancelled" 1012 return $FAILURE 1013 fi |
1014 1015 # Initialize geli(8) on each of the target partitions |
1016 for disk in $disks; do |
1017 f_dialog_info "$msg_geli_setup" \ 1018 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD |
1019 if ! echo "$pw_password" | f_eval_catch \ 1020 $funcname geli "$GELI_PASSWORD_INIT" \ 1021 "$bootpool/boot/$disk$targetpart.eli" \ 1022 AES-XTS "$bootpool/$zroot_key" \ 1023 $disk$targetpart |
1024 then 1025 f_interactive || f_die |
1026 unset pw_password # Sensitive info |
1027 return $FAILURE 1028 fi |
1029 if ! echo "$pw_password" | f_eval_catch \ 1030 $funcname geli "$GELI_ATTACH" \ 1031 "$bootpool/$zroot_key" $disk$targetpart |
1032 then 1033 f_interactive || f_die |
1034 unset pw_password # Sensitive info |
1035 return $FAILURE 1036 fi |
1037 done |
1038 unset pw_password # Sensitive info 1039 1040 # Clean up 1041 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" || 1042 return $FAILURE 1043 f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs |
1044 fi 1045 1046 # |
1047 # Create the ZFS root pool with desired type and disk devices |
1048 # |
1049 f_dprintf "$funcname: Creating root pool..." |
1050 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ |
1051 "-o altroot=$BSDINSTALL_CHROOT -m none -f" \ 1052 "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" || 1053 return $FAILURE |
1054 |
1055 # Customize the zroot a bit... |
1056 local option |
1057 f_dprintf "$funcname: Setting miscellaneous options on root pool..." 1058 for option in atime=off; do 1059 f_eval_catch $funcname zfs "$ZFS_SET" $option "$zroot_name" || 1060 return $FAILURE |
1061 done 1062 1063 # |
1064 # Create ZFS dataset layout within the new root pool |
1065 # 1066 f_dprintf "$funcname: Creating ZFS datasets..." 1067 echo "$ZFSBOOT_DATASETS" | while read dataset options; do 1068 # Skip blank lines and comments 1069 case "$dataset" in "#"*|"") continue; esac 1070 # Remove potential inline comments in options 1071 options="${options%%#*}" 1072 # Replace tabs with spaces 1073 f_replaceall "$options" " " " " options 1074 # Reduce contiguous runs of space to one single space 1075 oldoptions= 1076 while [ "$oldoptions" != "$options" ]; do 1077 oldoptions="$options" 1078 f_replaceall "$options" " " " " options 1079 done 1080 # Replace both commas and spaces with ` -o ' 1081 f_replaceall "$options" "[ ,]" " -o " options 1082 # Create the dataset with desired options |
1083 f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \ |
1084 "${options:+-o $options}" "$zroot_name$dataset" || |
1085 return $FAILURE 1086 done 1087 1088 # Touch up permissions on the tmp directories 1089 f_dprintf "$funcname: Modifying directory permissions..." 1090 local dir 1091 for dir in /tmp /var/tmp; do |
1092 f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \ |
1093 $BSDINSTALL_CHROOTDIR$dir || return $FAILURE |
1094 done 1095 1096 # Create symlink(s) |
1097 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1098 f_dprintf "$funcname: Creating /boot symlink for boot pool..." 1099 f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \ 1100 $BSDINSTALL_CHROOT/boot || return $FAILURE |
1101 fi 1102 1103 # Set bootfs property |
1104 local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" |
1105 f_dprintf "$funcname: Setting bootfs property..." |
1106 f_eval_catch $funcname zpool "$ZPOOL_SET" \ |
1107 "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" || 1108 return $FAILURE |
1109 1110 # Export the pool(s) 1111 f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..." |
1112 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" "$zroot_name" || |
1113 return $FAILURE |
1114 if [ "$ZFSBOOT_BOOT_POOL" ]; then |
1115 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \ |
1116 "$bootpool_name" || return $FAILURE |
1117 fi 1118 1119 # Destroy the gnop devices (if enabled) 1120 for disk in ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:+$disks}; do |
1121 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1122 f_eval_catch -d $funcname gnop "$GNOP_DESTROY" \ 1123 $disk$bootpart.nop |
1124 fi |
1125 if [ ! "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1126 f_eval_catch -d $funcname gnop "$GNOP_DESTROY" \ 1127 $disk$targetpart.nop 1128 fi |
1129 done 1130 |
1131 # MBR boot loader touch-up |
1132 if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1133 f_dprintf "$funcname: Updating MBR boot loader on disks..." |
1134 # Stick the ZFS boot loader in the "convienient hole" after 1135 # the ZFS internal metadata 1136 for disk in $disks; do |
1137 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ |
1138 /boot/zfsboot /dev/$disk$bootpart \ |
1139 "skip=1 seek=1024" || return $FAILURE 1140 done 1141 fi 1142 1143 # Re-import the ZFS pool(s) 1144 f_dprintf "$funcname: Re-importing ZFS pool(s)..." 1145 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ |
1146 "-o altroot=\"$BSDINSTALL_CHROOT\"" "$zroot_name" || |
1147 return $FAILURE |
1148 if [ "$ZFSBOOT_BOOT_POOL" ]; then |
1149 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ |
1150 "-o altroot=\"$BSDINSTALL_CHROOT\"" \ 1151 "$bootpool_name" || return $FAILURE |
1152 fi 1153 1154 # While this is apparently not needed, it seems to help MBR |
1155 f_dprintf "$funcname: Configuring zpool.cache for zroot..." 1156 f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs || |
1157 return $FAILURE 1158 f_eval_catch $funcname zpool "$ZPOOL_SET" \ |
1159 "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 1160 "$zroot_name" || return $FAILURE |
1161 1162 # Last, but not least... required lines for rc.conf(5)/loader.conf(5) 1163 # NOTE: We later concatenate these into their destination 1164 f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \ 1165 "$funcname" 1166 f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \ |
1167 $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE |
1168 f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_load=\"YES\"' \ |
1169 $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE |
1170 |
1171 # We're all done unless we should go on for boot pool 1172 [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS |
1173 |
1174 # Set cachefile for boot pool so it auto-imports at system start 1175 f_dprintf "$funcname: Configuring zpool.cache for boot pool..." 1176 f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1177 "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 1178 "$bootpool_name" || return $FAILURE 1179 |
1180 # Some additional geli(8) requirements for loader.conf(5) 1181 for option in \ |
1182 'zpool_cache_load=\"YES\"' \ 1183 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \ 1184 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \ |
1185 ; do |
1186 f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \ 1187 $BSDINSTALL_TMPBOOT/loader.conf.zfs || |
1188 return $FAILURE 1189 done |
1190 f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \ 1191 "\"zfs:$zroot_name/$zroot_bootfs\"" \ 1192 $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE |
1193 |
1194 # We're all done unless we should go on to do encryption 1195 [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS 1196 |
1197 # 1198 # Configure geli(8)-based encryption 1199 # 1200 f_dprintf "$funcname: Configuring disk encryption..." 1201 f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \ |
1202 $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE |
1203 f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \ |
1204 $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE |
1205 for disk in $disks; do |
1206 f_eval_catch $funcname printf "$PRINTF_CONF" \ |
1207 geli_%s_keyfile0_load "$disk$targetpart YES" \ 1208 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || |
1209 return $FAILURE 1210 f_eval_catch $funcname printf "$PRINTF_CONF" \ 1211 geli_%s_keyfile0_type \ |
1212 "$disk$targetpart $disk$targetpart:geli_keyfile0" \ 1213 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || |
1214 return $FAILURE 1215 f_eval_catch $funcname printf "$PRINTF_CONF" \ 1216 geli_%s_keyfile0_name \ |
1217 "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \ 1218 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || |
1219 return $FAILURE 1220 done 1221 1222 return $SUCCESS 1223} 1224 1225# dialog_menu_diskinfo 1226# --- 32 unchanged lines hidden (view full) --- 1259# User may have specifically requested ZFS-related operations be interactive 1260! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE 1261 1262# 1263# Debugging 1264# 1265f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT" 1266f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC" |
1267f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" |
1268 1269# 1270# Loop over the main menu until we've accomplished what we came here to do 1271# 1272while :; do 1273 if ! f_interactive; then 1274 retval=$DIALOG_OK 1275 mtag=">>> $msg_install" --- 21 unchanged lines hidden (view full) --- 1297 1298 # Validate vdev type against number of disks selected/scripted 1299 # (also validates that ZFSBOOT_DISKS are real [probed] disks) 1300 # NB: dialog_menu_layout supports running non-interactively 1301 dialog_menu_layout || continue 1302 1303 # Make sure each disk will be at least 50% ZFS 1304 if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize && |
1305 f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize |
1306 then 1307 minsize=$swapsize teeny_disks= |
1308 [ "$ZFSBOOT_BOOT_POOL" ] && 1309 minsize=$(( $minsize + $bootsize )) |
1310 for disk in $ZFSBOOT_DISKS; do 1311 device_$disk get capacity disksize || continue 1312 disksize=$(( $disksize - $minsize )) 1313 [ $disksize -lt $minsize ] && 1314 teeny_disks="$teeny_disks $disk" 1315 done 1316 if [ "$teeny_disks" ]; then |
1317 f_dprintf "swapsize=[%s] bootsize[%s] %s" \ |
1318 "$ZFSBOOT_SWAP_SIZE" \ |
1319 "$ZFSBOOT_BOOT_POOL_SIZE" \ 1320 "minsize=[$minsize]" |
1321 f_dprintf "These disks are too small: %s" \ 1322 "$teeny_disks" 1323 f_show_err "$msg_these_disks_are_too_small" \ 1324 "$ZFSBOOT_SWAP_SIZE" \ |
1325 "$ZFSBOOT_BOOT_POOL_SIZE" \ |
1326 "$teeny_disks" 1327 continue 1328 fi 1329 fi 1330 1331 # 1332 # Last Chance! 1333 # --- 38 unchanged lines hidden (view full) --- 1372 ZFSBOOT_GNOP_4K_FORCE_ALIGN=1 1373 fi 1374 ;; 1375 ?" $msg_encrypt_disks") 1376 # Toggle the variable referenced both by the menu and later 1377 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1378 ZFSBOOT_GELI_ENCRYPTION= 1379 else |
1380 ZFSBOOT_GNOP_4K_FORCE_ALIGN=1 |
1381 ZFSBOOT_GELI_ENCRYPTION=1 1382 fi 1383 ;; 1384 ?" $msg_partition_scheme") 1385 # Toggle between GPT and MBR 1386 if [ "$ZFSBOOT_PARTITION_SCHEME" = GPT ]; then 1387 ZFSBOOT_PARTITION_SCHEME=MBR 1388 else 1389 ZFSBOOT_PARTITION_SCHEME=GPT 1390 fi 1391 ;; 1392 ?" $msg_swap_size") 1393 # Prompt the user to input/change the swap size for each disk 1394 f_dialog_input input \ 1395 "$msg_please_enter_amount_of_swap_space" \ 1396 "$ZFSBOOT_SWAP_SIZE" && |
1397 ZFSBOOT_SWAP_SIZE="${input:-0}" |
1398 ;; 1399 esac 1400done 1401 1402return $SUCCESS 1403 1404################################################################################ 1405# END 1406################################################################################ |