Deleted Added
full compact
28c28
< # $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/zfsboot 259396 2013-12-14 20:55:53Z gjb $
---
> # $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/zfsboot 259621 2013-12-19 18:52:41Z dteske $
68a69
> # NB: Automatically enables ZFSBOOT_BOOT_POOL
73c74
< # Default name the unencrypted pool when using geli(8) to encrypt the drives
---
> # Default path to the geli(8) keyfile used in drive encryption
75c76
< : ${ZFSBOOT_GELI_POOL_NAME:=bootpool}
---
> : ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key}
78c79,80
< # Default size for the unencrypted boot pool when using geli(8)
---
> # Create a separate boot pool?
> # NB: Automatically set when using geli(8) or MBR
80c82
< : ${ZFSBOOT_GELI_BOOT_SIZE:=2g}
---
> : ${ZFSBOOT_BOOT_POOL=}
83c85
< # Default path to the geli(8) keyfile used in drive encryption
---
> # Default name for boot pool when enabled (e.g., geli(8) or MBR)
85c87
< : ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key}
---
> : ${ZFSBOOT_BOOT_POOL_NAME:=bootpool}
87a90,94
> # Default size for boot pool when enabled (e.g., geli(8) or MBR)
> #
> : ${ZFSBOOT_BOOT_POOL_SIZE:=2g}
>
> #
134a142
> /var/mail compression=lz4,atime=on
157a166
> GELI_DETACH_F='geli detach -f "%s"'
159a169
> GNOP_DESTROY='gnop destroy "%s"'
167a178
> GPART_DESTROY_F='gpart destroy -F "%s"'
168a180
> GRAID_DELETE='graid delete "%s"'
174a187
> UMOUNT='umount "%s"'
180a194
> ZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"'
204c218
< msg_geli_setup="Initializing encryption on the selected disks, this will take several seconds per disk"
---
> msg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk"
207a222
> msg_invalid_boot_pool_size="Invalid boot pool size \`%s'"
209d223
< msg_invalid_geli_boot_size="Invalid geli(8) boot size \`%s'"
613c627,628
< # NOTE: The MBR layout is more complicated (GPT is preferred).
---
> # NOTE: $swapsize and $bootsize should be defined by the calling function.
> # NOTE: Sets $bootpart and $targetpart for the calling function.
619d633
< local disksize partsize
666,668c680,682
< f_quietly gpart destroy -F $disk
< f_quietly graid destroy $disk
< f_quietly zpool labelclear -f /dev/$disk # Kill it with fire
---
> f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk
> f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk
671,672c685,686
< f_quietly gpart create -s gpt $disk
< f_quietly gpart destroy -F $disk
---
> f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk
> f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk
674,685c688,691
< # Calculate partition size given desired amount of swap
< f_dprintf "$funcname: Getting disk capactiy for \`%s'" "$disk"
< if ! device_$disk get capacity disksize; then
< f_dprintf "$funcname: Unable to get disk capacity of \`%s'" \
< "$disk"
< msg_error="$msg_error: $funcname" \
< f_show_err "$msg_unable_to_get_disk_capacity" "$disk"
< return $FAILURE
< fi
< partsize=$(( $disksize - $swapsize ))
< f_dprintf "$funcname: disksize=[%s] partsize=[%s]" \
< "$disksize" "$partsize"
---
> #
> # Enable boot pool if encryption is desired
> #
> [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1
696c702
< f_eval_catch $funcname gpart "$GPART_CREATE" gpt \$disk ||
---
> f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk ||
703c709
< gptboot\$index freebsd-boot 512k \$disk ||
---
> gptboot$index freebsd-boot 512k $disk ||
706c712
< /boot/pmbr /boot/gptzfsboot 1 \$disk ||
---
> /boot/pmbr /boot/gptzfsboot 1 $disk ||
709c715
< # zpool will use the `zfs#' GPT labels
---
> # NB: zpool will use the `zfs#' GPT labels
710a717
> [ ${swapsize:-0} -gt 0 ] && targetpart=p3
712,713c719,722
< # Change things around if we are using geli(8)
< if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
---
> #
> # Prepare boot pool if enabled (e.g., for geli(8))
> #
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
715,717c724
< partsize=$(( $partsize - $gelisize ))
< f_dprintf "$funcname: gelisize=[%s]" \
< "gelisize=[$gelisize]"
---
> [ ${swapsize:-0} -gt 0 ] && targetpart=p4
719,720c726,727
< "$GPART_ADD_LABEL_WITH_SIZE" boot\$index \
< freebsd-zfs \${gelisize}b \$disk ||
---
> "$GPART_ADD_LABEL_WITH_SIZE" boot$index \
> freebsd-zfs ${bootsize}b $disk ||
722,725c729,737
<
< # Pedantically nuke any old labels, stop geli
< f_quietly zpool labelclear -f "/dev/$disk$bootpart"
< f_quietly geli detach -f "/dev/$disk$targetpart"
---
> # Pedantically nuke any old labels
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
> /dev/$disk$bootpart
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> # Pedantically detach targetpart for later
> f_eval_catch -d $funcname geli \
> "$GELI_DETACH_F" \
> /dev/$disk$targetpart
> fi
729,730c741
< # 3. Add freebsd-zfs partition labeled `zfs#' for zpool
< # NOTE: Using above calculated partsize to leave room for swap.
---
> # 3. Add freebsd-swap partition labeled `swap#'
733,734d743
< f_dprintf "$funcname: partsize=[%s]" \
< "partsize=[$partsize]"
736,737c745,746
< "$GPART_ADD_LABEL_WITH_SIZE" zfs\$index \
< freebsd-zfs \${partsize}b \$disk ||
---
> "$GPART_ADD_LABEL_WITH_SIZE" swap$index \
> freebsd-swap ${swapsize}b $disk ||
739,741c748,754
< else
< f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
< zfs\$index freebsd-zfs \$disk ||
---
> # Pedantically nuke any old labels on the swap
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
> /dev/gpt/swap$index
> # Update fstab(5)
> f_eval_catch $funcname printf "$PRINTF_FSTAB" \
> /dev/gpt/swap$index none swap sw 0 0 \
> $BSDINSTALL_TMPETC/fstab ||
744d756
< f_quietly zpool labelclear -f "/dev/$disk$targetpart"
747c759
< # 4. Add freebsd-swap partition labeled `swap#'
---
> # 4. Add freebsd-zfs partition labeled `zfs#' for zroot
749,758c761,764
< if [ $swapsize -gt 0 ]; then
< f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
< swap\$index freebsd-swap \$disk ||
< return $FAILURE
< # Update fstab(5)
< f_eval_catch $funcname printf "$PRINTF_FSTAB" \
< /dev/gpt/swap\$index none swap sw 0 0 \
< \$BSDINSTALL_TMPETC/fstab ||
< return $FAILURE
< fi
---
> f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
> zfs$index freebsd-zfs $disk || return $FAILURE
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
> /dev/$disk$targetpart
765c771
< f_eval_catch $funcname gpart "$GPART_CREATE" mbr \$disk ||
---
> f_eval_catch $funcname gpart "$GPART_CREATE" mbr $disk ||
768c774
< \$disk || return $FAILURE
---
> $disk || return $FAILURE
773c779
< f_eval_catch $funcname gpart "$GPART_ADD" freebsd \$disk ||
---
> f_eval_catch $funcname gpart "$GPART_ADD" freebsd $disk ||
775c781
< f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 \$disk ||
---
> f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 $disk ||
777,778c783,787
< f_quietly zpool labelclear -f /dev/${disk}s1 # Pedantic
< f_quietly gpart destroy -F ${disk}s1 # Pedantic
---
> # Pedantically nuke any old labels
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
> /dev/${disk}s1
> # Pedantically nuke any old scheme
> f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" ${disk}s1
783c792
< f_eval_catch $funcname gpart "$GPART_CREATE" BSD \${disk}s1 ||
---
> f_eval_catch $funcname gpart "$GPART_CREATE" BSD ${disk}s1 ||
786,787c795,796
< # zpool will use s1a (no labels)
< bootpart=s1a targetpart=s1a mbrindex=1
---
> # NB: zpool will use s1a (no labels)
> bootpart=s1a targetpart=s1d mbrindex=4
789c798,808
< # Change things around if we are using geli(8)
---
> #
> # Always prepare a boot pool on MBR
> #
> ZFSBOOT_BOOT_POOL=1
> f_eval_catch $funcname gpart \
> "$GPART_ADD_INDEX_WITH_SIZE" \
> 1 freebsd-zfs ${bootsize}b ${disk}s1 ||
> return $FAILURE
> # Pedantically nuke any old labels
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
> /dev/$disk$bootpart
791,802c810,813
< bootpart=s1a targetpart=s1d
< partsize=$(( $partsize - $gelisize ))
< mbrindex=4 # If this is s1a then make the zpool s1d
< f_dprintf "$funcname: mbrindex=[%s] gelisize=[%s]" \
< "$mbrindex" "$gelisize"
< f_eval_catch $funcname gpart \
< "$GPART_ADD_INDEX_WITH_SIZE" \
< 1 freebsd-zfs \${gelisize}b \${disk}s1 ||
< return $FAILURE
< # Pedantically nuke any old labels, stop geli
< f_quietly zpool labelclear -f "/dev/$disk$bootpart"
< f_quietly geli detach -f "/dev/$disk$targetpart"
---
> # Pedantically detach targetpart for later
> f_eval_catch -d $funcname geli \
> "$GELI_DETACH_F" \
> /dev/$disk$targetpart
806,807c817
< # 4. Partition the BSD slice for ZFS
< # NOTE: Using above calculated partsize to leave room for swap.
---
> # 4. Add freebsd-swap partition
810,811d819
< f_dprintf "$funcname: mbrindex=[%s] partsize=[%s]" \
< "$mbrindex" "$partsize"
813,819c821,822
< "$GPART_ADD_INDEX_WITH_SIZE" \
< \$mbrindex freebsd-zfs \${partsize}b \
< \${disk}s1 || return $FAILURE
< else
< f_dprintf "$funcname: mbrindex=[%s]" "$mbrindex"
< f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
< \$mbrindex freebsd-zfs \${disk}s1 ||
---
> "$GPART_ADD_INDEX_WITH_SIZE" 2 \
> freebsd-swap ${swapsize}b ${disk}s1 ||
821,830c824,826
< fi
< f_quietly zpool labelclear -f /dev/$disk$targetpart # Pedantic
<
< #
< # 5. Add freebsd-swap partition
< #
< if [ $swapsize -gt 0 ]; then
< f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
< 2 freebsd-swap \${disk}s1 ||
< return $FAILURE
---
> # Pedantically nuke any old labels on the swap
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
> /dev/${disk}s1b
833,834c829,830
< /dev/\${disk}s1b none swap sw 0 0 \
< \$BSDINSTALL_TMPETC/fstab ||
---
> /dev/${disk}s1b none swap sw 0 0 \
> $BSDINSTALL_TMPETC/fstab ||
836a833,843
>
> #
> # 5. Add freebsd-zfs partition for zroot
> #
> f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
> $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE
> f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
> /dev/$disk$targetpart # Pedantic
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /boot/zfsboot /dev/${disk}s1 count=1 ||
> return $FAILURE
852,853c859,865
< local poolname="$1" vdev_type="$2"
< local bootpart targetpart
---
> local zroot_name="$1"
> local zroot_vdevtype="$2"
> local zroot_vdevs= # Calculated below
> local boot_vdevs= # Used for geli(8) and/or MBR layouts
> shift 2 # poolname vdev_type
> local disks="$*" disk
> local bootpart targetpart # Set by zfs_create_diskpart() below
855,859c867
< shift 2 # name vdev_type
<
< # We may need this later
< local disks="$*"
<
---
> #
861c869,870
< if [ ! "$poolname" ]; then
---
> #
> if [ ! "$zroot_name" ]; then
874c883
< "$poolname" "$vdev_type"
---
> "$zroot_name" "$zroot_vdevtype"
875a885
> #
876a887
> #
878,879c889
< f_eval_catch $funcname sh \
< "$SHELL_TRUNCATE" \$BSDINSTALL_TMPETC/fstab ||
---
> f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab ||
883c893
< \$BSDINSTALL_TMPETC/fstab || return $FAILURE
---
> $BSDINSTALL_TMPETC/fstab || return $FAILURE
884a895
> #
886,887c897,899
< f_dprintf "$funcname: Expanding supplied swapsize/gelisize values..."
< local swapsize gelisize
---
> #
> f_dprintf "$funcname: Expanding supplied size values..."
> local swapsize bootsize
894,898c906,910
< if ! f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize; then
< f_dprintf "$funcname: Invalid geli(8) boot size \`%s'" \
< "$ZFSBOOT_GELI_BOOT_SIZE"
< f_show_err "$msg_invalid_geli_boot_size" \
< "$ZFSBOOT_GELI_BOOT_SIZE"
---
> if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then
> f_dprintf "$funcname: Invalid boot pool size \`%s'" \
> "$ZFSBOOT_BOOT_POOL_SIZE"
> f_show_err "$msg_invalid_boot_pool_size" \
> "$ZFSBOOT_BOOT_POOL_SIZE"
903,904c915,916
< f_dprintf "$funcname: ZFSBOOT_GELI_BOOT_SIZE=[%s] gelisize=[%s]" \
< "$ZFSBOOT_GELI_BOOT_SIZE" "$gelisize"
---
> f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \
> "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize"
906c918,920
< # Prepare the disks
---
> #
> # Prepare the disks and build pool device list(s)
> #
907a922,923
> [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ] &&
> f_dprintf "$funcname: With 4k alignment using gnop(8)..."
909c925
< for disk in $*; do
---
> for disk in $disks; do
911,942c927,936
< n=$(( $n + 1 ))
< done
<
< # MBR boot loader hack part 1
< # We have to do this early because geli gets in the way later
< if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then
< f_dprintf "$funcname: Copying MBR boot loader to disks..."
< f_dprintf "$funcname: disks=[%s]" "$disks"
< for disk in $disks; do
< f_dprintf "$funcname: disk=[%s]" "$disk"
< f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
< /boot/zfsboot /dev/\${disk}s1 count=1 ||
< return $FAILURE
< done
< fi
<
< # Forced 4k alignment support provided by Geom NOP (see gnop(8))
< local unenc_list=
< if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then
< local part="$targetpart" new_list=
<
< # We don't gnop the encrypted partition because geli will do
< # this for us gnop the unencrypted disk
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] && part="$bootpart"
<
< f_dprintf "$funcname: Applying 4k alignment with gnop(8)..."
< f_dprintf "$funcname: *=[%s]" "$*"
< for disk in $*; do
< f_dprintf "$funcname: disk=[%s] part=[%s]" \
< "$disk" "$part"
< f_eval_catch $funcname gnop "$GNOP_CREATE" \
< \$disk\$part || return $FAILURE
---
> # Now $bootpart and $targetpart are set (suffix for $disk)
>
> # Forced 4k alignment support using Geom NOP (see gnop(8))
> if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
> boot_vdevs="$boot_vdevs $disk$bootpart.nop"
> f_eval_catch $funcname gnop "$GNOP_CREATE" \
> $disk$bootpart || return $FAILURE
> fi
> # Don't gnop encrypted partition
944c938
< unenc_list="$unenc_list $disk$part.nop"
---
> zroot_vdevs="$zroot_vdevs $disk$targetpart.eli"
946c940,943
< new_list="$new_list $disk$targetpart.nop"
---
> zroot_vdevs="$zroot_vdevs $disk$targetpart.nop"
> f_eval_catch $funcname gnop "$GNOP_CREATE" \
> $disk$targetpart ||
> return $FAILURE
948,958c945,950
< done
< set -- $new_list
< else
< local new_list=
< for disk in $*; do
< new_list="$new_list $disk$targetpart"
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< unenc_list="$unenc_list $disk$bootpart"
< done
< set -- $new_list
< fi
---
> else
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
> boot_vdevs="$boot_vdevs $disk$bootpart"
> fi
> zroot_vdevs="$zroot_vdevs $disk$targetpart"
> fi
959a952,954
> n=$(( $n + 1 ))
> done # disks
>
961c956
< # If encryption is enabled, we need to create the GEOMs
---
> # If we need/want a boot pool, create it
963,966c958,963
< if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
< local bootvdev= options=
< local geli_pool="$BSDINSTALL_CHROOT/$ZFSBOOT_GELI_POOL_NAME"
< local key="$ZFSBOOT_GELI_KEY_FILE"
---
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
> local bootpool_vdevtype= # Calculated below
> local bootpool_options= # Calculated below
> local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME"
> local bootpool="$BSDINSTALL_CHROOT/$bootpool_name"
> local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}"
968c965,967
< f_dprintf "$funcname: Setting up disk encryption..."
---
> f_dprintf "$funcname: Setting up boot pool..."
> [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
> f_dprintf "$funcname: For encrypted root disk..."
970,971c969,970
< # Create the parent directories for our unencrypted pool
< f_quietly umount /mnt
---
> # Create parent directory for boot pool
> f_eval_catch -d $funcname umount "$UMOUNT" /mnt
973c972
< \$BSDINSTALL_CHROOT || return $FAILURE
---
> $BSDINSTALL_CHROOT || return $FAILURE
975,976c974,976
< # Create mirror across the unencrypted partition on all disks
< [ $( set -- $unenc_list; echo $# ) -gt 1 ] && bootvdev=mirror
---
> # Create mirror across the boot partition on all disks
> [ $( set -- $boot_vdevs; echo $# ) -gt 1 ] &&
> bootpool_vdevtype=mirror
978,983c978,979
< f_dprintf "$funcname: %s %s %s" \
< "ZFSBOOT_GELI_POOL_NAME=[$ZFSBOOT_GELI_POOL_NAME]" \
< "bootvdev=[$bootvdev]" "unenc_list=[$unenc_list]"
< options="-o altroot=\"\$BSDINSTALL_CHROOT\""
< options="$options -m \"/\$ZFSBOOT_GELI_POOL_NAME\""
< options="$options -f"
---
> bootpool_options="-o altroot=$BSDINSTALL_CHROOT"
> bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f"
985,989c981,982
< "$options" \$ZFSBOOT_GELI_POOL_NAME \$bootvdev \
< \$unenc_list || return $FAILURE
<
< f_dprintf "$funcname: geli_pool=[%s]" "$geli_pool"
< f_eval_catch $funcname mkdir "$MKDIR_P" \$geli_pool/boot ||
---
> "$bootpool_options" "$bootpool_name" \
> "$bootpool_vdevtype" "$boot_vdevs" ||
992,995c985
< # Generate an encryption key using random(4)
< f_dprintf "$funcname: key=[%s]" "$key"
< f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
< /dev/random \$geli_pool/\$key "bs=4096 count=1" ||
---
> f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" ||
998,999c988,1006
< # Create the geli(8) GEOMS
< local geli_list
---
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> # Generate an encryption key using random(4)
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /dev/random "$bootpool/$zroot_key" \
> "bs=4096 count=1" || return $FAILURE
> else
> # Clean up
> f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \
> "$bootpool_name" || return $FAILURE
> f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs
> fi
>
> fi
>
> #
> # Create the geli(8) GEOMS
> #
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> # Prompt user for password (twice)
1007c1014,1015
< f_dprintf "$funcname: disks=[%s]" "$disks"
---
>
> # Initialize geli(8) on each of the target partitions
1009,1010d1016
< f_dprintf "$funcname: disk=[%s] targetpart=[%s]" \
< "$disk" "$targetpart"
1013,1016c1019,1023
< if ! echo "$pw_password" | f_eval_catch $funcname \
< geli "$GELI_PASSWORD_INIT" \
< \$geli_pool/boot/\$disk\$targetpart.eli \
< AES-XTS \$geli_pool/\$key \$disk\$targetpart
---
> if ! echo "$pw_password" | f_eval_catch \
> $funcname geli "$GELI_PASSWORD_INIT" \
> "$bootpool/boot/$disk$targetpart.eli" \
> AES-XTS "$bootpool/$zroot_key" \
> $disk$targetpart
1018a1026
> unset pw_password # Sensitive info
1021,1023c1029,1031
< if ! echo "$pw_password" | f_eval_catch $funcname \
< geli "$GELI_ATTACH" \$geli_pool/\$key \
< \$disk\$targetpart
---
> if ! echo "$pw_password" | f_eval_catch \
> $funcname geli "$GELI_ATTACH" \
> "$bootpool/$zroot_key" $disk$targetpart
1025a1034
> unset pw_password # Sensitive info
1028d1036
< geli_list="$geli_list $disk$targetpart.eli"
1030,1033c1038,1043
< set -- $geli_list
< f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \
< \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
< f_quietly umount /mnt # done with tmpfs
---
> unset pw_password # Sensitive info
>
> # Clean up
> f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" ||
> return $FAILURE
> f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs
1037c1047
< # Create the ZFS pool with desired type and disk devices
---
> # Create the ZFS root pool with desired type and disk devices
1039,1042c1049
< local vdevs="$*"
< f_dprintf "$funcname: Creating boot pool..."
< f_dprintf "poolname=[%s] vdev_type=[%s] vdevs=[%s]" \
< "$poolname" "$vdev_type" "$vdevs"
---
> f_dprintf "$funcname: Creating root pool..."
1044,1045c1051,1053
< "-o altroot=\"\$BSDINSTALL_CHROOT\" -m none -f" \
< \$poolname \$vdev_type \$vdevs
---
> "-o altroot=$BSDINSTALL_CHROOT -m none -f" \
> "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" ||
> return $FAILURE
1047c1055
< # Customize the zpool a bit...
---
> # Customize the zroot a bit...
1049,1053c1057,1060
< f_dprintf "$funcname: Setting miscellaneous options on boot pool..."
< for option in checksum=fletcher4 atime=off; do
< f_dprintf "$funcname: option=[%s]" "$option"
< f_eval_catch $funcname zfs "$ZFS_SET" \$option \$poolname ||
< return $FAILURE
---
> f_dprintf "$funcname: Setting miscellaneous options on root pool..."
> for option in atime=off; do
> f_eval_catch $funcname zfs "$ZFS_SET" $option "$zroot_name" ||
> return $FAILURE
1057c1064
< # Create ZFS dataset layout within the new boot pool
---
> # Create ZFS dataset layout within the new root pool
1076,1077d1082
< f_dprintf "$funcname: dataset=[%s] options=[%s]" \
< "$dataset" "$options"
1079c1084
< "\${options:+-o \$options}" \$poolname\$dataset ||
---
> "${options:+-o $options}" "$zroot_name$dataset" ||
1087d1091
< f_dprintf "$funcname: dir=[%s]" "$dir"
1089c1093
< \$BSDINSTALL_CHROOTDIR\$dir || return $FAILURE
---
> $BSDINSTALL_CHROOTDIR$dir || return $FAILURE
1093,1097c1097,1100
< if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
< f_dprintf "$funcname: Creating /boot symlink for GELI..."
< f_eval_catch $funcname ln "$LN_SF" \
< \$ZFSBOOT_GELI_POOL_NAME/boot \
< \$BSDINSTALL_CHROOT/boot || return $FAILURE
---
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
> f_dprintf "$funcname: Creating /boot symlink for boot pool..."
> f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \
> $BSDINSTALL_CHROOT/boot || return $FAILURE
1100a1104
> local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME"
1102,1104d1105
< f_dprintf "$funcname: %s %s" \
< "ZFSBOOT_BEROOT_NAME=[$ZFSBOOT_BEROOT_NAME]" \
< "ZFSBOOT_BOOTFS_NAME=[$ZFSBOOT_BOOTFS_NAME]"
1106,1107c1107,1108
< bootfs=\"\$poolname/\$ZFSBOOT_BEROOT_NAME/\$ZFSBOOT_BOOTFS_NAME\" \
< \$poolname || return $FAILURE
---
> "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" ||
> return $FAILURE
1111c1112
< f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \$poolname ||
---
> f_eval_catch $funcname zpool "$ZPOOL_EXPORT" "$zroot_name" ||
1113c1114
< if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
---
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
1115c1116
< \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
---
> "$bootpool_name" || return $FAILURE
1120,1123c1121,1123
< if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
< f_quietly gnop destroy $disk$bootpart.nop
< else
< f_quietly gnop destroy $disk$targetpart.nop
---
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
> f_eval_catch -d $funcname gnop "$GNOP_DESTROY" \
> $disk$bootpart.nop
1124a1125,1128
> if [ ! "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> f_eval_catch -d $funcname gnop "$GNOP_DESTROY" \
> $disk$targetpart.nop
> fi
1127c1131
< # MBR boot loader hack part 2
---
> # MBR boot loader touch-up
1130d1133
< f_dprintf "$funcname: disks=[%s]"
1134,1135d1136
< f_dprintf "$funcname: disk=[%s] bootpart=[%s]" \
< "$disk" "$bootpart"
1137c1138
< /boot/zfsboot /dev/\$disk\$bootpart \
---
> /boot/zfsboot /dev/$disk$bootpart \
1145c1146
< "-o altroot=\"\$BSDINSTALL_CHROOT\"" \$poolname ||
---
> "-o altroot=\"$BSDINSTALL_CHROOT\"" "$zroot_name" ||
1147c1148
< if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
---
> if [ "$ZFSBOOT_BOOT_POOL" ]; then
1149,1150c1150,1151
< "-o altroot=\"\$BSDINSTALL_CHROOT\"" \
< \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
---
> "-o altroot=\"$BSDINSTALL_CHROOT\"" \
> "$bootpool_name" || return $FAILURE
1154,1155c1155,1156
< f_dprintf "$funcname: Configuring zpool.cache..."
< f_eval_catch $funcname mkdir "$MKDIR_P" \$BSDINSTALL_CHROOT/boot/zfs ||
---
> f_dprintf "$funcname: Configuring zpool.cache for zroot..."
> f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs ||
1158,1159c1159,1160
< cachefile=\"\$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\" \
< \$poolname || return $FAILURE
---
> "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \
> "$zroot_name" || return $FAILURE
1166c1167
< \$BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE
---
> $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE
1168c1169
< \$BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
---
> $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
1170,1171c1171,1172
< # We're all done unless we should go on to do encryption
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS
---
> # We're all done unless we should go on for boot pool
> [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS
1172a1174,1179
> # Set cachefile for boot pool so it auto-imports at system start
> f_dprintf "$funcname: Configuring zpool.cache for boot pool..."
> f_eval_catch $funcname zpool "$ZPOOL_SET" \
> "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \
> "$bootpool_name" || return $FAILURE
>
1175,1177c1182,1184
< zpool_cache_load=\"YES\" \
< zpool_cache_type=\"/boot/zfs/zpool.cache\" \
< zpool_cache_name=\"/boot/zfs/zpool.cache\" \
---
> 'zpool_cache_load=\"YES\"' \
> 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \
> 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \
1179,1180c1186,1187
< f_eval_catch $funcname echo "$ECHO_APPEND" \$option \
< \$BSDINSTALL_TMPBOOT/loader.conf.zfs ||
---
> f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \
> $BSDINSTALL_TMPBOOT/loader.conf.zfs ||
1182a1190,1192
> f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \
> "\"zfs:$zroot_name/$zroot_bootfs\"" \
> $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
1183a1194,1196
> # We're all done unless we should go on to do encryption
> [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS
>
1189c1202
< \$BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
---
> $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
1191,1195c1204
< \$BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
< f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \
< '"zfs:$poolname/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME"' \
< \$BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
< f_dprintf "$funcname: disks=[%s]" "$disks"
---
> $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
1197,1199d1205
< f_dprintf "$funcname: %s %s %s" \
< "disk=[$disk]" "targetpart=[$targetpart]" \
< "ZFSBOOT_GELI_KEY_FILE=[$ZFSBOOT_GELI_KEY_FILE]"
1201,1202c1207,1208
< geli_%s_keyfile0_load '"$disk$targetpart" YES' \
< \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
---
> geli_%s_keyfile0_load "$disk$targetpart YES" \
> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
1206,1207c1212,1213
< '"$disk$targetpart" "$disk$targetpart:geli_keyfile0"' \
< \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
---
> "$disk$targetpart $disk$targetpart:geli_keyfile0" \
> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
1211,1212c1217,1218
< '"$disk$targetpart" "$ZFSBOOT_GELI_KEY_FILE"' \
< \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
---
> "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \
> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
1261c1267
< f_dprintf "PRINTF_FSTAB=[%s]" "$PRINTF_FSTAB"
---
> f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT"
1299c1305
< f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize
---
> f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize
1302,1303c1308,1309
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< minsize=$(( $minsize + $gelisize ))
---
> [ "$ZFSBOOT_BOOT_POOL" ] &&
> minsize=$(( $minsize + $bootsize ))
1311c1317
< f_dprintf "swapsize=[%s] gelisize[%s]" \
---
> f_dprintf "swapsize=[%s] bootsize[%s] %s" \
1313c1319,1320
< "$ZFSBOOT_GELI_BOOT_SIZE"
---
> "$ZFSBOOT_BOOT_POOL_SIZE" \
> "minsize=[$minsize]"
1318c1325
< "$ZFSBOOT_GELI_BOOT_SIZE" \
---
> "$ZFSBOOT_BOOT_POOL_SIZE" \
1372a1380
> ZFSBOOT_GNOP_4K_FORCE_ALIGN=1
1389c1397
< ZFSBOOT_SWAP_SIZE="$input"
---
> ZFSBOOT_SWAP_SIZE="${input:-0}"