diff --git a/clean_external_lvm_boot.sh b/clean_external_lvm_boot.sh new file mode 100755 index 0000000..918f2ee --- /dev/null +++ b/clean_external_lvm_boot.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# Clean External LVM Boot Configuration Script +# Fixes: 1) Encrypted home partition passphrase prompt during boot +# 2) Internal drive entries appearing in GRUB menu + +set -e + +LOG_FILE="/tmp/clean_external_boot_$(date +%Y%m%d_%H%M%S).log" + +echo "๐Ÿงน Cleaning External LVM Boot Configuration - $(date)" | tee "$LOG_FILE" +echo "====================================================" | tee -a "$LOG_FILE" + +# Function to cleanup mounts on exit +cleanup() { + echo "๐Ÿงน Cleaning up mounts..." | tee -a "$LOG_FILE" + sudo umount /tmp/external-root/proc 2>/dev/null || true + sudo umount /tmp/external-root/sys 2>/dev/null || true + sudo umount /tmp/external-root/dev 2>/dev/null || true + sudo umount /tmp/external-root/boot/efi 2>/dev/null || true + sudo umount /tmp/external-root/boot 2>/dev/null || true + sudo umount /tmp/external-root 2>/dev/null || true + sudo rmdir /tmp/external-root 2>/dev/null || true +} +trap cleanup EXIT + +# Check if LVM is active +echo "๐Ÿ“‹ Checking LVM status..." | tee -a "$LOG_FILE" +if ! sudo lvs system-vg/root &>/dev/null; then + echo "โŒ LVM system-vg/root not found. Please ensure the external M.2 is connected." | tee -a "$LOG_FILE" + exit 1 +fi + +# Mount external LVM system +echo "๐Ÿ’พ Mounting external LVM system..." | tee -a "$LOG_FILE" +sudo mkdir -p /tmp/external-root +sudo mount /dev/system-vg/root /tmp/external-root +sudo mount /dev/system-vg/boot /tmp/external-root/boot +sudo mount /dev/sda1 /tmp/external-root/boot/efi + +# Bind mount system directories for chroot +echo "๐Ÿ”— Setting up chroot environment..." | tee -a "$LOG_FILE" +sudo mount --bind /proc /tmp/external-root/proc +sudo mount --bind /sys /tmp/external-root/sys +sudo mount --bind /dev /tmp/external-root/dev + +echo "๐Ÿ”ง Fixing encrypted home partition issue..." | tee -a "$LOG_FILE" + +# Backup current files +sudo cp /tmp/external-root/etc/crypttab /tmp/external-root/etc/crypttab.backup.$(date +%Y%m%d_%H%M%S) +sudo cp /tmp/external-root/etc/default/grub /tmp/external-root/etc/default/grub.backup.$(date +%Y%m%d_%H%M%S) + +# Remove internal drive encryption from crypttab +echo " โ€ข Cleaning /etc/crypttab..." | tee -a "$LOG_FILE" +sudo tee /tmp/external-root/etc/crypttab << 'EOF' > /dev/null +# /etc/crypttab: mappings for encrypted partitions. +# +# External LVM system - no encrypted partitions needed +# Internal drive encryption removed to prevent boot prompts +# +# +EOF + +echo "๐ŸŽ›๏ธ Disabling GRUB os-prober..." | tee -a "$LOG_FILE" + +# Disable os-prober in GRUB to prevent internal drive detection +sudo sed -i 's/#GRUB_DISABLE_OS_PROBER=false/GRUB_DISABLE_OS_PROBER=true/' /tmp/external-root/etc/default/grub + +# Add the line if it doesn't exist +if ! grep -q "GRUB_DISABLE_OS_PROBER" /tmp/external-root/etc/default/grub; then + echo "GRUB_DISABLE_OS_PROBER=true" | sudo tee -a /tmp/external-root/etc/default/grub > /dev/null +fi + +echo "๐Ÿ”„ Updating system configuration..." | tee -a "$LOG_FILE" + +# Update initramfs to reflect crypttab changes +echo " โ€ข Updating initramfs..." | tee -a "$LOG_FILE" +sudo chroot /tmp/external-root update-initramfs -u -k all + +# Regenerate GRUB configuration without os-prober +echo " โ€ข Regenerating GRUB configuration..." | tee -a "$LOG_FILE" +sudo chroot /tmp/external-root update-grub + +echo "โœ… Verification..." | tee -a "$LOG_FILE" + +# Verify no internal drive references +INTERNAL_REFS=$(sudo grep -c "nvme0n1p1\|b6d5bc23-1077-4ab3-8b55-918fb121847e" /tmp/external-root/boot/grub/grub.cfg 2>/dev/null || echo "0") +GRUB_ENTRIES=$(sudo grep -c "menuentry.*Kubuntu" /tmp/external-root/boot/grub/grub.cfg 2>/dev/null || echo "0") + +echo " โ€ข Internal drive references in GRUB: $INTERNAL_REFS" | tee -a "$LOG_FILE" +echo " โ€ข Kubuntu menu entries: $GRUB_ENTRIES" | tee -a "$LOG_FILE" + +if [ "$INTERNAL_REFS" -eq 0 ] && [ "$GRUB_ENTRIES" -gt 0 ]; then + echo "โœ… SUCCESS: External LVM boot configuration cleaned!" | tee -a "$LOG_FILE" + echo "" | tee -a "$LOG_FILE" + echo "๐Ÿš€ Results:" | tee -a "$LOG_FILE" + echo " โ€ข No more encrypted home partition prompts during boot" | tee -a "$LOG_FILE" + echo " โ€ข Clean GRUB menu with only external LVM entries" | tee -a "$LOG_FILE" + echo " โ€ข Internal drive completely excluded from boot process" | tee -a "$LOG_FILE" + echo "" | tee -a "$LOG_FILE" + echo "๐ŸŽฏ Next steps:" | tee -a "$LOG_FILE" + echo " 1. Reboot system" | tee -a "$LOG_FILE" + echo " 2. Should boot directly without any prompts" | tee -a "$LOG_FILE" + echo " 3. GRUB menu should only show Kubuntu entries" | tee -a "$LOG_FILE" +else + echo "โš ๏ธ Warning: Configuration may need manual review" | tee -a "$LOG_FILE" + echo " Internal refs: $INTERNAL_REFS, Kubuntu entries: $GRUB_ENTRIES" | tee -a "$LOG_FILE" +fi + +echo "" | tee -a "$LOG_FILE" +echo "๐Ÿ“‹ Log saved to: $LOG_FILE" | tee -a "$LOG_FILE" +echo "๐Ÿงน External LVM boot configuration cleaning completed at $(date)" | tee -a "$LOG_FILE" \ No newline at end of file