xref: /freebsd/usr.sbin/bsdinstall/scripts/zfsboot (revision cd88b8869f9b2c280b1de02608f52fdf497b4cb1)
1*cd88b886SDevin Teske#!/bin/sh
2*cd88b886SDevin Teske#-
3*cd88b886SDevin Teske# Copyright (c) 2013 Allan Jude
4*cd88b886SDevin Teske# Copyright (c) 2013 Devin Teske
5*cd88b886SDevin Teske# All rights reserved.
6*cd88b886SDevin Teske#
7*cd88b886SDevin Teske# Redistribution and use in source and binary forms, with or without
8*cd88b886SDevin Teske# modification, are permitted provided that the following conditions
9*cd88b886SDevin Teske# are met:
10*cd88b886SDevin Teske# 1. Redistributions of source code must retain the above copyright
11*cd88b886SDevin Teske#    notice, this list of conditions and the following disclaimer.
12*cd88b886SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
13*cd88b886SDevin Teske#    notice, this list of conditions and the following disclaimer in the
14*cd88b886SDevin Teske#    documentation and/or other materials provided with the distribution.
15*cd88b886SDevin Teske#
16*cd88b886SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*cd88b886SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*cd88b886SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*cd88b886SDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*cd88b886SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*cd88b886SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*cd88b886SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*cd88b886SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*cd88b886SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*cd88b886SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*cd88b886SDevin Teske# SUCH DAMAGE.
27*cd88b886SDevin Teske#
28*cd88b886SDevin Teske# $FreeBSD$
29*cd88b886SDevin Teske#
30*cd88b886SDevin Teske############################################################ INCLUDES
31*cd88b886SDevin Teske
32*cd88b886SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
33*cd88b886SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
34*cd88b886SDevin Teskef_dprintf "%s: loading includes..." "$0"
35*cd88b886SDevin Teskef_include $BSDCFG_SHARE/device.subr
36*cd88b886SDevin Teskef_include $BSDCFG_SHARE/dialog.subr
37*cd88b886SDevin Teskef_include $BSDCFG_SHARE/password/password.subr
38*cd88b886SDevin Teskef_include $BSDCFG_SHARE/variable.subr
39*cd88b886SDevin Teske
40*cd88b886SDevin Teske############################################################ CONFIGURATION
41*cd88b886SDevin Teske
42*cd88b886SDevin Teske#
43*cd88b886SDevin Teske# Default name of the boot-pool
44*cd88b886SDevin Teske#
45*cd88b886SDevin Teske: ${ZFSBOOT_POOL_NAME:=zroot}
46*cd88b886SDevin Teske
47*cd88b886SDevin Teske#
48*cd88b886SDevin Teske# Default name for the boot environment parent dataset
49*cd88b886SDevin Teske#
50*cd88b886SDevin Teske: ${ZFSBOOT_BEROOT_NAME:=bootenv}
51*cd88b886SDevin Teske
52*cd88b886SDevin Teske#
53*cd88b886SDevin Teske# Default name for the primany boot environment
54*cd88b886SDevin Teske#
55*cd88b886SDevin Teske: ${ZFSBOOT_BOOTFS_NAME:=default}
56*cd88b886SDevin Teske
57*cd88b886SDevin Teske#
58*cd88b886SDevin Teske# Default Virtual Device (vdev) type to create
59*cd88b886SDevin Teske#
60*cd88b886SDevin Teske: ${ZFSBOOT_VDEV_TYPE:=stripe}
61*cd88b886SDevin Teske
62*cd88b886SDevin Teske#
63*cd88b886SDevin Teske# Should we use gnop(8) to configure a transparent mapping to 4K sectors?
64*cd88b886SDevin Teske#
65*cd88b886SDevin Teske: ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:=1}
66*cd88b886SDevin Teske
67*cd88b886SDevin Teske#
68*cd88b886SDevin Teske# Should we use geli(8) to encrypt the drives?
69*cd88b886SDevin Teske#
70*cd88b886SDevin Teske: ${ZFSBOOT_GELI_ENCRYPTION:=}
71*cd88b886SDevin Teske
72*cd88b886SDevin Teske#
73*cd88b886SDevin Teske# Default name the unencrypted pool when using geli(8) to encrypt the drives
74*cd88b886SDevin Teske#
75*cd88b886SDevin Teske: ${ZFSBOOT_GELI_POOL_NAME:=bootpool}
76*cd88b886SDevin Teske
77*cd88b886SDevin Teske#
78*cd88b886SDevin Teske# Default size for the unencrypted boot pool when using geli(8)
79*cd88b886SDevin Teske#
80*cd88b886SDevin Teske: ${ZFSBOOT_GELI_BOOT_SIZE:=2g}
81*cd88b886SDevin Teske
82*cd88b886SDevin Teske#
83*cd88b886SDevin Teske# Default path to the geli(8) keyfile used in drive encryption
84*cd88b886SDevin Teske#
85*cd88b886SDevin Teske: ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key}
86*cd88b886SDevin Teske
87*cd88b886SDevin Teske#
88*cd88b886SDevin Teske# Default disks to use (always empty unless being scripted)
89*cd88b886SDevin Teske#
90*cd88b886SDevin Teske: ${ZFSBOOT_DISKS:=}
91*cd88b886SDevin Teske
92*cd88b886SDevin Teske#
93*cd88b886SDevin Teske# Default partitioning scheme to use on disks
94*cd88b886SDevin Teske#
95*cd88b886SDevin Teske: ${ZFSBOOT_PARTITION_SCHEME:=GPT}
96*cd88b886SDevin Teske
97*cd88b886SDevin Teske#
98*cd88b886SDevin Teske# How much swap to put on each block device in the boot zpool
99*cd88b886SDevin Teske# NOTE: Value passed to gpart(8); which supports SI unit suffixes.
100*cd88b886SDevin Teske#
101*cd88b886SDevin Teske: ${ZFSBOOT_SWAP_SIZE:=2g}
102*cd88b886SDevin Teske
103*cd88b886SDevin Teske#
104*cd88b886SDevin Teske# Default ZFS layout for root zpool
105*cd88b886SDevin Teske#
106*cd88b886SDevin Teske# NOTE: Requires /tmp, /var/tmp, /$ZFSBOOT_BOOTFS_NAME/$ZFSBOOT_BOOTFS_NAME
107*cd88b886SDevin Teske# NOTE: Anything after pound/hash character [#] is ignored as a comment.
108*cd88b886SDevin Teske#
109*cd88b886SDevin Teskef_isset ZFSBOOT_DATASETS || ZFSBOOT_DATASETS="
110*cd88b886SDevin Teske	# DATASET	OPTIONS (comma or space separated; or both)
111*cd88b886SDevin Teske
112*cd88b886SDevin Teske	# Boot Environment [BE] root and default boot dataset
113*cd88b886SDevin Teske	/$ZFSBOOT_BEROOT_NAME				mountpoint=none
114*cd88b886SDevin Teske	/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME	mountpoint=/
115*cd88b886SDevin Teske
116*cd88b886SDevin Teske	# Compress /tmp, allow exec but not setuid
117*cd88b886SDevin Teske	/tmp		mountpoint=/tmp,compression=lz4,exec=on,setuid=off
118*cd88b886SDevin Teske
119*cd88b886SDevin Teske	# Don't mount /usr so that 'base' files go to the BEROOT
120*cd88b886SDevin Teske	/usr		mountpoint=/usr,canmount=off
121*cd88b886SDevin Teske
122*cd88b886SDevin Teske	/usr/local # local files (i.e. from packages) separate from base system
123*cd88b886SDevin Teske
124*cd88b886SDevin Teske	# Home directories separated so they are common to all BEs
125*cd88b886SDevin Teske	/usr/home	setuid=off
126*cd88b886SDevin Teske
127*cd88b886SDevin Teske	# Ports tree
128*cd88b886SDevin Teske	/usr/ports		compression=lz4,setuid=off
129*cd88b886SDevin Teske	/usr/ports/distfiles	compression=off,exec=off,setuid=off
130*cd88b886SDevin Teske	/usr/ports/packages	compression=off,exec=off,setuid=off
131*cd88b886SDevin Teske
132*cd88b886SDevin Teske	# Source tree (compressed)
133*cd88b886SDevin Teske	/usr/src	compression=lz4,exec=off,setuid=off
134*cd88b886SDevin Teske	/usr/obj	# Object files
135*cd88b886SDevin Teske
136*cd88b886SDevin Teske	# Create /var and friends
137*cd88b886SDevin Teske	/var		mountpoint=/var
138*cd88b886SDevin Teske	/var/crash	compression=lz4,exec=off,setuid=off
139*cd88b886SDevin Teske	/var/db		exec=off,setuid=off
140*cd88b886SDevin Teske	/var/db/pkg	compression=lz4,exec=off,setuid=off
141*cd88b886SDevin Teske	/var/empty	exec=off,setuid=off
142*cd88b886SDevin Teske	/var/log	compression=lz4,exec=off,setuid=off
143*cd88b886SDevin Teske	/var/mail	compression=lz4,exec=off,setuid=off
144*cd88b886SDevin Teske	/var/run	exec=off,setuid=off
145*cd88b886SDevin Teske	/var/tmp	compression=lz4,exec=on,setuid=off
146*cd88b886SDevin Teske" # END-QUOTE
147*cd88b886SDevin Teske
148*cd88b886SDevin Teske############################################################ GLOBALS
149*cd88b886SDevin Teske
150*cd88b886SDevin Teske#
151*cd88b886SDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang()
152*cd88b886SDevin Teske#
153*cd88b886SDevin Teskehline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER"
154*cd88b886SDevin Teskehline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER"
155*cd88b886SDevin Teskehline_arrows_tab_enter="Press arrows, TAB or ENTER"
156*cd88b886SDevin Teskemsg_back="Back"
157*cd88b886SDevin Teskemsg_cancel="Cancel"
158*cd88b886SDevin Teskemsg_change="Change Selection"
159*cd88b886SDevin Teskemsg_configure_options="Configure Options:"
160*cd88b886SDevin Teskemsg_create="Install"
161*cd88b886SDevin Teskemsg_create_desc="Proceed with Installation"
162*cd88b886SDevin Teskemsg_create_help="Create ZFS boot pool with displayed options"
163*cd88b886SDevin Teskemsg_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"
164*cd88b886SDevin Teskemsg_disk_info="Disk Info"
165*cd88b886SDevin Teskemsg_disk_info_help="Get detailed information on disk device(s)"
166*cd88b886SDevin Teskemsg_disks_to_use="Disks To Use"
167*cd88b886SDevin Teskemsg_disks_to_use_help="Choose which disks to use for the Virtual Device (Required)"
168*cd88b886SDevin Teskemsg_force_4k_sectors="Force 4K Sectors?"
169*cd88b886SDevin Teskemsg_force_4k_sectors_help="Use gnop(8) to configure forced 4K sector alignment"
170*cd88b886SDevin Teskemsg_freebsd_installer="FreeBSD Installer"
171*cd88b886SDevin Teskemsg_geli_encryption="Encrypt Disks?"
172*cd88b886SDevin Teskemsg_geli_encryption_help="Use geli(8) to encrypt all data partitions"
173*cd88b886SDevin Teskemsg_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"
174*cd88b886SDevin Teskemsg_geli_setup="Initializing encryption on the selected disks, this will take several seconds per disk"
175*cd88b886SDevin Teskemsg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'"
176*cd88b886SDevin Teskemsg_invalid_virtual_device_type_help="Select another Virtual Device type or Cancel to\nreturn to the ZFS menu. From there you can select\nmore disks or rescan for additional devices."
177*cd88b886SDevin Teskemsg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy the current contents of the following disks:\n%s"
178*cd88b886SDevin Teskemsg_last_chance_are_you_sure_color="\\\\ZrLast Chance!\\\\ZR Are you \\\\Z1sure\\\\Zn you want to \\\\Zr\\\\Z1destroy\\\\Zn the current contents of the following disks:\n%s"
179*cd88b886SDevin Teskemsg_mirror_desc="Mirror - n-Way Mirroring"
180*cd88b886SDevin Teskemsg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage"
181*cd88b886SDevin Teskemsg_no="NO"
182*cd88b886SDevin Teskemsg_no_disks_present_to_configure="No disk(s) present to configure"
183*cd88b886SDevin Teskemsg_no_disks_selected="No disks selected."
184*cd88b886SDevin Teskemsg_not_enough_disks_selected="Not enough disks selected. (%u < %u wanted)"
185*cd88b886SDevin Teskemsg_ok="OK"
186*cd88b886SDevin Teskemsg_partition_scheme="Partition Scheme"
187*cd88b886SDevin Teskemsg_partition_scheme_help="Toggle between GPT and MBR partitioning schemes"
188*cd88b886SDevin Teskemsg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:"
189*cd88b886SDevin Teskemsg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):"
190*cd88b886SDevin Teskemsg_please_select_one_or_more_disks="Please select one or more disks to create a zpool:"
191*cd88b886SDevin Teskemsg_pool_name="Pool Name"
192*cd88b886SDevin Teskemsg_pool_name_cannot_be_empty="Pool name cannot be empty."
193*cd88b886SDevin Teskemsg_pool_name_help="Customize the name of the zpool to be created (Required)"
194*cd88b886SDevin Teskemsg_processing_selection="Processing selection..."
195*cd88b886SDevin Teskemsg_raidz1_desc="RAID-Z1 - Single Redundant RAID"
196*cd88b886SDevin Teskemsg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks"
197*cd88b886SDevin Teskemsg_raidz2_desc="RAID-Z2 - Double Redundant RAID"
198*cd88b886SDevin Teskemsg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks"
199*cd88b886SDevin Teskemsg_raidz3_desc="RAID-Z3 - Triple Redundant RAID"
200*cd88b886SDevin Teskemsg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks"
201*cd88b886SDevin Teskemsg_rescan_devices="Rescan Devices"
202*cd88b886SDevin Teskemsg_rescan_devices_help="Scan for device changes"
203*cd88b886SDevin Teskemsg_select="Select"
204*cd88b886SDevin Teskemsg_select_a_disk_device="Select a disk device"
205*cd88b886SDevin Teskemsg_select_virtual_device_type="Select Virtual Device type:"
206*cd88b886SDevin Teskemsg_stripe_desc="Stripe - No Redundancy"
207*cd88b886SDevin Teskemsg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy"
208*cd88b886SDevin Teskemsg_swap_size="Swap Size"
209*cd88b886SDevin Teskemsg_swap_size_help="Customize how much swap space is allocated to each selected disk"
210*cd88b886SDevin Teskemsg_these_disks_are_too_small="These disks are too small given the amount of requested\nswap (%s) and/or GELI (%s) partitions, which would take\n50%% or more (not recommended) of each of the following\nselected disk devices:\n\n  %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of devices."
211*cd88b886SDevin Teskemsg_yes="YES"
212*cd88b886SDevin Teskemsg_zfs_configuration="ZFS Configuration"
213*cd88b886SDevin Teskemsg_zfs_vdev_type="ZFS VDev Type"
214*cd88b886SDevin Teskemsg_zfs_vdev_type_help="Select type of ZFS Virtual Device to create"
215*cd88b886SDevin Teske
216*cd88b886SDevin Teske############################################################ FUNCTIONS
217*cd88b886SDevin Teske
218*cd88b886SDevin Teske# dialog_menu_main
219*cd88b886SDevin Teske#
220*cd88b886SDevin Teske# Display the dialog(1)-based application main menu.
221*cd88b886SDevin Teske#
222*cd88b886SDevin Teskedialog_menu_main()
223*cd88b886SDevin Teske{
224*cd88b886SDevin Teske	local title="$DIALOG_TITLE"
225*cd88b886SDevin Teske	local btitle="$DIALOG_BACKTITLE"
226*cd88b886SDevin Teske	local prompt="$msg_configure_options"
227*cd88b886SDevin Teske	local force4k="$msg_no"
228*cd88b886SDevin Teske	local usegeli="$msg_no"
229*cd88b886SDevin Teske	[ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ] && force4k="$msg_yes"
230*cd88b886SDevin Teske	[ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes"
231*cd88b886SDevin Teske	local menu_list="
232*cd88b886SDevin Teske		'>>> $msg_create'         '$msg_create_desc'
233*cd88b886SDevin Teske		                          '$msg_create_help'
234*cd88b886SDevin Teske		'- $msg_rescan_devices'   '*'
235*cd88b886SDevin Teske		                          '$msg_rescan_devices_help'
236*cd88b886SDevin Teske		'- $msg_disk_info'        '*'
237*cd88b886SDevin Teske		                          '$msg_disk_info_help'
238*cd88b886SDevin Teske		'1 $msg_pool_name'        '$ZFSBOOT_POOL_NAME'
239*cd88b886SDevin Teske		                          '$msg_pool_name_help'
240*cd88b886SDevin Teske		'2 $msg_disks_to_use'     '$ZFSBOOT_DISKS'
241*cd88b886SDevin Teske		                          '$msg_disks_to_use_help'
242*cd88b886SDevin Teske		'3 $msg_zfs_vdev_type'    '$ZFSBOOT_VDEV_TYPE'
243*cd88b886SDevin Teske		                          '$msg_zfs_vdev_type_help'
244*cd88b886SDevin Teske		'4 $msg_force_4k_sectors' '$force4k'
245*cd88b886SDevin Teske		                          '$msg_force_4k_sectors_help'
246*cd88b886SDevin Teske		'5 $msg_geli_encryption'  '$usegeli'
247*cd88b886SDevin Teske		                          '$msg_geli_encryption_help'
248*cd88b886SDevin Teske		'6 $msg_partition_scheme' '$ZFSBOOT_PARTITION_SCHEME'
249*cd88b886SDevin Teske		                          '$msg_partition_scheme_help'
250*cd88b886SDevin Teske		'7 $msg_swap_size'        '$ZFSBOOT_SWAP_SIZE'
251*cd88b886SDevin Teske		                          '$msg_swap_size_help'
252*cd88b886SDevin Teske	" # END-QUOTE
253*cd88b886SDevin Teske	local defaultitem= # Calculated below
254*cd88b886SDevin Teske	local hline="$hline_alnum_arrows_punc_tab_enter"
255*cd88b886SDevin Teske
256*cd88b886SDevin Teske	local height width rows
257*cd88b886SDevin Teske	eval f_dialog_menu_with_help_size height width rows \
258*cd88b886SDevin Teske		\"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list
259*cd88b886SDevin Teske
260*cd88b886SDevin Teske	# Obtain default-item from previously stored selection
261*cd88b886SDevin Teske	f_dialog_default_fetch defaultitem
262*cd88b886SDevin Teske
263*cd88b886SDevin Teske	local menu_choice
264*cd88b886SDevin Teske	menu_choice=$( eval $DIALOG \
265*cd88b886SDevin Teske		--title \"\$title\"              \
266*cd88b886SDevin Teske		--backtitle \"\$btitle\"         \
267*cd88b886SDevin Teske		--hline \"\$hline\"              \
268*cd88b886SDevin Teske		--item-help                      \
269*cd88b886SDevin Teske		--ok-label \"\$msg_select\"      \
270*cd88b886SDevin Teske		--cancel-label \"\$msg_cancel\"  \
271*cd88b886SDevin Teske		--default-item \"\$defaultitem\" \
272*cd88b886SDevin Teske		--menu \"\$prompt\"              \
273*cd88b886SDevin Teske		$height $width $rows             \
274*cd88b886SDevin Teske		$menu_list                       \
275*cd88b886SDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
276*cd88b886SDevin Teske	)
277*cd88b886SDevin Teske	local retval=$?
278*cd88b886SDevin Teske	f_dialog_data_sanitize menu_choice
279*cd88b886SDevin Teske	f_dialog_menutag_store "$menu_choice"
280*cd88b886SDevin Teske
281*cd88b886SDevin Teske	# Only update default-item on success
282*cd88b886SDevin Teske	[ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice"
283*cd88b886SDevin Teske
284*cd88b886SDevin Teske	return $retval
285*cd88b886SDevin Teske}
286*cd88b886SDevin Teske
287*cd88b886SDevin Teske# dialog_edit_disks
288*cd88b886SDevin Teske#
289*cd88b886SDevin Teske# Edit the list of disks to be used by the ZFS boot pool.
290*cd88b886SDevin Teske#
291*cd88b886SDevin Teskedialog_edit_disks()
292*cd88b886SDevin Teske{
293*cd88b886SDevin Teske	local title="$DIALOG_TITLE"
294*cd88b886SDevin Teske	local btitle="$DIALOG_BACKTITLE"
295*cd88b886SDevin Teske	local prompt="$msg_please_select_one_or_more_disks"
296*cd88b886SDevin Teske	local check_list= # Calculated below
297*cd88b886SDevin Teske	local hline="$hline_arrows_space_tab_enter"
298*cd88b886SDevin Teske	local dev vardev disks=
299*cd88b886SDevin Teske
300*cd88b886SDevin Teske	#
301*cd88b886SDevin Teske	# Get a [new] list of disk devices
302*cd88b886SDevin Teske	#
303*cd88b886SDevin Teske	f_device_find "" $DEVICE_TYPE_DISK disks
304*cd88b886SDevin Teske	if [ ! "$disks" ]; then
305*cd88b886SDevin Teske		f_show_msg "$msg_no_disks_present_to_configure"
306*cd88b886SDevin Teske		return $FAILURE
307*cd88b886SDevin Teske	fi
308*cd88b886SDevin Teske
309*cd88b886SDevin Teske	# Lets sort the disks array to be more user friendly
310*cd88b886SDevin Teske	disks=$( echo "$disks" | tr ' ' '\n' | sort | tr '\n' ' ' )
311*cd88b886SDevin Teske
312*cd88b886SDevin Teske	#
313*cd88b886SDevin Teske	# Loop through the list of selected disks and create temporary local
314*cd88b886SDevin Teske	# variables mapping their status onto an up-to-date list of disks.
315*cd88b886SDevin Teske	#
316*cd88b886SDevin Teske	for dev in $ZFSBOOT_DISKS; do
317*cd88b886SDevin Teske		f_str2varname "$dev" vardev
318*cd88b886SDevin Teske		local _${vardev}_status=on
319*cd88b886SDevin Teske	done
320*cd88b886SDevin Teske
321*cd88b886SDevin Teske	#
322*cd88b886SDevin Teske	# Create the checklist menu of discovered disk devices
323*cd88b886SDevin Teske	#
324*cd88b886SDevin Teske	local on_off
325*cd88b886SDevin Teske	for dev in $disks; do
326*cd88b886SDevin Teske		local desc=
327*cd88b886SDevin Teske		device_$dev get desc desc
328*cd88b886SDevin Teske		f_shell_escape "$desc" desc
329*cd88b886SDevin Teske		f_str2varname "$dev" vardev
330*cd88b886SDevin Teske		f_getvar _${vardev}_status:-off on_off
331*cd88b886SDevin Teske		check_list="$check_list '$dev' '$desc' $on_off"
332*cd88b886SDevin Teske	done
333*cd88b886SDevin Teske
334*cd88b886SDevin Teske	#
335*cd88b886SDevin Teske	# Prompt the user to check some disks
336*cd88b886SDevin Teske	#
337*cd88b886SDevin Teske	local height width rows
338*cd88b886SDevin Teske	eval f_dialog_checklist_size height width rows \
339*cd88b886SDevin Teske		\"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $check_list
340*cd88b886SDevin Teske	disks=$( eval $DIALOG \
341*cd88b886SDevin Teske		--title \"\$DIALOG_TITLE\"         \
342*cd88b886SDevin Teske		--backtitle \"\$DIALOG_BACKTITLE\" \
343*cd88b886SDevin Teske		--hline \"\$hline\"                \
344*cd88b886SDevin Teske		--ok-label \"\$msg_ok\"            \
345*cd88b886SDevin Teske		--cancel-label \"\$msg_cancel\"    \
346*cd88b886SDevin Teske		--checklist \"\$prompt\"           \
347*cd88b886SDevin Teske		$height $width $rows               \
348*cd88b886SDevin Teske		$check_list                        \
349*cd88b886SDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
350*cd88b886SDevin Teske	) || return $?
351*cd88b886SDevin Teske		# Exit if user either pressed ESC or chose Cancel/No
352*cd88b886SDevin Teske	f_dialog_data_sanitize disks
353*cd88b886SDevin Teske
354*cd88b886SDevin Teske	ZFSBOOT_DISKS="$disks"
355*cd88b886SDevin Teske
356*cd88b886SDevin Teske	return $DIALOG_OK
357*cd88b886SDevin Teske}
358*cd88b886SDevin Teske
359*cd88b886SDevin Teske# dialog_menu_vdev
360*cd88b886SDevin Teske#
361*cd88b886SDevin Teske# Prompt the user to select a a Virtual Device type.
362*cd88b886SDevin Teske#
363*cd88b886SDevin Teskedialog_menu_vdev()
364*cd88b886SDevin Teske{
365*cd88b886SDevin Teske	local title="$DIALOG_TITLE"
366*cd88b886SDevin Teske	local btitle="$DIALOG_BACKTITLE"
367*cd88b886SDevin Teske	local prompt="$msg_select_virtual_device_type"
368*cd88b886SDevin Teske
369*cd88b886SDevin Teske	# Make sure [potentially scripted] selections are real
370*cd88b886SDevin Teske	real_disks=
371*cd88b886SDevin Teske	for disk in $ZFSBOOT_DISKS; do
372*cd88b886SDevin Teske		f_struct device_$disk && real_disks="$real_disks $disk"
373*cd88b886SDevin Teske	done
374*cd88b886SDevin Teske	# Make sure we have at least one real disk selected
375*cd88b886SDevin Teske	ndisks=$( set -- $real_disks; echo $# )
376*cd88b886SDevin Teske
377*cd88b886SDevin Teske	local menu_list="
378*cd88b886SDevin Teske		'stripe' '$msg_stripe_desc' '$msg_stripe_help'
379*cd88b886SDevin Teske		'mirror' '$msg_mirror_desc' '$msg_mirror_help'
380*cd88b886SDevin Teske		'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help'
381*cd88b886SDevin Teske		'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help'
382*cd88b886SDevin Teske		'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help'
383*cd88b886SDevin Teske	" # END-QUOTE
384*cd88b886SDevin Teske
385*cd88b886SDevin Teske	local defaultitem="$ZFSBOOT_VDEV_TYPE"
386*cd88b886SDevin Teske	local hline="$hline_arrows_tab_enter"
387*cd88b886SDevin Teske	local error_msg revalidate_choice
388*cd88b886SDevin Teske
389*cd88b886SDevin Teske	local mheight mwidth mrows
390*cd88b886SDevin Teske	eval f_dialog_menu_size mheight mwidth mrows \
391*cd88b886SDevin Teske		\"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list
392*cd88b886SDevin Teske	local iheight iwidth
393*cd88b886SDevin Teske	f_dialog_infobox_size iheight iwidth \
394*cd88b886SDevin Teske		"$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_processing_selection"
395*cd88b886SDevin Teske
396*cd88b886SDevin Teske	local menu_choice
397*cd88b886SDevin Teske	menu_choice=$( eval $DIALOG \
398*cd88b886SDevin Teske		--title \"\$title\"              \
399*cd88b886SDevin Teske		--backtitle \"\$btitle\"         \
400*cd88b886SDevin Teske		--hline \"\$hline\"              \
401*cd88b886SDevin Teske		--ok-label \"\$msg_ok\"          \
402*cd88b886SDevin Teske		--cancel-label \"\$msg_cancel\"  \
403*cd88b886SDevin Teske		--item-help                      \
404*cd88b886SDevin Teske		--default-item \"\$defaultitem\" \
405*cd88b886SDevin Teske		--menu \"\$prompt\"              \
406*cd88b886SDevin Teske		$mheight $mwidth $mrows          \
407*cd88b886SDevin Teske		$menu_list                       \
408*cd88b886SDevin Teske		--and-widget                     \
409*cd88b886SDevin Teske		${USE_XDIALOG:+--no-buttons}     \
410*cd88b886SDevin Teske		--infobox \"\$msg_processing_selection\" \
411*cd88b886SDevin Teske		$iheight $iwidth                 \
412*cd88b886SDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
413*cd88b886SDevin Teske	) || return $FAILURE
414*cd88b886SDevin Teske	f_dialog_data_sanitize menu_choice
415*cd88b886SDevin Teske	sleep 0.5 # Give time to read `--and-widget --info-box'
416*cd88b886SDevin Teske
417*cd88b886SDevin Teske	# Make sure we have enough disks for the desired vdev type
418*cd88b886SDevin Teske	case "$menu_choice" in
419*cd88b886SDevin Teske	stripe) want_disks=1 ;;
420*cd88b886SDevin Teske	mirror) want_disks=2 ;;
421*cd88b886SDevin Teske	raidz1) want_disks=3 ;;
422*cd88b886SDevin Teske	raidz2) want_disks=4 ;;
423*cd88b886SDevin Teske	raidz3) want_disks=5 ;;
424*cd88b886SDevin Teske	*)
425*cd88b886SDevin Teske		f_show_msg "$msg_invalid_virtual_device_type" \
426*cd88b886SDevin Teske	                   "$menu_choice"
427*cd88b886SDevin Teske		continue
428*cd88b886SDevin Teske	esac
429*cd88b886SDevin Teske	if [ $ndisks -lt $want_disks ]; then
430*cd88b886SDevin Teske		msg_yes="$msg_change" msg_no="$msg_cancel" f_yesno \
431*cd88b886SDevin Teske			"%s: $msg_not_enough_disks_selected\n%s" \
432*cd88b886SDevin Teske			"$menu_choice" $ndisks $want_disks \
433*cd88b886SDevin Teske			"$msg_invalid_virtual_device_type_help" ||
434*cd88b886SDevin Teske			return $FAILURE
435*cd88b886SDevin Teske		dialog_menu_vdev
436*cd88b886SDevin Teske	else
437*cd88b886SDevin Teske		ZFSBOOT_VDEV_TYPE="$menu_choice"
438*cd88b886SDevin Teske	fi
439*cd88b886SDevin Teske}
440*cd88b886SDevin Teske
441*cd88b886SDevin Teske# zfs_create_diskpart $disk $index
442*cd88b886SDevin Teske#
443*cd88b886SDevin Teske# For each block device to be used in the zpool, rather than just create the
444*cd88b886SDevin Teske# zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions
445*cd88b886SDevin Teske# so we can have some real swap. This also provides wiggle room incase your
446*cd88b886SDevin Teske# replacement drivers do not have the exact same sector counts.
447*cd88b886SDevin Teske#
448*cd88b886SDevin Teske# NOTE: The MBR layout is more complicated (GPT is preferred).
449*cd88b886SDevin Teske#
450*cd88b886SDevin Teskezfs_create_diskpart()
451*cd88b886SDevin Teske{
452*cd88b886SDevin Teske	local disk="$1" index="$2"
453*cd88b886SDevin Teske	local funcname=zfs_create_diskpart
454*cd88b886SDevin Teske	local disksize partsize
455*cd88b886SDevin Teske
456*cd88b886SDevin Teske	# Check arguments
457*cd88b886SDevin Teske	[ "$disk" -a "$index" ] || return $FAILURE
458*cd88b886SDevin Teske
459*cd88b886SDevin Teske	#
460*cd88b886SDevin Teske	# Destroy whatever partition layout is currently on disk.
461*cd88b886SDevin Teske	# NOTE: `-F' required to destroy if partitions still exist.
462*cd88b886SDevin Teske	# NOTE: Failure is ok here, blank disk will have nothing to destroy.
463*cd88b886SDevin Teske	#
464*cd88b886SDevin Teske	f_quietly gpart destroy -F $disk
465*cd88b886SDevin Teske	f_quietly zpool labelclear -f /dev/$disk # Kill it with fire
466*cd88b886SDevin Teske
467*cd88b886SDevin Teske	# Make doubly-sure backup GPT is destroyed
468*cd88b886SDevin Teske	f_quietly gpart create -s gpt $disk || return $FAILURE
469*cd88b886SDevin Teske	f_quietly gpart destroy -F $disk || return $FAILURE
470*cd88b886SDevin Teske
471*cd88b886SDevin Teske	# Calculate partition size given desired amount of swap
472*cd88b886SDevin Teske	device_$disk get capacity disksize || return $FAILURE
473*cd88b886SDevin Teske	partsize=$(( $disksize - $swapsize ))
474*cd88b886SDevin Teske
475*cd88b886SDevin Teske	#
476*cd88b886SDevin Teske	# Lay down the desired type of partition scheme
477*cd88b886SDevin Teske	#
478*cd88b886SDevin Teske	local setsize mbrindex
479*cd88b886SDevin Teske	case "$ZFSBOOT_PARTITION_SCHEME" in
480*cd88b886SDevin Teske	""|GPT)
481*cd88b886SDevin Teske		#
482*cd88b886SDevin Teske		# 1. Create GPT layout using labels
483*cd88b886SDevin Teske		#
484*cd88b886SDevin Teske		gpart create -s gpt $disk || return $FAILURE
485*cd88b886SDevin Teske
486*cd88b886SDevin Teske		#
487*cd88b886SDevin Teske		# 2. Add small freebsd-boot partition labeled `boot#'
488*cd88b886SDevin Teske		#
489*cd88b886SDevin Teske		gpart add -l gptboot$index -t freebsd-boot -s 512k $disk ||
490*cd88b886SDevin Teske			return $FAILURE
491*cd88b886SDevin Teske		gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $disk ||
492*cd88b886SDevin Teske			return $FAILURE
493*cd88b886SDevin Teske
494*cd88b886SDevin Teske		# zpool will use the `zfs#' GPT labels
495*cd88b886SDevin Teske		bootpart=p2 targetpart=p2
496*cd88b886SDevin Teske
497*cd88b886SDevin Teske		# Change things around if we are using GELI
498*cd88b886SDevin Teske		if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
499*cd88b886SDevin Teske			bootpart=p2 targetpart=p3
500*cd88b886SDevin Teske			partsize=$(( $partsize - $gelisize ))
501*cd88b886SDevin Teske			gpart add -l boot$index -t freebsd-zfs \
502*cd88b886SDevin Teske				-s ${gelisize}b -a 1m $disk || return $FAILURE
503*cd88b886SDevin Teske			# Pedantically nuke any old labels, stop geli
504*cd88b886SDevin Teske			f_quietly zpool labelclear -f /dev/$disk$bootpart
505*cd88b886SDevin Teske			f_quietly geli detach -f /dev/$disk$targetpart
506*cd88b886SDevin Teske		fi
507*cd88b886SDevin Teske
508*cd88b886SDevin Teske		#
509*cd88b886SDevin Teske		# 3. Add freebsd-zfs partition labeled `zfs#' for zpool
510*cd88b886SDevin Teske		# NOTE: Using above calculated partsize to leave room for swap.
511*cd88b886SDevin Teske		#
512*cd88b886SDevin Teske		[ $swapsize -gt 0 ] && setsize="-s ${partsize}b"
513*cd88b886SDevin Teske		gpart add -l zfs$index -t freebsd-zfs $setsize -a 1m $disk ||
514*cd88b886SDevin Teske			return $FAILURE
515*cd88b886SDevin Teske		f_quietly zpool labelclear -f /dev/$disk$targetpart # Pedantic
516*cd88b886SDevin Teske
517*cd88b886SDevin Teske		#
518*cd88b886SDevin Teske		# 4. Add freebsd-swap partition labeled `swap#'
519*cd88b886SDevin Teske		#
520*cd88b886SDevin Teske		if [ $swapsize -gt 0 ]; then
521*cd88b886SDevin Teske			gpart add -l swap$index -t freebsd-swap -a 1m $disk ||
522*cd88b886SDevin Teske				return $FAILURE
523*cd88b886SDevin Teske			# Update fstab(5)
524*cd88b886SDevin Teske			printf "$fstab_fmt" \
525*cd88b886SDevin Teske				/dev/gpt/swap$index none swap sw 0 0 \
526*cd88b886SDevin Teske				>> $BSDINSTALL_TMPETC/fstab || return $FAILURE
527*cd88b886SDevin Teske		fi
528*cd88b886SDevin Teske		;;
529*cd88b886SDevin Teske
530*cd88b886SDevin Teske	MBR)
531*cd88b886SDevin Teske		#
532*cd88b886SDevin Teske		# 1. Create MBR layout (no labels)
533*cd88b886SDevin Teske		#
534*cd88b886SDevin Teske		gpart create -s mbr $disk || return $FAILURE
535*cd88b886SDevin Teske		gpart bootcode -b /boot/boot0 $disk || return $FAILURE
536*cd88b886SDevin Teske
537*cd88b886SDevin Teske		#
538*cd88b886SDevin Teske		# 2. Add freebsd slice with all available space
539*cd88b886SDevin Teske		#
540*cd88b886SDevin Teske		gpart add -t freebsd $disk || return $FAILURE
541*cd88b886SDevin Teske		gpart set -a active -i 1 $disk || return $FAILURE
542*cd88b886SDevin Teske		f_quietly zpool labelclear -f /dev/${disk}s1 # Pedantic
543*cd88b886SDevin Teske		f_quietly gpart destroy -F ${disk}s1 # Pedantic
544*cd88b886SDevin Teske
545*cd88b886SDevin Teske		#
546*cd88b886SDevin Teske		# 3. Write BSD sceme to the freebsd slice
547*cd88b886SDevin Teske		#
548*cd88b886SDevin Teske		gpart create -s BSD ${disk}s1 || return $FAILURE
549*cd88b886SDevin Teske
550*cd88b886SDevin Teske		# zpool will use s1a (no labels)
551*cd88b886SDevin Teske		bootpart=s1a targetpart=s1a mbrindex=1
552*cd88b886SDevin Teske
553*cd88b886SDevin Teske		# Change things around if we are using GELI
554*cd88b886SDevin Teske		if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
555*cd88b886SDevin Teske			bootpart=s1a targetpart=s1d
556*cd88b886SDevin Teske			partsize=$(( $partsize - $gelisize ))
557*cd88b886SDevin Teske			mbrindex=4 # If this is s1a then make the zpool s1d
558*cd88b886SDevin Teske			gpart add -t freebsd-zfs -i 1 -s ${gelisize}b \
559*cd88b886SDevin Teske				${disk}s1 || return $FAILURE
560*cd88b886SDevin Teske			# Pedantically nuke any old labels, stop geli
561*cd88b886SDevin Teske			f_quietly zpool labelclear -f /dev/$disk$bootpart
562*cd88b886SDevin Teske			f_quietly geli detach -f /dev/$disk$targetpart
563*cd88b886SDevin Teske		fi
564*cd88b886SDevin Teske
565*cd88b886SDevin Teske		#
566*cd88b886SDevin Teske		# 4. Partition the BSD slice for ZFS
567*cd88b886SDevin Teske		# NOTE: Using above calculated partsize to leave room for swap.
568*cd88b886SDevin Teske		#
569*cd88b886SDevin Teske		[ $swapsize -gt 0 ] && setsize="-s ${partsize}b"
570*cd88b886SDevin Teske		gpart add -t freebsd-zfs -i $mbrindex $setsize ${disk}s1 ||
571*cd88b886SDevin Teske			return $FAILURE
572*cd88b886SDevin Teske		f_quietly zpool labelclear -f /dev/$disk$targetpart # Pedantic
573*cd88b886SDevin Teske
574*cd88b886SDevin Teske		#
575*cd88b886SDevin Teske		# 5. Add freebsd-swap partition
576*cd88b886SDevin Teske		#
577*cd88b886SDevin Teske		if [ $swapsize -gt 0 ]; then
578*cd88b886SDevin Teske			gpart add -t freebsd-swap -i 2 ${disk}s1 ||
579*cd88b886SDevin Teske				return $FAILURE
580*cd88b886SDevin Teske			# Update fstab(5)
581*cd88b886SDevin Teske			printf "$fstab_fmt" /dev/${disk}s1b none swap sw 0 0 \
582*cd88b886SDevin Teske				>> $BSDINSTALL_TMPETC/fstab || return $FAILURE
583*cd88b886SDevin Teske		fi
584*cd88b886SDevin Teske		;;
585*cd88b886SDevin Teske
586*cd88b886SDevin Teske	*)
587*cd88b886SDevin Teske		printf "%s: %s is an unsupported partition scheme" \
588*cd88b886SDevin Teske		       "$funcname" "$ZFSBOOT_PARTITION_SCHEME" >&2
589*cd88b886SDevin Teske		return $FAILURE
590*cd88b886SDevin Teske
591*cd88b886SDevin Teske	esac # $ZFSBOOT_PARTITION_SCHEME
592*cd88b886SDevin Teske
593*cd88b886SDevin Teske	return $SUCCESS
594*cd88b886SDevin Teske}
595*cd88b886SDevin Teske
596*cd88b886SDevin Teske# zfs_create_boot $poolname $vdev_type $real_disks ...
597*cd88b886SDevin Teske#
598*cd88b886SDevin Teske# Creates boot pool and dataset layout. Returns error if something goes wrong.
599*cd88b886SDevin Teske# Errors are printed to stderr for collection and display.
600*cd88b886SDevin Teske#
601*cd88b886SDevin Teskezfs_create_boot()
602*cd88b886SDevin Teske{
603*cd88b886SDevin Teske	local poolname="$1" vdev_type="$2"
604*cd88b886SDevin Teske	local fstab_fmt="%s\t\t%s\t%s\t%s\t\t%s\t%s\n"
605*cd88b886SDevin Teske	local funcname=zfs_create_boot
606*cd88b886SDevin Teske	local bootpart targetpart
607*cd88b886SDevin Teske
608*cd88b886SDevin Teske	shift 2 # name vdev_type
609*cd88b886SDevin Teske
610*cd88b886SDevin Teske	# We may need this later
611*cd88b886SDevin Teske	local realdisks=$*
612*cd88b886SDevin Teske
613*cd88b886SDevin Teske	# Pedantic checks; should never be seen
614*cd88b886SDevin Teske	if [ ! "$poolname" ]; then
615*cd88b886SDevin Teske		echo "$funcname: NULL poolname" >&2
616*cd88b886SDevin Teske		return $FAILURE
617*cd88b886SDevin Teske	fi
618*cd88b886SDevin Teske	if [ $# -lt 1 ]; then
619*cd88b886SDevin Teske		echo "$funcname: missing disk arguments" >&2
620*cd88b886SDevin Teske		return $FAILURE
621*cd88b886SDevin Teske	fi
622*cd88b886SDevin Teske
623*cd88b886SDevin Teske	# Initialize fstab(5)
624*cd88b886SDevin Teske	printf "$fstab_fmt" \
625*cd88b886SDevin Teske		"# Device" Mountpoint FStype Options Dump "Pass#" \
626*cd88b886SDevin Teske		>> $BSDINSTALL_TMPETC/fstab || return $FAILURE
627*cd88b886SDevin Teske
628*cd88b886SDevin Teske	# Expand SI units in desired sizes
629*cd88b886SDevin Teske	local swapsize gelisize
630*cd88b886SDevin Teske	f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize || return $FAILURE
631*cd88b886SDevin Teske	f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize || return $FAILURE
632*cd88b886SDevin Teske
633*cd88b886SDevin Teske	# Prepare the disks
634*cd88b886SDevin Teske	local n=0
635*cd88b886SDevin Teske	for disk in $*; do
636*cd88b886SDevin Teske		zfs_create_diskpart $disk $n || return $FAILURE
637*cd88b886SDevin Teske		n=$(( $n + 1 ))
638*cd88b886SDevin Teske	done
639*cd88b886SDevin Teske
640*cd88b886SDevin Teske	# MBR boot loader hack part 1
641*cd88b886SDevin Teske	# We have to do this early because geli gets in the way later
642*cd88b886SDevin Teske	if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then
643*cd88b886SDevin Teske		for disk in $realdisks; do
644*cd88b886SDevin Teske			dd if=/boot/zfsboot of=/dev/${disk}s1 count=1 ||
645*cd88b886SDevin Teske				return $FAILURE
646*cd88b886SDevin Teske		done
647*cd88b886SDevin Teske	fi
648*cd88b886SDevin Teske
649*cd88b886SDevin Teske	# Forced 4k alignment support provided by Geom NOP (see gnop(8))
650*cd88b886SDevin Teske	local unenc_list=
651*cd88b886SDevin Teske	if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then
652*cd88b886SDevin Teske		local new_list=
653*cd88b886SDevin Teske		for disk in $*; do
654*cd88b886SDevin Teske			if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
655*cd88b886SDevin Teske				# We don't gnop the encrypted partition
656*cd88b886SDevin Teske				# because geli will do this for us
657*cd88b886SDevin Teske				# gnop the unencrypted disk
658*cd88b886SDevin Teske				gnop create -S 4096 $disk$bootpart ||
659*cd88b886SDevin Teske					return $FAILURE
660*cd88b886SDevin Teske				unenc_list="$unenc_list $disk$bootpart.nop"
661*cd88b886SDevin Teske			else
662*cd88b886SDevin Teske				gnop create -S 4096 $disk$targetpart ||
663*cd88b886SDevin Teske					return $FAILURE
664*cd88b886SDevin Teske				new_list="$new_list $disk$targetpart.nop"
665*cd88b886SDevin Teske			fi
666*cd88b886SDevin Teske		done
667*cd88b886SDevin Teske		set -- $new_list
668*cd88b886SDevin Teske	else
669*cd88b886SDevin Teske		local new_list=
670*cd88b886SDevin Teske		for disk in $*; do
671*cd88b886SDevin Teske			new_list="$new_list $disk$targetpart"
672*cd88b886SDevin Teske			[ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
673*cd88b886SDevin Teske				unenc_list="$unenc_list $disk$bootpart"
674*cd88b886SDevin Teske		done
675*cd88b886SDevin Teske		set -- $new_list
676*cd88b886SDevin Teske	fi
677*cd88b886SDevin Teske
678*cd88b886SDevin Teske	#
679*cd88b886SDevin Teske	# If encryption is enabled, we need to create the GEOMs
680*cd88b886SDevin Teske	#
681*cd88b886SDevin Teske	if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
682*cd88b886SDevin Teske		local bootvdev=
683*cd88b886SDevin Teske		local geli_pool="$BSDINSTALL_CHROOT/$ZFSBOOT_GELI_POOL_NAME"
684*cd88b886SDevin Teske		local key="$ZFSBOOT_GELI_KEY_FILE"
685*cd88b886SDevin Teske
686*cd88b886SDevin Teske		# Create the parent directories for our unencrypted pool
687*cd88b886SDevin Teske		f_quietly umount /mnt
688*cd88b886SDevin Teske		mount -t tmpfs none $BSDINSTALL_CHROOT || return $FAILURE
689*cd88b886SDevin Teske
690*cd88b886SDevin Teske		# Create mirror across the unencrypted partition on all disks
691*cd88b886SDevin Teske		[ $( set -- $unenc_list; echo $# ) -gt 1 ] && bootvdev=mirror
692*cd88b886SDevin Teske
693*cd88b886SDevin Teske		zpool create -o altroot=$BSDINSTALL_CHROOT \
694*cd88b886SDevin Teske			-m "/$ZFSBOOT_GELI_POOL_NAME" -f \
695*cd88b886SDevin Teske			"$ZFSBOOT_GELI_POOL_NAME" $bootvdev $unenc_list ||
696*cd88b886SDevin Teske			return $FAILURE
697*cd88b886SDevin Teske		mkdir -p $geli_pool/boot || return $FAILURE
698*cd88b886SDevin Teske
699*cd88b886SDevin Teske		# Generate an encryption key using random(4)
700*cd88b886SDevin Teske		dd if=/dev/random of="$geli_pool/$key" bs=4096 count=1 ||
701*cd88b886SDevin Teske			return $FAILURE
702*cd88b886SDevin Teske
703*cd88b886SDevin Teske		# Create the geli(8) GEOMS
704*cd88b886SDevin Teske		local geli_list
705*cd88b886SDevin Teske		msg_enter_new_password="$msg_geli_password" \
706*cd88b886SDevin Teske			f_dialog_input_password || return $FAILURE
707*cd88b886SDevin Teske		f_dialog_info "$msg_geli_setup" \
708*cd88b886SDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
709*cd88b886SDevin Teske		for disk in $realdisks; do
710*cd88b886SDevin Teske			echo "$pw_password" | geli init -b -B \
711*cd88b886SDevin Teske				"$geli_pool/boot/$disk$targetpart.eli" \
712*cd88b886SDevin Teske				-e AES-XTS -J - -K "$geli_pool/$key" -l 256 \
713*cd88b886SDevin Teske				-s 4096 $disk$targetpart || return $FAILURE
714*cd88b886SDevin Teske			echo "$pw_password" | geli attach -j - \
715*cd88b886SDevin Teske				-k "$geli_pool/$key" $disk$targetpart ||
716*cd88b886SDevin Teske				return $FAILURE
717*cd88b886SDevin Teske			geli_list="$geli_list $disk$targetpart.eli"
718*cd88b886SDevin Teske		done
719*cd88b886SDevin Teske		set -- $geli_list
720*cd88b886SDevin Teske		zfs unmount "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE
721*cd88b886SDevin Teske		f_quietly umount /mnt # done with tmpfs
722*cd88b886SDevin Teske	fi
723*cd88b886SDevin Teske
724*cd88b886SDevin Teske	#
725*cd88b886SDevin Teske	# Create the ZFS pool with desired type and disk devices
726*cd88b886SDevin Teske	#
727*cd88b886SDevin Teske	zpool create -o altroot=$BSDINSTALL_CHROOT -m none -f \
728*cd88b886SDevin Teske		"$poolname" $vdev_type $* || return $FAILURE
729*cd88b886SDevin Teske
730*cd88b886SDevin Teske	# Customize the zpool a bit...
731*cd88b886SDevin Teske	zfs set checksum=fletcher4	"$poolname" || return $FAILURE
732*cd88b886SDevin Teske	zfs set atime=off		"$poolname" || return $FAILURE
733*cd88b886SDevin Teske
734*cd88b886SDevin Teske	#
735*cd88b886SDevin Teske	# Create ZFS dataset layout within the new boot pool
736*cd88b886SDevin Teske	#
737*cd88b886SDevin Teske	echo "$ZFSBOOT_DATASETS" | while read dataset options; do
738*cd88b886SDevin Teske		# Skip blank lines and comments
739*cd88b886SDevin Teske		case "$dataset" in "#"*|"") continue; esac
740*cd88b886SDevin Teske		# Remove potential inline comments in options
741*cd88b886SDevin Teske		options="${options%%#*}"
742*cd88b886SDevin Teske		# Replace tabs with spaces
743*cd88b886SDevin Teske		f_replaceall "$options" "	" " " options
744*cd88b886SDevin Teske		# Reduce contiguous runs of space to one single space
745*cd88b886SDevin Teske		oldoptions=
746*cd88b886SDevin Teske		while [ "$oldoptions" != "$options" ]; do
747*cd88b886SDevin Teske			oldoptions="$options"
748*cd88b886SDevin Teske			f_replaceall "$options" "  " " " options
749*cd88b886SDevin Teske		done
750*cd88b886SDevin Teske		# Replace both commas and spaces with ` -o '
751*cd88b886SDevin Teske		f_replaceall "$options" "[ ,]" " -o " options
752*cd88b886SDevin Teske		# Create the dataset with desired options
753*cd88b886SDevin Teske		zfs create ${options:+-o $options} "$poolname$dataset" ||
754*cd88b886SDevin Teske			return $FAILURE
755*cd88b886SDevin Teske	done
756*cd88b886SDevin Teske
757*cd88b886SDevin Teske	# Touch up permissions on the tmp directories
758*cd88b886SDevin Teske	chmod 1777 $BSDINSTALL_CHROOT/tmp || return $FAILURE
759*cd88b886SDevin Teske	chmod 1777 $BSDINSTALL_CHROOT/var/tmp || return $FAILURE
760*cd88b886SDevin Teske
761*cd88b886SDevin Teske	# Create symlink(s)
762*cd88b886SDevin Teske	[ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
763*cd88b886SDevin Teske		{ ln -s $ZFSBOOT_GELI_POOL_NAME/boot $BSDINSTALL_CHROOT/boot ||
764*cd88b886SDevin Teske			return $FAILURE; }
765*cd88b886SDevin Teske
766*cd88b886SDevin Teske	# Set bootfs property
767*cd88b886SDevin Teske	zpool set bootfs="$poolname/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" \
768*cd88b886SDevin Teske		"$poolname" || return $FAILURE
769*cd88b886SDevin Teske
770*cd88b886SDevin Teske	# Export the pool(s)
771*cd88b886SDevin Teske	zpool export "$poolname" || return $FAILURE
772*cd88b886SDevin Teske	[ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
773*cd88b886SDevin Teske		{ zpool export "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE; }
774*cd88b886SDevin Teske
775*cd88b886SDevin Teske	# Destroy the gnop devices (if enabled)
776*cd88b886SDevin Teske	for disk in ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:+$realdisks}; do
777*cd88b886SDevin Teske		if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
778*cd88b886SDevin Teske			f_quietly gnop destroy $disk$bootpart.nop
779*cd88b886SDevin Teske		else
780*cd88b886SDevin Teske			f_quietly gnop destroy $disk$targetpart.nop
781*cd88b886SDevin Teske		fi
782*cd88b886SDevin Teske	done
783*cd88b886SDevin Teske
784*cd88b886SDevin Teske	# MBR boot loader hack part 2
785*cd88b886SDevin Teske	if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then
786*cd88b886SDevin Teske		# Stick the ZFS boot loader in the "convienient hole" after
787*cd88b886SDevin Teske		# the ZFS internal metadata
788*cd88b886SDevin Teske		for disk in $realdisks; do
789*cd88b886SDevin Teske			dd if=/boot/zfsboot of=/dev/$disk$bootpart \
790*cd88b886SDevin Teske				skip=1 seek=1024 || return $FAILURE
791*cd88b886SDevin Teske		done
792*cd88b886SDevin Teske	fi
793*cd88b886SDevin Teske
794*cd88b886SDevin Teske	# Re-import the ZFS pool(s)
795*cd88b886SDevin Teske	zpool import -o altroot=$BSDINSTALL_CHROOT $poolname ||	return $FAILURE
796*cd88b886SDevin Teske	[ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
797*cd88b886SDevin Teske		{ zpool import -o altroot=$BSDINSTALL_CHROOT \
798*cd88b886SDevin Teske			"$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE; }
799*cd88b886SDevin Teske
800*cd88b886SDevin Teske	# While this is apparently not needed, it seems to help MBR
801*cd88b886SDevin Teske	mkdir -p $BSDINSTALL_CHROOT/boot/zfs || return $FAILURE
802*cd88b886SDevin Teske	zpool set cachefile=$BSDINSTALL_CHROOT/boot/zfs/zpool.cache \
803*cd88b886SDevin Teske		"$poolname" || return $FAILURE
804*cd88b886SDevin Teske
805*cd88b886SDevin Teske	# Last, but not least... add required lines to rc.conf(5)
806*cd88b886SDevin Teske	# NOTE: We later concatenate these into their destination
807*cd88b886SDevin Teske	echo 'zfs_enable="YES"' > $BSDINSTALL_TMPETC/rc.conf.zfs ||
808*cd88b886SDevin Teske		return $FAILURE
809*cd88b886SDevin Teske	echo 'zfs_load="YES"' > $BSDINSTALL_TMPBOOT/loader.conf.zfs ||
810*cd88b886SDevin Teske		return $FAILURE
811*cd88b886SDevin Teske
812*cd88b886SDevin Teske	# We're all done unless we should go on to do encryption
813*cd88b886SDevin Teske	[ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS
814*cd88b886SDevin Teske
815*cd88b886SDevin Teske	#
816*cd88b886SDevin Teske	# Configure geli(8)-based encryption
817*cd88b886SDevin Teske	#
818*cd88b886SDevin Teske	echo 'aesni_load="YES"' \
819*cd88b886SDevin Teske		> $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
820*cd88b886SDevin Teske	echo 'geom_eli_load="YES"' \
821*cd88b886SDevin Teske		> $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
822*cd88b886SDevin Teske	printf 'vfs.root.mountfrom="zfs:%s/%s/%s"\n' "$poolname" \
823*cd88b886SDevin Teske		"$ZFSBOOT_BEROOT_NAME" "$ZFSBOOT_BOOTFS_NAME" \
824*cd88b886SDevin Teske		> $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
825*cd88b886SDevin Teske	for disk in $realdisks; do
826*cd88b886SDevin Teske		printf 'geli_%s_keyfile0_load="YES"\n' \
827*cd88b886SDevin Teske			"$disk$targetpart" \
828*cd88b886SDevin Teske			> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
829*cd88b886SDevin Teske			return $FAILURE
830*cd88b886SDevin Teske		printf 'geli_%s_keyfile0_type="%s:geli_keyfile0"\n' \
831*cd88b886SDevin Teske			"$disk$targetpart" "$disk$targetpart" \
832*cd88b886SDevin Teske			>> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
833*cd88b886SDevin Teske			return $FAILURE
834*cd88b886SDevin Teske		printf 'geli_%s_keyfile0_name="%s"\n' \
835*cd88b886SDevin Teske			"$disk$targetpart" "$ZFSBOOT_GELI_KEY_FILE" \
836*cd88b886SDevin Teske			>> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
837*cd88b886SDevin Teske			return $FAILURE
838*cd88b886SDevin Teske	done
839*cd88b886SDevin Teske
840*cd88b886SDevin Teske	return $SUCCESS
841*cd88b886SDevin Teske}
842*cd88b886SDevin Teske
843*cd88b886SDevin Teske# dialog_menu_diskinfo
844*cd88b886SDevin Teske#
845*cd88b886SDevin Teske# Prompt the user to select a disk and then provide detailed info on it.
846*cd88b886SDevin Teske#
847*cd88b886SDevin Teskedialog_menu_diskinfo()
848*cd88b886SDevin Teske{
849*cd88b886SDevin Teske	local disk
850*cd88b886SDevin Teske
851*cd88b886SDevin Teske	#
852*cd88b886SDevin Teske	# Break from loop when user cancels disk selection
853*cd88b886SDevin Teske	#
854*cd88b886SDevin Teske	while :; do
855*cd88b886SDevin Teske		disk=$( msg_cancel="$msg_back" f_device_menu \
856*cd88b886SDevin Teske			"$DIALOG_TITLE" "$msg_select_a_disk_device" "" \
857*cd88b886SDevin Teske			$DEVICE_TYPE_DISK 2>&1 ) || break
858*cd88b886SDevin Teske
859*cd88b886SDevin Teske		# Show gpart(8) `show' and camcontrol(8) `inquiry' data
860*cd88b886SDevin Teske		f_show_msg "$msg_detailed_disk_info" \
861*cd88b886SDevin Teske			"$disk" "$( gpart show $disk 2> /dev/null )" \
862*cd88b886SDevin Teske			"$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \
863*cd88b886SDevin Teske			"$disk" "$( camcontrol identify $disk 2> /dev/null )"
864*cd88b886SDevin Teske	done
865*cd88b886SDevin Teske
866*cd88b886SDevin Teske	return $SUCCESS
867*cd88b886SDevin Teske}
868*cd88b886SDevin Teske
869*cd88b886SDevin Teske############################################################ MAIN
870*cd88b886SDevin Teske
871*cd88b886SDevin Teske#
872*cd88b886SDevin Teske# Initialize
873*cd88b886SDevin Teske#
874*cd88b886SDevin Teskef_dialog_title "$msg_zfs_configuration"
875*cd88b886SDevin Teskef_dialog_backtitle "$msg_freebsd_installer"
876*cd88b886SDevin Teske
877*cd88b886SDevin Teske# User may have specifically requested ZFS-related operations be interactive
878*cd88b886SDevin Teske! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE
879*cd88b886SDevin Teske
880*cd88b886SDevin Teske#
881*cd88b886SDevin Teske# Loop over the main menu until we've accomplished what we came here to do
882*cd88b886SDevin Teske#
883*cd88b886SDevin Teskewhile :; do
884*cd88b886SDevin Teske	if ! f_interactive; then
885*cd88b886SDevin Teske		retval=$DIALOG_OK
886*cd88b886SDevin Teske		mtag=">>> $msg_create"
887*cd88b886SDevin Teske	else
888*cd88b886SDevin Teske		dialog_menu_main
889*cd88b886SDevin Teske		retval=$?
890*cd88b886SDevin Teske		f_dialog_menutag_fetch mtag
891*cd88b886SDevin Teske	fi
892*cd88b886SDevin Teske
893*cd88b886SDevin Teske	f_dprintf "retval=%u mtag=[%s]" $reval "$mtag"
894*cd88b886SDevin Teske	[ $retval -eq $DIALOG_OK ] || f_die
895*cd88b886SDevin Teske
896*cd88b886SDevin Teske	case "$mtag" in
897*cd88b886SDevin Teske	">>> $msg_create")
898*cd88b886SDevin Teske		#
899*cd88b886SDevin Teske		# First, validate the user's selections
900*cd88b886SDevin Teske		#
901*cd88b886SDevin Teske
902*cd88b886SDevin Teske		# Make sure they gave us a name for the pool
903*cd88b886SDevin Teske		if [ ! "$ZFSBOOT_POOL_NAME" ]; then
904*cd88b886SDevin Teske			f_show_msg "$msg_pool_name_cannot_be_empty"
905*cd88b886SDevin Teske			f_interactive || f_die
906*cd88b886SDevin Teske			continue
907*cd88b886SDevin Teske		fi
908*cd88b886SDevin Teske		# Make sure [potentially scripted] selections are real
909*cd88b886SDevin Teske		real_disks=
910*cd88b886SDevin Teske		for disk in $ZFSBOOT_DISKS; do
911*cd88b886SDevin Teske			f_struct device_$disk && real_disks="$real_disks $disk"
912*cd88b886SDevin Teske		done
913*cd88b886SDevin Teske		# Make sure we have at least one real disk selected
914*cd88b886SDevin Teske		ndisks=$( set -- $real_disks; echo $# )
915*cd88b886SDevin Teske		if [ $ndisks -lt 1 ]; then
916*cd88b886SDevin Teske			f_show_msg "$msg_no_disks_selected"
917*cd88b886SDevin Teske			f_interactive || f_die
918*cd88b886SDevin Teske			continue
919*cd88b886SDevin Teske		fi
920*cd88b886SDevin Teske		# Make sure we have enough disks for the desired vdev type
921*cd88b886SDevin Teske		case "$ZFSBOOT_VDEV_TYPE" in
922*cd88b886SDevin Teske		stripe) want_disks=1 ;;
923*cd88b886SDevin Teske		mirror) want_disks=2 ;;
924*cd88b886SDevin Teske		raidz1) want_disks=3 ;;
925*cd88b886SDevin Teske		raidz2) want_disks=4 ;;
926*cd88b886SDevin Teske		raidz3) want_disks=5 ;;
927*cd88b886SDevin Teske		*)
928*cd88b886SDevin Teske			f_show_msg "$msg_invalid_virtual_device_type" \
929*cd88b886SDevin Teske		                   "$ZFSBOOT_VDEV_TYPE"
930*cd88b886SDevin Teske			f_interactive || f_die
931*cd88b886SDevin Teske			continue
932*cd88b886SDevin Teske		esac
933*cd88b886SDevin Teske		if [ $ndisks -lt $want_disks ]; then
934*cd88b886SDevin Teske			f_show_msg "%s: $msg_not_enough_disks_selected" \
935*cd88b886SDevin Teske			           "$ZFSBOOT_VDEV_TYPE" "$want_disks"
936*cd88b886SDevin Teske			f_interactive || f_die
937*cd88b886SDevin Teske			continue
938*cd88b886SDevin Teske		fi
939*cd88b886SDevin Teske		# Make sure each disk will be at least 50% ZFS
940*cd88b886SDevin Teske		if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize &&
941*cd88b886SDevin Teske		   f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize
942*cd88b886SDevin Teske		then
943*cd88b886SDevin Teske			minsize=$swapsize teeny_disks=
944*cd88b886SDevin Teske			[ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
945*cd88b886SDevin Teske				minsize=$(( $minsize + $gelisize ))
946*cd88b886SDevin Teske			for disk in $real_disks; do
947*cd88b886SDevin Teske				device_$disk get capacity disksize || continue
948*cd88b886SDevin Teske				disksize=$(( $disksize - $minsize ))
949*cd88b886SDevin Teske				[ $disksize -lt $minsize ] &&
950*cd88b886SDevin Teske					teeny_disks="$teeny_disks $disk"
951*cd88b886SDevin Teske			done
952*cd88b886SDevin Teske			if [ "$teeny_disks" ]; then
953*cd88b886SDevin Teske				f_show_msg "$msg_these_disks_are_too_small" \
954*cd88b886SDevin Teske				           "$ZFSBOOT_SWAP_SIZE" \
955*cd88b886SDevin Teske				           "$ZFSBOOT_GELI_BOOT_SIZE" \
956*cd88b886SDevin Teske				           "$teeny_disks"
957*cd88b886SDevin Teske				f_interactive || f_die
958*cd88b886SDevin Teske				continue
959*cd88b886SDevin Teske			fi
960*cd88b886SDevin Teske		fi
961*cd88b886SDevin Teske
962*cd88b886SDevin Teske		#
963*cd88b886SDevin Teske		# Last Chance!
964*cd88b886SDevin Teske		#
965*cd88b886SDevin Teske		if [ ! "$USE_XDIALOG" ]; then
966*cd88b886SDevin Teske			f_interactive && DIALOG="$DIALOG --colors" f_noyes \
967*cd88b886SDevin Teske				"$msg_last_chance_are_you_sure_color" \
968*cd88b886SDevin Teske				"$ZFSBOOT_DISKS" || continue
969*cd88b886SDevin Teske		else
970*cd88b886SDevin Teske			f_interactive && f_noyes \
971*cd88b886SDevin Teske				"$msg_last_chance_are_you_sure" \
972*cd88b886SDevin Teske				"$ZFSBOOT_DISKS" || continue
973*cd88b886SDevin Teske		fi
974*cd88b886SDevin Teske
975*cd88b886SDevin Teske		#
976*cd88b886SDevin Teske		# Let's do this
977*cd88b886SDevin Teske		#
978*cd88b886SDevin Teske
979*cd88b886SDevin Teske		vdev_type="$ZFSBOOT_VDEV_TYPE"
980*cd88b886SDevin Teske
981*cd88b886SDevin Teske		# Blank the vdev type for the default layout
982*cd88b886SDevin Teske		[ "$vdev_type" = "stripe" ] && vdev_type=
983*cd88b886SDevin Teske
984*cd88b886SDevin Teske		if ! error=$( zfs_create_boot "$ZFSBOOT_POOL_NAME" \
985*cd88b886SDevin Teske			"$vdev_type" $real_disks 2>&1 )
986*cd88b886SDevin Teske		then
987*cd88b886SDevin Teske			f_dialog_msgbox "$error"
988*cd88b886SDevin Teske			f_interactive || f_die
989*cd88b886SDevin Teske			continue
990*cd88b886SDevin Teske		fi
991*cd88b886SDevin Teske
992*cd88b886SDevin Teske		break # to success
993*cd88b886SDevin Teske		;;
994*cd88b886SDevin Teske	"- $msg_rescan_devices") f_device_rescan ;;
995*cd88b886SDevin Teske	"- $msg_disk_info") dialog_menu_diskinfo ;;
996*cd88b886SDevin Teske	?" $msg_pool_name")
997*cd88b886SDevin Teske		# Prompt the user to input/change the name for the new pool
998*cd88b886SDevin Teske		f_dialog_input input \
999*cd88b886SDevin Teske			"$msg_please_enter_a_name_for_your_zpool" \
1000*cd88b886SDevin Teske			"$ZFSBOOT_POOL_NAME" &&
1001*cd88b886SDevin Teske			ZFSBOOT_POOL_NAME="$input"
1002*cd88b886SDevin Teske		;;
1003*cd88b886SDevin Teske	?" $msg_disks_to_use") dialog_edit_disks ;;
1004*cd88b886SDevin Teske	?" $msg_zfs_vdev_type") dialog_menu_vdev ;;
1005*cd88b886SDevin Teske	?" $msg_force_4k_sectors")
1006*cd88b886SDevin Teske		# Toggle the variable referenced both by the menu and later
1007*cd88b886SDevin Teske		if [ "$ZFSBOOT_GNOP_4K_FORCE_ALIGN" ]; then
1008*cd88b886SDevin Teske			ZFSBOOT_GNOP_4K_FORCE_ALIGN=
1009*cd88b886SDevin Teske		else
1010*cd88b886SDevin Teske			ZFSBOOT_GNOP_4K_FORCE_ALIGN=1
1011*cd88b886SDevin Teske		fi
1012*cd88b886SDevin Teske		;;
1013*cd88b886SDevin Teske	?" $msg_geli_encryption")
1014*cd88b886SDevin Teske		# Toggle the variable referenced both by the menu and later
1015*cd88b886SDevin Teske		if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
1016*cd88b886SDevin Teske			ZFSBOOT_GELI_ENCRYPTION=
1017*cd88b886SDevin Teske		else
1018*cd88b886SDevin Teske			ZFSBOOT_GELI_ENCRYPTION=1
1019*cd88b886SDevin Teske		fi
1020*cd88b886SDevin Teske		;;
1021*cd88b886SDevin Teske	?" $msg_partition_scheme")
1022*cd88b886SDevin Teske		# Toggle between GPT and MBR
1023*cd88b886SDevin Teske		if [ "$ZFSBOOT_PARTITION_SCHEME" = GPT ]; then
1024*cd88b886SDevin Teske			ZFSBOOT_PARTITION_SCHEME=MBR
1025*cd88b886SDevin Teske		else
1026*cd88b886SDevin Teske			ZFSBOOT_PARTITION_SCHEME=GPT
1027*cd88b886SDevin Teske		fi
1028*cd88b886SDevin Teske		;;
1029*cd88b886SDevin Teske	?" $msg_swap_size")
1030*cd88b886SDevin Teske		# Prompt the user to input/change the swap size for each disk
1031*cd88b886SDevin Teske		f_dialog_input input \
1032*cd88b886SDevin Teske			"$msg_please_enter_amount_of_swap_space" \
1033*cd88b886SDevin Teske			"$ZFSBOOT_SWAP_SIZE" &&
1034*cd88b886SDevin Teske			ZFSBOOT_SWAP_SIZE="$input"
1035*cd88b886SDevin Teske		;;
1036*cd88b886SDevin Teske	esac
1037*cd88b886SDevin Teskedone
1038*cd88b886SDevin Teske
1039*cd88b886SDevin Teskereturn $SUCCESS
1040*cd88b886SDevin Teske
1041*cd88b886SDevin Teske################################################################################
1042*cd88b886SDevin Teske# END
1043*cd88b886SDevin Teske################################################################################
1044