diff --git a/src/filesystems.sh b/src/filesystems.sh index e280df9..63d05a0 100644 --- a/src/filesystems.sh +++ b/src/filesystems.sh @@ -64,6 +64,18 @@ format_filesystems() { local temp_mount temp_mount="/tmp/void-wrapper-btrfs" mkdir -p "$temp_mount" + + # Ensure cleanup on error + cleanup_temp_mount() { + if mountpoint -q "$temp_mount" 2>/dev/null; then + umount "$temp_mount" || log_warn "Failed to unmount temp mount: $temp_mount" + fi + if [[ -d "$temp_mount" ]]; then + rmdir "$temp_mount" 2>/dev/null || true + fi + } + trap cleanup_temp_mount EXIT + mount "$root_device" "$temp_mount" btrfs subvolume create "$temp_mount/@" btrfs subvolume create "$temp_mount/@home" @@ -73,6 +85,7 @@ format_filesystems() { btrfs subvolume create "$temp_mount/@swap" umount "$temp_mount" rmdir "$temp_mount" + trap - EXIT else log_info "Formatting root as ext4 on $root_device" mkfs.ext4 -L "$ROOT_LABEL" "$root_device"