More fixes to install to disk

This commit is contained in:
Storm Dragon
2025-10-11 15:34:34 -04:00
parent 3c274ea4fe
commit b75afdbb10

View File

@@ -19,9 +19,23 @@ log_error() {
echo "[ERROR] $*" | tee -a "$LOGFILE" >&2
}
cleanup_mounts() {
# Clean up any leftover mounts
local mount_point="${1:-/mnt/stormux_target}"
if [[ -d "$mount_point" ]]; then
sudo umount "$mount_point/boot" 2>/dev/null || true
sudo umount "$mount_point/proc" 2>/dev/null || true
sudo umount "$mount_point/sys" 2>/dev/null || true
sudo umount "$mount_point/dev" 2>/dev/null || true
sudo umount "$mount_point" 2>/dev/null || true
sudo rmdir "$mount_point" 2>/dev/null || true
fi
}
error_exit() {
log_error "$1"
echo "Installation failed. Log file: $LOGFILE"
cleanup_mounts
restore_speech
echo
read -rp "Press enter to continue..."
@@ -102,6 +116,8 @@ detect_partitions() {
part=$(echo "$line" | awk '{print $1}')
# Remove lsblk tree characters that break mount commands
part="${part//[├─└│]/}"
# Add /dev/ prefix if not present
[[ "$part" != /dev/* ]] && part="/dev/$part"
fstype=$(echo "$line" | awk '{print $2}')
label=$(echo "$line" | awk '{print $3}')
@@ -440,7 +456,8 @@ log "Syncing data to disk..."
sudo sync
log "Refreshing partition table..."
sudo partprobe "$TARGET_DEVICE" 2>&1 | tee -a "$LOGFILE" || log "Warning: partprobe reported issues"
# Use -s flag for script mode, pipe 'Fix' response for GPT expansion
echo "Fix" | sudo partprobe -s "$TARGET_DEVICE" 2>&1 | tee -a "$LOGFILE" || log "Warning: partprobe reported issues"
sudo udevadm settle --timeout=10 || log "Warning: udevadm settle timeout"
sleep 2
@@ -461,6 +478,17 @@ log " BIOS: ${target_partitions[bios]:-none}"
log " EFI: ${target_partitions[efi]:-none}"
log " Root: ${target_partitions[root]}"
# Regenerate UUIDs and labels BEFORE mounting
log "Regenerating partition identifiers..."
mapfile -t uuid_mappings < <(regenerate_partition_identifiers "$TARGET_DEVICE" target_partitions)
log "Generated ${#uuid_mappings[@]} UUID mappings"
# Trigger udev to update with new UUIDs
log "Updating system device database..."
sudo udevadm trigger --subsystem-match=block
sudo udevadm settle --timeout=10 || log "Warning: udevadm settle timeout"
sleep 1
# Mount root partition
TEMP_MOUNT="/mnt/stormux_target"
sudo mkdir -p "$TEMP_MOUNT"
@@ -472,11 +500,6 @@ fi
log "Root partition mounted successfully"
# Regenerate UUIDs and labels
log "Regenerating partition identifiers..."
mapfile -t uuid_mappings < <(regenerate_partition_identifiers "$TARGET_DEVICE" target_partitions)
log "Generated ${#uuid_mappings[@]} UUID mappings"
# Update fstab with new UUIDs
if ! update_fstab "$TEMP_MOUNT" "${uuid_mappings[@]}"; then
error_exit "Failed to update fstab"
@@ -501,16 +524,9 @@ if ! validate_installation "$TEMP_MOUNT"; then
error_exit "Installation validation failed"
fi
# Unmount EFI partition if mounted
if [[ -n "${target_partitions[efi]:-}" ]] && mountpoint -q "$TEMP_MOUNT/boot"; then
log "Unmounting EFI partition..."
sudo umount "$TEMP_MOUNT/boot"
fi
# Unmount root partition
log "Unmounting root partition..."
sudo umount "$TEMP_MOUNT"
sudo rmdir "$TEMP_MOUNT"
# Clean up all mounts
log "Unmounting filesystems..."
cleanup_mounts "$TEMP_MOUNT"
# Restore speech
restore_speech