3 # Copyright (c) 2013 Allan Jude
4 # Copyright (c) 2013 Devin Teske
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
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
30 ############################################################ INCLUDES
32 BSDCFG_SHARE="/usr/share/bsdconfig"
33 . $BSDCFG_SHARE/common.subr || exit 1
34 f_dprintf "%s: loading includes..." "$0"
35 f_include $BSDCFG_SHARE/device.subr
36 f_include $BSDCFG_SHARE/dialog.subr
37 f_include $BSDCFG_SHARE/password/password.subr
38 f_include $BSDCFG_SHARE/variable.subr
40 ############################################################ CONFIGURATION
43 # Default name of the boot-pool
45 : ${ZFSBOOT_POOL_NAME:=zroot}
48 # Default name for the boot environment parent dataset
50 : ${ZFSBOOT_BEROOT_NAME:=ROOT}
53 # Default name for the primany boot environment
55 : ${ZFSBOOT_BOOTFS_NAME:=default}
58 # Default Virtual Device (vdev) type to create
60 : ${ZFSBOOT_VDEV_TYPE:=stripe}
63 # Should we use gnop(8) to configure a transparent mapping to 4K sectors?
65 : ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:=1}
68 # Should we use geli(8) to encrypt the drives?
70 : ${ZFSBOOT_GELI_ENCRYPTION=}
73 # Default name the unencrypted pool when using geli(8) to encrypt the drives
75 : ${ZFSBOOT_GELI_POOL_NAME:=bootpool}
78 # Default size for the unencrypted boot pool when using geli(8)
80 : ${ZFSBOOT_GELI_BOOT_SIZE:=2g}
83 # Default path to the geli(8) keyfile used in drive encryption
85 : ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key}
88 # Default disks to use (always empty unless being scripted)
93 # Default partitioning scheme to use on disks
95 : ${ZFSBOOT_PARTITION_SCHEME:=GPT}
98 # How much swap to put on each block device in the boot zpool
99 # NOTE: Value passed to gpart(8); which supports SI unit suffixes.
101 : ${ZFSBOOT_SWAP_SIZE:=2g}
104 # Default ZFS datasets for root zpool
106 # NOTE: Requires /tmp, /var/tmp, /$ZFSBOOT_BOOTFS_NAME/$ZFSBOOT_BOOTFS_NAME
107 # NOTE: Anything after pound/hash character [#] is ignored as a comment.
109 f_isset ZFSBOOT_DATASETS || ZFSBOOT_DATASETS="
110 # DATASET OPTIONS (comma or space separated; or both)
112 # Boot Environment [BE] root and default boot dataset
113 /$ZFSBOOT_BEROOT_NAME mountpoint=none
114 /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/
116 # Compress /tmp, allow exec but not setuid
117 /tmp mountpoint=/tmp,compression=lz4,exec=on,setuid=off
119 # Don't mount /usr so that 'base' files go to the BEROOT
120 /usr mountpoint=/usr,canmount=off
122 # Home directories separated so they are common to all BEs
123 /usr/home # NB: /home is a symlink to /usr/home
126 /usr/ports compression=lz4,setuid=off
128 # Source tree (compressed)
129 /usr/src compression=lz4,exec=off,setuid=off
131 # Create /var and friends
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
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.
142 : ${ZFSBOOT_CONFIRM_LAYOUT:=1}
144 ############################################################ GLOBALS
147 # Format of a line in printf(1) syntax to add to fstab(5)
149 FSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n"
152 # Command strings for various tasks
154 CHMOD_MODE='chmod %s "%s"'
155 DD_WITH_OPTIONS='dd if="%s" of="%s" %s'
156 ECHO_APPEND='echo "%s" >> "%s"'
157 GELI_ATTACH='geli attach -j - -k "%s" "%s"'
158 GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"'
159 GNOP_CREATE='gnop create -S 4096 "%s"'
160 GPART_ADD='gpart add -t %s "%s"'
161 GPART_ADD_INDEX='gpart add -i %s -t %s "%s"'
162 GPART_ADD_INDEX_WITH_SIZE='gpart add -i %s -t %s -s %s "%s"'
163 GPART_ADD_LABEL='gpart add -l %s -t %s "%s"'
164 GPART_ADD_LABEL_WITH_SIZE='gpart add -l %s -t %s -s %s "%s"'
165 GPART_BOOTCODE='gpart bootcode -b "%s" "%s"'
166 GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"'
167 GPART_CREATE='gpart create -s %s "%s"'
168 GPART_SET_ACTIVE='gpart set -a active -i %s "%s"'
169 LN_SF='ln -sf "%s" "%s"'
170 MKDIR_P='mkdir -p "%s"'
171 MOUNT_TYPE='mount -t %s "%s" "%s"'
172 PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\""
173 PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"'
174 SHELL_TRUNCATE=':> "%s"'
175 ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"'
176 ZFS_SET='zfs set "%s" "%s"'
177 ZFS_UNMOUNT='zfs unmount "%s"'
178 ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s'
179 ZPOOL_EXPORT='zpool export "%s"'
180 ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"'
181 ZPOOL_SET='zpool set %s "%s"'
184 # Strings that should be moved to an i18n file and loaded with f_include_lang()
186 hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER"
187 hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER"
188 hline_arrows_tab_enter="Press arrows, TAB or ENTER"
189 msg_an_unknown_error_occurred="An unknown error occurred"
192 msg_change_selection="Change Selection"
193 msg_configure_options="Configure Options:"
194 msg_detailed_disk_info="gpart(8) show %s:\n%s\n\ncamcontrol(8) inquiry %s:\n%s\n\n\ncamcontrol(8) identify %s:\n%s\n"
195 msg_disk_info="Disk Info"
196 msg_disk_info_help="Get detailed information on disk device(s)"
197 msg_encrypt_disks="Encrypt Disks?"
198 msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions"
200 msg_force_4k_sectors="Force 4K Sectors?"
201 msg_force_4k_sectors_help="Use gnop(8) to configure forced 4K sector alignment"
202 msg_freebsd_installer="FreeBSD Installer"
203 msg_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"
204 msg_geli_setup="Initializing encryption on the selected disks, this will take several seconds per disk"
205 msg_install="Install"
206 msg_install_desc="Proceed with Installation"
207 msg_install_help="Create ZFS boot pool with displayed options"
208 msg_invalid_disk_argument="Invalid disk argument \`%s'"
209 msg_invalid_geli_boot_size="Invalid geli(8) boot size \`%s'"
210 msg_invalid_index_argument="Invalid index argument \`%s'"
211 msg_invalid_swap_size="Invalid swap size \`%s'"
212 msg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'"
213 msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s"
214 msg_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'
215 msg_mirror_desc="Mirror - n-Way Mirroring"
216 msg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage"
217 msg_missing_disk_arguments="missing disk arguments"
218 msg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!"
220 msg_no_disks_present_to_configure="No disk(s) present to configure"
221 msg_no_disks_selected="No disks selected."
222 msg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)"
223 msg_null_disk_argument="NULL disk argument"
224 msg_null_index_argument="NULL index argument"
225 msg_null_poolname="NULL poolname"
227 msg_partition_scheme="Partition Scheme"
228 msg_partition_scheme_help="Toggle between GPT and MBR partitioning schemes"
229 msg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:"
230 msg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):"
231 msg_please_select_one_or_more_disks="Please select one or more disks to create a zpool:"
232 msg_pool_name="Pool Name"
233 msg_pool_name_cannot_be_empty="Pool name cannot be empty."
234 msg_pool_name_help="Customize the name of the zpool to be created (Required)"
235 msg_pool_type_disks="Pool Type/Disks:"
236 msg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)"
237 msg_processing_selection="Processing selection..."
238 msg_raidz1_desc="RAID-Z1 - Single Redundant RAID"
239 msg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks"
240 msg_raidz2_desc="RAID-Z2 - Double Redundant RAID"
241 msg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks"
242 msg_raidz3_desc="RAID-Z3 - Triple Redundant RAID"
243 msg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks"
244 msg_rescan_devices="Rescan Devices"
245 msg_rescan_devices_help="Scan for device changes"
247 msg_select_a_disk_device="Select a disk device"
248 msg_select_virtual_device_type="Select Virtual Device type:"
249 msg_stripe_desc="Stripe - No Redundancy"
250 msg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy"
251 msg_swap_size="Swap Size"
252 msg_swap_size_help="Customize how much swap space is allocated to each selected disk"
253 msg_these_disks_are_too_small="These disks are too small given the amount of requested\nswap (%s) and/or geli(8) (%s) partitions, which would\ntake 50%% or more of each of the following selected disk\ndevices (not recommended):\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of devices."
254 msg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'"
255 msg_unsupported_partition_scheme="%s is an unsupported partition scheme"
256 msg_user_cancelled="User Cancelled."
258 msg_zfs_configuration="ZFS Configuration"
260 ############################################################ FUNCTIONS
264 # Display the dialog(1)-based application main menu.
268 local title="$DIALOG_TITLE"
269 local btitle="$DIALOG_BACKTITLE"
270 local prompt="$msg_configure_options"
271 local force4k="$msg_no"
272 local usegeli="$msg_no"
273 [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ] && force4k="$msg_yes"
274 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes"
275 local disks n=$( set -- $ZFSBOOT_DISKS; echo $# )
276 { [ $n -eq 1 ] && disks=disk; } || disks=disks # grammar
278 '>>> $msg_install' '$msg_install_desc'
280 'T $msg_pool_type_disks' '$ZFSBOOT_VDEV_TYPE: $n $disks'
281 '$msg_pool_type_disks_help'
282 '- $msg_rescan_devices' '*'
283 '$msg_rescan_devices_help'
284 '- $msg_disk_info' '*'
285 '$msg_disk_info_help'
286 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME'
287 '$msg_pool_name_help'
288 '4 $msg_force_4k_sectors' '$force4k'
289 '$msg_force_4k_sectors_help'
290 'E $msg_encrypt_disks' '$usegeli'
291 '$msg_encrypt_disks_help'
292 'P $msg_partition_scheme' '$ZFSBOOT_PARTITION_SCHEME'
293 '$msg_partition_scheme_help'
294 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE'
295 '$msg_swap_size_help'
297 local defaultitem= # Calculated below
298 local hline="$hline_alnum_arrows_punc_tab_enter"
300 local height width rows
301 eval f_dialog_menu_with_help_size height width rows \
302 \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list
304 # Obtain default-item from previously stored selection
305 f_dialog_default_fetch defaultitem
308 menu_choice=$( eval $DIALOG \
309 --title \"\$title\" \
310 --backtitle \"\$btitle\" \
311 --hline \"\$hline\" \
313 --ok-label \"\$msg_select\" \
314 --cancel-label \"\$msg_cancel\" \
315 --default-item \"\$defaultitem\" \
316 --menu \"\$prompt\" \
317 $height $width $rows \
319 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
322 f_dialog_data_sanitize menu_choice
323 f_dialog_menutag_store "$menu_choice"
325 # Only update default-item on success
326 [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice"
331 # dialog_last_chance $disks ...
333 # Display a list of the disks that the user is about to destroy. The default
334 # action is to return error status unless the user explicitly (non-default)
335 # selects "Yes" from the noyes dialog.
339 local title="$DIALOG_TITLE"
340 local btitle="$DIALOG_BACKTITLE"
341 local prompt # Calculated below
342 local hline="$hline_arrows_tab_enter"
344 local height=8 width=50 prefix=" "
345 local plen=${#prefix} list= line=
346 local max_width=$(( $width - 3 - $plen ))
348 local yes no defaultno extra_args format
349 if [ "$USE_XDIALOG" ]; then
350 yes=ok no=cancel defaultno=default-no
351 extra_args="--wrap --left"
352 format="$msg_last_chance_are_you_sure"
354 yes=yes no=no defaultno=defaultno
355 extra_args="--colors --cr-wrap"
356 format="$msg_last_chance_are_you_sure_color"
359 local disk line_width
366 line_width=$(( $line_width + 1 + ${#disk} ))
367 # Add newline before disk if it would exceed max_width
368 if [ $line_width -gt $max_width ]; then
371 height=$(( $height + 1 ))
373 # Add the disk to the list
376 # Append the left-overs
377 if [ "${line#$prefix}" ]; then
379 height=$(( $height + 1 ))
382 # Add height for Xdialog(1)
383 [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
385 prompt=$( printf "$format" "$list" )
386 f_dprintf "%s: Last Chance!" "$0"
389 --backtitle "$btitle" \
392 --$yes-label "$msg_yes" \
393 --$no-label "$msg_no" \
395 --yesno "$prompt" $height $width
400 # Configure Virtual Device type and disks to use for the ZFS boot pool. User
401 # must select enough disks to satisfy the chosen vdev type.
405 local funcname=dialog_menu_layout
406 local title="$DIALOG_TITLE"
407 local btitle="$DIALOG_BACKTITLE"
408 local vdev_prompt="$msg_select_virtual_device_type"
409 local disk_prompt="$msg_please_select_one_or_more_disks"
410 local vdev_menu_list="
411 'stripe' '$msg_stripe_desc' '$msg_stripe_help'
412 'mirror' '$msg_mirror_desc' '$msg_mirror_help'
413 'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help'
414 'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help'
415 'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help'
417 local disk_check_list= # Calculated below
418 local vdev_hline="$hline_arrows_tab_enter"
419 local disk_hline="$hline_arrows_space_tab_enter"
421 # Warn the user if vdev type is not valid
422 case "$ZFSBOOT_VDEV_TYPE" in
423 stripe|mirror|raidz1|raidz2|raidz3) : known good ;;
425 f_dprintf "%s: Invalid virtual device type \`%s'" \
426 $funcname "$ZFSBOOT_VDEV_TYPE"
427 f_show_err "$msg_invalid_virtual_device_type" \
429 f_interactive || return $FAILURE
432 # Calculate size of vdev menu once only
433 local vheight vwidth vrows
434 eval f_dialog_menu_with_help_size vheight vwidth vrows \
435 \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \
438 # Get a list of probed disk devices
440 f_device_find "" $DEVICE_TYPE_DISK disks
441 f_dprintf "$funcname: disks=[%s]" "$disks"
442 if [ ! "$disks" ]; then
443 f_dprintf "No disk(s) present to configure"
444 f_show_err "$msg_no_disks_present_to_configure"
448 # Lets sort the disks array to be more user friendly
449 disks=$( echo "$disks" | tr ' ' '\n' | sort | tr '\n' ' ' )
452 # Operate in a loop so we can (if interactive) repeat if not enough
453 # disks are selected to satisfy the chosen vdev type or user wants to
454 # back-up to the previous menu.
456 local vardisk ndisks onoff selections vdev_choice
459 # Confirm the vdev type that was selected
461 if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
462 vdev_choice=$( eval $DIALOG \
463 --title \"\$title\" \
464 --backtitle \"\$btitle\" \
465 --hline \"\$vdev_hline\" \
466 --ok-label \"\$msg_ok\" \
467 --cancel-label \"\$msg_cancel\" \
469 --default-item \"\$ZFSBOOT_VDEV_TYPE\" \
470 --menu \"\$vdev_prompt\" \
471 $vheight $vwidth $vrows \
473 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
475 # Exit if user pressed ESC or chose Cancel/No
476 f_dialog_data_sanitize vdev_choice
478 ZFSBOOT_VDEV_TYPE="$vdev_choice"
479 f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \
483 # Determine the number of disks needed for this vdev type
485 case "$ZFSBOOT_VDEV_TYPE" in
486 stripe) want_disks=1 ;;
487 mirror) want_disks=2 ;;
488 raidz1) want_disks=3 ;;
489 raidz2) want_disks=4 ;;
490 raidz3) want_disks=5 ;;
493 # Warn the user if any scripted disks are invalid
494 local disk valid_disks=
495 local all_valid=${ZFSBOOT_DISKS:+1} # optimism
496 for disk in $ZFSBOOT_DISKS; do
497 if f_struct device_$disk; then
498 valid_disks="$valid_disks $disk"
501 f_dprintf "$funcname: \`%s' is not a real disk" "$disk"
504 if [ ! "$all_valid" ]; then
505 if [ "$ZFSBOOT_DISKS" ]; then
507 "$msg_missing_one_or_more_scripted_disks"
509 f_dprintf "No disks selected."
511 f_show_err "$msg_no_disks_selected"
513 f_interactive || return $FAILURE
515 ZFSBOOT_DISKS="${valid_disks# }"
518 # Short-circuit if we're running non-interactively
520 if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
521 ndisks=$( set -- $ZFSBOOT_DISKS; echo $# )
522 [ $ndisks -ge $want_disks ] && break # to success
524 # Not enough disks selected
525 f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
526 "$ZFSBOOT_VDEV_TYPE" \
527 "Not enough disks selected." \
529 f_interactive || return $FAILURE
530 msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
531 f_yesno "%s: $msg_not_enough_disks_selected" \
532 "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
537 # Confirm the disks that were selected
538 # Loop until the user cancels or selects enough disks
542 # Loop over list of available disks, resetting state
543 for disk in $disks; do unset _${disk}_status; done
545 # Loop over list of selected disks and create temporary
546 # locals to map statuses onto up-to-date list of disks
547 for disk in $ZFSBOOT_DISKS; do
548 local _${disk}_status=on
551 # Create the checklist menu of discovered disk devices
553 for disk in $disks; do
555 device_$disk get desc desc
556 f_shell_escape "$desc" desc
557 f_getvar _${disk}_status:-off onoff
558 disk_check_list="$disk_check_list
559 $disk '$desc' $onoff"
562 local height width rows
563 eval f_dialog_checklist_size height width rows \
564 \"\$title\" \"\$btitle\" \"\$prompt\" \
565 \"\$hline\" $disk_check_list
567 selections=$( eval $DIALOG \
568 --title \"\$DIALOG_TITLE\" \
569 --backtitle \"\$DIALOG_BACKTITLE\" \
570 --hline \"\$hline\" \
571 --ok-label \"\$msg_ok\" \
572 --cancel-label \"\$msg_back\" \
573 --checklist \"\$prompt\" \
574 $height $width $rows \
576 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
578 # Loop if user pressed ESC or chose Cancel/No
579 f_dialog_data_sanitize selections
581 ZFSBOOT_DISKS="$selections"
582 f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \
585 ndisks=$( set -- $ZFSBOOT_DISKS; echo $# )
586 [ $ndisks -ge $want_disks ] &&
587 breakout=break && break
589 # Not enough disks selected
590 f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
591 "$ZFSBOOT_VDEV_TYPE" \
592 "Not enough disks selected." \
594 msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
595 f_yesno "%s: $msg_not_enough_disks_selected" \
596 "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
599 [ "$breakout" = "break" ] && break
600 [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE
606 # zfs_create_diskpart $disk $index
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.
613 # NOTE: The MBR layout is more complicated (GPT is preferred).
615 zfs_create_diskpart()
617 local funcname=zfs_create_diskpart
618 local disk="$1" index="$2"
619 local disksize partsize
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"
628 if [ "${disk#*[$IFS]}" != "$disk" ]; then
629 f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk"
630 msg_error="$msg_error: $funcname" \
631 f_show_err "$msg_invalid_disk_argument" "$disk"
634 if [ ! "$index" ]; then
635 f_dprintf "$funcname: NULL index argument"
636 msg_error="$msg_error: $funcname" \
637 f_show_err "$msg_null_index_argument"
640 if ! f_isinteger "$index"; then
641 f_dprintf "$funcname: Invalid index argument \`%s'" "$index"
642 msg_error="$msg_error: $funcname" \
643 f_show_err "$msg_invalid_index_argument" "$index"
646 f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index"
648 # Check for unknown partition scheme before proceeding further
649 case "$ZFSBOOT_PARTITION_SCHEME" in
650 ""|MBR|GPT) : known good ;;
652 f_dprintf "$funcname: %s is an unsupported partition scheme" \
653 "$ZFSBOOT_PARTITION_SCHEME"
654 msg_error="$msg_error: $funcname" f_show_err \
655 "$msg_unsupported_partition_scheme" \
656 "$ZFSBOOT_PARTITION_SCHEME"
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.
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
670 # Make doubly-sure backup GPT is destroyed
671 f_quietly gpart create -s gpt $disk
672 f_quietly gpart destroy -F $disk
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'" \
679 msg_error="$msg_error: $funcname" \
680 f_show_err "$msg_unable_to_get_disk_capacity" "$disk"
683 partsize=$(( $disksize - $swapsize ))
684 f_dprintf "$funcname: disksize=[%s] partsize=[%s]" \
685 "$disksize" "$partsize"
688 # Lay down the desired type of partition scheme
690 local setsize mbrindex
691 case "$ZFSBOOT_PARTITION_SCHEME" in
692 ""|GPT) f_dprintf "$funcname: Creating GPT layout..."
694 # 1. Create GPT layout using labels
696 f_eval_catch $funcname gpart "$GPART_CREATE" gpt \$disk ||
700 # 2. Add small freebsd-boot partition labeled `boot#'
702 f_eval_catch $funcname gpart "$GPART_ADD_LABEL_WITH_SIZE" \
703 gptboot\$index freebsd-boot 512k \$disk ||
705 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \
706 /boot/pmbr /boot/gptzfsboot 1 \$disk ||
709 # zpool will use the `zfs#' GPT labels
710 bootpart=p2 targetpart=p2
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 ||
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"
729 # 3. Add freebsd-zfs partition labeled `zfs#' for zpool
730 # NOTE: Using above calculated partsize to leave room for swap.
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 ||
740 f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
741 zfs\$index freebsd-zfs \$disk ||
744 f_quietly zpool labelclear -f "/dev/$disk$targetpart"
747 # 4. Add freebsd-swap partition labeled `swap#'
749 if [ $swapsize -gt 0 ]; then
750 f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
751 swap\$index freebsd-swap \$disk ||
754 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
755 /dev/gpt/swap\$index none swap sw 0 0 \
756 \$BSDINSTALL_TMPETC/fstab ||
761 MBR) f_dprintf "$funcname: Creating MBR layout..."
763 # 1. Create MBR layout (no labels)
765 f_eval_catch $funcname gpart "$GPART_CREATE" mbr \$disk ||
767 f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \
768 \$disk || return $FAILURE
771 # 2. Add freebsd slice with all available space
773 f_eval_catch $funcname gpart "$GPART_ADD" freebsd \$disk ||
775 f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 \$disk ||
777 f_quietly zpool labelclear -f /dev/${disk}s1 # Pedantic
778 f_quietly gpart destroy -F ${disk}s1 # Pedantic
781 # 3. Write BSD scheme to the freebsd slice
783 f_eval_catch $funcname gpart "$GPART_CREATE" BSD \${disk}s1 ||
786 # zpool will use s1a (no labels)
787 bootpart=s1a targetpart=s1a mbrindex=1
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 ||
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"
806 # 4. Partition the BSD slice for ZFS
807 # NOTE: Using above calculated partsize to leave room for swap.
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
817 f_dprintf "$funcname: mbrindex=[%s]" "$mbrindex"
818 f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
819 \$mbrindex freebsd-zfs \${disk}s1 ||
822 f_quietly zpool labelclear -f /dev/$disk$targetpart # Pedantic
825 # 5. Add freebsd-swap partition
827 if [ $swapsize -gt 0 ]; then
828 f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
829 2 freebsd-swap \${disk}s1 ||
832 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
833 /dev/\${disk}s1b none swap sw 0 0 \
834 \$BSDINSTALL_TMPETC/fstab ||
839 esac # $ZFSBOOT_PARTITION_SCHEME
844 # zfs_create_boot $poolname $vdev_type $disks ...
846 # Creates boot pool and dataset layout. Returns error if something goes wrong.
847 # Errors are printed to stderr for collection and display.
851 local funcname=zfs_create_boot
852 local poolname="$1" vdev_type="$2"
853 local bootpart targetpart
855 shift 2 # name vdev_type
857 # We may need this later
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"
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"
873 f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \
874 "$poolname" "$vdev_type"
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 ||
881 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
882 "# Device" Mountpoint FStype Options Dump "Pass#" \
883 \$BSDINSTALL_TMPETC/fstab || return $FAILURE
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'" \
891 f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE"
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"
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"
907 f_dprintf "$funcname: Preparing disk partitions for ZFS pool..."
910 zfs_create_diskpart $disk $n || return $FAILURE
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 ||
927 # Forced 4k alignment support provided by Geom NOP (see gnop(8))
929 if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then
930 local part="$targetpart" new_list=
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"
936 f_dprintf "$funcname: Applying 4k alignment with gnop(8)..."
937 f_dprintf "$funcname: *=[%s]" "$*"
939 f_dprintf "$funcname: disk=[%s] part=[%s]" \
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"
946 new_list="$new_list $disk$targetpart.nop"
953 new_list="$new_list $disk$targetpart"
954 [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
955 unenc_list="$unenc_list $disk$bootpart"
961 # If encryption is enabled, we need to create the GEOMs
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"
968 f_dprintf "$funcname: Setting up disk encryption..."
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
975 # Create mirror across the unencrypted partition on all disks
976 [ $( set -- $unenc_list; echo $# ) -gt 1 ] && bootvdev=mirror
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
988 f_dprintf "$funcname: geli_pool=[%s]" "$geli_pool"
989 f_eval_catch $funcname mkdir "$MKDIR_P" \$geli_pool/boot ||
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" ||
998 # Create the geli(8) GEOMS
1000 if ! msg_enter_new_password="$msg_geli_password" \
1001 f_dialog_input_password
1003 f_dprintf "$funcname: User cancelled"
1004 f_show_err "$msg_user_cancelled"
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
1018 f_interactive || f_die
1021 if ! echo "$pw_password" | f_eval_catch $funcname \
1022 geli "$GELI_ATTACH" \$geli_pool/\$key \
1025 f_interactive || f_die
1028 geli_list="$geli_list $disk$targetpart.eli"
1031 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \
1032 \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
1033 f_quietly umount /mnt # done with tmpfs
1037 # Create the ZFS pool with desired type and disk devices
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
1047 # Customize the zpool a bit...
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 ||
1057 # Create ZFS dataset layout within the new boot pool
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
1069 while [ "$oldoptions" != "$options" ]; do
1070 oldoptions="$options"
1071 f_replaceall "$options" " " " " options
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 ||
1083 # Touch up permissions on the tmp directories
1084 f_dprintf "$funcname: Modifying directory permissions..."
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
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
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
1109 # Export the pool(s)
1110 f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..."
1111 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \$poolname ||
1113 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1114 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \
1115 \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
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
1123 f_quietly gnop destroy $disk$targetpart.nop
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]" \
1136 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
1137 /boot/zfsboot /dev/\$disk\$bootpart \
1138 "skip=1 seek=1024" || return $FAILURE
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 ||
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
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 ||
1157 f_eval_catch $funcname zpool "$ZPOOL_SET" \
1158 cachefile=\"\$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\" \
1159 \$poolname || return $FAILURE
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..." \
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
1170 # We're all done unless we should go on to do encryption
1171 [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS
1173 # Some additional geli(8) requirements for loader.conf(5)
1175 zpool_cache_load=\"YES\" \
1176 zpool_cache_type=\"/boot/zfs/zpool.cache\" \
1177 zpool_cache_name=\"/boot/zfs/zpool.cache\" \
1179 f_eval_catch $funcname echo "$ECHO_APPEND" \$option \
1180 \$BSDINSTALL_TMPBOOT/loader.conf.zfs ||
1185 # Configure geli(8)-based encryption
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_BOOT_FSNAME"' \
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 ||
1204 f_eval_catch $funcname printf "$PRINTF_CONF" \
1205 geli_%s_keyfile0_type \
1206 '"$disk$targetpart" "$disk$targetpart"' \
1207 \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
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 ||
1219 # dialog_menu_diskinfo
1221 # Prompt the user to select a disk and then provide detailed info on it.
1223 dialog_menu_diskinfo()
1228 # Break from loop when user cancels disk selection
1231 disk=$( msg_cancel="$msg_back" f_device_menu \
1232 "$DIALOG_TITLE" "$msg_select_a_disk_device" "" \
1233 $DEVICE_TYPE_DISK 2>&1 ) || break
1235 # Show gpart(8) `show' and camcontrol(8) `inquiry' data
1236 f_show_msg "$msg_detailed_disk_info" \
1237 "$disk" "$( gpart show $disk 2> /dev/null )" \
1238 "$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \
1239 "$disk" "$( camcontrol identify $disk 2> /dev/null )"
1245 ############################################################ MAIN
1250 f_dialog_title "$msg_zfs_configuration"
1251 f_dialog_backtitle "$msg_freebsd_installer"
1253 # User may have specifically requested ZFS-related operations be interactive
1254 ! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE
1259 f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT"
1260 f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC"
1261 f_dprintf "PRINTF_FSTAB=[%s]" "$PRINTF_FSTAB"
1264 # Loop over the main menu until we've accomplished what we came here to do
1267 if ! f_interactive; then
1269 mtag=">>> $msg_install"
1273 f_dialog_menutag_fetch mtag
1276 f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
1277 [ $retval -eq $DIALOG_OK ] || f_die
1282 # First, validate the user's selections
1285 # Make sure they gave us a name for the pool
1286 if [ ! "$ZFSBOOT_POOL_NAME" ]; then
1287 f_dprintf "Pool name cannot be empty."
1288 f_show_err "$msg_pool_name_cannot_be_empty"
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
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
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"
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" \
1316 f_show_err "$msg_these_disks_are_too_small" \
1317 "$ZFSBOOT_SWAP_SIZE" \
1318 "$ZFSBOOT_GELI_BOOT_SIZE" \
1327 if f_interactive; then
1328 dialog_last_chance $ZFSBOOT_DISKS || continue
1335 vdev_type="$ZFSBOOT_VDEV_TYPE"
1337 # Blank the vdev type for the default layout
1338 [ "$vdev_type" = "stripe" ] && vdev_type=
1340 zfs_create_boot "$ZFSBOOT_POOL_NAME" \
1341 "$vdev_type" $ZFSBOOT_DISKS || continue
1345 ?" $msg_pool_type_disks")
1346 ZFSBOOT_CONFIRM_LAYOUT=1
1348 # User has poked settings, disable later confirmation
1349 ZFSBOOT_CONFIRM_LAYOUT=
1351 "- $msg_rescan_devices") f_device_rescan ;;
1352 "- $msg_disk_info") dialog_menu_diskinfo ;;
1354 # Prompt the user to input/change the name for the new pool
1355 f_dialog_input input \
1356 "$msg_please_enter_a_name_for_your_zpool" \
1357 "$ZFSBOOT_POOL_NAME" &&
1358 ZFSBOOT_POOL_NAME="$input"
1360 ?" $msg_force_4k_sectors")
1361 # Toggle the variable referenced both by the menu and later
1362 if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then
1363 ZFSBOOT_GNOP_4K_FORCE_ALIGN=
1365 ZFSBOOT_GNOP_4K_FORCE_ALIGN=1
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=
1373 ZFSBOOT_GELI_ENCRYPTION=1
1376 ?" $msg_partition_scheme")
1377 # Toggle between GPT and MBR
1378 if [ "$ZFSBOOT_PARTITION_SCHEME" = GPT ]; then
1379 ZFSBOOT_PARTITION_SCHEME=MBR
1381 ZFSBOOT_PARTITION_SCHEME=GPT
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"
1396 ################################################################################
1398 ################################################################################