Why unmount /var/log
?
I surmise the user was preparing to export (zpool export
) the ZFS pool after importing it in a rescue environment. The export fails unless all mounted datasets, like /var/log
, are unmounted first.
The error cannot unmount '/var/log': pool or dataset is busy
occurs because a process on the system is actively using /var/log
, preventing it from being unmounted. This is common on live systems where logs are constantly being written.
The solution was correct:
This allows one to manually control import and mount behavior, useful for recovery or manual intervention.
Here is a script to import a ZFS pool in a Devuan (or Debian-based) rescue environment, prevent automatic mounting, and allow safe export:
#!/bin/bash
# zfs-rescue-import.sh
set -euo pipefail
POOL="zroot"
MOUNTFILE="/etc/default/zfs"
ZPOOL_CACHE="/etc/zfs/zpool.cache"
check_zfs_version() {
echo "[*] Checking ZFS versions..."
USERLAND_VERSION=$(zfs version | awk '/zfs-/{print $2}' | head -n1)
KERNEL_VERSION=$(modinfo zfs | awk '/^version:/ {print $2}' | head -n1)
if [ -z "$USERLAND_VERSION" ] || [ -z "$KERNEL_VERSION" ]; then
echo "[!] Could not detect ZFS versions properly. Exiting."
exit 1
fi
echo "[*] Userland ZFS version: $USERLAND_VERSION"
echo "[*] Kernel ZFS module version: $KERNEL_VERSION"
if [ "$USERLAND_VERSION" != "$KERNEL_VERSION" ]; then
echo "[!] Mismatch detected between userland and kernel ZFS versions."
echo "[!] Userland: $USERLAND_VERSION | Kernel: $KERNEL_VERSION"
echo "[!] Aborting to avoid pool damage."
exit 2
fi
echo "[+] ZFS versions match."
}
echo "=== ZFS Rescue Import Script ==="
check_zfs_version
echo "[*] Importing pool: $POOL"
zpool import -f "$POOL"
echo "[*] Disabling automatic mount on boot"
if [ -f "$MOUNTFILE" ]; then
sed -i 's/^ZFS_MOUNT=.*/ZFS_MOUNT="no"/' "$MOUNTFILE"
else
echo 'ZFS_MOUNT="no"' > "$MOUNTFILE"
fi
echo "[*] Removing cached pool import settings"
rm -f "$ZPOOL_CACHE"
echo "[*] Unmounting all mounted datasets under $POOL"
zfs unmount -a || true
echo "[*] Forcibly unmounting known busy paths (if needed)"
umount -lf /var/log || true
umount -lf /var/audit || true
umount -lf /var/crash || true
umount -lf /home || true
umount -lf /tmp || true
echo "[*] Attempting pool export"
zpool export "$POOL" && echo "[+] Pool exported successfully" || echo "[!] Export failed. Pool may still be busy."
echo "[*] Done."
Added ZFS consistency check to avoid pool damage as well.