#!/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 <