Deleted Added
sdiff udiff text old ( 259396 ) new ( 259621 )
full compact
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 259396 2013-12-14 20:55:53Z gjb $
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#
70: ${ZFSBOOT_GELI_ENCRYPTION=}
71
72#
73# Default name the unencrypted pool when using geli(8) to encrypt the drives
74#
75: ${ZFSBOOT_GELI_POOL_NAME:=bootpool}
76
77#
78# Default size for the unencrypted boot pool when using geli(8)
79#
80: ${ZFSBOOT_GELI_BOOT_SIZE:=2g}
81
82#
83# Default path to the geli(8) keyfile used in drive encryption
84#
85: ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key}
86
87#
88# Default disks to use (always empty unless being scripted)
89#
90: ${ZFSBOOT_DISKS:=}
91
92#
93# Default partitioning scheme to use on disks
94#
95: ${ZFSBOOT_PARTITION_SCHEME:=GPT}

--- 31 unchanged lines hidden (view full) ---

127
128 # Source tree (compressed)
129 /usr/src compression=lz4,exec=off,setuid=off
130
131 # Create /var and friends
132 /var mountpoint=/var
133 /var/crash compression=lz4,exec=off,setuid=off
134 /var/log compression=lz4,exec=off,setuid=off
135 /var/tmp compression=lz4,exec=on,setuid=off
136" # END-QUOTE
137
138#
139# If interactive and the user has not explicitly chosen a vdev type or disks,
140# make the user confirm scripted/default choices when proceeding to install.
141#
142: ${ZFSBOOT_CONFIRM_LAYOUT:=1}

--- 7 unchanged lines hidden (view full) ---

150
151#
152# Command strings for various tasks
153#
154CHMOD_MODE='chmod %s "%s"'
155DD_WITH_OPTIONS='dd if="%s" of="%s" %s'
156ECHO_APPEND='echo "%s" >> "%s"'
157GELI_ATTACH='geli attach -j - -k "%s" "%s"'
158GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"'
159GNOP_CREATE='gnop create -S 4096 "%s"'
160GPART_ADD='gpart add -t %s "%s"'
161GPART_ADD_INDEX='gpart add -i %s -t %s "%s"'
162GPART_ADD_INDEX_WITH_SIZE='gpart add -i %s -t %s -s %s "%s"'
163GPART_ADD_LABEL='gpart add -l %s -t %s "%s"'
164GPART_ADD_LABEL_WITH_SIZE='gpart add -l %s -t %s -s %s "%s"'
165GPART_BOOTCODE='gpart bootcode -b "%s" "%s"'
166GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"'
167GPART_CREATE='gpart create -s %s "%s"'
168GPART_SET_ACTIVE='gpart set -a active -i %s "%s"'
169LN_SF='ln -sf "%s" "%s"'
170MKDIR_P='mkdir -p "%s"'
171MOUNT_TYPE='mount -t %s "%s" "%s"'
172PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\""
173PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"'
174SHELL_TRUNCATE=':> "%s"'
175ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"'
176ZFS_SET='zfs set "%s" "%s"'
177ZFS_UNMOUNT='zfs unmount "%s"'
178ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s'
179ZPOOL_EXPORT='zpool export "%s"'
180ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"'
181ZPOOL_SET='zpool set %s "%s"'
182
183#
184# Strings that should be moved to an i18n file and loaded with f_include_lang()
185#
186hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER"
187hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER"
188hline_arrows_tab_enter="Press arrows, TAB or ENTER"

--- 7 unchanged lines hidden (view full) ---

196msg_disk_info_help="Get detailed information on disk device(s)"
197msg_encrypt_disks="Encrypt Disks?"
198msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions"
199msg_error="Error"
200msg_force_4k_sectors="Force 4K Sectors?"
201msg_force_4k_sectors_help="Use gnop(8) to configure forced 4K sector alignment"
202msg_freebsd_installer="FreeBSD Installer"
203msg_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"
204msg_geli_setup="Initializing encryption on the selected disks, this will take several seconds per disk"
205msg_install="Install"
206msg_install_desc="Proceed with Installation"
207msg_install_help="Create ZFS boot pool with displayed options"
208msg_invalid_disk_argument="Invalid disk argument \`%s'"
209msg_invalid_geli_boot_size="Invalid geli(8) boot size \`%s'"
210msg_invalid_index_argument="Invalid index argument \`%s'"
211msg_invalid_swap_size="Invalid swap size \`%s'"
212msg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'"
213msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s"
214msg_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'
215msg_mirror_desc="Mirror - n-Way Mirroring"
216msg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage"
217msg_missing_disk_arguments="missing disk arguments"

--- 387 unchanged lines hidden (view full) ---

605
606# zfs_create_diskpart $disk $index
607#
608# For each block device to be used in the zpool, rather than just create the
609# zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions
610# so we can have some real swap. This also provides wiggle room incase your
611# replacement drivers do not have the exact same sector counts.
612#
613# NOTE: The MBR layout is more complicated (GPT is preferred).
614#
615zfs_create_diskpart()
616{
617 local funcname=zfs_create_diskpart
618 local disk="$1" index="$2"
619 local disksize partsize
620
621 # Check arguments
622 if [ ! "$disk" ]; then
623 f_dprintf "$funcname: NULL disk argument"
624 msg_error="$msg_error: $funcname" \
625 f_show_err "$msg_null_disk_argument"
626 return $FAILURE
627 fi

--- 30 unchanged lines hidden (view full) ---

658 esac
659
660 #
661 # Destroy whatever partition layout is currently on disk.
662 # NOTE: `-F' required to destroy if partitions still exist.
663 # NOTE: Failure is ok here, blank disk will have nothing to destroy.
664 #
665 f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk"
666 f_quietly gpart destroy -F $disk
667 f_quietly graid destroy $disk
668 f_quietly zpool labelclear -f /dev/$disk # Kill it with fire
669
670 # Make doubly-sure backup GPT is destroyed
671 f_quietly gpart create -s gpt $disk
672 f_quietly gpart destroy -F $disk
673
674 # Calculate partition size given desired amount of swap
675 f_dprintf "$funcname: Getting disk capactiy for \`%s'" "$disk"
676 if ! device_$disk get capacity disksize; then
677 f_dprintf "$funcname: Unable to get disk capacity of \`%s'" \
678 "$disk"
679 msg_error="$msg_error: $funcname" \
680 f_show_err "$msg_unable_to_get_disk_capacity" "$disk"
681 return $FAILURE
682 fi
683 partsize=$(( $disksize - $swapsize ))
684 f_dprintf "$funcname: disksize=[%s] partsize=[%s]" \
685 "$disksize" "$partsize"
686
687 #
688 # Lay down the desired type of partition scheme
689 #
690 local setsize mbrindex
691 case "$ZFSBOOT_PARTITION_SCHEME" in
692 ""|GPT) f_dprintf "$funcname: Creating GPT layout..."
693 #
694 # 1. Create GPT layout using labels
695 #
696 f_eval_catch $funcname gpart "$GPART_CREATE" gpt \$disk ||
697 return $FAILURE
698
699 #
700 # 2. Add small freebsd-boot partition labeled `boot#'
701 #
702 f_eval_catch $funcname gpart "$GPART_ADD_LABEL_WITH_SIZE" \
703 gptboot\$index freebsd-boot 512k \$disk ||
704 return $FAILURE
705 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \
706 /boot/pmbr /boot/gptzfsboot 1 \$disk ||
707 return $FAILURE
708
709 # zpool will use the `zfs#' GPT labels
710 bootpart=p2 targetpart=p2
711
712 # Change things around if we are using geli(8)
713 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
714 bootpart=p2 targetpart=p3
715 partsize=$(( $partsize - $gelisize ))
716 f_dprintf "$funcname: gelisize=[%s]" \
717 "gelisize=[$gelisize]"
718 f_eval_catch $funcname gpart \
719 "$GPART_ADD_LABEL_WITH_SIZE" boot\$index \
720 freebsd-zfs \${gelisize}b \$disk ||
721 return $FAILURE
722
723 # Pedantically nuke any old labels, stop geli
724 f_quietly zpool labelclear -f "/dev/$disk$bootpart"
725 f_quietly geli detach -f "/dev/$disk$targetpart"
726 fi
727
728 #
729 # 3. Add freebsd-zfs partition labeled `zfs#' for zpool
730 # NOTE: Using above calculated partsize to leave room for swap.
731 #
732 if [ ${swapsize:-0} -gt 0 ]; then
733 f_dprintf "$funcname: partsize=[%s]" \
734 "partsize=[$partsize]"
735 f_eval_catch $funcname gpart \
736 "$GPART_ADD_LABEL_WITH_SIZE" zfs\$index \
737 freebsd-zfs \${partsize}b \$disk ||
738 return $FAILURE
739 else
740 f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
741 zfs\$index freebsd-zfs \$disk ||
742 return $FAILURE
743 fi
744 f_quietly zpool labelclear -f "/dev/$disk$targetpart"
745
746 #
747 # 4. Add freebsd-swap partition labeled `swap#'
748 #
749 if [ $swapsize -gt 0 ]; then
750 f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
751 swap\$index freebsd-swap \$disk ||
752 return $FAILURE
753 # Update fstab(5)
754 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
755 /dev/gpt/swap\$index none swap sw 0 0 \
756 \$BSDINSTALL_TMPETC/fstab ||
757 return $FAILURE
758 fi
759 ;;
760
761 MBR) f_dprintf "$funcname: Creating MBR layout..."
762 #
763 # 1. Create MBR layout (no labels)
764 #
765 f_eval_catch $funcname gpart "$GPART_CREATE" mbr \$disk ||
766 return $FAILURE
767 f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \
768 \$disk || return $FAILURE
769
770 #
771 # 2. Add freebsd slice with all available space
772 #
773 f_eval_catch $funcname gpart "$GPART_ADD" freebsd \$disk ||
774 return $FAILURE
775 f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 \$disk ||
776 return $FAILURE
777 f_quietly zpool labelclear -f /dev/${disk}s1 # Pedantic
778 f_quietly gpart destroy -F ${disk}s1 # Pedantic
779
780 #
781 # 3. Write BSD scheme to the freebsd slice
782 #
783 f_eval_catch $funcname gpart "$GPART_CREATE" BSD \${disk}s1 ||
784 return $FAILURE
785
786 # zpool will use s1a (no labels)
787 bootpart=s1a targetpart=s1a mbrindex=1
788
789 # Change things around if we are using geli(8)
790 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
791 bootpart=s1a targetpart=s1d
792 partsize=$(( $partsize - $gelisize ))
793 mbrindex=4 # If this is s1a then make the zpool s1d
794 f_dprintf "$funcname: mbrindex=[%s] gelisize=[%s]" \
795 "$mbrindex" "$gelisize"
796 f_eval_catch $funcname gpart \
797 "$GPART_ADD_INDEX_WITH_SIZE" \
798 1 freebsd-zfs \${gelisize}b \${disk}s1 ||
799 return $FAILURE
800 # Pedantically nuke any old labels, stop geli
801 f_quietly zpool labelclear -f "/dev/$disk$bootpart"
802 f_quietly geli detach -f "/dev/$disk$targetpart"
803 fi
804
805 #
806 # 4. Partition the BSD slice for ZFS
807 # NOTE: Using above calculated partsize to leave room for swap.
808 #
809 if [ ${swapsize:-0} -gt 0 ]; then
810 f_dprintf "$funcname: mbrindex=[%s] partsize=[%s]" \
811 "$mbrindex" "$partsize"
812 f_eval_catch $funcname gpart \
813 "$GPART_ADD_INDEX_WITH_SIZE" \
814 \$mbrindex freebsd-zfs \${partsize}b \
815 \${disk}s1 || return $FAILURE
816 else
817 f_dprintf "$funcname: mbrindex=[%s]" "$mbrindex"
818 f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
819 \$mbrindex freebsd-zfs \${disk}s1 ||
820 return $FAILURE
821 fi
822 f_quietly zpool labelclear -f /dev/$disk$targetpart # Pedantic
823
824 #
825 # 5. Add freebsd-swap partition
826 #
827 if [ $swapsize -gt 0 ]; then
828 f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
829 2 freebsd-swap \${disk}s1 ||
830 return $FAILURE
831 # Update fstab(5)
832 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
833 /dev/\${disk}s1b none swap sw 0 0 \
834 \$BSDINSTALL_TMPETC/fstab ||
835 return $FAILURE
836 fi
837 ;;
838
839 esac # $ZFSBOOT_PARTITION_SCHEME
840
841 return $SUCCESS
842}
843
844# zfs_create_boot $poolname $vdev_type $disks ...
845#
846# Creates boot pool and dataset layout. Returns error if something goes wrong.
847# Errors are printed to stderr for collection and display.
848#
849zfs_create_boot()
850{
851 local funcname=zfs_create_boot
852 local poolname="$1" vdev_type="$2"
853 local bootpart targetpart
854
855 shift 2 # name vdev_type
856
857 # We may need this later
858 local disks="$*"
859
860 # Pedantic checks; should never be seen
861 if [ ! "$poolname" ]; then
862 f_dprintf "$funcname: NULL poolname"
863 msg_error="$msg_error: $funcname" \
864 f_show_err "$msg_null_poolname"
865 return $FAILURE
866 fi
867 if [ $# -lt 1 ]; then
868 f_dprintf "$funcname: missing disk arguments"
869 msg_error="$msg_error: $funcname" \
870 f_show_err "$msg_missing_disk_arguments"
871 return $FAILURE
872 fi
873 f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \
874 "$poolname" "$vdev_type"
875
876 # Initialize fstab(5)
877 f_dprintf "$funcname: Initializing temporary fstab(5) file..."
878 f_eval_catch $funcname sh \
879 "$SHELL_TRUNCATE" \$BSDINSTALL_TMPETC/fstab ||
880 return $FAILURE
881 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
882 "# Device" Mountpoint FStype Options Dump "Pass#" \
883 \$BSDINSTALL_TMPETC/fstab || return $FAILURE
884
885 # Expand SI units in desired sizes
886 f_dprintf "$funcname: Expanding supplied swapsize/gelisize values..."
887 local swapsize gelisize
888 if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then
889 f_dprintf "$funcname: Invalid swap size \`%s'" \
890 "$ZFSBOOT_SWAP_SIZE"
891 f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE"
892 return $FAILURE
893 fi
894 if ! f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize; then
895 f_dprintf "$funcname: Invalid geli(8) boot size \`%s'" \
896 "$ZFSBOOT_GELI_BOOT_SIZE"
897 f_show_err "$msg_invalid_geli_boot_size" \
898 "$ZFSBOOT_GELI_BOOT_SIZE"
899 return $FAILURE
900 fi
901 f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \
902 "$ZFSBOOT_SWAP_SIZE" "$swapsize"
903 f_dprintf "$funcname: ZFSBOOT_GELI_BOOT_SIZE=[%s] gelisize=[%s]" \
904 "$ZFSBOOT_GELI_BOOT_SIZE" "$gelisize"
905
906 # Prepare the disks
907 f_dprintf "$funcname: Preparing disk partitions for ZFS pool..."
908 local n=0
909 for disk in $*; do
910 zfs_create_diskpart $disk $n || return $FAILURE
911 n=$(( $n + 1 ))
912 done
913
914 # MBR boot loader hack part 1
915 # We have to do this early because geli gets in the way later
916 if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then
917 f_dprintf "$funcname: Copying MBR boot loader to disks..."
918 f_dprintf "$funcname: disks=[%s]" "$disks"
919 for disk in $disks; do
920 f_dprintf "$funcname: disk=[%s]" "$disk"
921 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
922 /boot/zfsboot /dev/\${disk}s1 count=1 ||
923 return $FAILURE
924 done
925 fi
926
927 # Forced 4k alignment support provided by Geom NOP (see gnop(8))
928 local unenc_list=
929 if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then
930 local part="$targetpart" new_list=
931
932 # We don't gnop the encrypted partition because geli will do
933 # this for us gnop the unencrypted disk
934 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && part="$bootpart"
935
936 f_dprintf "$funcname: Applying 4k alignment with gnop(8)..."
937 f_dprintf "$funcname: *=[%s]" "$*"
938 for disk in $*; do
939 f_dprintf "$funcname: disk=[%s] part=[%s]" \
940 "$disk" "$part"
941 f_eval_catch $funcname gnop "$GNOP_CREATE" \
942 \$disk\$part || return $FAILURE
943 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
944 unenc_list="$unenc_list $disk$part.nop"
945 else
946 new_list="$new_list $disk$targetpart.nop"
947 fi
948 done
949 set -- $new_list
950 else
951 local new_list=
952 for disk in $*; do
953 new_list="$new_list $disk$targetpart"
954 [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
955 unenc_list="$unenc_list $disk$bootpart"
956 done
957 set -- $new_list
958 fi
959
960 #
961 # If encryption is enabled, we need to create the GEOMs
962 #
963 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
964 local bootvdev= options=
965 local geli_pool="$BSDINSTALL_CHROOT/$ZFSBOOT_GELI_POOL_NAME"
966 local key="$ZFSBOOT_GELI_KEY_FILE"
967
968 f_dprintf "$funcname: Setting up disk encryption..."
969
970 # Create the parent directories for our unencrypted pool
971 f_quietly umount /mnt
972 f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \
973 \$BSDINSTALL_CHROOT || return $FAILURE
974
975 # Create mirror across the unencrypted partition on all disks
976 [ $( set -- $unenc_list; echo $# ) -gt 1 ] && bootvdev=mirror
977
978 f_dprintf "$funcname: %s %s %s" \
979 "ZFSBOOT_GELI_POOL_NAME=[$ZFSBOOT_GELI_POOL_NAME]" \
980 "bootvdev=[$bootvdev]" "unenc_list=[$unenc_list]"
981 options="-o altroot=\"\$BSDINSTALL_CHROOT\""
982 options="$options -m \"/\$ZFSBOOT_GELI_POOL_NAME\""
983 options="$options -f"
984 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
985 "$options" \$ZFSBOOT_GELI_POOL_NAME \$bootvdev \
986 \$unenc_list || return $FAILURE
987
988 f_dprintf "$funcname: geli_pool=[%s]" "$geli_pool"
989 f_eval_catch $funcname mkdir "$MKDIR_P" \$geli_pool/boot ||
990 return $FAILURE
991
992 # Generate an encryption key using random(4)
993 f_dprintf "$funcname: key=[%s]" "$key"
994 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
995 /dev/random \$geli_pool/\$key "bs=4096 count=1" ||
996 return $FAILURE
997
998 # Create the geli(8) GEOMS
999 local geli_list
1000 if ! msg_enter_new_password="$msg_geli_password" \
1001 f_dialog_input_password
1002 then
1003 f_dprintf "$funcname: User cancelled"
1004 f_show_err "$msg_user_cancelled"
1005 return $FAILURE
1006 fi
1007 f_dprintf "$funcname: disks=[%s]" "$disks"
1008 for disk in $disks; do
1009 f_dprintf "$funcname: disk=[%s] targetpart=[%s]" \
1010 "$disk" "$targetpart"
1011 f_dialog_info "$msg_geli_setup" \
1012 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
1013 if ! echo "$pw_password" | f_eval_catch $funcname \
1014 geli "$GELI_PASSWORD_INIT" \
1015 \$geli_pool/boot/\$disk\$targetpart.eli \
1016 AES-XTS \$geli_pool/\$key \$disk\$targetpart
1017 then
1018 f_interactive || f_die
1019 return $FAILURE
1020 fi
1021 if ! echo "$pw_password" | f_eval_catch $funcname \
1022 geli "$GELI_ATTACH" \$geli_pool/\$key \
1023 \$disk\$targetpart
1024 then
1025 f_interactive || f_die
1026 return $FAILURE
1027 fi
1028 geli_list="$geli_list $disk$targetpart.eli"
1029 done
1030 set -- $geli_list
1031 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \
1032 \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
1033 f_quietly umount /mnt # done with tmpfs
1034 fi
1035
1036 #
1037 # Create the ZFS pool with desired type and disk devices
1038 #
1039 local vdevs="$*"
1040 f_dprintf "$funcname: Creating boot pool..."
1041 f_dprintf "poolname=[%s] vdev_type=[%s] vdevs=[%s]" \
1042 "$poolname" "$vdev_type" "$vdevs"
1043 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
1044 "-o altroot=\"\$BSDINSTALL_CHROOT\" -m none -f" \
1045 \$poolname \$vdev_type \$vdevs
1046
1047 # Customize the zpool a bit...
1048 local option
1049 f_dprintf "$funcname: Setting miscellaneous options on boot pool..."
1050 for option in checksum=fletcher4 atime=off; do
1051 f_dprintf "$funcname: option=[%s]" "$option"
1052 f_eval_catch $funcname zfs "$ZFS_SET" \$option \$poolname ||
1053 return $FAILURE
1054 done
1055
1056 #
1057 # Create ZFS dataset layout within the new boot pool
1058 #
1059 f_dprintf "$funcname: Creating ZFS datasets..."
1060 echo "$ZFSBOOT_DATASETS" | while read dataset options; do
1061 # Skip blank lines and comments
1062 case "$dataset" in "#"*|"") continue; esac
1063 # Remove potential inline comments in options
1064 options="${options%%#*}"
1065 # Replace tabs with spaces
1066 f_replaceall "$options" " " " " options
1067 # Reduce contiguous runs of space to one single space
1068 oldoptions=
1069 while [ "$oldoptions" != "$options" ]; do
1070 oldoptions="$options"
1071 f_replaceall "$options" " " " " options
1072 done
1073 # Replace both commas and spaces with ` -o '
1074 f_replaceall "$options" "[ ,]" " -o " options
1075 # Create the dataset with desired options
1076 f_dprintf "$funcname: dataset=[%s] options=[%s]" \
1077 "$dataset" "$options"
1078 f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \
1079 "\${options:+-o \$options}" \$poolname\$dataset ||
1080 return $FAILURE
1081 done
1082
1083 # Touch up permissions on the tmp directories
1084 f_dprintf "$funcname: Modifying directory permissions..."
1085 local dir
1086 for dir in /tmp /var/tmp; do
1087 f_dprintf "$funcname: dir=[%s]" "$dir"
1088 f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \
1089 \$BSDINSTALL_CHROOTDIR\$dir || return $FAILURE
1090 done
1091
1092 # Create symlink(s)
1093 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1094 f_dprintf "$funcname: Creating /boot symlink for GELI..."
1095 f_eval_catch $funcname ln "$LN_SF" \
1096 \$ZFSBOOT_GELI_POOL_NAME/boot \
1097 \$BSDINSTALL_CHROOT/boot || return $FAILURE
1098 fi
1099
1100 # Set bootfs property
1101 f_dprintf "$funcname: Setting bootfs property..."
1102 f_dprintf "$funcname: %s %s" \
1103 "ZFSBOOT_BEROOT_NAME=[$ZFSBOOT_BEROOT_NAME]" \
1104 "ZFSBOOT_BOOTFS_NAME=[$ZFSBOOT_BOOTFS_NAME]"
1105 f_eval_catch $funcname zpool "$ZPOOL_SET" \
1106 bootfs=\"\$poolname/\$ZFSBOOT_BEROOT_NAME/\$ZFSBOOT_BOOTFS_NAME\" \
1107 \$poolname || return $FAILURE
1108
1109 # Export the pool(s)
1110 f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..."
1111 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \$poolname ||
1112 return $FAILURE
1113 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1114 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \
1115 \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
1116 fi
1117
1118 # Destroy the gnop devices (if enabled)
1119 for disk in ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:+$disks}; do
1120 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1121 f_quietly gnop destroy $disk$bootpart.nop
1122 else
1123 f_quietly gnop destroy $disk$targetpart.nop
1124 fi
1125 done
1126
1127 # MBR boot loader hack part 2
1128 if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then
1129 f_dprintf "$funcname: Updating MBR boot loader on disks..."
1130 f_dprintf "$funcname: disks=[%s]"
1131 # Stick the ZFS boot loader in the "convienient hole" after
1132 # the ZFS internal metadata
1133 for disk in $disks; do
1134 f_dprintf "$funcname: disk=[%s] bootpart=[%s]" \
1135 "$disk" "$bootpart"
1136 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
1137 /boot/zfsboot /dev/\$disk\$bootpart \
1138 "skip=1 seek=1024" || return $FAILURE
1139 done
1140 fi
1141
1142 # Re-import the ZFS pool(s)
1143 f_dprintf "$funcname: Re-importing ZFS pool(s)..."
1144 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
1145 "-o altroot=\"\$BSDINSTALL_CHROOT\"" \$poolname ||
1146 return $FAILURE
1147 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1148 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
1149 "-o altroot=\"\$BSDINSTALL_CHROOT\"" \
1150 \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
1151 fi
1152
1153 # While this is apparently not needed, it seems to help MBR
1154 f_dprintf "$funcname: Configuring zpool.cache..."
1155 f_eval_catch $funcname mkdir "$MKDIR_P" \$BSDINSTALL_CHROOT/boot/zfs ||
1156 return $FAILURE
1157 f_eval_catch $funcname zpool "$ZPOOL_SET" \
1158 cachefile=\"\$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\" \
1159 \$poolname || return $FAILURE
1160
1161 # Last, but not least... required lines for rc.conf(5)/loader.conf(5)
1162 # NOTE: We later concatenate these into their destination
1163 f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \
1164 "$funcname"
1165 f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \
1166 \$BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE
1167 f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_load=\"YES\"' \
1168 \$BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
1169
1170 # We're all done unless we should go on to do encryption
1171 [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS
1172
1173 # Some additional geli(8) requirements for loader.conf(5)
1174 for option in \
1175 zpool_cache_load=\"YES\" \
1176 zpool_cache_type=\"/boot/zfs/zpool.cache\" \
1177 zpool_cache_name=\"/boot/zfs/zpool.cache\" \
1178 ; do
1179 f_eval_catch $funcname echo "$ECHO_APPEND" \$option \
1180 \$BSDINSTALL_TMPBOOT/loader.conf.zfs ||
1181 return $FAILURE
1182 done
1183
1184 #
1185 # Configure geli(8)-based encryption
1186 #
1187 f_dprintf "$funcname: Configuring disk encryption..."
1188 f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \
1189 \$BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
1190 f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \
1191 \$BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
1192 f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \
1193 '"zfs:$poolname/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME"' \
1194 \$BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
1195 f_dprintf "$funcname: disks=[%s]" "$disks"
1196 for disk in $disks; do
1197 f_dprintf "$funcname: %s %s %s" \
1198 "disk=[$disk]" "targetpart=[$targetpart]" \
1199 "ZFSBOOT_GELI_KEY_FILE=[$ZFSBOOT_GELI_KEY_FILE]"
1200 f_eval_catch $funcname printf "$PRINTF_CONF" \
1201 geli_%s_keyfile0_load '"$disk$targetpart" YES' \
1202 \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
1203 return $FAILURE
1204 f_eval_catch $funcname printf "$PRINTF_CONF" \
1205 geli_%s_keyfile0_type \
1206 '"$disk$targetpart" "$disk$targetpart:geli_keyfile0"' \
1207 \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
1208 return $FAILURE
1209 f_eval_catch $funcname printf "$PRINTF_CONF" \
1210 geli_%s_keyfile0_name \
1211 '"$disk$targetpart" "$ZFSBOOT_GELI_KEY_FILE"' \
1212 \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
1213 return $FAILURE
1214 done
1215
1216 return $SUCCESS
1217}
1218
1219# dialog_menu_diskinfo
1220#

--- 32 unchanged lines hidden (view full) ---

1253# User may have specifically requested ZFS-related operations be interactive
1254! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE
1255
1256#
1257# Debugging
1258#
1259f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT"
1260f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC"
1261f_dprintf "PRINTF_FSTAB=[%s]" "$PRINTF_FSTAB"
1262
1263#
1264# Loop over the main menu until we've accomplished what we came here to do
1265#
1266while :; do
1267 if ! f_interactive; then
1268 retval=$DIALOG_OK
1269 mtag=">>> $msg_install"

--- 21 unchanged lines hidden (view full) ---

1291
1292 # Validate vdev type against number of disks selected/scripted
1293 # (also validates that ZFSBOOT_DISKS are real [probed] disks)
1294 # NB: dialog_menu_layout supports running non-interactively
1295 dialog_menu_layout || continue
1296
1297 # Make sure each disk will be at least 50% ZFS
1298 if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize &&
1299 f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize
1300 then
1301 minsize=$swapsize teeny_disks=
1302 [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
1303 minsize=$(( $minsize + $gelisize ))
1304 for disk in $ZFSBOOT_DISKS; do
1305 device_$disk get capacity disksize || continue
1306 disksize=$(( $disksize - $minsize ))
1307 [ $disksize -lt $minsize ] &&
1308 teeny_disks="$teeny_disks $disk"
1309 done
1310 if [ "$teeny_disks" ]; then
1311 f_dprintf "swapsize=[%s] gelisize[%s]" \
1312 "$ZFSBOOT_SWAP_SIZE" \
1313 "$ZFSBOOT_GELI_BOOT_SIZE"
1314 f_dprintf "These disks are too small: %s" \
1315 "$teeny_disks"
1316 f_show_err "$msg_these_disks_are_too_small" \
1317 "$ZFSBOOT_SWAP_SIZE" \
1318 "$ZFSBOOT_GELI_BOOT_SIZE" \
1319 "$teeny_disks"
1320 continue
1321 fi
1322 fi
1323
1324 #
1325 # Last Chance!
1326 #

--- 38 unchanged lines hidden (view full) ---

1365 ZFSBOOT_GNOP_4K_FORCE_ALIGN=1
1366 fi
1367 ;;
1368 ?" $msg_encrypt_disks")
1369 # Toggle the variable referenced both by the menu and later
1370 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1371 ZFSBOOT_GELI_ENCRYPTION=
1372 else
1373 ZFSBOOT_GELI_ENCRYPTION=1
1374 fi
1375 ;;
1376 ?" $msg_partition_scheme")
1377 # Toggle between GPT and MBR
1378 if [ "$ZFSBOOT_PARTITION_SCHEME" = GPT ]; then
1379 ZFSBOOT_PARTITION_SCHEME=MBR
1380 else
1381 ZFSBOOT_PARTITION_SCHEME=GPT
1382 fi
1383 ;;
1384 ?" $msg_swap_size")
1385 # Prompt the user to input/change the swap size for each disk
1386 f_dialog_input input \
1387 "$msg_please_enter_amount_of_swap_space" \
1388 "$ZFSBOOT_SWAP_SIZE" &&
1389 ZFSBOOT_SWAP_SIZE="$input"
1390 ;;
1391 esac
1392done
1393
1394return $SUCCESS
1395
1396################################################################################
1397# END
1398################################################################################