From 9bb626327fd8f50d5f8c350d11f11baf4a27f5e1 Mon Sep 17 00:00:00 2001 From: beatzaplenty Date: Wed, 22 Jul 2026 04:07:32 +0000 Subject: [PATCH] Unmount nixos-install's leftover chroot bind mounts before zpool export nixos-install bind-mounts /dev, /proc, /sys (and usually /run) into /mnt to run the target's activation script in a chroot, and doesn't unmount them again afterward. Left in place, those nested mounts made ZFS refuse to unmount its own root dataset at /mnt: zpool export failed with "cannot unmount '/mnt': pool or dataset busy", and because of this script's set -e, that killed the script before it ever reached reboot -- silently defeating the export-before-reboot fix from #40 on every real run, which is why the ZFS-import stall kept recurring. --- scripts/installer/auto-install.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/installer/auto-install.sh b/scripts/installer/auto-install.sh index 9b7d273..93001f4 100755 --- a/scripts/installer/auto-install.sh +++ b/scripts/installer/auto-install.sh @@ -179,6 +179,21 @@ nixos-install \ # makes boot stall waiting on the ZFS import. Exporting here (a no-op # if the chosen host has no ZFS root, e.g. proxmox-*/linode-*) clears # that in-use state so the next import, from any hostid, succeeds. + # + # nixos-install bind-mounts /dev, /proc, /sys (and usually /run) into + # /mnt to run the target's activation script (switch-to-configuration + # boot) in a chroot, and doesn't unmount them again once it's done. + # Left in place, those nested mounts make ZFS refuse to unmount its own + # root dataset at /mnt -- confirmed live: zpool export failed with + # "cannot unmount '/mnt': pool or dataset busy", and because of this + # script's `set -e`, that killed the script before it ever reached + # reboot, silently defeating the whole point of exporting first. + for chroot_mount in dev proc sys run; do + if mountpoint -q "/mnt/${chroot_mount}"; then + umount -R "/mnt/${chroot_mount}" + fi + done + if [[ -n "$(zpool list -H -o name 2>/dev/null)" ]]; then echo "Exporting ZFS pool(s) before reboot..." zpool export -a