git: 7ef92163ab81 - main - Allows user to specify an optional ZFSBOOT_POOL_SIZE for their zroot

Warner Losh imp at FreeBSD.org
Wed Jun 2 17:13:20 UTC 2021


The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=7ef92163ab81b1b14f2a111d17baf2b352338577

commit 7ef92163ab81b1b14f2a111d17baf2b352338577
Author:     John Ko <git at johnko.ca>
AuthorDate: 2021-06-02 17:12:14 +0000
Commit:     Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-06-02 17:12:14 +0000

    Allows user to specify an optional ZFSBOOT_POOL_SIZE for their zroot
    
    The default is to create a zroot that consumes the whole disk because if
    used with geli(8) this makes sense.
    
    Without geli(8), I like to keep my data pool separate from my system
    pool.
    
    This is different than ZFSBOOT_BOOT_POOL_SIZE which is named bootpool.
    
    Reviewed by:            allenjude
    Pull Request:           https://github.com/freebsd/freebsd-src/pull/53
    Differential Revision:  https://reviews.freebsd.org/D30588
---
 usr.sbin/bsdinstall/scripts/zfsboot | 46 ++++++++++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/usr.sbin/bsdinstall/scripts/zfsboot b/usr.sbin/bsdinstall/scripts/zfsboot
index 3b673addb10a..45c8b001c393 100755
--- a/usr.sbin/bsdinstall/scripts/zfsboot
+++ b/usr.sbin/bsdinstall/scripts/zfsboot
@@ -44,6 +44,11 @@ f_include $BSDCFG_SHARE/variable.subr
 #
 : ${ZFSBOOT_POOL_NAME:=zroot}
 
+#
+# Default pool size is optional
+#
+: ${ZFSBOOT_POOL_SIZE=}
+
 #
 # Default options to use when creating zroot pool
 #
@@ -262,6 +267,7 @@ msg_install_help="Create ZFS boot pool with displayed options"
 msg_invalid_boot_pool_size="Invalid boot pool size \`%s'"
 msg_invalid_disk_argument="Invalid disk argument \`%s'"
 msg_invalid_index_argument="Invalid index argument \`%s'"
+msg_invalid_pool_size="Invalid pool size \`%s'"
 msg_invalid_swap_size="Invalid swap size \`%s'"
 msg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'"
 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"
@@ -943,9 +949,15 @@ zfs_create_diskpart()
 		#
 		# 4. Add freebsd-zfs partition labeled `zfs#' for zroot
 		#
-		f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL" \
-		             "$align_big" zfs$index freebsd-zfs $disk ||
-		             return $FAILURE
+		if [ "$ZFSBOOT_POOL_SIZE" ]; then
+			f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \
+					"$align_big" zfs$index freebsd-zfs $ZFSBOOT_POOL_SIZE $disk ||
+					return $FAILURE
+		else
+			f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL" \
+					"$align_big" zfs$index freebsd-zfs $disk ||
+					return $FAILURE
+		fi
 		f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
 		                /dev/$disk$targetpart
 		;;
@@ -1020,9 +1032,13 @@ zfs_create_diskpart()
 		#
 		# 5. Add freebsd-zfs partition for zroot
 		#
-		f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_INDEX" \
-		             "$align_small" $mbrindex freebsd-zfs ${disk}s1 ||
-		             return $FAILURE
+		if [ "$ZFSBOOT_POOL_SIZE" ]; then
+			f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_INDEX_WITH_SIZE" \
+					"$align_small" $mbrindex freebsd-zfs $ZFSBOOT_POOL_SIZE ${disk}s1 || return $FAILURE
+		else
+			f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_INDEX" \
+					"$align_small" $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE
+		fi
 		f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \
 		                /dev/$disk$targetpart # Pedantic
 		f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
@@ -1114,7 +1130,7 @@ zfs_create_boot()
 	# Expand SI units in desired sizes
 	#
 	f_dprintf "$funcname: Expanding supplied size values..."
-	local swapsize bootsize
+	local swapsize bootsize poolsize
 	if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then
 		f_dprintf "$funcname: Invalid swap size \`%s'" \
 		          "$ZFSBOOT_SWAP_SIZE"
@@ -1128,6 +1144,16 @@ zfs_create_boot()
 		           "$ZFSBOOT_BOOT_POOL_SIZE"
 		return $FAILURE
 	fi
+	if [ "$ZFSBOOT_POOL_SIZE" ]; then
+		if ! f_expand_number "$ZFSBOOT_POOL_SIZE" poolsize; then
+			f_dprintf "$funcname: Invalid pool size \`%s'" \
+				  "$ZFSBOOT_POOL_SIZE"
+			f_show_err "$msg_invalid_pool_size" \
+				   "$ZFSBOOT_POOL_SIZE"
+		fi
+		f_dprintf "$funcname: ZFSBOOT_POOL_SIZE=[%s] poolsize=[%s]" \
+			  "$ZFSBOOT_POOL_SIZE" "$poolsize"
+	fi
 	f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \
 	          "$ZFSBOOT_SWAP_SIZE" "$swapsize"
 	f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \
@@ -1627,7 +1653,11 @@ while :; do
 		   f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize &&
 		   f_expand_number "1g" zpoolmin
 		then
-			minsize=$(( $swapsize + $zpoolmin )) teeny_disks=
+			minsize=$swapsize teeny_disks=
+			if [ "$ZFSBOOT_POOL_SIZE" ]; then
+				f_expand_number "$ZFSBOOT_POOL_SIZE" poolsize
+				minsize=$(( $minsize + $poolsize ))
+			fi
 			[ "$ZFSBOOT_BOOT_POOL" ] &&
 				minsize=$(( $minsize + $bootsize ))
 			for disk in $ZFSBOOT_DISKS; do


More information about the dev-commits-src-all mailing list