- Removed 40+ broken/messy scripts, moved to old_scripts/ - Created lvm_block_backup.sh - proper block-level LVM snapshot backup - Uses dd for block-level cloning instead of file-level rsync - Successfully tested: 462GB backup in 33 minutes - Creates exact, bootable clone of internal drive to external drive - Proper LVM snapshot management with cleanup - Clear documentation in README_BACKUP.md - Clean, minimal solution that actually works
112 lines
4.9 KiB
Bash
Executable File
112 lines
4.9 KiB
Bash
Executable File
#!/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
|
|
#
|
|
# <name> <device> <password> <options>
|
|
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" |