166 lines
4.9 KiB
Bash
Executable file
166 lines
4.9 KiB
Bash
Executable file
#!/bin/bash
|
|
# NAME: Script to transition from systemd-boot to Limine bootloader
|
|
# REQUIRES: sudo
|
|
|
|
set -euo pipefail
|
|
|
|
echo "do you confirm this transition?"
|
|
|
|
read -r -p "Are you sure? [y/N] " response
|
|
|
|
if [[ "$response" != "y" ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
print_status() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
|
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
|
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
print_error "This script must be run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v pacman &>/dev/null; then
|
|
print_error "This script is designed for Arch Linux / CachyOS systems"
|
|
exit 1
|
|
fi
|
|
|
|
print_status "Starting transition from systemd-boot to Limine..."
|
|
|
|
ESP_PATH=""
|
|
if command -v bootctl &>/dev/null; then
|
|
ESP_PATH=$(bootctl --print-esp-path 2>/dev/null || echo "")
|
|
fi
|
|
|
|
if [[ -z "$ESP_PATH" ]]; then
|
|
if [[ -d "/boot/EFI" ]]; then
|
|
ESP_PATH="/boot"
|
|
elif [[ -d "/efi/EFI" ]]; then
|
|
ESP_PATH="/efi"
|
|
else
|
|
print_error "Could not detect ESP path"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
print_success "ESP detected at: $ESP_PATH"
|
|
|
|
BACKUP_DIR="/root/bootloader-backup-$(date +%Y%m%d-%H%M%S)"
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
[[ -d "$ESP_PATH/loader" ]] && cp -r "$ESP_PATH/loader" "$BACKUP_DIR/" 2>/dev/null || true
|
|
[[ -d "$ESP_PATH/EFI/systemd" ]] && cp -r "$ESP_PATH/EFI/systemd" "$BACKUP_DIR/" 2>/dev/null || true
|
|
efibootmgr -v >"$BACKUP_DIR/efibootmgr-backup.txt" 2>/dev/null || true
|
|
|
|
print_success "Backup created at: $BACKUP_DIR"
|
|
|
|
CURRENT_CMDLINE=""
|
|
if [[ -f "/etc/kernel/cmdline" ]]; then
|
|
CURRENT_CMDLINE=$(cat /etc/kernel/cmdline)
|
|
print_status "Found existing /etc/kernel/cmdline: $CURRENT_CMDLINE"
|
|
else
|
|
CURRENT_CMDLINE=$(cat /proc/cmdline | sed 's/BOOT_IMAGE=[^ ]* //')
|
|
print_status "Using current /proc/cmdline: $CURRENT_CMDLINE"
|
|
fi
|
|
|
|
print_status "Installing Limine and related packages..."
|
|
pacman -S --needed --noconfirm limine limine-snapper-sync limine-mkinitcpio-hook
|
|
print_success "Limine packages installed"
|
|
|
|
print_status "Installing Limine bootloader to ESP..."
|
|
mkdir -p "$ESP_PATH/EFI/Limine"
|
|
|
|
if [[ -f "/usr/share/limine/limine_x64.efi" ]]; then
|
|
cp /usr/share/limine/limine_x64.efi "$ESP_PATH/EFI/Limine/"
|
|
elif [[ -f "/usr/share/limine/BOOTX64.EFI" ]]; then
|
|
cp /usr/share/limine/BOOTX64.EFI "$ESP_PATH/EFI/Limine/limine_x64.efi"
|
|
else
|
|
print_error "Could not find Limine EFI files"
|
|
exit 1
|
|
fi
|
|
|
|
print_success "Limine files installed to ESP"
|
|
|
|
print_status "Creating UEFI boot entry for Limine..."
|
|
ESP_DEVICE=$(df "$ESP_PATH" | tail -1 | awk '{print $1}')
|
|
ESP_DISK=$(echo "$ESP_DEVICE" | sed 's/[0-9]*$//')
|
|
ESP_PART_NUM=$(echo "$ESP_DEVICE" | sed 's/.*[^0-9]//')
|
|
|
|
efibootmgr -c -d "$ESP_DISK" -p "$ESP_PART_NUM" -L "Limine" -l "\\EFI\\Limine\\limine_x64.efi" || {
|
|
print_warning "Could not create UEFI boot entry automatically"
|
|
}
|
|
|
|
print_success "Limine UEFI boot entry created"
|
|
|
|
print_status "Configuring kernel command line..."
|
|
echo "$CURRENT_CMDLINE" >/etc/kernel/cmdline
|
|
print_success "Kernel command line configured: $CURRENT_CMDLINE"
|
|
|
|
print_status "Configuring Limine..."
|
|
[[ ! -f "/etc/default/limine" ]] && cat >/etc/default/limine <<EOF
|
|
SPACE_NUMBER=2
|
|
ENABLE_VERIFICATION=yes
|
|
BACKUP_THRESHOLD=8
|
|
BOOT_ORDER="*, *fallback, Snapshots"
|
|
ENABLE_SORT=no
|
|
ENABLE_LIMINE_FALLBACK=no
|
|
FIND_BOOTLOADERS=yes
|
|
EOF
|
|
|
|
print_status "Generating Limine configuration..."
|
|
limine-update
|
|
print_success "Limine configuration created"
|
|
|
|
print_status "Setting Limine as default boot option..."
|
|
LIMINE_ENTRY=$(efibootmgr | grep "Limine" | head -1 | cut -c5-8)
|
|
|
|
if [[ -n "$LIMINE_ENTRY" ]]; then
|
|
CURRENT_ORDER=$(efibootmgr | grep "BootOrder" | cut -d' ' -f2)
|
|
NEW_ORDER=$(echo "$CURRENT_ORDER" | sed "s/$LIMINE_ENTRY,//g" | sed "s/,$LIMINE_ENTRY//g" | sed "s/^$LIMINE_ENTRY$//g")
|
|
|
|
if [[ -n "$NEW_ORDER" ]]; then
|
|
efibootmgr -o "$LIMINE_ENTRY,$NEW_ORDER"
|
|
else
|
|
efibootmgr -o "$LIMINE_ENTRY"
|
|
fi
|
|
|
|
print_success "Limine set as default boot option"
|
|
else
|
|
print_warning "Could not find Limine boot entry to set as default"
|
|
fi
|
|
|
|
print_status "Keeping systemd-boot as fallback (recommended for first boot)"
|
|
|
|
if [[ -f "$ESP_PATH/limine.conf" ]] || [[ -f "$ESP_PATH/limine.cfg" ]]; then
|
|
print_success "Limine configuration file exists"
|
|
else
|
|
print_error "Limine configuration file missing!"
|
|
fi
|
|
|
|
if [[ -f "$ESP_PATH/EFI/Limine/limine_x64.efi" ]]; then
|
|
print_success "Limine EFI bootloader exists"
|
|
else
|
|
print_error "Limine EFI bootloader missing!"
|
|
fi
|
|
|
|
echo
|
|
print_success "TRANSITION COMPLETED SUCCESSFULLY!"
|
|
echo
|
|
print_status "Summary:"
|
|
echo " • Limine bootloader installed to: $ESP_PATH/EFI/Limine/"
|
|
echo " • Configuration file: $ESP_PATH/limine.conf"
|
|
echo " • Kernel command line: /etc/kernel/cmdline"
|
|
echo " • Backup created at: $BACKUP_DIR"
|
|
echo " • Boot order updated"
|
|
echo " • systemd-boot kept as fallback"
|
|
echo
|
|
print_warning "IMPORTANT: Reboot to test the new Limine setup!"
|
|
print_success "Script completed. Please reboot when ready."
|