fix(postinstall): improve error handling and user feedback
Add three critical improvements to post-install phase: 1. Cleanup trap for bind mounts: Ensure /dev, /proc, /sys, /run are unmounted even if chroot script fails. Prevents orphaned mounts blocking cleanup. 2. Fallocate fallback: Use dd as fallback if fallocate fails (can happen on some filesystems or with insufficient space). Includes intelligent size conversion and progress display. 3. Progress messages: Add informative echo statements before long-running operations (xbps-reconfigure, grub-install, grub-mkconfig) so users know the system is working. Decision: Use trap EXIT instead of manual cleanup to guarantee execution on both success and error paths. Remove redundant explicit cleanup call. Trade-offs: dd fallback is slower but ensures swap file creation succeeds. Progress messages add noise but significantly improve UX during multi-minute operations.
This commit is contained in:
parent
551cb98a9d
commit
98aebc5f09
@ -78,6 +78,7 @@ postinstall_run() {
|
||||
|
||||
log_info "Post-install: configuring target system in chroot"
|
||||
postinstall_bind_mounts
|
||||
trap postinstall_unbind_mounts EXIT
|
||||
|
||||
LUKS_UUID="$luks_uuid" ROOT_UUID="$root_uuid" FS_TYPE="$FS_TYPE" SWAP_SIZE="$SWAP_SIZE" HOSTNAME="$HOSTNAME" \
|
||||
chroot "$MOUNT_ROOT" /bin/bash -s <<'EOS'
|
||||
@ -117,7 +118,26 @@ if [[ "$SWAP_SIZE" != "0" ]]; then
|
||||
btrfs property set /swap compression none || true
|
||||
fi
|
||||
fi
|
||||
fallocate -l "$SWAP_SIZE" /swap/swapfile
|
||||
|
||||
# Try fallocate first, fall back to dd if it fails
|
||||
if ! fallocate -l "$SWAP_SIZE" /swap/swapfile 2>/dev/null; then
|
||||
echo "fallocate failed, using dd as fallback..."
|
||||
# Extract numeric size and unit for dd
|
||||
local size_num="${SWAP_SIZE%%[^0-9.]*}"
|
||||
local size_unit="${SWAP_SIZE##*[0-9]}"
|
||||
local bs="1M"
|
||||
local count="$size_num"
|
||||
|
||||
# Convert to MB count for dd
|
||||
case "$size_unit" in
|
||||
GiB|G|GB) count=$(awk "BEGIN {print int($size_num * 1024)}") ;;
|
||||
MiB|M|MB) count=$(awk "BEGIN {print int($size_num)}") ;;
|
||||
*) echo "Warning: unknown size unit, assuming MiB"; count="$size_num" ;;
|
||||
esac
|
||||
|
||||
dd if=/dev/zero of=/swap/swapfile bs="$bs" count="$count" status=progress
|
||||
fi
|
||||
|
||||
chmod 600 /swap/swapfile
|
||||
mkswap /swap/swapfile
|
||||
if ! grep -q '^/swap/swapfile' /etc/fstab; then
|
||||
@ -168,12 +188,15 @@ else
|
||||
fi
|
||||
|
||||
# Regenerate initramfs and GRUB configuration.
|
||||
echo "Regenerating initramfs for all kernels (this may take a while)..."
|
||||
xbps-reconfigure -fa
|
||||
|
||||
echo "Installing GRUB bootloader..."
|
||||
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Void --recheck
|
||||
|
||||
echo "Generating GRUB configuration..."
|
||||
grub-mkconfig -o /boot/grub/grub.cfg
|
||||
EOS
|
||||
|
||||
postinstall_unbind_mounts
|
||||
log_info "Post-install complete."
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user