diff --git a/builder/build-iso.sh b/builder/build-iso.sh index 1279a55..3680a8c 100755 --- a/builder/build-iso.sh +++ b/builder/build-iso.sh @@ -73,7 +73,7 @@ mkdir -p "$build_cache_dir/airootfs/opt/packages/" cp "/tmp/$NODE_FILENAME" "$build_cache_dir/airootfs/opt/packages/" # Add our additional packages to packages.x86_64 -arch_packages=(linux-t2 git gum jq openssl plymouth tzupdate omarchy-keyring) +arch_packages=(linux-t2 git gum jq openssl plymouth tzupdate omarchy-keyring lvm2 cryptsetup parted) printf '%s\n' "${arch_packages[@]}" >>"$build_cache_dir/packages.x86_64" # Build list of all the packages needed for the offline mirror diff --git a/configs/airootfs/root/.automated_script.sh b/configs/airootfs/root/.automated_script.sh index 6e396bd..7566803 100644 --- a/configs/airootfs/root/.automated_script.sh +++ b/configs/airootfs/root/.automated_script.sh @@ -70,6 +70,61 @@ set_tokyo_night_colors() { fi } +install_disk() { + jq -er 'first(.disk_config.device_modifications[]? | select(.wipe == true) | .device)' user_configuration.json +} + +cleanup_install_disk() { + local disk="$1" + + if [[ -z "$disk" || ! -b "$disk" ]]; then + echo "Could not determine install disk for cleanup" >&2 + return 1 + fi + + echo "Cleaning up existing holders on install disk: $disk" + + # Ensure that no mounts exist from past install attempts. + findmnt -R /mnt >/dev/null && umount -R /mnt || true + + # Turn off swap and unmount anything backed by the selected disk, including + # device-mapper children from a previous install. Active LVM/swap holders can + # prevent the kernel from re-reading the partition table after archinstall + # wipes and recreates it. + while read -r dev; do + [[ -b "$dev" ]] || continue + + swapoff "$dev" 2>/dev/null || true + + while read -r target; do + [[ -n "$target" ]] || continue + umount "$target" 2>/dev/null || true + done < <(findmnt -rn -S "$dev" -o TARGET 2>/dev/null || true) + done < <(lsblk -rnpo PATH "$disk") + + # Deactivate any LVM volume groups whose physical volumes live on the selected + # disk. This is the common case when replacing Fedora/Alma/RHEL installs. + while read -r dev type; do + [[ "$type" == "disk" || "$type" == "part" || "$type" == "crypt" ]] || continue + + while read -r vg; do + [[ -n "$vg" ]] || continue + vgchange -an "$vg" 2>/dev/null || true + done < <(pvs --noheadings -o vg_name "$dev" 2>/dev/null | awk '{$1=$1; print}' | sort -u) + done < <(lsblk -rnpo PATH,TYPE "$disk") + + # Close any LUKS mappings stacked on the selected disk after filesystems and + # swap have been released. + while read -r dev type; do + [[ "$type" == "crypt" ]] || continue + cryptsetup close "$dev" 2>/dev/null || true + done < <(lsblk -rnpo PATH,TYPE "$disk") + + blockdev --flushbufs "$disk" 2>/dev/null || true + partprobe "$disk" 2>/dev/null || true + udevadm settle || true +} + install_base_system() { # Initialize and populate the keyring pacman-key --init @@ -79,8 +134,7 @@ install_base_system() { # Sync the offline database so pacman can find packages pacman -Sy --noconfirm - # Ensure that no mounts exist from past install attempts - findmnt -R /mnt >/dev/null && umount -R /mnt + cleanup_install_disk "$(install_disk)" # Workarounds for archinstall 4.2 regressions under Python 3.14: # 1. sync_log_to_install_medium: `self.target / absolute_logfile` drops