#!/bin/bash # LVM Boot Diagnostics Script # Checks the current state of the LVM migration and identifies boot issues # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color log() { echo -e "${BLUE}[$(date '+%H:%M:%S')]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; } success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; } warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; } echo -e "${GREEN}=== LVM Boot Diagnostics ===${NC}" echo # Check system state log "Checking current system state..." echo "Currently booted from: $(df / | tail -1 | awk '{print $1}')" echo "Running kernel: $(uname -r)" echo "System: $(hostname)" echo # Check available drives log "Available block devices:" lsblk -f echo # Check LVM status log "LVM Status:" echo "Physical Volumes:" sudo pvs 2>/dev/null || echo "No PVs found" echo "Volume Groups:" sudo vgs 2>/dev/null || echo "No VGs found" echo "Logical Volumes:" sudo lvs 2>/dev/null || echo "No LVs found" echo # Check for system-vg specifically if sudo vgs system-vg >/dev/null 2>&1; then success "Found system-vg volume group" log "system-vg details:" sudo vgs system-vg sudo lvs system-vg # Try to mount and check contents log "Checking external system contents..." if [ ! -d /tmp/check-external ]; then mkdir -p /tmp/check-external if sudo mount /dev/system-vg/root /tmp/check-external >/dev/null 2>&1; then success "External root filesystem is mountable" # Check key system directories for dir in "/etc" "/boot" "/usr" "/var"; do if [ -d "/tmp/check-external$dir" ]; then success "Found system directory: $dir" else warning "Missing system directory: $dir" fi done # Check for GRUB files if [ -d "/tmp/check-external/boot/grub" ]; then success "GRUB directory found" if [ -f "/tmp/check-external/boot/grub/grub.cfg" ]; then success "GRUB configuration found" else warning "GRUB configuration missing" fi else warning "GRUB directory missing" fi # Check fstab if [ -f "/tmp/check-external/etc/fstab" ]; then success "fstab found" log "fstab LVM entries:" grep -E "system-vg|UUID=" "/tmp/check-external/etc/fstab" || echo "No LVM entries found" else warning "fstab missing" fi sudo umount /tmp/check-external else error "Cannot mount external root filesystem" fi fi else error "system-vg volume group not found" echo "This suggests the LVM migration did not complete successfully" fi echo # Check EFI partition log "Checking for EFI boot partition..." if [ -b /dev/sda1 ]; then success "Found EFI partition /dev/sda1" if [ ! -d /tmp/check-efi ]; then mkdir -p /tmp/check-efi if sudo mount /dev/sda1 /tmp/check-efi >/dev/null 2>&1; then success "EFI partition is mountable" if [ -d "/tmp/check-efi/EFI" ]; then success "EFI directory found" log "EFI boot entries:" ls -la "/tmp/check-efi/EFI/" 2>/dev/null || echo "No EFI entries" if [ -f "/tmp/check-efi/EFI/debian/grubx64.efi" ]; then success "Debian GRUB EFI bootloader found" else warning "Debian GRUB EFI bootloader missing" fi else warning "EFI directory missing" fi sudo umount /tmp/check-efi else error "Cannot mount EFI partition" fi fi else error "EFI partition /dev/sda1 not found" fi echo # Provide diagnosis and recommendations log "=== DIAGNOSIS ===" if sudo vgs system-vg >/dev/null 2>&1; then success "LVM migration appears to have completed" if [ -b /dev/sda1 ] && sudo mount /dev/sda1 /tmp/check-efi >/dev/null 2>&1; then if [ -f "/tmp/check-efi/EFI/debian/grubx64.efi" ]; then success "GRUB bootloader appears to be installed" echo echo -e "${BLUE}Likely causes of boot reset issue:${NC}" echo "1. GRUB configuration points to wrong device" echo "2. initramfs missing LVM support" echo "3. BIOS/UEFI boot order incorrect" echo "4. Secure Boot enabled (conflicts with GRUB)" echo echo -e "${GREEN}Recommended action:${NC}" echo "Run: sudo ./fix_grub_boot.sh" else warning "GRUB bootloader missing" echo -e "${GREEN}Recommended action:${NC}" echo "Run: sudo ./fix_grub_boot.sh" fi sudo umount /tmp/check-efi 2>/dev/null || true else error "EFI partition issues detected" echo -e "${GREEN}Recommended action:${NC}" echo "Run: sudo ./fix_grub_boot.sh" fi else error "LVM migration incomplete or failed" echo -e "${GREEN}Recommended action:${NC}" echo "Re-run migration: sudo ./migrate_to_lvm.sh" fi # Cleanup rm -rf /tmp/check-external /tmp/check-efi 2>/dev/null || true