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 options to use when creating zroot pool
50 : ${ZFSBOOT_POOL_CREATE_OPTIONS:=-O compress=lz4 -O atime=off}
53 # Default name for the boot environment parent dataset
55 : ${ZFSBOOT_BEROOT_NAME:=ROOT}
58 # Default name for the primany boot environment
60 : ${ZFSBOOT_BOOTFS_NAME:=default}
63 # Default Virtual Device (vdev) type to create
65 : ${ZFSBOOT_VDEV_TYPE:=stripe}
68 # Should we use sysctl(8) vfs.zfs.min_auto_ashift=12 to force 4K sectors?
70 : ${ZFSBOOT_FORCE_4K_SECTORS:=1}
73 # Should we use geli(8) to encrypt the drives?
74 # NB: Automatically enables ZFSBOOT_BOOT_POOL
76 : ${ZFSBOOT_GELI_ENCRYPTION=}
79 # Default path to the geli(8) keyfile used in drive encryption
81 : ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key}
84 # Create a separate boot pool?
85 # NB: Automatically set when using geli(8) or MBR
87 : ${ZFSBOOT_BOOT_POOL=}
90 # Options to use when creating separate boot pool (if any)
92 : ${ZFSBOOT_BOOT_POOL_CREATE_OPTIONS:=}
95 # Default name for boot pool when enabled (e.g., geli(8) or MBR)
97 : ${ZFSBOOT_BOOT_POOL_NAME:=bootpool}
100 # Default size for boot pool when enabled (e.g., geli(8) or MBR)
102 : ${ZFSBOOT_BOOT_POOL_SIZE:=2g}
105 # Default disks to use (always empty unless being scripted)
110 # Default partitioning scheme to use on disks
112 : ${ZFSBOOT_PARTITION_SCHEME:=GPT}
115 # How much swap to put on each block device in the boot zpool
116 # NOTE: Value passed to gpart(8); which supports SI unit suffixes.
118 : ${ZFSBOOT_SWAP_SIZE:=2g}
121 # Should we use geli(8) to encrypt the swap?
123 : ${ZFSBOOT_SWAP_ENCRYPTION=}
126 # Should we use gmirror(8) to mirror the swap?
128 : ${ZFSBOOT_SWAP_MIRROR=}
131 # Default ZFS datasets for root zpool
133 # NOTE: Requires /tmp, /var/tmp, /$ZFSBOOT_BOOTFS_NAME/$ZFSBOOT_BOOTFS_NAME
134 # NOTE: Anything after pound/hash character [#] is ignored as a comment.
136 f_isset ZFSBOOT_DATASETS || ZFSBOOT_DATASETS="
137 # DATASET OPTIONS (comma or space separated; or both)
139 # Boot Environment [BE] root and default boot dataset
140 /$ZFSBOOT_BEROOT_NAME mountpoint=none
141 /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/
143 # Compress /tmp, allow exec but not setuid
144 /tmp mountpoint=/tmp,exec=on,setuid=off
146 # Don't mount /usr so that 'base' files go to the BEROOT
147 /usr mountpoint=/usr,canmount=off
149 # Home directories separated so they are common to all BEs
150 /usr/home # NB: /home is a symlink to /usr/home
153 /usr/ports setuid=off
155 # Source tree (compressed)
158 # Create /var and friends
159 /var mountpoint=/var,canmount=off
160 /var/crash exec=off,setuid=off
161 /var/log exec=off,setuid=off
167 # If interactive and the user has not explicitly chosen a vdev type or disks,
168 # make the user confirm scripted/default choices when proceeding to install.
170 : ${ZFSBOOT_CONFIRM_LAYOUT:=1}
172 ############################################################ GLOBALS
175 # Format of a line in printf(1) syntax to add to fstab(5)
177 FSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n"
180 # Command strings for various tasks
182 CHMOD_MODE='chmod %s "%s"'
183 DD_WITH_OPTIONS='dd if="%s" of="%s" %s'
184 ECHO_APPEND='echo "%s" >> "%s"'
185 GELI_ATTACH='geli attach -j - -k "%s" "%s"'
186 GELI_DETACH_F='geli detach -f "%s"'
187 GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"'
188 GPART_ADD='gpart add -t %s "%s"'
189 GPART_ADD_INDEX='gpart add -i %s -t %s "%s"'
190 GPART_ADD_INDEX_WITH_SIZE='gpart add -i %s -t %s -s %s "%s"'
191 GPART_ADD_LABEL='gpart add -l %s -t %s "%s"'
192 GPART_ADD_LABEL_WITH_SIZE='gpart add -l %s -t %s -s %s "%s"'
193 GPART_BOOTCODE='gpart bootcode -b "%s" "%s"'
194 GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"'
195 GPART_CREATE='gpart create -s %s "%s"'
196 GPART_DESTROY_F='gpart destroy -F "%s"'
197 GPART_SET_ACTIVE='gpart set -a active -i %s "%s"'
198 GRAID_DELETE='graid delete "%s"'
199 LN_SF='ln -sf "%s" "%s"'
200 MKDIR_P='mkdir -p "%s"'
201 MOUNT_TYPE='mount -t %s "%s" "%s"'
202 PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\""
203 PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"'
204 SHELL_TRUNCATE=':> "%s"'
205 SWAP_GMIRROR_LABEL='gmirror label swap %s'
206 SYSCTL_ZFS_MIN_ASHIFT_12='sysctl vfs.zfs.min_auto_ashift=12'
208 ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"'
209 ZFS_SET='zfs set "%s" "%s"'
210 ZFS_UNMOUNT='zfs unmount "%s"'
211 ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s'
212 ZPOOL_DESTROY='zpool destroy "%s"'
213 ZPOOL_EXPORT='zpool export "%s"'
214 ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"'
215 ZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"'
216 ZPOOL_SET='zpool set %s "%s"'
219 # Strings that should be moved to an i18n file and loaded with f_include_lang()
221 hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER"
222 hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER"
223 hline_arrows_tab_enter="Press arrows, TAB or ENTER"
224 msg_an_unknown_error_occurred="An unknown error occurred"
227 msg_change_selection="Change Selection"
228 msg_configure_options="Configure Options:"
229 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"
230 msg_disk_info="Disk Info"
231 msg_disk_info_help="Get detailed information on disk device(s)"
232 msg_disk_singular="disk"
233 msg_disk_plural="disks"
234 msg_encrypt_disks="Encrypt Disks?"
235 msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions"
237 msg_force_4k_sectors="Force 4K Sectors?"
238 msg_force_4k_sectors_help="Use sysctl(8) vfs.zfs.min_auto_ashift=12 to force 4K sectors"
239 msg_freebsd_installer="FreeBSD Installer"
240 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"
241 msg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk"
242 msg_install="Install"
243 msg_install_desc="Proceed with Installation"
244 msg_install_help="Create ZFS boot pool with displayed options"
245 msg_invalid_boot_pool_size="Invalid boot pool size \`%s'"
246 msg_invalid_disk_argument="Invalid disk argument \`%s'"
247 msg_invalid_index_argument="Invalid index argument \`%s'"
248 msg_invalid_swap_size="Invalid swap size \`%s'"
249 msg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'"
250 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"
251 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'
252 msg_mirror_desc="Mirror - n-Way Mirroring"
253 msg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage"
254 msg_missing_disk_arguments="missing disk arguments"
255 msg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!"
257 msg_no_disks_present_to_configure="No disk(s) present to configure"
258 msg_no_disks_selected="No disks selected."
259 msg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)"
260 msg_null_disk_argument="NULL disk argument"
261 msg_null_index_argument="NULL index argument"
262 msg_null_poolname="NULL poolname"
264 msg_partition_scheme="Partition Scheme"
265 msg_partition_scheme_help="Toggle between GPT and MBR partitioning schemes"
266 msg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:"
267 msg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):"
268 msg_please_select_one_or_more_disks="Please select one or more disks to create a zpool:"
269 msg_pool_name="Pool Name"
270 msg_pool_name_cannot_be_empty="Pool name cannot be empty."
271 msg_pool_name_help="Customize the name of the zpool to be created (Required)"
272 msg_pool_type_disks="Pool Type/Disks:"
273 msg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)"
274 msg_processing_selection="Processing selection..."
275 msg_raidz1_desc="RAID-Z1 - Single Redundant RAID"
276 msg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks"
277 msg_raidz2_desc="RAID-Z2 - Double Redundant RAID"
278 msg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks"
279 msg_raidz3_desc="RAID-Z3 - Triple Redundant RAID"
280 msg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks"
281 msg_rescan_devices="Rescan Devices"
282 msg_rescan_devices_help="Scan for device changes"
284 msg_select_a_disk_device="Select a disk device"
285 msg_select_virtual_device_type="Select Virtual Device type:"
286 msg_stripe_desc="Stripe - No Redundancy"
287 msg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy"
288 msg_swap_encrypt="Encrypt Swap?"
289 msg_swap_encrypt_help="Encrypt swap partitions with temporary keys, discarded on reboot"
290 msg_swap_mirror="Mirror Swap?"
291 msg_swap_mirror_help="Mirror swap partitions for redundancy, breaks crash dumps"
292 msg_swap_size="Swap Size"
293 msg_swap_size_help="Customize how much swap space is allocated to each selected disk"
294 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."
295 msg_uefi_not_supported="The FreeBSD UEFI loader does not currently support booting root-on-ZFS. Your system will need to boot in legacy (CSM) mode.\nDo you want to continue?"
296 msg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'"
297 msg_unsupported_partition_scheme="%s is an unsupported partition scheme"
298 msg_user_cancelled="User Cancelled."
300 msg_zfs_configuration="ZFS Configuration"
302 ############################################################ FUNCTIONS
306 # Display the dialog(1)-based application main menu.
310 local title="$DIALOG_TITLE"
311 local btitle="$DIALOG_BACKTITLE"
312 local prompt="$msg_configure_options"
313 local force4k="$msg_no"
314 local usegeli="$msg_no"
315 local swapgeli="$msg_no"
316 local swapmirror="$msg_no"
317 [ "$ZFSBOOT_FORCE_4K_SECTORS" ] && force4k="$msg_yes"
318 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes"
319 [ "$ZFSBOOT_SWAP_ENCRYPTION" ] && swapgeli="$msg_yes"
320 [ "$ZFSBOOT_SWAP_MIRROR" ] && swapmirror="$msg_yes"
321 local disks n disks_grammar
322 f_count n $ZFSBOOT_DISKS
323 { [ $n -eq 1 ] && disks_grammar=$msg_disk_singular; } ||
324 disks_grammar=$msg_disk_plural # grammar
326 '>>> $msg_install' '$msg_install_desc'
328 'T $msg_pool_type_disks' '$ZFSBOOT_VDEV_TYPE: $n $disks_grammar'
329 '$msg_pool_type_disks_help'
330 '- $msg_rescan_devices' '*'
331 '$msg_rescan_devices_help'
332 '- $msg_disk_info' '*'
333 '$msg_disk_info_help'
334 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME'
335 '$msg_pool_name_help'
336 '4 $msg_force_4k_sectors' '$force4k'
337 '$msg_force_4k_sectors_help'
338 'E $msg_encrypt_disks' '$usegeli'
339 '$msg_encrypt_disks_help'
340 'P $msg_partition_scheme' '$ZFSBOOT_PARTITION_SCHEME'
341 '$msg_partition_scheme_help'
342 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE'
343 '$msg_swap_size_help'
344 'M $msg_swap_mirror' '$swapmirror'
345 '$msg_swap_mirror_help'
346 'W $msg_swap_encrypt' '$swapgeli'
347 '$msg_swap_encrypt_help'
349 local defaultitem= # Calculated below
350 local hline="$hline_alnum_arrows_punc_tab_enter"
352 local height width rows
353 eval f_dialog_menu_with_help_size height width rows \
354 \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list
356 # Obtain default-item from previously stored selection
357 f_dialog_default_fetch defaultitem
360 menu_choice=$( eval $DIALOG \
361 --title \"\$title\" \
362 --backtitle \"\$btitle\" \
363 --hline \"\$hline\" \
365 --ok-label \"\$msg_select\" \
366 --cancel-label \"\$msg_cancel\" \
367 --default-item \"\$defaultitem\" \
368 --menu \"\$prompt\" \
369 $height $width $rows \
371 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
374 f_dialog_data_sanitize menu_choice
375 f_dialog_menutag_store "$menu_choice"
377 # Only update default-item on success
378 [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice"
383 # dialog_last_chance $disks ...
385 # Display a list of the disks that the user is about to destroy. The default
386 # action is to return error status unless the user explicitly (non-default)
387 # selects "Yes" from the noyes dialog.
391 local title="$DIALOG_TITLE"
392 local btitle="$DIALOG_BACKTITLE"
393 local prompt # Calculated below
394 local hline="$hline_arrows_tab_enter"
396 local height=8 width=50 prefix=" "
397 local plen=${#prefix} list= line=
398 local max_width=$(( $width - 3 - $plen ))
400 local yes no defaultno extra_args format
401 if [ "$USE_XDIALOG" ]; then
402 yes=ok no=cancel defaultno=default-no
403 extra_args="--wrap --left"
404 format="$msg_last_chance_are_you_sure"
406 yes=yes no=no defaultno=defaultno
407 extra_args="--colors --cr-wrap"
408 format="$msg_last_chance_are_you_sure_color"
411 local disk line_width
418 line_width=$(( $line_width + 1 + ${#disk} ))
419 # Add newline before disk if it would exceed max_width
420 if [ $line_width -gt $max_width ]; then
423 height=$(( $height + 1 ))
425 # Add the disk to the list
428 # Append the left-overs
429 if [ "${line#$prefix}" ]; then
431 height=$(( $height + 1 ))
434 # Add height for Xdialog(1)
435 [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
437 prompt=$( printf "$format" "$list" )
438 f_dprintf "%s: Last Chance!" "$0"
441 --backtitle "$btitle" \
444 --$yes-label "$msg_yes" \
445 --$no-label "$msg_no" \
447 --yesno "$prompt" $height $width
452 # Configure Virtual Device type and disks to use for the ZFS boot pool. User
453 # must select enough disks to satisfy the chosen vdev type.
457 local funcname=dialog_menu_layout
458 local title="$DIALOG_TITLE"
459 local btitle="$DIALOG_BACKTITLE"
460 local vdev_prompt="$msg_select_virtual_device_type"
461 local disk_prompt="$msg_please_select_one_or_more_disks"
462 local vdev_menu_list="
463 'stripe' '$msg_stripe_desc' '$msg_stripe_help'
464 'mirror' '$msg_mirror_desc' '$msg_mirror_help'
465 'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help'
466 'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help'
467 'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help'
469 local disk_check_list= # Calculated below
470 local vdev_hline="$hline_arrows_tab_enter"
471 local disk_hline="$hline_arrows_space_tab_enter"
473 # Warn the user if vdev type is not valid
474 case "$ZFSBOOT_VDEV_TYPE" in
475 stripe|mirror|raidz1|raidz2|raidz3) : known good ;;
477 f_dprintf "%s: Invalid virtual device type \`%s'" \
478 $funcname "$ZFSBOOT_VDEV_TYPE"
479 f_show_err "$msg_invalid_virtual_device_type" \
481 f_interactive || return $FAILURE
484 # Calculate size of vdev menu once only
485 local vheight vwidth vrows
486 eval f_dialog_menu_with_help_size vheight vwidth vrows \
487 \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \
490 # Get a list of probed disk devices
492 debug= f_device_find "" $DEVICE_TYPE_DISK disks
494 # Prune out mounted md(4) devices that may be part of the boot process
495 local disk name new_list=
496 for disk in $disks; do
497 debug= $disk get name name
499 md[0-9]*) f_mounted -b "/dev/$name" && continue ;;
501 new_list="$new_list $disk"
503 disks="${new_list# }"
506 if [ "$debug" ]; then
508 for disk in $disks; do
509 debug= $disk get name name
510 disk_names="$disk_names $name"
512 f_dprintf "$funcname: disks=[%s]" "${disk_names# }"
515 if [ ! "$disks" ]; then
516 f_dprintf "No disk(s) present to configure"
517 f_show_err "$msg_no_disks_present_to_configure"
521 # Lets sort the disks array to be more user friendly
522 f_device_sort_by name disks disks
525 # Operate in a loop so we can (if interactive) repeat if not enough
526 # disks are selected to satisfy the chosen vdev type or user wants to
527 # back-up to the previous menu.
529 local vardisk ndisks onoff selections vdev_choice breakout device
530 local valid_disks all_valid want_disks desc height width rows
533 # Confirm the vdev type that was selected
535 if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
536 vdev_choice=$( eval $DIALOG \
537 --title \"\$title\" \
538 --backtitle \"\$btitle\" \
539 --hline \"\$vdev_hline\" \
540 --ok-label \"\$msg_ok\" \
541 --cancel-label \"\$msg_cancel\" \
543 --default-item \"\$ZFSBOOT_VDEV_TYPE\" \
544 --menu \"\$vdev_prompt\" \
545 $vheight $vwidth $vrows \
547 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
549 # Exit if user pressed ESC or chose Cancel/No
550 f_dialog_data_sanitize vdev_choice
552 ZFSBOOT_VDEV_TYPE="$vdev_choice"
553 f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \
557 # Determine the number of disks needed for this vdev type
559 case "$ZFSBOOT_VDEV_TYPE" in
560 stripe) want_disks=1 ;;
561 mirror) want_disks=2 ;;
562 raidz1) want_disks=3 ;;
563 raidz2) want_disks=4 ;;
564 raidz3) want_disks=5 ;;
568 # Warn the user if any scripted disks are invalid
570 valid_disks= all_valid=${ZFSBOOT_DISKS:+1} # optimism
571 for disk in $ZFSBOOT_DISKS; do
572 if debug= f_device_find -1 \
573 $disk $DEVICE_TYPE_DISK device
575 valid_disks="$valid_disks $disk"
578 f_dprintf "$funcname: \`%s' is not a real disk" "$disk"
581 if [ ! "$all_valid" ]; then
582 if [ "$ZFSBOOT_DISKS" ]; then
584 "$msg_missing_one_or_more_scripted_disks"
586 f_dprintf "No disks selected."
588 f_show_err "$msg_no_disks_selected"
590 f_interactive || return $FAILURE
592 ZFSBOOT_DISKS="${valid_disks# }"
595 # Short-circuit if we're running non-interactively
597 if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
598 f_count ndisks $ZFSBOOT_DISKS
599 [ $ndisks -ge $want_disks ] && break # to success
601 # Not enough disks selected
602 f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
603 "$ZFSBOOT_VDEV_TYPE" \
604 "Not enough disks selected." \
606 f_interactive || return $FAILURE
607 msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
608 f_yesno "%s: $msg_not_enough_disks_selected" \
609 "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
614 # Confirm the disks that were selected
615 # Loop until the user cancels or selects enough disks
619 # Loop over list of available disks, resetting state
620 for disk in $disks; do
621 f_isset _${disk}_status && _${disk}_status=
624 # Loop over list of selected disks and create temporary
625 # locals to map statuses onto up-to-date list of disks
626 for disk in $ZFSBOOT_DISKS; do
627 debug= f_device_find -1 \
628 $disk $DEVICE_TYPE_DISK disk
629 f_isset _${disk}_status ||
630 local _${disk}_status
634 # Create the checklist menu of discovered disk devices
636 for disk in $disks; do
640 f_shell_escape "$desc" desc
641 f_getvar _${disk}_status:-off onoff
642 disk_check_list="$disk_check_list
643 $name '$desc' $onoff"
646 eval f_dialog_checklist_size height width rows \
647 \"\$title\" \"\$btitle\" \"\$prompt\" \
648 \"\$hline\" $disk_check_list
650 selections=$( eval $DIALOG \
651 --title \"\$DIALOG_TITLE\" \
652 --backtitle \"\$DIALOG_BACKTITLE\" \
654 --hline \"\$hline\" \
655 --ok-label \"\$msg_ok\" \
656 --cancel-label \"\$msg_back\" \
657 --checklist \"\$prompt\" \
658 $height $width $rows \
660 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
662 # Loop if user pressed ESC or chose Cancel/No
663 f_dialog_data_sanitize selections
665 ZFSBOOT_DISKS="$selections"
666 f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \
669 f_count ndisks $ZFSBOOT_DISKS
670 [ $ndisks -ge $want_disks ] &&
671 breakout=break && break
673 # Not enough disks selected
674 f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
675 "$ZFSBOOT_VDEV_TYPE" \
676 "Not enough disks selected." \
678 msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
679 f_yesno "%s: $msg_not_enough_disks_selected" \
680 "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
683 [ "$breakout" = "break" ] && break
684 [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE
692 # Confirm that the user wants to continue with the installation on a BIOS
693 # system when they have booted with UEFI
697 local title="$DIALOG_TITLE"
698 local btitle="$DIALOG_BACKTITLE"
699 local prompt # Calculated below
700 local hline="$hline_arrows_tab_enter"
702 local height=8 width=50 prefix=" "
703 local plen=${#prefix} list= line=
704 local max_width=$(( $width - 3 - $plen ))
706 local yes no defaultno extra_args format
707 if [ "$USE_XDIALOG" ]; then
708 yes=ok no=cancel defaultno=default-no
709 extra_args="--wrap --left"
710 format="$msg_uefi_not_supported"
712 yes=yes no=no defaultno=defaultno
713 extra_args="--cr-wrap"
714 format="$msg_uefi_not_supported"
717 # Add height for Xdialog(1)
718 [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
720 prompt=$( printf "$format" )
721 f_dprintf "%s: UEFI prompt" "$0"
724 --backtitle "$btitle" \
726 --$yes-label "$msg_yes" \
727 --$no-label "$msg_no" \
729 --yesno "$prompt" $height $width
732 # zfs_create_diskpart $disk $index
734 # For each block device to be used in the zpool, rather than just create the
735 # zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions
736 # so we can have some real swap. This also provides wiggle room incase your
737 # replacement drivers do not have the exact same sector counts.
739 # NOTE: $swapsize and $bootsize should be defined by the calling function.
740 # NOTE: Sets $bootpart and $targetpart for the calling function.
742 zfs_create_diskpart()
744 local funcname=zfs_create_diskpart
745 local disk="$1" index="$2"
748 if [ ! "$disk" ]; then
749 f_dprintf "$funcname: NULL disk argument"
750 msg_error="$msg_error: $funcname" \
751 f_show_err "$msg_null_disk_argument"
754 if [ "${disk#*[$IFS]}" != "$disk" ]; then
755 f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk"
756 msg_error="$msg_error: $funcname" \
757 f_show_err "$msg_invalid_disk_argument" "$disk"
760 if [ ! "$index" ]; then
761 f_dprintf "$funcname: NULL index argument"
762 msg_error="$msg_error: $funcname" \
763 f_show_err "$msg_null_index_argument"
766 if ! f_isinteger "$index"; then
767 f_dprintf "$funcname: Invalid index argument \`%s'" "$index"
768 msg_error="$msg_error: $funcname" \
769 f_show_err "$msg_invalid_index_argument" "$index"
772 f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index"
774 # Check for unknown partition scheme before proceeding further
775 case "$ZFSBOOT_PARTITION_SCHEME" in
776 ""|MBR|GPT) : known good ;;
778 f_dprintf "$funcname: %s is an unsupported partition scheme" \
779 "$ZFSBOOT_PARTITION_SCHEME"
780 msg_error="$msg_error: $funcname" f_show_err \
781 "$msg_unsupported_partition_scheme" \
782 "$ZFSBOOT_PARTITION_SCHEME"
787 # Destroy whatever partition layout is currently on disk.
788 # NOTE: `-F' required to destroy if partitions still exist.
789 # NOTE: Failure is ok here, blank disk will have nothing to destroy.
791 f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk"
792 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk
793 f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk
794 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk
796 # Make doubly-sure backup GPT is destroyed
797 f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk
798 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk
801 # Enable boot pool if encryption is desired
803 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1
806 # Lay down the desired type of partition scheme
808 local setsize mbrindex
809 case "$ZFSBOOT_PARTITION_SCHEME" in
810 ""|GPT) f_dprintf "$funcname: Creating GPT layout..."
812 # 1. Create GPT layout using labels
814 f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk ||
818 # 2. Add small freebsd-boot partition labeled `boot#'
820 f_eval_catch $funcname gpart "$GPART_ADD_LABEL_WITH_SIZE" \
821 gptboot$index freebsd-boot 512k $disk ||
823 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \
824 /boot/pmbr /boot/gptzfsboot 1 $disk ||
827 # NB: zpool will use the `zfs#' GPT labels
828 bootpart=p2 swappart=p2 targetpart=p2
829 [ ${swapsize:-0} -gt 0 ] && targetpart=p3
832 # Prepare boot pool if enabled (e.g., for geli(8))
834 if [ "$ZFSBOOT_BOOT_POOL" ]; then
835 bootpart=p2 swappart=p3 targetpart=p3
836 [ ${swapsize:-0} -gt 0 ] && targetpart=p4
837 f_eval_catch $funcname gpart \
838 "$GPART_ADD_LABEL_WITH_SIZE" boot$index \
839 freebsd-zfs ${bootsize}b $disk ||
841 # Pedantically nuke any old labels
842 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
844 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
845 # Pedantically detach targetpart for later
846 f_eval_catch -d $funcname geli \
848 /dev/$disk$targetpart
853 # 3. Add freebsd-swap partition labeled `swap#'
855 if [ ${swapsize:-0} -gt 0 ]; then
856 f_eval_catch $funcname gpart \
857 "$GPART_ADD_LABEL_WITH_SIZE" swap$index \
858 freebsd-swap ${swapsize}b $disk ||
860 # Pedantically nuke any old labels on the swap
861 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
866 # 4. Add freebsd-zfs partition labeled `zfs#' for zroot
868 f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
869 zfs$index freebsd-zfs $disk || return $FAILURE
870 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
871 /dev/$disk$targetpart
874 MBR) f_dprintf "$funcname: Creating MBR layout..."
876 # 1. Create MBR layout (no labels)
878 f_eval_catch $funcname gpart "$GPART_CREATE" mbr $disk ||
880 f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \
881 $disk || return $FAILURE
884 # 2. Add freebsd slice with all available space
886 f_eval_catch $funcname gpart "$GPART_ADD" freebsd $disk ||
888 f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 $disk ||
890 # Pedantically nuke any old labels
891 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
893 # Pedantically nuke any old scheme
894 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" ${disk}s1
897 # 3. Write BSD scheme to the freebsd slice
899 f_eval_catch $funcname gpart "$GPART_CREATE" BSD ${disk}s1 ||
902 # NB: zpool will use s1a (no labels)
903 bootpart=s1a swappart=s1b targetpart=s1d mbrindex=4
906 # Always prepare a boot pool on MBR
909 f_eval_catch $funcname gpart \
910 "$GPART_ADD_INDEX_WITH_SIZE" \
911 1 freebsd-zfs ${bootsize}b ${disk}s1 ||
913 # Pedantically nuke any old labels
914 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
916 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
917 # Pedantically detach targetpart for later
918 f_eval_catch -d $funcname geli \
920 /dev/$disk$targetpart
924 # 4. Add freebsd-swap partition
926 if [ ${swapsize:-0} -gt 0 ]; then
927 f_eval_catch $funcname gpart \
928 "$GPART_ADD_INDEX_WITH_SIZE" 2 \
929 freebsd-swap ${swapsize}b ${disk}s1 ||
931 # Pedantically nuke any old labels on the swap
932 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
937 # 5. Add freebsd-zfs partition for zroot
939 f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
940 $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE
941 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
942 /dev/$disk$targetpart # Pedantic
943 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
944 /boot/zfsboot /dev/${disk}s1 count=1 ||
948 esac # $ZFSBOOT_PARTITION_SCHEME
951 if [ "$isswapmirror" ]; then
952 # This is not the first disk in the mirror, do nothing
953 elif [ "$ZFSBOOT_SWAP_ENCRYPTION" -a "$ZFSBOOT_SWAP_MIRROR" ]; then
954 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
955 /dev/mirror/swap.eli none swap sw 0 0 \
956 $BSDINSTALL_TMPETC/fstab ||
959 elif [ "$ZFSBOOT_SWAP_MIRROR" ]; then
960 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
961 /dev/mirror/swap none swap sw 0 0 \
962 $BSDINSTALL_TMPETC/fstab ||
965 elif [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then
966 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
967 /dev/$disk${swappart}.eli none swap sw 0 0 \
968 $BSDINSTALL_TMPETC/fstab ||
971 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
972 /dev/$disk$swappart none swap sw 0 0 \
973 $BSDINSTALL_TMPETC/fstab ||
980 # zfs_create_boot $poolname $vdev_type $disks ...
982 # Creates boot pool and dataset layout. Returns error if something goes wrong.
983 # Errors are printed to stderr for collection and display.
987 local funcname=zfs_create_boot
988 local zroot_name="$1"
989 local zroot_vdevtype="$2"
990 local zroot_vdevs= # Calculated below
991 local swap_devs= # Calculated below
992 local boot_vdevs= # Used for geli(8) and/or MBR layouts
993 shift 2 # poolname vdev_type
994 local disks="$*" disk
996 local bootpart targetpart swappart # Set by zfs_create_diskpart() below
1000 # Pedantic checks; should never be seen
1002 if [ ! "$zroot_name" ]; then
1003 f_dprintf "$funcname: NULL poolname"
1004 msg_error="$msg_error: $funcname" \
1005 f_show_err "$msg_null_poolname"
1008 if [ $# -lt 1 ]; then
1009 f_dprintf "$funcname: missing disk arguments"
1010 msg_error="$msg_error: $funcname" \
1011 f_show_err "$msg_missing_disk_arguments"
1014 f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \
1015 "$zroot_name" "$zroot_vdevtype"
1018 # Initialize fstab(5)
1020 f_dprintf "$funcname: Initializing temporary fstab(5) file..."
1021 f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab ||
1023 f_eval_catch $funcname printf "$PRINTF_FSTAB" \
1024 "# Device" Mountpoint FStype Options Dump "Pass#" \
1025 $BSDINSTALL_TMPETC/fstab || return $FAILURE
1028 # Expand SI units in desired sizes
1030 f_dprintf "$funcname: Expanding supplied size values..."
1031 local swapsize bootsize
1032 if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then
1033 f_dprintf "$funcname: Invalid swap size \`%s'" \
1034 "$ZFSBOOT_SWAP_SIZE"
1035 f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE"
1038 if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then
1039 f_dprintf "$funcname: Invalid boot pool size \`%s'" \
1040 "$ZFSBOOT_BOOT_POOL_SIZE"
1041 f_show_err "$msg_invalid_boot_pool_size" \
1042 "$ZFSBOOT_BOOT_POOL_SIZE"
1045 f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \
1046 "$ZFSBOOT_SWAP_SIZE" "$swapsize"
1047 f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \
1048 "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize"
1051 # Destroy the pool in-case this is our second time 'round (case of
1052 # failure and installer presented ``Retry'' option to come back).
1054 # NB: If we don't destroy the pool, later gpart(8) destroy commands
1055 # that try to clear existing partitions (see zfs_create_diskpart())
1056 # will fail with a `Device Busy' error, leading to `GEOM exists'.
1058 f_eval_catch -d $funcname zpool "$ZPOOL_DESTROY" "$zroot_name"
1061 # Prepare the disks and build pool device list(s)
1063 f_dprintf "$funcname: Preparing disk partitions for ZFS pool..."
1065 # Force 4K sectors using vfs.zfs.min_auto_ashift=12
1066 if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then
1067 f_dprintf "$funcname: With 4K sectors..."
1068 f_eval_catch $funcname sysctl "$SYSCTL_ZFS_MIN_ASHIFT_12" \
1072 for disk in $disks; do
1073 zfs_create_diskpart $disk $n || return $FAILURE
1074 # Now $bootpart, $targetpart, and $swappart are set (suffix
1076 if [ "$ZFSBOOT_BOOT_POOL" ]; then
1077 boot_vdevs="$boot_vdevs $disk$bootpart"
1079 zroot_vdevs="$zroot_vdevs $disk$targetpart"
1080 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1081 zroot_vdevs="$zroot_vdevs.eli"
1088 # If we need/want a boot pool, create it
1090 if [ "$ZFSBOOT_BOOT_POOL" ]; then
1091 local bootpool_vdevtype= # Calculated below
1092 local bootpool_options= # Calculated below
1093 local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME"
1094 local bootpool="$BSDINSTALL_CHROOT/$bootpool_name"
1095 local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}"
1097 f_dprintf "$funcname: Setting up boot pool..."
1098 [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
1099 f_dprintf "$funcname: For encrypted root disk..."
1101 # Create parent directory for boot pool
1102 f_eval_catch -d $funcname umount "$UMOUNT" /mnt
1103 f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \
1104 $BSDINSTALL_CHROOT || return $FAILURE
1106 # Create mirror across the boot partition on all disks
1108 f_count nvdevs $boot_vdevs
1109 [ $nvdevs -gt 1 ] && bootpool_vdevtype=mirror
1111 create_options="$ZFSBOOT_BOOT_POOL_CREATE_OPTIONS"
1112 bootpool_options="-o altroot=$BSDINSTALL_CHROOT"
1113 bootpool_options="$bootpool_options $create_options"
1114 bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f"
1115 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
1116 "$bootpool_options" "$bootpool_name" \
1117 "$bootpool_vdevtype" "$boot_vdevs" ||
1120 f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" ||
1123 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1124 # Generate an encryption key using random(4)
1125 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
1126 /dev/random "$bootpool/$zroot_key" \
1127 "bs=4096 count=1" || return $FAILURE
1128 f_eval_catch $funcname chmod "$CHMOD_MODE" \
1129 go-wrx "$bootpool/$zroot_key" ||
1133 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \
1134 "$bootpool_name" || return $FAILURE
1135 f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs
1141 # Create the geli(8) GEOMS
1143 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1144 # Prompt user for password (twice)
1145 if ! msg_enter_new_password="$msg_geli_password" \
1146 f_dialog_input_password
1148 f_dprintf "$funcname: User cancelled"
1149 f_show_err "$msg_user_cancelled"
1153 # Initialize geli(8) on each of the target partitions
1154 for disk in $disks; do
1155 f_dialog_info "$msg_geli_setup" \
1156 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
1157 if ! echo "$pw_password" | f_eval_catch \
1158 $funcname geli "$GELI_PASSWORD_INIT" \
1159 "$bootpool/boot/$disk$targetpart.eli" \
1160 AES-XTS "$bootpool/$zroot_key" \
1163 f_interactive || f_die
1164 unset pw_password # Sensitive info
1167 if ! echo "$pw_password" | f_eval_catch \
1168 $funcname geli "$GELI_ATTACH" \
1169 "$bootpool/$zroot_key" $disk$targetpart
1171 f_interactive || f_die
1172 unset pw_password # Sensitive info
1176 unset pw_password # Sensitive info
1179 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" ||
1181 f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs
1184 # Create the gmirror(8) GEOMS for swap
1186 if [ "$ZFSBOOT_SWAP_MIRROR" ]; then
1187 for disk in $disks; do
1188 swap_devs="$swap_devs $disk$swappart"
1190 f_eval_catch $funcname gmirror "$SWAP_GMIRROR_LABEL" \
1191 "$swap_devs" || return $FAILURE
1195 # Create the ZFS root pool with desired type and disk devices
1197 f_dprintf "$funcname: Creating root pool..."
1198 create_options="$ZFSBOOT_POOL_CREATE_OPTIONS"
1199 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
1200 "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \
1201 "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" ||
1205 # Create ZFS dataset layout within the new root pool
1207 f_dprintf "$funcname: Creating ZFS datasets..."
1208 echo "$ZFSBOOT_DATASETS" | while read dataset options; do
1209 # Skip blank lines and comments
1210 case "$dataset" in "#"*|"") continue; esac
1211 # Remove potential inline comments in options
1212 options="${options%%#*}"
1213 # Replace tabs with spaces
1214 f_replaceall "$options" " " " " options
1215 # Reduce contiguous runs of space to one single space
1217 while [ "$oldoptions" != "$options" ]; do
1218 oldoptions="$options"
1219 f_replaceall "$options" " " " " options
1221 # Replace both commas and spaces with ` -o '
1222 f_replaceall "$options" "[ ,]" " -o " options
1223 # Create the dataset with desired options
1224 f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \
1225 "${options:+-o $options}" "$zroot_name$dataset" ||
1229 # Touch up permissions on the tmp directories
1230 f_dprintf "$funcname: Modifying directory permissions..."
1232 for dir in /tmp /var/tmp; do
1233 f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \
1234 $BSDINSTALL_CHROOTDIR$dir || return $FAILURE
1238 if [ "$ZFSBOOT_BOOT_POOL" ]; then
1239 f_dprintf "$funcname: Creating /boot symlink for boot pool..."
1240 f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \
1241 $BSDINSTALL_CHROOT/boot || return $FAILURE
1244 # Set bootfs property
1245 local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME"
1246 f_dprintf "$funcname: Setting bootfs property..."
1247 f_eval_catch $funcname zpool "$ZPOOL_SET" \
1248 "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" ||
1251 # Export the pool(s)
1252 f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..."
1253 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" "$zroot_name" ||
1255 if [ "$ZFSBOOT_BOOT_POOL" ]; then
1256 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \
1257 "$bootpool_name" || return $FAILURE
1260 # MBR boot loader touch-up
1261 if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then
1262 f_dprintf "$funcname: Updating MBR boot loader on disks..."
1263 # Stick the ZFS boot loader in the "convienient hole" after
1264 # the ZFS internal metadata
1265 for disk in $disks; do
1266 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
1267 /boot/zfsboot /dev/$disk$bootpart \
1268 "skip=1 seek=1024" || return $FAILURE
1272 # Re-import the ZFS pool(s)
1273 f_dprintf "$funcname: Re-importing ZFS pool(s)..."
1274 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
1275 "-o altroot=\"$BSDINSTALL_CHROOT\"" "$zroot_name" ||
1277 if [ "$ZFSBOOT_BOOT_POOL" ]; then
1278 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
1279 "-o altroot=\"$BSDINSTALL_CHROOT\"" \
1280 "$bootpool_name" || return $FAILURE
1283 # While this is apparently not needed, it seems to help MBR
1284 f_dprintf "$funcname: Configuring zpool.cache for zroot..."
1285 f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs ||
1287 f_eval_catch $funcname zpool "$ZPOOL_SET" \
1288 "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \
1289 "$zroot_name" || return $FAILURE
1291 # Last, but not least... required lines for rc.conf(5)/loader.conf(5)
1292 # NOTE: We later concatenate these into their destination
1293 f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \
1295 f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \
1296 $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE
1297 f_eval_catch $funcname echo "$ECHO_APPEND" \
1298 'kern.geom.label.gptid.enable=\"0\"' \
1299 $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
1301 if [ "$ZFSBOOT_SWAP_MIRROR" ]; then
1302 f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_mirror_load=\"YES\"' \
1303 $BSDINSTALL_TMPBOOT/loader.conf.gmirror || return $FAILURE
1306 # We're all done unless we should go on for boot pool
1307 [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS
1309 # Set cachefile for boot pool so it auto-imports at system start
1310 f_dprintf "$funcname: Configuring zpool.cache for boot pool..."
1311 f_eval_catch $funcname zpool "$ZPOOL_SET" \
1312 "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \
1313 "$bootpool_name" || return $FAILURE
1315 # Some additional geli(8) requirements for loader.conf(5)
1317 'zpool_cache_load=\"YES\"' \
1318 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \
1319 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \
1321 f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \
1322 $BSDINSTALL_TMPBOOT/loader.conf.zfs ||
1325 f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \
1326 "\"zfs:$zroot_name/$zroot_bootfs\"" \
1327 $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
1329 # We're all done unless we should go on to do encryption
1330 [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS
1333 # Configure geli(8)-based encryption
1335 f_dprintf "$funcname: Configuring disk encryption..."
1336 f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \
1337 $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
1338 f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \
1339 $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
1340 f_eval_catch $funcname echo "$ECHO_APPEND" \
1341 'geom_eli_passphrase_prompt=\"YES\"' \
1342 $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
1343 for disk in $disks; do
1344 f_eval_catch $funcname printf "$PRINTF_CONF" \
1345 geli_%s_keyfile0_load "$disk$targetpart YES" \
1346 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
1348 f_eval_catch $funcname printf "$PRINTF_CONF" \
1349 geli_%s_keyfile0_type \
1350 "$disk$targetpart $disk$targetpart:geli_keyfile0" \
1351 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
1353 f_eval_catch $funcname printf "$PRINTF_CONF" \
1354 geli_%s_keyfile0_name \
1355 "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \
1356 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
1363 # dialog_menu_diskinfo
1365 # Prompt the user to select a disk and then provide detailed info on it.
1367 dialog_menu_diskinfo()
1372 # Break from loop when user cancels disk selection
1375 device=$( msg_cancel="$msg_back" f_device_menu \
1376 "$DIALOG_TITLE" "$msg_select_a_disk_device" "" \
1377 $DEVICE_TYPE_DISK 2>&1 ) || break
1378 $device get name disk
1380 # Show gpart(8) `show' and camcontrol(8) `inquiry' data
1381 f_show_msg "$msg_detailed_disk_info" \
1382 "$disk" "$( gpart show $disk 2> /dev/null )" \
1383 "$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \
1384 "$disk" "$( camcontrol identify $disk 2> /dev/null )"
1390 ############################################################ MAIN
1395 f_dialog_title "$msg_zfs_configuration"
1396 f_dialog_backtitle "$msg_freebsd_installer"
1398 # User may have specifically requested ZFS-related operations be interactive
1399 ! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE
1404 f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT"
1405 f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC"
1406 f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT"
1409 # If the system was booted with UEFI, warn the user that FreeBSD can't do
1412 if f_interactive; then
1413 bootmethod=$(sysctl -n machdep.bootmethod)
1414 f_dprintf "machdep.bootmethod=[%s]" "$bootmethod"
1415 if [ "$bootmethod" != "BIOS" ]; then
1418 f_dprintf "uefi_prompt=[%s]" "$retval"
1419 [ $retval -eq $DIALOG_OK ] || f_die
1424 # Loop over the main menu until we've accomplished what we came here to do
1427 if ! f_interactive; then
1429 mtag=">>> $msg_install"
1433 f_dialog_menutag_fetch mtag
1436 f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
1437 [ $retval -eq $DIALOG_OK ] || f_die
1442 # First, validate the user's selections
1445 # Make sure they gave us a name for the pool
1446 if [ ! "$ZFSBOOT_POOL_NAME" ]; then
1447 f_dprintf "Pool name cannot be empty."
1448 f_show_err "$msg_pool_name_cannot_be_empty"
1452 # Validate vdev type against number of disks selected/scripted
1453 # (also validates that ZFSBOOT_DISKS are real [probed] disks)
1454 # NB: dialog_menu_layout supports running non-interactively
1455 dialog_menu_layout || continue
1457 # Make sure each disk will be at least 50% ZFS
1458 if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize &&
1459 f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize
1461 minsize=$swapsize teeny_disks=
1462 [ "$ZFSBOOT_BOOT_POOL" ] &&
1463 minsize=$(( $minsize + $bootsize ))
1464 for disk in $ZFSBOOT_DISKS; do
1465 debug= f_device_find -1 \
1466 $disk $DEVICE_TYPE_DISK device
1467 $device get capacity disksize || continue
1468 [ ${disksize:-0} -ge 0 ] || disksize=0
1469 disksize=$(( $disksize - $minsize ))
1470 [ $disksize -lt $minsize ] &&
1471 teeny_disks="$teeny_disks $disk"
1473 if [ "$teeny_disks" ]; then
1474 f_dprintf "swapsize=[%s] bootsize[%s] %s" \
1475 "$ZFSBOOT_SWAP_SIZE" \
1476 "$ZFSBOOT_BOOT_POOL_SIZE" \
1477 "minsize=[$minsize]"
1478 f_dprintf "These disks are too small: %s" \
1480 f_show_err "$msg_these_disks_are_too_small" \
1481 "$ZFSBOOT_SWAP_SIZE" \
1482 "$ZFSBOOT_BOOT_POOL_SIZE" \
1491 if f_interactive; then
1492 dialog_last_chance $ZFSBOOT_DISKS || continue
1499 vdev_type="$ZFSBOOT_VDEV_TYPE"
1501 # Blank the vdev type for the default layout
1502 [ "$vdev_type" = "stripe" ] && vdev_type=
1504 zfs_create_boot "$ZFSBOOT_POOL_NAME" \
1505 "$vdev_type" $ZFSBOOT_DISKS || continue
1509 ?" $msg_pool_type_disks")
1510 ZFSBOOT_CONFIRM_LAYOUT=1
1512 # User has poked settings, disable later confirmation
1513 ZFSBOOT_CONFIRM_LAYOUT=
1515 "- $msg_rescan_devices") f_device_rescan ;;
1516 "- $msg_disk_info") dialog_menu_diskinfo ;;
1518 # Prompt the user to input/change the name for the new pool
1519 f_dialog_input input \
1520 "$msg_please_enter_a_name_for_your_zpool" \
1521 "$ZFSBOOT_POOL_NAME" &&
1522 ZFSBOOT_POOL_NAME="$input"
1524 ?" $msg_force_4k_sectors")
1525 # Toggle the variable referenced both by the menu and later
1526 if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then
1527 ZFSBOOT_FORCE_4K_SECTORS=
1529 ZFSBOOT_FORCE_4K_SECTORS=1
1532 ?" $msg_encrypt_disks")
1533 # Toggle the variable referenced both by the menu and later
1534 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1535 ZFSBOOT_GELI_ENCRYPTION=
1537 ZFSBOOT_FORCE_4K_SECTORS=1
1538 ZFSBOOT_GELI_ENCRYPTION=1
1541 ?" $msg_partition_scheme")
1542 # Toggle between GPT and MBR
1543 if [ "$ZFSBOOT_PARTITION_SCHEME" = GPT ]; then
1544 ZFSBOOT_PARTITION_SCHEME=MBR
1546 ZFSBOOT_PARTITION_SCHEME=GPT
1550 # Prompt the user to input/change the swap size for each disk
1551 f_dialog_input input \
1552 "$msg_please_enter_amount_of_swap_space" \
1553 "$ZFSBOOT_SWAP_SIZE" &&
1554 ZFSBOOT_SWAP_SIZE="${input:-0}"
1556 ?" $msg_swap_mirror")
1557 # Toggle the variable referenced both by the menu and later
1558 if [ "$ZFSBOOT_SWAP_MIRROR" ]; then
1559 ZFSBOOT_SWAP_MIRROR=
1561 ZFSBOOT_SWAP_MIRROR=1
1564 ?" $msg_swap_encrypt")
1565 # Toggle the variable referenced both by the menu and later
1566 if [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then
1567 ZFSBOOT_SWAP_ENCRYPTION=
1569 ZFSBOOT_SWAP_ENCRYPTION=1
1577 ################################################################################
1579 ################################################################################