git: d3c02201f9db - releng/15.2 - bsdinstall: Set TMPDIR in pkgbase install

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Thu, 12 Nov 2026 23:41:51 UTC
The branch releng/15.2 has been updated by cperciva:

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

commit d3c02201f9db71a935ccaec1a45f025a096a1de9
Author:     Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2026-11-10 02:34:43 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-12 23:41:17 +0000

    bsdinstall: Set TMPDIR in pkgbase install
    
    The FreeBSD-base repository (aka "pkgbase") is now created using 'pkg
    repo -l' in order to make 'pkg rwhich' work.  Unfortunately this makes
    the data.pkg file considerably larger, and FreeBSD 15.2-BETA1 fails to
    install using a remote repository since the installer has a small /tmp
    (20 MB).
    
    Run pkg commands with 'env TMPDIR=<chrootdir>/tmp' since the /tmp in
    the system being installed is considerably larger than the tmpfs which
    the installer runs with.  Create <chrootdir>/tmp first so we can ensure
    it has 1777 permissions.
    
    Approved by:    re (cperciva)
    Reviewed by:    bapt
    MFC after:      1 day
    Differential Revision:  https://reviews.freebsd.org/D61380
    
    (cherry picked from commit a7163bd76986282fdcb059b91301d3214da49642)
    (cherry picked from commit f3555a0e240ae2b26fdf0db2e3f68ec6846bbb58)
---
 usr.sbin/bsdinstall/scripts/pkgbase.in | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/usr.sbin/bsdinstall/scripts/pkgbase.in b/usr.sbin/bsdinstall/scripts/pkgbase.in
index 2c7d6bcae904..b872e9ad8d67 100755
--- a/usr.sbin/bsdinstall/scripts/pkgbase.in
+++ b/usr.sbin/bsdinstall/scripts/pkgbase.in
@@ -345,10 +345,15 @@ local function pkgbase()
 		assert(os.execute("cp -R /usr/share/keys/* " .. chroot .. "/usr/share/keys/"))
 	end
 
+	-- Create <chroot>/tmp and point at it with TMPDIR; otherwise pkg uses
+	-- /tmp which is a small tmpfs in the installer environment and fails
+	-- to extract data.pkg.
 	-- We must use --repo-conf-dir rather than -o REPOS_DIR here as the latter
 	-- is interpreted relative to the --rootdir. BSDINSTALL_PKG_REPOS_DIR must
 	-- be allowed to point to a path outside the chroot.
-	local pkg = "pkg --rootdir " .. chroot ..
+	assert(os.execute("mkdir -p " .. chroot .. "/tmp"))
+	assert(os.execute("chmod 1777 " .. chroot .. "/tmp"))
+	local pkg = "env TMPDIR=" .. chroot .. "/tmp pkg --rootdir " .. chroot ..
 		" --repo-conf-dir " .. repos_dir .. " -o IGNORE_OSVERSION=yes "
 
 	while not os.execute(pkg .. "update") do