Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jul 2022 14:09:25 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: f82f93ffc12d - stable/13 - rc: Add a zpoolreguid rc.d script
Message-ID:  <202207191409.26JE9PqA051963@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by markj:

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

commit f82f93ffc12da319aff0e0411167cc32ed375a87
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-05-30 14:43:44 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-07-19 13:49:44 +0000

    rc: Add a zpoolreguid rc.d script
    
    If one boots up multiple copies of a template VM image containing a
    zpool, the pool GUIDs will be identical, making it impossible to, e.g.,
    share datasets between them.
    
    This diff introduces a simple workaround for the problem: one can use
    the script to, upon first boot, assign a new GUID to one or more zpools.
    This will be useful when building ZFS-based VM images from release(7).
    
    Reviewed by:    mav, allanjude, asomers
    Reviewed by:    Pau Amma (docs)
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 227caacc918a8c9b32608cff42116e7d890b9ddc)
---
 libexec/rc/rc.conf          |  2 ++
 libexec/rc/rc.d/Makefile    |  1 +
 libexec/rc/rc.d/zpoolreguid | 25 +++++++++++++++++++++++++
 share/man/man5/rc.conf.5    |  6 ++++++
 4 files changed, 34 insertions(+)

diff --git a/libexec/rc/rc.conf b/libexec/rc/rc.conf
index f3fb3fd9473c..422c2efa9b59 100644
--- a/libexec/rc/rc.conf
+++ b/libexec/rc/rc.conf
@@ -69,6 +69,8 @@ rc_conf_files="/etc/rc.conf /etc/rc.conf.local"
 zfs_enable="NO"		# Set to YES to automatically mount ZFS file systems
 zfskeys_enable="NO"	# Set YES to autoload ZFS encryption keys
 zfs_bootonce_activate="NO" # Set YES to make successful bootonce BE permanent
+zpool_reguid=""		# Set to zpools for which the GUID should be replaced
+			# upon first boot.
 
 # ZFSD support
 zfsd_enable="NO"	# Set to YES to automatically start the ZFS fault
diff --git a/libexec/rc/rc.d/Makefile b/libexec/rc/rc.d/Makefile
index c724119cdf48..34846411dce9 100644
--- a/libexec/rc/rc.d/Makefile
+++ b/libexec/rc/rc.d/Makefile
@@ -328,6 +328,7 @@ ZFS+=		zfsbe
 ZFS+=		zfsd
 ZFS+=		zfskeys
 ZFS+=		zpool
+ZFS+=		zpoolreguid
 ZFS+=		zvol
 ZFSPACKAGE=	rc
 .endif
diff --git a/libexec/rc/rc.d/zpoolreguid b/libexec/rc/rc.d/zpoolreguid
new file mode 100755
index 000000000000..83c703d5d6c4
--- /dev/null
+++ b/libexec/rc/rc.d/zpoolreguid
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# PROVIDE: zpoolreguid
+# REQUIRE: zpool
+# BEFORE: mountcritlocal
+# KEYWORD: firstboot nojail
+
+. /etc/rc.subr
+
+name="zpoolreguid"
+desc="Generate a new zpool GUID"
+rcvar="zfs_enable"
+start_cmd="zpoolreguid_start"
+
+zpoolreguid_start()
+{
+	local pool
+
+	for pool in "${zpool_reguid}"; do
+		zpool reguid $pool
+	done
+}
+
+load_rc_config $name
+run_rc_command "$1"
diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5
index 2581783794be..1f268ada7f47 100644
--- a/share/man/man5/rc.conf.5
+++ b/share/man/man5/rc.conf.5
@@ -2051,6 +2051,12 @@ If set to
 .Pa /etc/rc.d/zfs
 will attempt to automatically mount ZFS file systems and initialize ZFS volumes
 (ZVOLs).
+.It Va zpool_reguid
+.Pq Vt str
+A space-separated list of ZFS pool names for which new pool GUIDs should be
+assigned upon first boot.
+This is useful when using a ZFS pool copied from a template, such as a virtual
+machine image.
 .It Va gptboot_enable
 .Pq Vt bool
 If set to



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202207191409.26JE9PqA051963>