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)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35336
This commit is contained in:
Mark Johnston
2022-05-30 10:43:44 -04:00
parent ef7a6f1ded
commit 227caacc91
4 changed files with 35 additions and 1 deletions
+2
View File
@@ -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
+1
View File
@@ -326,6 +326,7 @@ ZFS+= zfsbe
ZFS+= zfsd
ZFS+= zfskeys
ZFS+= zpool
ZFS+= zpoolreguid
ZFS+= zvol
ZFSPACKAGE= rc
.endif
+25
View File
@@ -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"