git: 49e3c256e461 - main - bsdinstall: use the GPT label for swap in fstab

From: Devin Teske <dteske_at_FreeBSD.org>
Date: Sun, 18 Oct 2026 19:10:12 UTC
The branch main has been updated by dteske:

URL: https://cgit.FreeBSD.org/src/commit/?id=49e3c256e4619c56acc09660bc3c49b68ec32c20

commit 49e3c256e4619c56acc09660bc3c49b68ec32c20
Author:     Devin Teske <dteske@FreeBSD.org>
AuthorDate: 2026-10-18 19:06:48 +0000
Commit:     Devin Teske <dteske@FreeBSD.org>
CommitDate: 2026-10-18 19:06:48 +0000

    bsdinstall: use the GPT label for swap in fstab
    
    The GPT layout already labels the swap partition swapN, but fstab
    named the disk device. That name changes when disks are added or
    reordered, and swap does not come up until fstab is edited. Write
    /dev/gpt/swapN instead, appending .eli when swap encryption is on.
    Mirrored swap still uses /dev/mirror/swap, with the same suffix.
    
    Submitted by:   Wanpeng Qian <wanpengqian@gmail.com>
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D32936
---
 usr.sbin/bsdinstall/scripts/zfsboot | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/usr.sbin/bsdinstall/scripts/zfsboot b/usr.sbin/bsdinstall/scripts/zfsboot
index dbf7e19c6f5b..ad1d4370b62e 100755
--- a/usr.sbin/bsdinstall/scripts/zfsboot
+++ b/usr.sbin/bsdinstall/scripts/zfsboot
@@ -1000,29 +1000,34 @@ zfs_create_diskpart()
 
 	# Update fstab(5)
 	local swapsize
+	local suffix=
+
 	f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize
+	if [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then
+		suffix=".eli"
+	fi
 	if [ "$isswapmirror" ]; then
 		# This is not the first disk in the mirror, do nothing
 	elif [ ${swapsize:-0} -eq 0 ]; then
 		# If swap is 0 sized, don't add it to fstab
-	elif [ "$ZFSBOOT_SWAP_ENCRYPTION" -a "$ZFSBOOT_SWAP_MIRROR" ]; then
-		f_eval_catch $funcname printf "$PRINTF_FSTAB" \
-		             /dev/mirror/swap.eli none swap sw 0 0 \
-		             $BSDINSTALL_TMPETC/fstab || return $FAILURE
-		isswapmirror=1
 	elif [ "$ZFSBOOT_SWAP_MIRROR" ]; then
 		f_eval_catch $funcname printf "$PRINTF_FSTAB" \
-		             /dev/mirror/swap none swap sw 0 0 \
+		             /dev/mirror/swap$suffix none swap sw 0 0 \
 		             $BSDINSTALL_TMPETC/fstab || return $FAILURE
 		isswapmirror=1
-	elif [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then
-		f_eval_catch $funcname printf "$PRINTF_FSTAB" \
-		             /dev/$disk${swappart}.eli none swap sw 0 0 \
-		             $BSDINSTALL_TMPETC/fstab || return $FAILURE
 	else
-		f_eval_catch $funcname printf "$PRINTF_FSTAB" \
-		             /dev/$disk$swappart none swap sw 0 0 \
-		             $BSDINSTALL_TMPETC/fstab || return $FAILURE
+		case "$ZFSBOOT_PARTITION_SCHEME" in
+		GPT*)
+			f_eval_catch $funcname printf "$PRINTF_FSTAB" \
+			    /dev/gpt/swap$index$suffix none swap sw 0 0 \
+			    $BSDINSTALL_TMPETC/fstab || return $FAILURE
+			;;
+		*)
+			f_eval_catch $funcname printf "$PRINTF_FSTAB" \
+			    /dev/$disk$swappart$suffix none swap sw 0 0 \
+			    $BSDINSTALL_TMPETC/fstab || return $FAILURE
+			;;
+		esac
 	fi
 
 	return $SUCCESS