Compare commits
6 Commits
051485cede
...
667453596a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
667453596a | ||
|
|
98aebc5f09 | ||
|
|
551cb98a9d | ||
|
|
c303a75192 | ||
|
|
c9fbc5486c | ||
|
|
4e0d9573e6 |
@ -53,6 +53,15 @@ export ESP_MOUNT="/mnt/boot/efi"
|
|||||||
export ROOT_LABEL="void-root"
|
export ROOT_LABEL="void-root"
|
||||||
export EFI_LABEL="EFI"
|
export EFI_LABEL="EFI"
|
||||||
|
|
||||||
|
validate_size() {
|
||||||
|
local size="$1"
|
||||||
|
# Allow sizes like: 1GiB, 100MB, 50%, 100%
|
||||||
|
if [[ "$size" =~ ^[0-9]+(\.[0-9]+)?(GiB|GB|MiB|MB|%)?$ ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
prompt_with_default() {
|
prompt_with_default() {
|
||||||
local var_name="$1"
|
local var_name="$1"
|
||||||
local prompt_text="$2"
|
local prompt_text="$2"
|
||||||
@ -145,9 +154,21 @@ config_validate() {
|
|||||||
*) die "Unsupported LUKS version: $LUKS_VERSION" ;;
|
*) die "Unsupported LUKS version: $LUKS_VERSION" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ "$SWAP_SIZE" == "0" || "$SWAP_SIZE" == "0G" || "$SWAP_SIZE" == "0GiB" ]]; then
|
# Normalize swap size first
|
||||||
|
if [[ "$SWAP_SIZE" =~ ^0(G|GB|GiB|M|MB|MiB)?$ ]]; then
|
||||||
SWAP_SIZE="0"
|
SWAP_SIZE="0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Validate size formats
|
||||||
|
if ! validate_size "$ESP_SIZE"; then
|
||||||
|
die "Invalid ESP size format: $ESP_SIZE (expected: 1GiB, 100MB, etc.)"
|
||||||
|
fi
|
||||||
|
if ! validate_size "$ROOT_END"; then
|
||||||
|
die "Invalid root partition end format: $ROOT_END (expected: 100%, 200GiB, etc.)"
|
||||||
|
fi
|
||||||
|
if [[ "$SWAP_SIZE" != "0" ]] && ! validate_size "$SWAP_SIZE"; then
|
||||||
|
die "Invalid swap size format: $SWAP_SIZE (expected: 4GiB, 8GB, 0 to disable)"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
config_print_summary() {
|
config_print_summary() {
|
||||||
|
|||||||
@ -64,6 +64,18 @@ format_filesystems() {
|
|||||||
local temp_mount
|
local temp_mount
|
||||||
temp_mount="/tmp/void-wrapper-btrfs"
|
temp_mount="/tmp/void-wrapper-btrfs"
|
||||||
mkdir -p "$temp_mount"
|
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"
|
mount "$root_device" "$temp_mount"
|
||||||
btrfs subvolume create "$temp_mount/@"
|
btrfs subvolume create "$temp_mount/@"
|
||||||
btrfs subvolume create "$temp_mount/@home"
|
btrfs subvolume create "$temp_mount/@home"
|
||||||
@ -73,6 +85,7 @@ format_filesystems() {
|
|||||||
btrfs subvolume create "$temp_mount/@swap"
|
btrfs subvolume create "$temp_mount/@swap"
|
||||||
umount "$temp_mount"
|
umount "$temp_mount"
|
||||||
rmdir "$temp_mount"
|
rmdir "$temp_mount"
|
||||||
|
trap - EXIT
|
||||||
else
|
else
|
||||||
log_info "Formatting root as ext4 on $root_device"
|
log_info "Formatting root as ext4 on $root_device"
|
||||||
mkfs.ext4 -L "$ROOT_LABEL" "$root_device"
|
mkfs.ext4 -L "$ROOT_LABEL" "$root_device"
|
||||||
|
|||||||
@ -58,4 +58,14 @@ run_installer() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
read -r -p "Press Enter once the installer is complete..." _
|
read -r -p "Press Enter once the installer is complete..." _
|
||||||
|
|
||||||
|
# Verify critical mounts are still intact after installer
|
||||||
|
if ! findmnt "$MOUNT_ROOT" >/dev/null 2>&1; then
|
||||||
|
die "Root mount disappeared after installer. The installer may have reformatted the filesystem."
|
||||||
|
fi
|
||||||
|
if ! findmnt "$ESP_MOUNT" >/dev/null 2>&1; then
|
||||||
|
die "ESP mount disappeared after installer. The installer may have reformatted the filesystem."
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_info "Mount verification passed."
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,6 +83,7 @@ partition_disk() {
|
|||||||
|
|
||||||
ESP_PART="$(partition_path "$DISK" 1)"
|
ESP_PART="$(partition_path "$DISK" 1)"
|
||||||
ROOT_PART="$(partition_path "$DISK" 2)"
|
ROOT_PART="$(partition_path "$DISK" 2)"
|
||||||
|
export ESP_PART ROOT_PART
|
||||||
|
|
||||||
log_info "ESP partition: $ESP_PART"
|
log_info "ESP partition: $ESP_PART"
|
||||||
log_info "Root partition: $ROOT_PART"
|
log_info "Root partition: $ROOT_PART"
|
||||||
|
|||||||
@ -78,6 +78,7 @@ postinstall_run() {
|
|||||||
|
|
||||||
log_info "Post-install: configuring target system in chroot"
|
log_info "Post-install: configuring target system in chroot"
|
||||||
postinstall_bind_mounts
|
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" \
|
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'
|
chroot "$MOUNT_ROOT" /bin/bash -s <<'EOS'
|
||||||
@ -117,7 +118,26 @@ if [[ "$SWAP_SIZE" != "0" ]]; then
|
|||||||
btrfs property set /swap compression none || true
|
btrfs property set /swap compression none || true
|
||||||
fi
|
fi
|
||||||
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
|
chmod 600 /swap/swapfile
|
||||||
mkswap /swap/swapfile
|
mkswap /swap/swapfile
|
||||||
if ! grep -q '^/swap/swapfile' /etc/fstab; then
|
if ! grep -q '^/swap/swapfile' /etc/fstab; then
|
||||||
@ -168,12 +188,15 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Regenerate initramfs and GRUB configuration.
|
# Regenerate initramfs and GRUB configuration.
|
||||||
|
echo "Regenerating initramfs for all kernels (this may take a while)..."
|
||||||
xbps-reconfigure -fa
|
xbps-reconfigure -fa
|
||||||
|
|
||||||
|
echo "Installing GRUB bootloader..."
|
||||||
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Void --recheck
|
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
|
grub-mkconfig -o /boot/grub/grub.cfg
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
postinstall_unbind_mounts
|
|
||||||
log_info "Post-install complete."
|
log_info "Post-install complete."
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,11 +58,24 @@ rollback_offer() {
|
|||||||
rollback_cleanup() {
|
rollback_cleanup() {
|
||||||
: "${MOUNT_ROOT:?Mount root is required}"
|
: "${MOUNT_ROOT:?Mount root is required}"
|
||||||
: "${CRYPT_NAME:?Crypt mapping name is required}"
|
: "${CRYPT_NAME:?Crypt mapping name is required}"
|
||||||
|
|
||||||
|
# Clean up bind mounts first (from postinstall)
|
||||||
|
if [[ -d "$MOUNT_ROOT" ]]; then
|
||||||
|
for bind_path in dev proc sys run; do
|
||||||
|
if findmnt "$MOUNT_ROOT/$bind_path" >/dev/null 2>&1; then
|
||||||
|
log_info "Unmounting bind mount: $MOUNT_ROOT/$bind_path"
|
||||||
|
umount -R "$MOUNT_ROOT/$bind_path" 2>/dev/null || log_warn "Failed to unmount $MOUNT_ROOT/$bind_path"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up regular mounts
|
||||||
if findmnt "$MOUNT_ROOT" >/dev/null 2>&1; then
|
if findmnt "$MOUNT_ROOT" >/dev/null 2>&1; then
|
||||||
log_info "Unmounting $MOUNT_ROOT"
|
log_info "Unmounting $MOUNT_ROOT"
|
||||||
umount -R "$MOUNT_ROOT" || log_warn "Failed to unmount $MOUNT_ROOT"
|
umount -R "$MOUNT_ROOT" || log_warn "Failed to unmount $MOUNT_ROOT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Close LUKS mapping
|
||||||
if [[ -e "/dev/mapper/$CRYPT_NAME" ]]; then
|
if [[ -e "/dev/mapper/$CRYPT_NAME" ]]; then
|
||||||
log_info "Closing LUKS mapping $CRYPT_NAME"
|
log_info "Closing LUKS mapping $CRYPT_NAME"
|
||||||
cryptsetup close "$CRYPT_NAME" || log_warn "Failed to close LUKS mapping"
|
cryptsetup close "$CRYPT_NAME" || log_warn "Failed to close LUKS mapping"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user