diff options
author | Jose Luis Duran <jlduran@users.noreply.github.com> | 2022-03-08 05:51:28 +0300 |
---|---|---|
committer | Emmanuel Vadot <manu@bidouilliste.com> | 2022-06-02 19:34:14 +0300 |
commit | 73b3a5169b640460c9bb8cbd295764e9e74838ab (patch) | |
tree | e56df9e974920985b41958f3b9757586bb10cb71 /src/share/poudriere | |
parent | fcb3f2d8c816761a69189a1a2c6d15956956e2dd (diff) |
image_zfs: Allow same-as-host pool names
Use `zpool create -t` to set the in-core pool name to a temporary,
random pool name, while the on-disk name will be the name specified as
the pool name in `ZFS_POOL_NAME`, by default `zroot` to match what is
currently used on release images.
Keep the check for a possible name collision on the randomly-created
pool name, to err on the side of caution.
Inspired by: https://reviews.freebsd.org/D34426
Diffstat (limited to 'src/share/poudriere')
-rw-r--r-- | src/share/poudriere/image.sh | 4 | ||||
-rw-r--r-- | src/share/poudriere/image_zfs.sh | 49 |
2 files changed, 29 insertions, 24 deletions
diff --git a/src/share/poudriere/image.sh b/src/share/poudriere/image.sh index bfa5b0da..95d2f18c 100644 --- a/src/share/poudriere/image.sh +++ b/src/share/poudriere/image.sh @@ -395,7 +395,7 @@ post_getopts : ${SWAPSIZE:=0} : ${PTNAME:=default} : ${ZFS_SEND_FLAGS:=-Rec} -: ${ZFS_POOL_NAME:=${IMAGENAME}root} +: ${ZFS_POOL_NAME:=zroot} : ${ZFS_BEROOT_NAME:=ROOT} : ${ZFS_BOOTFS_NAME:=default} @@ -406,6 +406,8 @@ MEDIAREMAINDER=${MEDIATYPE#*+} SUBMEDIATYPE=${MEDIAREMAINDER%%+*} MEDIAREMAINDER=${MEDIAREMAINDER#*+} +TMP_ZFS_POOL_NAME="${ZFS_POOL_NAME}.$(jot -r 1 1000000000)" + if [ "${MEDIATYPE}" = "none" ]; then err 1 "Missing -t option" fi diff --git a/src/share/poudriere/image_zfs.sh b/src/share/poudriere/image_zfs.sh index d788f088..7b2271e7 100644 --- a/src/share/poudriere/image_zfs.sh +++ b/src/share/poudriere/image_zfs.sh @@ -41,8 +41,8 @@ zfs_check() [ -n "${IMAGESIZE}" ] || err 1 "Please specify the imagesize" [ -n "${ZFS_POOL_NAME}" ] || err 1 "Please specify a pool name" - zpool list -Ho name ${ZFS_POOL_NAME} >/dev/null 2>&1 && \ - err 1 "Target pool name already exists" + zpool list -Ho name ${TMP_ZFS_POOL_NAME} >/dev/null 2>&1 && \ + err 1 "Temporary pool name already exists" case "${IMAGENAME}" in ''|*[!A-Za-z0-9]*) err 1 "Name can only contain alphanumeric characters" @@ -62,6 +62,7 @@ zfs_prepare() truncate -s ${IMAGESIZE} ${WRKDIR}/raw.img md=$(/sbin/mdconfig ${WRKDIR}/raw.img) zroot=${ZFS_POOL_NAME} + tmpzroot=${TMP_ZFS_POOL_NAME} msg "Creating temporary ZFS pool" zpool create \ @@ -70,27 +71,28 @@ zfs_prepare() -O checksum=sha512 \ -O compression=on \ -O atime=off \ + -t ${tmpzroot} \ -R ${WRKDIR}/world ${zroot} /dev/${md} || exit if [ -n "${ORIGIN_IMAGE}" ]; then msg "Importing previous ZFS Datasets" - zfs recv -F ${zroot} < "${ORIGIN_IMAGE}" + zfs recv -F ${tmpzroot} < "${ORIGIN_IMAGE}" else msg "Creating ZFS Datasets" - zfs create -o mountpoint=none ${zroot}/${ZFS_BEROOT_NAME} - zfs create -o mountpoint=/ ${zroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME} - zfs create -o mountpoint=/tmp -o exec=on -o setuid=off ${zroot}/tmp - zfs create -o mountpoint=/usr -o canmount=off ${zroot}/usr - zfs create ${zroot}/usr/home - zfs create -o setuid=off ${zroot}/usr/ports - zfs create ${zroot}/usr/src - zfs create ${zroot}/usr/obj - zfs create -o mountpoint=/var -o canmount=off ${zroot}/var - zfs create -o exec=off -o setuid=off ${zroot}/var/audit - zfs create -o exec=off -o setuid=off ${zroot}/var/crash - zfs create -o exec=off -o setuid=off ${zroot}/var/log - zfs create -o atime=on ${zroot}/var/mail - zfs create -o setuid=off ${zroot}/var/tmp + zfs create -o mountpoint=none ${tmpzroot}/${ZFS_BEROOT_NAME} + zfs create -o mountpoint=/ ${tmpzroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME} + zfs create -o mountpoint=/tmp -o exec=on -o setuid=off ${tmpzroot}/tmp + zfs create -o mountpoint=/usr -o canmount=off ${tmpzroot}/usr + zfs create ${tmpzroot}/usr/home + zfs create -o setuid=off ${tmpzroot}/usr/ports + zfs create ${tmpzroot}/usr/src + zfs create ${tmpzroot}/usr/obj + zfs create -o mountpoint=/var -o canmount=off ${tmpzroot}/var + zfs create -o exec=off -o setuid=off ${tmpzroot}/var/audit + zfs create -o exec=off -o setuid=off ${tmpzroot}/var/crash + zfs create -o exec=off -o setuid=off ${tmpzroot}/var/log + zfs create -o atime=on ${tmpzroot}/var/mail + zfs create -o setuid=off ${tmpzroot}/var/tmp chmod 1777 ${WRKDIR}/world/tmp ${WRKDIR}/world/var/tmp fi } @@ -115,11 +117,12 @@ zfs_generate() : ${SNAPSHOT_NAME:=$IMAGENAME} FINALIMAGE=${IMAGENAME}.img zroot="${ZFS_POOL_NAME}" - zpool set bootfs=${zroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME} ${zroot} - zpool set autoexpand=on ${zroot} - zfs set canmount=noauto ${zroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME} + tmpzroot="${TMP_ZFS_POOL_NAME}" + zpool set bootfs=${tmpzroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME} ${tmpzroot} + zpool set autoexpand=on ${tmpzroot} + zfs set canmount=noauto ${tmpzroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME} - SNAPSPEC="${zroot}@${SNAPSHOT_NAME}" + SNAPSPEC="${tmpzroot}@${SNAPSHOT_NAME}" msg "Creating snapshot(s) for image generation" zfs snapshot -r "$SNAPSPEC" @@ -137,7 +140,7 @@ zfs_generate() esac case "${MEDIAREMAINDER}" in *be*) - BESNAPSPEC="${zroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME}@${SNAPSHOT_NAME}" + BESNAPSPEC="${tmpzroot}/${ZFS_BEROOT_NAME}/${ZFS_BOOTFS_NAME}@${SNAPSHOT_NAME}" _zfs_writereplicationstream "${BESNAPSPEC}" "${IMAGENAME}.be.zfs" ;; esac @@ -145,7 +148,7 @@ zfs_generate() esac ## When generating a disk image, we need to export the pool first. - zpool export ${zroot} + zpool export ${tmpzroot} zroot= /sbin/mdconfig -d -u ${md#md} md= |