Skip to content

Commit b47eef7

Browse files
committed
bootc imports from the host namespace, so the container fixes never reached it
Three attempts at the same failure, each addressing a place the writing was not happening. TMPDIR in this script fixed the pull. TMPDIR in the container did nothing. Mounting the target over the container's /var/tmp did nothing either, and that is what identified it: bootc does the ostree import from the host mount namespace, which is what --pid=host is for, so the /var/tmp it fills is the live session's. On live media that is the RAM overlay, which is how a 3.4 GB import dies on a disk with sixty gigabytes free. The host's /var/tmp is now bound to the target for the duration of the install, and only when it is memory: a machine with a real /var/tmp needs no help, and moving somebody's temporary directory onto a disk being installed is not something to do for no reason. Unbound before the filesystem under it goes away.
1 parent 67b48b9 commit b47eef7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎src/partition.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub const REQUIRED_TOOLS: &[(&str, &str)] = &[
137137
("wipefs", "util-linux"),
138138
("sfdisk", "util-linux"),
139139
("blkid", "util-linux"),
140+
("findmnt", "util-linux"),
140141
("fstrim", "util-linux"),
141142
("udevadm", "systemd-udev"),
142143
("mkfs.vfat", "dosfstools"),
@@ -286,6 +287,8 @@ cleanup() {
286287
btrfs subvolume delete "$fsmnt/@STORE@" >/dev/null 2>&1 || true
287288
umount "$fsmnt" 2>/dev/null || true
288289
rm -f "${conf:-}" 2>/dev/null || true
290+
# Before the filesystem it lives on goes away.
291+
if [ -n "${bound_tmp:-}" ]; then umount /var/tmp 2>/dev/null || true; fi
289292
rm -rf "$fsmnt/tmp" 2>/dev/null || true
290293
rmdir "$mnt" "$fsmnt" 2>/dev/null || true
291294
if [ -n "$loop" ]; then losetup -d "$loop" 2>/dev/null || true; fi
@@ -342,6 +345,23 @@ mkdir -p /var/lib/containers/storage
342345
# path rather than by whether some library reads an environment.
343346
export TMPDIR="$fsmnt/tmp"
344347
mkdir -p "$TMPDIR"
348+
349+
# And bootc's half of it, which neither of the above reaches. bootc does
350+
# the ostree import from the host mount namespace, which is what
351+
# --pid=host is for, so the /var/tmp it writes to is this session's and
352+
# not the container's: passing TMPDIR in and mounting the container's
353+
# /var/tmp both leave it writing to the same RAM overlay it always was.
354+
#
355+
# Only when that directory is memory. A machine with a real /var/tmp
356+
# needs no help, and quietly moving somebody's temporary directory onto
357+
# a disk being installed is not a thing to do for no reason.
358+
bound_tmp=""
359+
case "$(findmnt -no FSTYPE --target /var/tmp)" in
360+
tmpfs|overlay|ramfs)
361+
mount --bind "$TMPDIR" /var/tmp
362+
bound_tmp=1
363+
;;
364+
esac
345365
podman --root "$store" --runroot /run/kuma-install --storage-driver overlay \
346366
--storage-opt additionalimagestore=/var/lib/containers/storage \
347367
build -q -t @TAG@ -f "$ctx/Containerfile" "$ctx" >/dev/null
@@ -620,6 +640,13 @@ mod tests {
620640
// doing the ostree import writes big files there by decision
621641
// rather than by environment.
622642
assert!(script.contains(r#"-v "$TMPDIR:/var/tmp""#));
643+
// And on the host, because bootc imports from the host mount
644+
// namespace and sees none of the above. Conditional, so a
645+
// machine with a real /var/tmp keeps it.
646+
assert!(script.contains(r#"mount --bind "$TMPDIR" /var/tmp"#));
647+
assert!(script.contains("tmpfs|overlay|ramfs"));
648+
let bind_at = script.find(r#"mount --bind "$TMPDIR""#).unwrap();
649+
assert!(bind_at < script.find("build -q").unwrap(), "bound before anything pulls");
623650
// bootc refuses a LABEL= for /boot however well formed, and says
624651
// so only once the disk has been formatted.
625652
assert!(script.contains(r#"--boot-mount-spec "UUID=$boot_uuid""#));

0 commit comments

Comments
 (0)