From bf82c46fbaa725f9d40116eb8df9c4e322aef2c6 Mon Sep 17 00:00:00 2001 From: Valeria Fadeeva Date: Thu, 9 Oct 2025 12:45:58 +0500 Subject: [PATCH] Update --- .../boot/menu-template-efi-first.txt | 35 ++++++++ .../menu-template-fallback-only-efi-first.txt | 25 ++++++ .../boot/menu-template-fallback-only-efi.txt | 13 +++ ...u-template-fallback-only-vmlinuz-first.txt | 29 +++++++ .../menu-template-fallback-only-vmlinuz.txt | 17 ++++ .../boot/menu-template-vmlinuz-first.txt | 41 +++++++++ .../boot/menu-template.txt | 35 ++++++++ .../{ => efi}/menu-template-efi-first.txt | 0 .../menu-template-fallback-only-efi-first.txt | 0 .../menu-template-fallback-only-efi.txt | 0 ...u-template-fallback-only-vmlinuz-first.txt | 0 .../menu-template-fallback-only-vmlinuz.txt | 0 .../{ => efi}/menu-template-vmlinuz-first.txt | 0 .../{ => efi}/menu-template.txt | 0 usr/bin/refind-menu-generator | 83 +++++++++++++++---- 15 files changed, 262 insertions(+), 16 deletions(-) create mode 100644 etc/refind-menu-generator/boot/menu-template-efi-first.txt create mode 100644 etc/refind-menu-generator/boot/menu-template-fallback-only-efi-first.txt create mode 100644 etc/refind-menu-generator/boot/menu-template-fallback-only-efi.txt create mode 100644 etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz-first.txt create mode 100644 etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz.txt create mode 100644 etc/refind-menu-generator/boot/menu-template-vmlinuz-first.txt create mode 100644 etc/refind-menu-generator/boot/menu-template.txt rename etc/refind-menu-generator/{ => efi}/menu-template-efi-first.txt (100%) rename etc/refind-menu-generator/{ => efi}/menu-template-fallback-only-efi-first.txt (100%) rename etc/refind-menu-generator/{ => efi}/menu-template-fallback-only-efi.txt (100%) rename etc/refind-menu-generator/{ => efi}/menu-template-fallback-only-vmlinuz-first.txt (100%) rename etc/refind-menu-generator/{ => efi}/menu-template-fallback-only-vmlinuz.txt (100%) rename etc/refind-menu-generator/{ => efi}/menu-template-vmlinuz-first.txt (100%) rename etc/refind-menu-generator/{ => efi}/menu-template.txt (100%) diff --git a/etc/refind-menu-generator/boot/menu-template-efi-first.txt b/etc/refind-menu-generator/boot/menu-template-efi-first.txt new file mode 100644 index 0000000..5505dd7 --- /dev/null +++ b/etc/refind-menu-generator/boot/menu-template-efi-first.txt @@ -0,0 +1,35 @@ +menuentry "EFI {OSNAME} ({KERNEL}) on Boot volume" { + icon /EFI/refind/themes/{THEME}/icons/os_{ICON}.png + ostype Linux + graphics on + + volume "Boot" + loader /{KERNEL_EFI}.efi + + submenuentry "EFI {OSNAME} ({KERNEL}) fallback" { + loader /{KERNEL_EFI}-fallback.efi + } + + submenuentry "EFI {OSNAME} ({KERNEL}) fallback terminal" { + loader /{KERNEL_EFI}-fallback-terminal.efi + } + + submenuentry "{OSNAME} ({KERNEL})" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}.img + options "{CMDLINE}" + } + + submenuentry "{OSNAME} ({KERNEL}) fallback" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback.img + options "{CMDLINE}" + } + + submenuentry "{OSNAME} ({KERNEL}) fallback terminal" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback-terminal.img + options "{CMDLINE_TERMINAL}" + } +} + diff --git a/etc/refind-menu-generator/boot/menu-template-fallback-only-efi-first.txt b/etc/refind-menu-generator/boot/menu-template-fallback-only-efi-first.txt new file mode 100644 index 0000000..a1ff9f2 --- /dev/null +++ b/etc/refind-menu-generator/boot/menu-template-fallback-only-efi-first.txt @@ -0,0 +1,25 @@ +menuentry "EFI {OSNAME} ({KERNEL}) on Boot volume" { + icon /EFI/refind/themes/{THEME}/icons/os_{ICON}.png + ostype Linux + graphics on + + volume "Boot" + loader /{KERNEL_EFI}-fallback.efi + + submenuentry "EFI {OSNAME} ({KERNEL}) terminal" { + loader /{KERNEL_EFI}-fallback-terminal.efi + } + + submenuentry "{OSNAME} ({KERNEL})" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback.img + options "{CMDLINE}" + } + + submenuentry "{OSNAME} ({KERNEL}) terminal" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback-terminal.img + options "{CMDLINE_TERMINAL}" + } +} + diff --git a/etc/refind-menu-generator/boot/menu-template-fallback-only-efi.txt b/etc/refind-menu-generator/boot/menu-template-fallback-only-efi.txt new file mode 100644 index 0000000..37e6b42 --- /dev/null +++ b/etc/refind-menu-generator/boot/menu-template-fallback-only-efi.txt @@ -0,0 +1,13 @@ +menuentry "EFI {OSNAME} ({KERNEL}) on Boot volume" { + icon /EFI/refind/themes/{THEME}/icons/os_{ICON}.png + ostype Linux + graphics on + + volume "Boot" + loader /{KERNEL_EFI}-fallback.efi + + submenuentry "EFI {OSNAME} ({KERNEL}) terminal" { + loader /{KERNEL_EFI}-fallback-terminal.efi + } +} + diff --git a/etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz-first.txt b/etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz-first.txt new file mode 100644 index 0000000..c05d93e --- /dev/null +++ b/etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz-first.txt @@ -0,0 +1,29 @@ +menuentry "{OSNAME} ({KERNEL}) on Boot volume" { + icon /EFI/refind/themes/{THEME}/icons/os_{ICON}.png + ostype Linux + graphics on + + volume "Boot" + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback.img + options "{CMDLINE}" + + submenuentry "{OSNAME} ({KERNEL}) terminal" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback-terminal.img + options "{CMDLINE_TERMINAL}" + } + + submenuentry "EFI {OSNAME} ({KERNEL})" { + loader /{KERNEL_EFI}-fallback.efi + initrd + options + } + + submenuentry "EFI {OSNAME} ({KERNEL}) terminal" { + loader /{KERNEL_EFI}-fallback-terminal.efi + initrd + options + } +} + diff --git a/etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz.txt b/etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz.txt new file mode 100644 index 0000000..2f4b319 --- /dev/null +++ b/etc/refind-menu-generator/boot/menu-template-fallback-only-vmlinuz.txt @@ -0,0 +1,17 @@ +menuentry "{OSNAME} ({KERNEL}) on Boot volume" { + icon /EFI/refind/themes/{THEME}/icons/os_{ICON}.png + ostype Linux + graphics on + + volume "Boot" + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback.img + options "{CMDLINE}" + + submenuentry "{OSNAME} ({KERNEL}) terminal" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback-terminal.img + options "{CMDLINE_TERMINAL}" + } +} + diff --git a/etc/refind-menu-generator/boot/menu-template-vmlinuz-first.txt b/etc/refind-menu-generator/boot/menu-template-vmlinuz-first.txt new file mode 100644 index 0000000..98f6bba --- /dev/null +++ b/etc/refind-menu-generator/boot/menu-template-vmlinuz-first.txt @@ -0,0 +1,41 @@ +menuentry "{OSNAME} ({KERNEL}) on Boot volume" { + icon /EFI/refind/themes/{THEME}/icons/os_{ICON}.png + ostype Linux + graphics on + + volume "Boot" + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}.img + options "{CMDLINE}" + + submenuentry "{OSNAME} ({KERNEL}) fallback" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback.img + options "{CMDLINE}" + } + + submenuentry "{OSNAME} ({KERNEL}) fallback terminal" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback-terminal.img + options "{CMDLINE_TERMINAL}" + } + + submenuentry "EFI {OSNAME} ({KERNEL})" { + loader /{KERNEL_EFI}.efi + initrd + options + } + + submenuentry "EFI {OSNAME} ({KERNEL}) fallback" { + loader /{KERNEL_EFI}-fallback.efi + initrd + options + } + + submenuentry "EFI {OSNAME} ({KERNEL}) fallback terminal" { + loader /{KERNEL_EFI}-fallback-terminal.efi + initrd + options + } +} + diff --git a/etc/refind-menu-generator/boot/menu-template.txt b/etc/refind-menu-generator/boot/menu-template.txt new file mode 100644 index 0000000..5505dd7 --- /dev/null +++ b/etc/refind-menu-generator/boot/menu-template.txt @@ -0,0 +1,35 @@ +menuentry "EFI {OSNAME} ({KERNEL}) on Boot volume" { + icon /EFI/refind/themes/{THEME}/icons/os_{ICON}.png + ostype Linux + graphics on + + volume "Boot" + loader /{KERNEL_EFI}.efi + + submenuentry "EFI {OSNAME} ({KERNEL}) fallback" { + loader /{KERNEL_EFI}-fallback.efi + } + + submenuentry "EFI {OSNAME} ({KERNEL}) fallback terminal" { + loader /{KERNEL_EFI}-fallback-terminal.efi + } + + submenuentry "{OSNAME} ({KERNEL})" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}.img + options "{CMDLINE}" + } + + submenuentry "{OSNAME} ({KERNEL}) fallback" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback.img + options "{CMDLINE}" + } + + submenuentry "{OSNAME} ({KERNEL}) fallback terminal" { + loader /{KERNEL_VMLINUZ} + initrd /{INITRAMFS}-fallback-terminal.img + options "{CMDLINE_TERMINAL}" + } +} + diff --git a/etc/refind-menu-generator/menu-template-efi-first.txt b/etc/refind-menu-generator/efi/menu-template-efi-first.txt similarity index 100% rename from etc/refind-menu-generator/menu-template-efi-first.txt rename to etc/refind-menu-generator/efi/menu-template-efi-first.txt diff --git a/etc/refind-menu-generator/menu-template-fallback-only-efi-first.txt b/etc/refind-menu-generator/efi/menu-template-fallback-only-efi-first.txt similarity index 100% rename from etc/refind-menu-generator/menu-template-fallback-only-efi-first.txt rename to etc/refind-menu-generator/efi/menu-template-fallback-only-efi-first.txt diff --git a/etc/refind-menu-generator/menu-template-fallback-only-efi.txt b/etc/refind-menu-generator/efi/menu-template-fallback-only-efi.txt similarity index 100% rename from etc/refind-menu-generator/menu-template-fallback-only-efi.txt rename to etc/refind-menu-generator/efi/menu-template-fallback-only-efi.txt diff --git a/etc/refind-menu-generator/menu-template-fallback-only-vmlinuz-first.txt b/etc/refind-menu-generator/efi/menu-template-fallback-only-vmlinuz-first.txt similarity index 100% rename from etc/refind-menu-generator/menu-template-fallback-only-vmlinuz-first.txt rename to etc/refind-menu-generator/efi/menu-template-fallback-only-vmlinuz-first.txt diff --git a/etc/refind-menu-generator/menu-template-fallback-only-vmlinuz.txt b/etc/refind-menu-generator/efi/menu-template-fallback-only-vmlinuz.txt similarity index 100% rename from etc/refind-menu-generator/menu-template-fallback-only-vmlinuz.txt rename to etc/refind-menu-generator/efi/menu-template-fallback-only-vmlinuz.txt diff --git a/etc/refind-menu-generator/menu-template-vmlinuz-first.txt b/etc/refind-menu-generator/efi/menu-template-vmlinuz-first.txt similarity index 100% rename from etc/refind-menu-generator/menu-template-vmlinuz-first.txt rename to etc/refind-menu-generator/efi/menu-template-vmlinuz-first.txt diff --git a/etc/refind-menu-generator/menu-template.txt b/etc/refind-menu-generator/efi/menu-template.txt similarity index 100% rename from etc/refind-menu-generator/menu-template.txt rename to etc/refind-menu-generator/efi/menu-template.txt diff --git a/usr/bin/refind-menu-generator b/usr/bin/refind-menu-generator index 8249210..20e585c 100755 --- a/usr/bin/refind-menu-generator +++ b/usr/bin/refind-menu-generator @@ -82,24 +82,35 @@ else if [ ! -d "${ESP}/EFI/Linux" ]; then mkdir -p "${ESP}/EFI/Linux" if [ -d "${ESP}/EFI/linux" ]; then - KERNEL_DIR="${ESP}/EFI/linux" + KERNEL_DIR_ON_EFI="${ESP}/EFI/linux" fi else - KERNEL_DIR="${ESP}/EFI/Linux" + KERNEL_DIR_ON_EFI="${ESP}/EFI/Linux" + fi + + if [ -d "/boot" ]; then + KERNEL_DIR_ON_BOOT="/boot" fi fi -echo "Found $KERNEL_DIR" +if [ -v KERNEL_DIR_ON_EFI ]; then + echo "Found ${KERNEL_DIR_ON_EFI}" +fi + +if [ -v KERNEL_DIR_ON_BOOT ]; then + echo "Found ${KERNEL_DIR_ON_BOOT}" +fi + #theme=$(grep "themes" "/efi/EFI/refind/refind.conf" | cut -d"/" -f2) theme=$(cat "/etc/refind-menu-generator/theme.conf" | awk '{$1=$1;print}') -if [ -d "$KERNEL_DIR" ]; then +if [ -d "${KERNEL_DIR_ON_EFI}" ]; then - if [ -f "${ESP}/EFI/Linux/cmdline.txt" ]; then - cmdline=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' "${ESP}/EFI/Linux/cmdline.txt" | tr '[:space:]' ' ' | tr -s ' ') + if [ -f "${KERNEL_DIR_ON_EFI}/cmdline.txt" ]; then + cmdline=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' "${KERNEL_DIR_ON_EFI}/cmdline.txt" | tr '[:space:]' ' ' | tr -s ' ') elif [ -f "/etc/kernel/cmdline" ]; then cmdline=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' "/etc/kernel/cmdline" | tr '[:space:]' ' ' | tr -s ' ') @@ -126,26 +137,33 @@ if [ -d "$KERNEL_DIR" ]; then template_choice=$(cat "/etc/refind-menu-generator/menu-template.conf" | awk '{$1=$1;print}') - if [ ! -f "/etc/refind-menu-generator/${template_choice}.txt" ] || [ "$(ls -l /etc/refind-menu-generator/${template_choice}.txt | awk '{print $5}')" -lt 10 ]; then - template="/etc/refind-menu-generator/menu-template.txt" + if [ ! -f "/etc/refind-menu-generator/efi/${template_choice}.txt" ] || [ "$(ls -l /etc/refind-menu-generator/efi/${template_choice}.txt | awk '{print $5}')" -lt 10 ]; then + template_on_efi="/etc/refind-menu-generator/efi/menu-template.txt" else - template="/etc/refind-menu-generator/${template_choice}.txt" + template_on_efi="/etc/refind-menu-generator/efi/${template_choice}.txt" + fi + + if [ ! -f "/etc/refind-menu-generator/boot/${template_choice}.txt" ] || [ "$(ls -l /etc/refind-menu-generator/boot/${template_choice}.txt | awk '{print $5}')" -lt 10 ]; then + template_on_boot="/etc/refind-menu-generator/boot/menu-template.txt" + else + template_on_boot="/etc/refind-menu-generator/boot/${template_choice}.txt" fi - kernels_list=$(ls -1 "${ESP}/EFI/Linux/" | grep 'linux' | grep -v 'fallback' | grep '\.efi$') - if [[ -z "$kernels_list" ]]; then - kernels_list=$(ls -1 "${ESP}/EFI/Linux/" | grep "^vmlinuz" | sed "s/vmlinuz-//") + + kernels_list_on_efi=$(ls -1 "${KERNEL_DIR_ON_EFI}/" | grep 'linux' | grep -v 'fallback' | grep '\.efi$') + if [[ -z "$kernels_list_on_efi" ]]; then + kernels_list_on_efi=$(ls -1 "${KERNEL_DIR_ON_EFI}/" | grep "^vmlinuz" | sed "s/vmlinuz-//") fi - echo -e "KERNELS:\n$kernels_list" + echo -e "KERNELS:\n$kernels_list_on_efi" - if [[ -z "$kernels_list" ]]; then + if [[ -z "$kernels_list_on_efi" ]]; then echo "ERROR: list of kernels is empty" exit 1 fi - for i in $kernels_list; + for i in $kernels_list_on_efi; do kernel=$(echo "$i" | sed 's/\.efi//g') kernel_efi=$kernel @@ -158,9 +176,42 @@ if [ -d "$KERNEL_DIR" ]; then initramfs="$initramfs_tpl" echo "OSNAME: $osname; THEME: $theme; ICON: $icon; KERNEL: $kernel; KERNEL_EFI: $kernel_efi; KERNEL_VMLINUZ: $kernel_vmlinuz; INITRAMFS: $initramfs; CMDLINE: $cmdline" - sed -e "s|{OSNAME}|$osname|g" -e "s|{THEME}|$theme|g" -e "s|{ICON}|$icon|g" -e "s|{KERNEL}|$kernel|g" -e "s|{KERNEL_EFI}|$kernel_efi|g" -e "s|{KERNEL_VMLINUZ}|$kernel_vmlinuz|g" -e "s|{INITRAMFS}|$initramfs|g" -e "s|{CMDLINE}|$cmdline|g" -e "s|{CMDLINE_TERMINAL}|$cmdline_terminal|g" "$template" >> "$manual_conf" + sed -e "s|{OSNAME}|$osname|g" -e "s|{THEME}|$theme|g" -e "s|{ICON}|$icon|g" -e "s|{KERNEL}|$kernel|g" -e "s|{KERNEL_EFI}|$kernel_efi|g" -e "s|{KERNEL_VMLINUZ}|$kernel_vmlinuz|g" -e "s|{INITRAMFS}|$initramfs|g" -e "s|{CMDLINE}|$cmdline|g" -e "s|{CMDLINE_TERMINAL}|$cmdline_terminal|g" "$template_on_efi" >> "$manual_conf" done + + + kernels_list_on_boot=$(ls -1 "${KERNEL_DIR_ON_BOOT}/" | grep 'linux' | grep -v 'fallback' | grep '\.efi$') + if [[ -z "$kernels_list_on_boot" ]]; then + kernels_list_on_boot=$(ls -1 "${KERNEL_DIR_ON_BOOT}/" | grep "^vmlinuz" | sed "s/vmlinuz-//") + fi + + echo -e "KERNELS:\n$kernels_list_on_boot" + + if [[ -z "$kernels_list_on_boot" ]]; then + echo "ERROR: list of kernels is empty" + exit 1 + fi + + for i in $kernels_list_on_boot; + do + kernel=$(echo "$i" | sed 's/\.efi//g') + kernel_efi=$kernel + kernel_vmlinuz="vmlinuz-$kernel" + + osname=$(grep "^NAME=" /etc/os-release | cut -d'=' -f2 | sed -e 's/"//g') + icon=$(grep "^ID=" /etc/os-release | cut -d'=' -f2 | sed -e 's/"//g') + + initramfs_tpl=$(echo "initramfs-$kernel" | sed "s/vmlinuz-//g") + initramfs="$initramfs_tpl" + + echo "OSNAME: $osname; THEME: $theme; ICON: $icon; KERNEL: $kernel; KERNEL_EFI: $kernel_efi; KERNEL_VMLINUZ: $kernel_vmlinuz; INITRAMFS: $initramfs; CMDLINE: $cmdline" + sed -e "s|{OSNAME}|$osname|g" -e "s|{THEME}|$theme|g" -e "s|{ICON}|$icon|g" -e "s|{KERNEL}|$kernel|g" -e "s|{KERNEL_EFI}|$kernel_efi|g" -e "s|{KERNEL_VMLINUZ}|$kernel_vmlinuz|g" -e "s|{INITRAMFS}|$initramfs|g" -e "s|{CMDLINE}|$cmdline|g" -e "s|{CMDLINE_TERMINAL}|$cmdline_terminal|g" "$template_on_boot" >> "$manual_conf" + done + + + + manual_end_conf=$(mktemp) template_end="/etc/refind-menu-generator/menu-end.txt"