211 lines
6.4 KiB
Bash
Executable file
211 lines
6.4 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
|
|
ROOT_SNAPSHOTS_PATH="/@snapshots"
|
|
EOF
|
|
|
|
print_status "Creating custom Limine configuration..."
|
|
cat >"$ESP_PATH/limine.conf" <<'EOF'
|
|
### Read more at config document: https://github.com/limine-bootloader/limine/blob/trunk/CONFIG.md
|
|
timeout: 1
|
|
### Note: For "default_entry" to select a sub-entry within an OS menu, modify "/OS name" to "/+OS name" to keep its submenus visible.
|
|
default_entry: 2
|
|
#interface_branding_color: 3
|
|
interface_branding:
|
|
hash_mismatch_panic: no
|
|
term_palette: 1e1e2e;f38ba8;a6e3a1;f9e2af;89b4fa;f5c2e7;94e2d5;cdd6f4
|
|
term_palette_bright: 585b70;f38ba8;a6e3a1;f9e2af;89b4fa;f5c2e7;94e2d5;cdd6f4
|
|
term_background: 1e1e2e
|
|
term_foreground: cdd6f4
|
|
term_background_bright: 585b70
|
|
term_foreground_bright: cdd6f4
|
|
|
|
EOF
|
|
|
|
print_status "Generating Limine boot entries..."
|
|
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 "Removing systemd-boot components..."
|
|
|
|
# Remove systemd-boot UEFI entries
|
|
SYSTEMD_ENTRIES=$(efibootmgr | grep -i "Linux Boot Manager\|systemd" | cut -c5-8 || true)
|
|
if [[ -n "$SYSTEMD_ENTRIES" ]]; then
|
|
for entry in $SYSTEMD_ENTRIES; do
|
|
print_status "Removing UEFI boot entry: Boot$entry"
|
|
efibootmgr -b "$entry" -B || print_warning "Failed to remove boot entry $entry"
|
|
done
|
|
fi
|
|
|
|
# Remove systemd-boot files from ESP
|
|
if [[ -d "$ESP_PATH/EFI/systemd" ]]; then
|
|
print_status "Removing systemd-boot EFI files..."
|
|
rm -rf "$ESP_PATH/EFI/systemd"
|
|
print_success "systemd-boot EFI files removed"
|
|
fi
|
|
|
|
if [[ -d "$ESP_PATH/loader" ]]; then
|
|
print_status "Removing systemd-boot configuration..."
|
|
rm -rf "$ESP_PATH/loader"
|
|
print_success "systemd-boot configuration removed"
|
|
fi
|
|
|
|
if [[ -f "$ESP_PATH/limine.conf" ]]; 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
|
|
|
|
sudo pacman -S snap-pac
|
|
sudo systemctl enable --now limine-snapper-sync.service
|
|
|
|
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 completely removed"
|
|
echo
|
|
print_warning "IMPORTANT: Reboot to test the new Limine setup!"
|
|
print_warning "systemd-boot has been completely removed - ensure Limine works before removing backup!"
|
|
print_success "Script completed. Please reboot when ready."
|