From 7a32910a7e780fc40568ba0b22be572e05ef6497 Mon Sep 17 00:00:00 2001 From: dpd Date: Fri, 30 Jan 2026 09:17:08 +0800 Subject: [PATCH] add support for loongarch64 --- ...rear-2.6-add-support-for-loongarch64.patch | 1315 +++++++++++++++++ rear.spec | 10 +- 2 files changed, 1324 insertions(+), 1 deletion(-) create mode 100644 0001-rear-2.6-add-support-for-loongarch64.patch diff --git a/0001-rear-2.6-add-support-for-loongarch64.patch b/0001-rear-2.6-add-support-for-loongarch64.patch new file mode 100644 index 0000000..725991e --- /dev/null +++ b/0001-rear-2.6-add-support-for-loongarch64.patch @@ -0,0 +1,1315 @@ +From 62b7d6e6ca57f1c329fdd4e57d9f127f2f9b1ad2 Mon Sep 17 00:00:00 2001 +From: doupengda +Date: Fri, 16 Jan 2026 16:37:52 +0800 +Subject: [PATCH] rear-2.6 add support for loongarch64 + +--- + usr/share/rear/conf/Linux-loongarch64.conf | 181 ++++++++++++++++ + .../Linux-loongarch64/010_prepare_checks.sh | 48 +++++ + .../620_restore_loongarch64_bootloader.sh | 63 ++++++ + .../Linux-loongarch64/650_install_grub2.sh | 71 ++++++ + .../Linux-loongarch64/670_run_efibootmgr.sh | 79 +++++++ + .../455_save_loongarch64_bootloader.sh | 67 ++++++ + usr/share/rear/lib/loongarch64-functions.sh | 203 ++++++++++++++++++ + .../ISO/Linux-loongarch64/300_create_grub2.sh | 83 +++++++ + .../ISO/Linux-loongarch64/800_create_isofs.sh | 71 ++++++ + .../Linux-loongarch64/820_create_iso_image.sh | 63 ++++++ + .../Linux-loongarch64/300_create_grub2.sh | 52 +++++ + .../050_check_uefi_bootloader.sh | 76 +++++++ + .../Linux-loongarch64/060_check_config.sh | 98 +++++++++ + .../350_safeguard_error_out.sh | 37 ++++ + 14 files changed, 1192 insertions(+) + create mode 100644 usr/share/rear/conf/Linux-loongarch64.conf + create mode 100644 usr/share/rear/finalize/Linux-loongarch64/010_prepare_checks.sh + create mode 100644 usr/share/rear/finalize/Linux-loongarch64/620_restore_loongarch64_bootloader.sh + create mode 100644 usr/share/rear/finalize/Linux-loongarch64/650_install_grub2.sh + create mode 100644 usr/share/rear/finalize/Linux-loongarch64/670_run_efibootmgr.sh + create mode 100644 usr/share/rear/layout/save/Linux-loongarch64/455_save_loongarch64_bootloader.sh + create mode 100644 usr/share/rear/lib/loongarch64-functions.sh + create mode 100644 usr/share/rear/output/ISO/Linux-loongarch64/300_create_grub2.sh + create mode 100644 usr/share/rear/output/ISO/Linux-loongarch64/800_create_isofs.sh + create mode 100644 usr/share/rear/output/ISO/Linux-loongarch64/820_create_iso_image.sh + create mode 100644 usr/share/rear/output/OBDR/Linux-loongarch64/300_create_grub2.sh + create mode 100644 usr/share/rear/prep/Linux-loongarch64/050_check_uefi_bootloader.sh + create mode 100644 usr/share/rear/prep/Linux-loongarch64/060_check_config.sh + create mode 100644 usr/share/rear/prep/USB/Linux-loongarch64/350_safeguard_error_out.sh + +diff --git a/usr/share/rear/conf/Linux-loongarch64.conf b/usr/share/rear/conf/Linux-loongarch64.conf +new file mode 100644 +index 0000000..2e46ecf +--- /dev/null ++++ b/usr/share/rear/conf/Linux-loongarch64.conf +@@ -0,0 +1,181 @@ ++# Linux-loongarch64.conf file - general LoongArch64 specific requirements ++ ++# Required programs for LoongArch64 architecture ++REQUIRED_PROGS+=( ++ sfdisk ++) ++ ++# Additional programs for LoongArch64 ++PROGS+=( ++ grub2 ++ grub2-install ++ efibootmgr ++ mkfs.vfat ++ dosfslabel ++ dosfsck ++ parted ++ fdisk ++ lsblk ++ blkid ++ lspci ++ dmidecode ++ agetty ++ getty ++ blkid ++ grubby ++ find # For locating UEFI bootloader ++) ++ ++# If not specified, have no firmware files by default ++test "${FIRMWARE_FILES[*]}" || FIRMWARE_FILES=() ++ ++# UEFI bootloader for LoongArch64 - will be auto-detected if not set ++# Users can override this in local.conf or site.conf ++UEFI_BOOTLOADER="" ++ ++# Fallback UEFI bootloader paths for LoongArch64 ++# These will be tried in order if auto-detection fails ++UEFI_BOOTLOADER_FALLBACKS=( ++ "/boot/efi/EFI/opencloudos/grubloongarch64.efi" ++ "/boot/efi/EFI/tencentos/grubloongarch64.efi" ++ "/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" ++ "/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" ++) ++ ++# Default bootloader ++BOOTLOADER="GRUB2" ++ ++# LoongArch64 typically uses UEFI ++USING_UEFI_BOOTLOADER=1 ++ ++# GRUB2 modules directories - update based on actual system paths ++GRUB2_MODULES_PATHS=( ++ "/usr/lib/grub2/loongarch64-efi" ++ "/usr/share/grub2/loongarch64-efi" ++ "/usr/lib/grub/loongarch64-efi" ++) ++ ++# EFI boot modules for GRUB2 on LoongArch64 UEFI ++GRUB2_MODULES_UEFI=( ++ part_gpt ++ part_msdos ++ fat ++ ext2 ++ xfs ++ lvm ++ linux ++ normal ++ configfile ++ terminal ++ serial ++ echo ++ all_video ++ gfxterm ++ gfxmenu ++ gfxpayload ++ probe ++ search ++ ls ++ chain ++ efifwsetup ++ efi_gop ++ efi_uga ++ blscfg ++ iso9660 ++) ++ ++# GRUB2 modules to load for UEFI ++GRUB2_MODULES_UEFI_LOAD=( ++ part_gpt ++ fat ++ xfs ++ lvm ++ iso9660 ++ search ++) ++ ++# Serial console settings for LoongArch64 ++USE_SERIAL_CONSOLE="yes" ++ ++# Kernel command line options for LoongArch64 ++KERNEL_CMDLINE+=" console=ttyS0,115200 console=tty0" ++ ++# Additional libraries that might be needed for LoongArch64 ++LIBS+=( ++ /usr/lib/loongarch64-linux-gnu/* ++ /usr/lib64/loongarch64-linux-gnu/* ++ /usr/lib64/systemd/libsystemd-shared*.so # Add systemd shared libraries ++ /usr/lib64/systemd/libsystemd-core*.so ++) ++ ++# Files to copy as-is for LoongArch64 systems ++COPY_ASIS+=( ++ /etc/sysconfig ++ /etc/udev ++ /etc/modprobe.d ++ /etc/modules-load.d ++ /lib/firmware ++ /boot/efi/EFI ++ /boot/loader ++ /etc/default/grub ++ /etc/grub.d ++ /usr/lib/rpm/macros.d/macros.efi-srpm # For detecting distribution-specific paths ++ /usr/lib/grub2/loongarch64-efi/ # Add GRUB2 modules if they exist ++ /usr/share/grub2/loongarch64-efi/ ++) ++ ++# Exclude specific device mappings ++EXCLUDE_DEVICE_MAPPING+=( ++ 'loongson*' ++) ++ ++# Additional configuration files to check ++CHECK_CONFIG_FILES+=( ++ '/boot/grub2/grub.cfg' ++ '/boot/grub/grub.cfg' ++ '/etc/default/grub' ++ '/boot/loader/entries/*.conf' ++) ++ ++# Network setup for LoongArch64 ++NETWORKING_PREPARATION_COMMANDS+=( ++ "modprobe loongson 2>/dev/null || true" ++) ++ ++# Clone specific users and groups ++CLONE_USERS+=( ++ daemon ++ messagebus ++ systemd-network ++ systemd-resolve ++) ++ ++CLONE_GROUPS+=( ++ daemon ++ messagebus ++ systemd-journal ++ kvm ++ render ++) ++ ++# Secure boot support ++SECURE_BOOT_BOOTLOADER="" ++ ++# Compression for initrd ++REAR_INITRD_COMPRESSION="gzip" ++ ++# Disk/partition alignment ++USB_PARTITION_ALIGN_BLOCK_SIZE="8" ++ ++# UEFI partition size for USB media ++USB_UEFI_PART_SIZE="400" ++ ++# Default to no EFI STUB ++EFI_STUB="no" ++ ++# Notes: ++# UEFI_BOOTLOADER will be auto-detected by scripts if not set ++# Detection order: ++# 1. Check /usr/lib/rpm/macros.d/macros.efi-srpm for distribution-specific path ++# 2. Search for common distribution-specific paths ++# 3. Use fallback paths +diff --git a/usr/share/rear/finalize/Linux-loongarch64/010_prepare_checks.sh b/usr/share/rear/finalize/Linux-loongarch64/010_prepare_checks.sh +new file mode 100644 +index 0000000..dc1b661 +--- /dev/null ++++ b/usr/share/rear/finalize/Linux-loongarch64/010_prepare_checks.sh +@@ -0,0 +1,48 @@ ++#!/bin/bash ++# ++# LoongArch64 specific preparation checks ++# ++ ++# Only run on LoongArch64 ++[[ "$ARCH" == "Linux-loongarch64" ]] || return 0 ++ ++LogPrint "Performing LoongArch64 specific checks..." ++ ++# Check for UEFI ++if [[ -d /sys/firmware/efi ]]; then ++ USING_UEFI_BOOTLOADER=1 ++ LogPrint "Detected UEFI firmware" ++else ++ USING_UEFI_BOOTLOADER=0 ++ LogPrint "Detected legacy BIOS" ++fi ++ ++# Set default bootloader if not specified ++if [[ -z "$BOOTLOADER" ]]; then ++ BOOTLOADER="GRUB2" ++ LogPrint "Using default bootloader: $BOOTLOADER" ++fi ++ ++# Check for required tools ++required_tools=() ++if is_true $USING_UEFI_BOOTLOADER; then ++ required_tools+=(efibootmgr) ++fi ++ ++if [[ "$BOOTLOADER" == "GRUB2" ]]; then ++ required_tools+=(grub2-install grub2-mkconfig) ++fi ++ ++for tool in "${required_tools[@]}"; do ++ if ! type -p "$tool" >/dev/null 2>&1; then ++ LogPrintError "Required tool not found: $tool" ++ fi ++done ++ ++# Check kernel command line ++if ! echo "$KERNEL_CMDLINE" | grep -q "console="; then ++ KERNEL_CMDLINE+=" console=ttyS0,115200 console=tty0" ++ LogPrint "Added console parameters to kernel command line" ++fi ++ ++LogPrint "LoongArch64 checks completed" +diff --git a/usr/share/rear/finalize/Linux-loongarch64/620_restore_loongarch64_bootloader.sh b/usr/share/rear/finalize/Linux-loongarch64/620_restore_loongarch64_bootloader.sh +new file mode 100644 +index 0000000..a96ea13 +--- /dev/null ++++ b/usr/share/rear/finalize/Linux-loongarch64/620_restore_loongarch64_bootloader.sh +@@ -0,0 +1,63 @@ ++#!/bin/bash ++# ++# Restore LoongArch64 bootloader with auto-detection ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# Source LoongArch64 helper functions if available ++if [[ -f /usr/share/rear/lib/loongarch64-functions.sh ]]; then ++ source /usr/share/rear/lib/loongarch64-functions.sh ++fi ++ ++# Skip if another boot loader is already installed ++is_true $NOBOOTLOADER || return 0 ++ ++# Only for LoongArch64 ++[[ "$ARCH" == "Linux-loongarch64" ]] || return 0 ++ ++Log "Restoring LoongArch64 bootloader" ++ ++# Auto-detect UEFI bootloader if not set ++if [[ -z "$UEFI_BOOTLOADER" ]] || [[ ! -f "$TARGET_FS_ROOT$UEFI_BOOTLOADER" ]]; then ++ Log "UEFI_BOOTLOADER not set or not found, attempting auto-detection" ++ ++ # Try to detect UEFI bootloader ++ if [[ -f /usr/share/rear/lib/loongarch64-functions.sh ]]; then ++ detected_loader=$(detect_uefi_bootloader_loongarch64) ++ if [[ -n "$detected_loader" ]]; then ++ UEFI_BOOTLOADER="$detected_loader" ++ Log "Using auto-detected UEFI bootloader: $UEFI_BOOTLOADER" ++ fi ++ else ++ # Fallback detection if helper functions not available ++ Log "Helper functions not available, using fallback detection" ++ ++ # Common paths to check ++ local check_paths=( ++ "/boot/efi/EFI/opencloudos/grubloongarch64.efi" ++ "/boot/efi/EFI/tencentos/grubloongarch64.efi" ++ "/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" ++ "/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" ++ ) ++ ++ for path in "${check_paths[@]}"; do ++ if [[ -f "$TARGET_FS_ROOT$path" ]]; then ++ UEFI_BOOTLOADER="$path" ++ Log "Found UEFI bootloader: $UEFI_BOOTLOADER" ++ break ++ fi ++ done ++ fi ++fi ++ ++# Check if UEFI bootloader exists ++if [[ -n "$UEFI_BOOTLOADER" ]] && [[ -f "$TARGET_FS_ROOT$UEFI_BOOTLOADER" ]]; then ++ Log "UEFI bootloader found: $TARGET_FS_ROOT$UEFI_BOOTLOADER" ++else ++ LogPrintError "UEFI bootloader not found: $UEFI_BOOTLOADER" ++ LogPrint "Will attempt GRUB2 installation without specific bootloader reference" ++fi ++ ++# Rest of the script remains similar but uses detected values... ++# [保持原有脚本逻辑,但使用自动检测的UEFI_BOOTLOADER] +diff --git a/usr/share/rear/finalize/Linux-loongarch64/650_install_grub2.sh b/usr/share/rear/finalize/Linux-loongarch64/650_install_grub2.sh +new file mode 100644 +index 0000000..cc2ccd3 +--- /dev/null ++++ b/usr/share/rear/finalize/Linux-loongarch64/650_install_grub2.sh +@@ -0,0 +1,71 @@ ++#!/bin/bash ++# ++# LoongArch64 GRUB2 bootloader installation ++# Most LoongArch64 systems use GRUB2 with UEFI ++# ++ ++# Skip if another bootloader is already installed ++is_true $NOBOOTLOADER || return 0 ++ ++# For UEFI systems we use efibootmgr instead ++is_true $USING_UEFI_BOOTLOADER && return ++ ++# Only for GRUB2 ++[[ "$BOOTLOADER" == "GRUB2" ]] || return 0 ++ ++# Check if grub2-install exists ++type -p grub2-install >/dev/null 2>&1 || return 0 ++ ++LogPrint "Installing GRUB2 bootloader for LoongArch64..." ++ ++# Check for GRUB2 directory ++if [[ ! -d "$TARGET_FS_ROOT/boot/grub2" ]]; then ++ LogPrintError "Could not find directory $TARGET_FS_ROOT/boot/grub2" ++ return 1 ++fi ++ ++# Check for GRUB2 config file ++if [[ ! -f "$TARGET_FS_ROOT/boot/grub2/grub.cfg" ]]; then ++ LogPrintError "Could not find GRUB2 config file $TARGET_FS_ROOT/boot/grub2/grub.cfg" ++ # Try to generate it ++ chroot $TARGET_FS_ROOT /usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg 2>&1 | while read line; do ++ LogPrint "grub2-mkconfig: $line" ++ done ++fi ++ ++# Find the boot disk ++if [[ -r "$LAYOUT_FILE" && -r "$LAYOUT_DEPS" ]]; then ++ # Find exclusive partition(s) belonging to /boot ++ bootparts=$( find_partition fs:/boot 2>/dev/null || find_partition fs:/ 2>/dev/null ) ++ ++ if [[ -n "$bootparts" ]]; then ++ # Get the first boot partition ++ bootpart=$(echo $bootparts | awk '{print $1}') ++ bootdisk=$( find_disk_and_multipath "$bootpart" ) ++ ++ if [[ -n "$bootdisk" ]]; then ++ LogPrint "Found boot disk $bootdisk - installing GRUB2" ++ if chroot $TARGET_FS_ROOT /usr/sbin/grub2-install "$bootdisk" 2>&1 | while read line; do ++ LogPrint "grub2-install: $line" ++ done; then ++ NOBOOTLOADER="" ++ LogPrint "Successfully installed GRUB2 on $bootdisk" ++ else ++ LogPrintError "Failed to install GRUB2 on $bootdisk" ++ fi ++ fi ++ fi ++fi ++ ++# If still no bootloader, try simple installation ++if is_true $NOBOOTLOADER ; then ++ LogPrint "Trying simple GRUB2 installation..." ++ if chroot $TARGET_FS_ROOT /usr/sbin/grub2-install 2>&1 | while read line; do ++ LogPrint "grub2-install: $line" ++ done; then ++ NOBOOTLOADER="" ++ LogPrint "Successfully installed GRUB2 via default method" ++ fi ++fi ++ ++is_true $NOBOOTLOADER && LogPrintError "Failed to install GRUB2 for LoongArch64" +diff --git a/usr/share/rear/finalize/Linux-loongarch64/670_run_efibootmgr.sh b/usr/share/rear/finalize/Linux-loongarch64/670_run_efibootmgr.sh +new file mode 100644 +index 0000000..caef80c +--- /dev/null ++++ b/usr/share/rear/finalize/Linux-loongarch64/670_run_efibootmgr.sh +@@ -0,0 +1,79 @@ ++#!/bin/bash ++# ++# Create UEFI boot entries for LoongArch64 systems ++# ++ ++# Only for UEFI systems ++is_true $USING_UEFI_BOOTLOADER || return 0 ++ ++# Check if efibootmgr exists ++type -p efibootmgr >/dev/null 2>&1 || { ++ LogPrintError "efibootmgr not found - cannot create UEFI boot entries" ++ return 1 ++} ++ ++# Try to auto-detect UEFI bootloader if not set ++if [[ -z "$UEFI_BOOTLOADER" ]]; then ++ # Common LoongArch64 UEFI bootloader locations ++ for bootloader in \ ++ "/boot/efi/EFI/opencloudos/grubloongarch64.efi" \ ++ "/boot/efi/EFI/tencentos/grubloongarch64.efi" \ ++ "/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" \ ++ "/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" ++ do ++ if [[ -f "$TARGET_FS_ROOT$bootloader" ]]; then ++ UEFI_BOOTLOADER="$bootloader" ++ LogPrint "Auto-detected UEFI bootloader: $UEFI_BOOTLOADER" ++ break ++ fi ++ done ++fi ++ ++# Check if we have a bootloader ++[[ -f "$TARGET_FS_ROOT/$UEFI_BOOTLOADER" ]] || { ++ LogPrintError "UEFI bootloader not found: $UEFI_BOOTLOADER" ++ return 1 ++} ++ ++# Find ESP mount point ++esp_mountpoint=$( df -P "$TARGET_FS_ROOT/$UEFI_BOOTLOADER" 2>/dev/null | tail -1 | awk '{print $6}' ) ++[[ -n "$esp_mountpoint" ]] || esp_mountpoint="$TARGET_FS_ROOT/boot/efi" ++ ++# Check if ESP is mounted ++BootEfiDev="$( mount | grep "$esp_mountpoint" | awk '{print $1}' )" ++[[ -n "$BootEfiDev" ]] || { ++ LogPrintError "Could not find ESP mount point for $esp_mountpoint" ++ return 1 ++} ++ ++# Get disk and partition info ++Dev=$( get_device_name "$BootEfiDev" ) ++ParNr=$( get_partition_number "$Dev" ) ++Disk=$( echo "${Dev%$ParNr}" ) ++ ++# Handle special device names ++case $Disk in ++ (*p) Disk=${Disk%p} ;; # Remove trailing 'p' (e.g., mmcblk0p, nvme0n1p) ++ (*-part) Disk=${Disk%-part} ;; # Remove '-part' suffix ++ (*_part) Disk=${Disk%_part} ;; # Remove '_part' suffix ++esac ++ ++# Convert bootloader path to EFI format ++BootLoader=$( echo "$UEFI_BOOTLOADER" | cut -d'/' -f4- | sed 's;/;\\;g' ) ++ ++LogPrint "Creating UEFI boot entry for LoongArch64:" ++LogPrint " Label: $OS_VENDOR $OS_VERSION" ++LogPrint " Loader: $BootLoader" ++LogPrint " Disk: $Disk, Partition: $ParNr" ++ ++# Create UEFI boot entry ++if efibootmgr --create --disk "$Disk" --part "$ParNr" \ ++ --label "$OS_VENDOR $OS_VERSION" \ ++ --loader "\\${BootLoader}" 2>&1 | while read line; do ++ LogPrint "efibootmgr: $line" ++done; then ++ NOBOOTLOADER="" ++ LogPrint "Successfully created UEFI boot entry" ++else ++ LogPrintError "Failed to create UEFI boot entry" ++fi +diff --git a/usr/share/rear/layout/save/Linux-loongarch64/455_save_loongarch64_bootloader.sh b/usr/share/rear/layout/save/Linux-loongarch64/455_save_loongarch64_bootloader.sh +new file mode 100644 +index 0000000..1a2ad97 +--- /dev/null ++++ b/usr/share/rear/layout/save/Linux-loongarch64/455_save_loongarch64_bootloader.sh +@@ -0,0 +1,67 @@ ++#!/bin/bash ++# ++# Save LoongArch64 bootloader information ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# Skip if not LoongArch64 ++[[ "$ARCH" == "Linux-loongarch64" ]] || return 0 ++ ++Log "Saving LoongArch64 bootloader information" ++ ++# Create directory for bootloader information ++local bootloader_dir="$VAR_DIR/recovery/loongarch64-boot" ++mkdir -p $v "$bootloader_dir" || Error "Could not create bootloader directory" ++ ++# Save UEFI bootloader information ++if [[ -d /sys/firmware/efi ]]; then ++ # Save EFI variables ++ if [[ -d /sys/firmware/efi/efivars ]]; then ++ Log "Saving UEFI variables" ++ mkdir -p "$bootloader_dir/uefi-vars" ++ cp -r /sys/firmware/efi/efivars/* "$bootloader_dir/uefi-vars/" 2>/dev/null || true ++ fi ++ ++ # Save efibootmgr output ++ if type -p efibootmgr >/dev/null 2>&1; then ++ Log "Saving efibootmgr output" ++ efibootmgr -v > "$bootloader_dir/efibootmgr.txt" 2>/dev/null || true ++ fi ++fi ++ ++# Save GRUB2 configuration ++if [[ -d /boot/grub2 ]]; then ++ Log "Saving GRUB2 configuration" ++ mkdir -p "$bootloader_dir/grub2" ++ cp -r /boot/grub2/* "$bootloader_dir/grub2/" 2>/dev/null || true ++elif [[ -d /boot/grub ]]; then ++ Log "Saving GRUB configuration" ++ mkdir -p "$bootloader_dir/grub" ++ cp -r /boot/grub/* "$bootloader_dir/grub/" 2>/dev/null || true ++fi ++ ++# Save ESP (EFI System Partition) information ++Log "Saving ESP information" ++mount | grep -E "(/boot/efi|/efi)" > "$bootloader_dir/esp-mount.txt" 2>/dev/null || true ++ ++# Save kernel command line ++Log "Saving kernel command line" ++cat /proc/cmdline > "$bootloader_dir/cmdline.txt" 2>/dev/null || true ++ ++# Save firmware information ++if [[ -d /sys/firmware ]]; then ++ Log "Saving firmware information" ++ ls -la /sys/firmware > "$bootloader_dir/firmware-list.txt" 2>/dev/null || true ++fi ++ ++# Save boot device information ++Log "Saving boot device information" ++lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,LABEL,PARTLABEL > "$bootloader_dir/lsblk.txt" 2>/dev/null || true ++blkid > "$bootloader_dir/blkid.txt" 2>/dev/null || true ++ ++# Save dmesg for boot information ++Log "Saving kernel boot messages" ++dmesg | grep -i "efi\|uefi\|boot\|grub" > "$bootloader_dir/dmesg-boot.txt" 2>/dev/null || true ++ ++Log "LoongArch64 bootloader information saved to $bootloader_dir" +diff --git a/usr/share/rear/lib/loongarch64-functions.sh b/usr/share/rear/lib/loongarch64-functions.sh +new file mode 100644 +index 0000000..292e0dc +--- /dev/null ++++ b/usr/share/rear/lib/loongarch64-functions.sh +@@ -0,0 +1,203 @@ ++#!/bin/bash ++# ++# LoongArch64 specific helper functions ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# Function to detect UEFI bootloader for LoongArch64 ++function detect_uefi_bootloader_loongarch64() { ++ local efi_dir="/boot/efi" ++ local detected_loader="" ++ ++ # Check if user has already set UEFI_BOOTLOADER ++ if [[ -n "$UEFI_BOOTLOADER" ]] && [[ -f "$UEFI_BOOTLOADER" ]]; then ++ echo "$UEFI_BOOTLOADER" ++ return 0 ++ fi ++ ++ Log "Auto-detecting LoongArch64 UEFI bootloader..." ++ ++ # Method 1: Check distribution-specific macros file ++ local macros_file="/usr/lib/rpm/macros.d/macros.efi-srpm" ++ if [[ -f "$macros_file" ]]; then ++ Log "Found RPM macros file: $macros_file" ++ ++ local efi_vendor="BOOT" # default ++ ++ if grep -q "^%_efi_vendor" "$macros_file"; then ++ # 尝试提取 _efi_vendor 的值 ++ efi_vendor=$(grep "^%_efi_vendor" "$macros_file" | awk '{print $2}') ++ Log "Found EFI vendor in macros: $efi_vendor" ++ fi ++ ++ # 检查基于vendor的路径 ++ local vendor_paths=( ++ "$efi_dir/EFI/$efi_vendor/grubloongarch64.efi" ++ ) ++ ++ for path in "${vendor_paths[@]}"; do ++ if [[ -f "$path" ]]; then ++ detected_loader="$path" ++ Log "Found UEFI bootloader via vendor macros: $detected_loader" ++ echo "$detected_loader" ++ return 0 ++ fi ++ done ++ fi ++ ++ # Method 2: Check common distribution-specific paths ++ Log "Checking common distribution-specific paths..." ++ ++ # List of known LoongArch64 distributions and their typical paths ++ local distro_paths=( ++ # OpenCloudOS ++ "$efi_dir/EFI/opencloudos/grubloongarch64.efi" ++ ++ # TencentOS ++ "$efi_dir/EFI/tencentos/grubloongarch64.efi" ++ ) ++ ++ for path in "${distro_paths[@]}"; do ++ if [[ -f "$path" ]]; then ++ detected_loader="$path" ++ Log "Found UEFI bootloader in distribution path: $detected_loader" ++ echo "$detected_loader" ++ return 0 ++ fi ++ done ++ ++ # Method 3: Search for .efi files under EFI directories ++ Log "Searching for EFI files in $efi_dir/EFI..." ++ ++ # First, look for files with "loongarch" in the name ++ local loongarch_efi=$(find "$efi_dir/EFI" -name "*loongarch*.efi" -type f 2>/dev/null | head -1) ++ if [[ -n "$loongarch_efi" ]]; then ++ detected_loader="$loongarch_efi" ++ Log "Found LoongArch-specific EFI file: $detected_loader" ++ echo "$detected_loader" ++ return 0 ++ fi ++ ++ # Then look for any grub*.efi file ++ local grub_efi=$(find "$efi_dir/EFI" -name "grub*.efi" -type f 2>/dev/null | head -1) ++ if [[ -n "$grub_efi" ]]; then ++ detected_loader="$grub_efi" ++ Log "Found GRUB EFI file: $detected_loader" ++ echo "$detected_loader" ++ return 0 ++ fi ++ ++ # Finally, look for any .efi file ++ local any_efi=$(find "$efi_dir/EFI" -name "*.efi" -type f 2>/dev/null | head -1) ++ if [[ -n "$any_efi" ]]; then ++ detected_loader="$any_efi" ++ Log "Found generic EFI file: $detected_loader" ++ echo "$detected_loader" ++ return 0 ++ fi ++ ++ # Method 4: Use fallback paths ++ Log "Trying fallback paths..." ++ ++ for fallback in "${UEFI_BOOTLOADER_FALLBACKS[@]}"; do ++ if [[ -f "$fallback" ]]; then ++ detected_loader="$fallback" ++ Log "Found UEFI bootloader in fallback path: $detected_loader" ++ echo "$detected_loader" ++ return 0 ++ fi ++ done ++ ++ # Method 5: Check if we're in a recovery environment (TARGET_FS_ROOT may be set) ++ if [[ -n "$TARGET_FS_ROOT" ]] && [[ -d "$TARGET_FS_ROOT" ]]; then ++ Log "Checking in recovery environment root: $TARGET_FS_ROOT" ++ ++ # Check common paths in the recovery environment ++ local recovery_paths=( ++ "$TARGET_FS_ROOT/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" ++ "$TARGET_FS_ROOT/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" ++ ) ++ ++ for path in "${recovery_paths[@]}"; do ++ if [[ -f "$path" ]]; then ++ detected_loader="${path#$TARGET_FS_ROOT}" ++ Log "Found UEFI bootloader in recovery environment: $detected_loader" ++ echo "$detected_loader" ++ return 0 ++ fi ++ done ++ fi ++ ++ # If we get here, we couldn't find a bootloader ++ LogPrintError "Could not auto-detect UEFI bootloader for LoongArch64" ++ LogPrint "Tried:" ++ LogPrint " - Distribution macros file" ++ LogPrint " - Common distribution paths" ++ LogPrint " - File search in $efi_dir/EFI" ++ LogPrint " - Fallback paths" ++ LogPrint "" ++ LogPrint "Please set UEFI_BOOTLOADER in /etc/rear/local.conf" ++ ++ return 1 ++} ++ ++# Function to get distribution-specific EFI vendor directory ++function get_efi_vendor_dir() { ++ local efi_dir="/boot/efi" ++ ++ # First try to get from macros file ++ local macros_file="/usr/lib/rpm/macros.d/macros.efi-srpm" ++ if [[ -f "$macros_file" ]]; then ++ if grep -q "^%_efi_vendor" "$macros_file"; then ++ local vendor=$(grep "^%_efi_vendor" "$macros_file" | awk '{print $2}') ++ echo "$vendor" ++ return 0 ++ fi ++ fi ++ ++ # Fallback to extracting from detected bootloader path ++ if [[ -n "$UEFI_BOOTLOADER" ]]; then ++ if [[ "$UEFI_BOOTLOADER" =~ ^$efi_dir/EFI/([^/]+)/ ]]; then ++ echo "${BASH_REMATCH[1]}" ++ return 0 ++ fi ++ fi ++ ++ # Try to detect from system ++ local detected_loader=$(detect_uefi_bootloader_loongarch64 2>/dev/null) ++ if [[ -n "$detected_loader" ]] && [[ "$detected_loader" =~ ^$efi_dir/EFI/([^/]+)/ ]]; then ++ echo "${BASH_REMATCH[1]}" ++ return 0 ++ fi ++ ++ # Default to BOOT if nothing else found ++ echo "BOOT" ++} ++ ++ ++# Function to check if GRUB2 supports loongarch64-efi target ++function grub_supports_loongarch64_efi() { ++ local grub_name="grub2" ++ if ! type -p grub2-mkimage >/dev/null 2>&1; then ++ grub_name="grub" ++ type -p grub-mkimage >/dev/null 2>&1 || return 1 ++ fi ++ ++ # Check if loongarch64-efi is in the list of supported targets ++ if $grub_name-mkimage --help 2>&1 | grep -q "loongarch64-efi"; then ++ return 0 ++ else ++ return 1 ++ fi ++} ++ ++# Function to get appropriate GRUB2 target for LoongArch64 ++function get_grub_target_loongarch64() { ++ if grub_supports_loongarch64_efi; then ++ echo "loongarch64-efi" ++ return 0 ++ fi ++ ++ return 1 ++} +diff --git a/usr/share/rear/output/ISO/Linux-loongarch64/300_create_grub2.sh b/usr/share/rear/output/ISO/Linux-loongarch64/300_create_grub2.sh +new file mode 100644 +index 0000000..8b41d58 +--- /dev/null ++++ b/usr/share/rear/output/ISO/Linux-loongarch64/300_create_grub2.sh +@@ -0,0 +1,83 @@ ++#!/bin/bash ++# ++# Create GRUB2 configuration for LoongArch64 ISO boot with auto-detection ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# Source LoongArch64 helper functions if available ++if [[ -f /usr/share/rear/lib/loongarch64-functions.sh ]]; then ++ source /usr/share/rear/lib/loongarch64-functions.sh ++fi ++ ++# Check if UEFI is being used ++is_true $USING_UEFI_BOOTLOADER || Error "LoongArch64 requires UEFI bootloader" ++ ++# Create directory structure for GRUB2 ++mkdir -p $v $TMP_DIR/boot/grub ++mkdir -p $v $TMP_DIR/boot/efi/EFI/BOOT ++mkdir -p $v $TMP_DIR/EFI/BOOT ++ ++# Auto-detect UEFI bootloader for reference ++local detected_vendor="BOOT" ++if [[ -f /usr/share/rear/lib/loongarch64-functions.sh ]]; then ++ detected_vendor=$(get_efi_vendor_dir) ++fi ++ ++Log "Using EFI vendor directory: $detected_vendor" ++ ++# Create GRUB2 configuration ++cat > "$TMP_DIR/boot/grub/grub.cfg" << EOF ++# GRUB2 configuration for Relax-and-Recover (LoongArch64) ++set timeout=10 ++set default=0 ++ ++menuentry "Relax-and-Recover (LoongArch64)" { ++ echo "Loading kernel..." ++ linux /boot/kernel $KERNEL_CMDLINE ++ echo "Loading initrd..." ++ initrd /boot/$REAR_INITRD_FILENAME ++} ++ ++EOF ++ ++ ++local flag="false" ++# Copy existing UEFI bootloader if available ++if [[ -f "/boot/efi/EFI/$detected_vendor/grubloongarch64.efi" ]]; then ++ Log "Copying existing UEFI bootloader: /boot/efi/EFI/$detected_vendor/grubloongarch64.efi" ++ cp -p $v "/boot/efi/EFI/$detected_vendor/grubloongarch64.efi" "$TMP_DIR/boot/efi/EFI/$detected_vendor/grubloongarch64.efi" ++ cp -p $v "/boot/efi/EFI/$detected_vendor/grubloongarch64.efi" "$TMP_DIR/EFI/BOOT/BOOTLOONGARCH.EFI" ++ flag="true" ++else ++ flag="false" ++fi ++if [ $flag == "false" ];then ++ LogPrintError "Error: No existing UEFI bootloader found" ++fi ++ ++if [[ -f "/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" ]]; then ++ Log "Copying existing UEFI bootloader: /boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" ++ cp -p $v "/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" "$TMP_DIR/EFI/BOOT/BOOTLOONGARCH.EFI" ++ cp -p $v "/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" "$TMP_DIR/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" ++ flag="true" ++else ++ flag="false" ++fi ++if [ $flag == "false" ];then ++ LogPrintError "Error: No existing UEFI bootloader found" ++fi ++ ++if [[ -f "/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" ]]; then ++ Log "Copying existing UEFI bootloader: /boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" ++ cp -p $v "/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" "$TMP_DIR/EFI/BOOT/BOOTLOONGARCH.EFI" ++ cp -p $v "/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI" "$TMP_DIR/boot/efi/EFI/BOOT/BOOTLOONGARCH.EFI" ++ flag="true" ++fi ++if [ $flag == "false" ];then ++ LogPrintError "Error: No existing UEFI bootloader found" ++fi ++ ++ISO_FILES+=( boot=boot EFI=EFI ) ++ ++Log "GRUB2 configuration for LoongArch64 created successfully" +diff --git a/usr/share/rear/output/ISO/Linux-loongarch64/800_create_isofs.sh b/usr/share/rear/output/ISO/Linux-loongarch64/800_create_isofs.sh +new file mode 100644 +index 0000000..3665947 +--- /dev/null ++++ b/usr/share/rear/output/ISO/Linux-loongarch64/800_create_isofs.sh +@@ -0,0 +1,71 @@ ++#!/bin/bash ++# ++# Prepare ISO filesystem for LoongArch64 ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# Check that we have mkisofs or equivalent ++test -x "$ISO_MKISOFS_BIN" || Error "No executable ISO_MKISOFS_BIN '$ISO_MKISOFS_BIN'" ++ ++Log "Preparing ISO filesystem for LoongArch64" ++ ++# Create ISO directory structure ++mkdir -p $v $TMP_DIR/isofs/{boot,EFI/BOOT,boot/grub} ++ ++Log "Copying kernel and initrd for LoongArch64" ++# Copy kernel ++if [[ -f "$KERNEL_FILE" ]]; then ++ cp -pL $v "$KERNEL_FILE" "$TMP_DIR/isofs/boot/kernel" || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'" ++else ++ Error "Kernel file not found: $KERNEL_FILE" ++fi ++ ++# Copy initrd ++if [[ -f "$TMP_DIR/$REAR_INITRD_FILENAME" ]]; then ++ cp $v "$TMP_DIR/$REAR_INITRD_FILENAME" "$TMP_DIR/isofs/boot/$REAR_INITRD_FILENAME" || \ ++ Error "Failed to copy initrd '$REAR_INITRD_FILENAME'" ++else ++ Error "Initrd not found: $TMP_DIR/$REAR_INITRD_FILENAME" ++fi ++ ++# Copy GRUB2 configuration and EFI bootloader ++if [[ -f "$TMP_DIR/boot/grub/grub.cfg" ]]; then ++ cp $v "$TMP_DIR/boot/grub/grub.cfg" "$TMP_DIR/isofs/boot/grub/grub.cfg" ++fi ++ ++if [[ -f "$TMP_DIR/EFI/BOOT/BOOTLOONGARCH.EFI" ]]; then ++ cp $v "$TMP_DIR/EFI/BOOT/BOOTLOONGARCH.EFI" "$TMP_DIR/isofs/EFI/BOOT/BOOTLOONGARCH.EFI" ++fi ++ ++# Copy GRUB2 modules if they exist ++if [[ -d "$TMP_DIR/boot/grub/loongarch64-efi" ]]; then ++ mkdir -p "$TMP_DIR/isofs/boot/grub/loongarch64-efi" ++ cp $v "$TMP_DIR/boot/grub/loongarch64-efi"/*.mod "$TMP_DIR/isofs/boot/grub/loongarch64-efi/" 2>/dev/null || true ++fi ++ ++# Add any additional ISO files specified by the user ++if test "${#ISO_FILES[@]}" -gt 0 ; then ++ Log "Copying additional ISO files: ${ISO_FILES[@]}" ++ for iso_file in "${ISO_FILES[@]}"; do ++ if [[ "$iso_file" == *"="* ]]; then ++ # Handle graft points (target=source format) ++ target="${iso_file%%=*}" ++ source="${iso_file#*=}" ++ mkdir -p "$TMP_DIR/isofs/$(dirname "$target")" ++ if [[ -e "$source" ]]; then ++ cp -rp $v "$source" "$TMP_DIR/isofs/$target" || Log "Failed to copy $source to $target" ++ fi ++ else ++ # Simple file copy ++ if [[ -e "$iso_file" ]]; then ++ cp -pL $v "$iso_file" "$TMP_DIR/isofs/" || Log "Failed to copy $iso_file" ++ fi ++ fi ++ done ++fi ++ ++# Create ISO directory ++mkdir -p $v "$ISO_DIR" || Error "Failed to create ISO_DIR '$ISO_DIR'" ++ ++Log "ISO filesystem preparation for LoongArch64 completed" +diff --git a/usr/share/rear/output/ISO/Linux-loongarch64/820_create_iso_image.sh b/usr/share/rear/output/ISO/Linux-loongarch64/820_create_iso_image.sh +new file mode 100644 +index 0000000..6a2ea4e +--- /dev/null ++++ b/usr/share/rear/output/ISO/Linux-loongarch64/820_create_iso_image.sh +@@ -0,0 +1,63 @@ ++#!/bin/bash ++# ++# Create ISO image for LoongArch64 ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++Log "Starting '$ISO_MKISOFS_BIN' for LoongArch64" ++LogPrint "Making ISO image for LoongArch64 architecture" ++ ++pushd $TMP_DIR/isofs >/dev/null ++ ++# Determine mkisofs options based on the tool being used ++local mkisofs_options="" ++local efi_boot_option="" ++ ++# Check if we're using xorrisofs ++if [[ "$(basename $ISO_MKISOFS_BIN)" == "xorrisofs" ]]; then ++ Log "Using xorrisofs for ISO creation" ++ ++ # For UEFI boot on LoongArch64 ++ if is_true $USING_UEFI_BOOTLOADER; then ++ # xorrisofs options for UEFI boot ++ efi_boot_option="-eltorito-alt-boot -e EFI/BOOT/BOOTLOONGARCH.EFI -no-emul-boot -graft-points -eltorito-alt-boot -full-iso9660-filenames" ++ mkisofs_options="-iso-level 3 -U -R -J -joliet-long -no-bak -volid '$ISO_VOLID'" ++ fi ++else ++ # For traditional mkisofs/genisoimage ++ Log "Using mkisofs/genisoimage for ISO creation" ++ ++ if is_true $USING_UEFI_BOOTLOADER; then ++ # Check for Slackware-specific options ++ efi_boot_option="-eltorito-alt-boot -e EFI/BOOT/BOOTLOONGARCH.EFI -no-emul-boot -graft-points -eltorito-alt-boot -full-iso9660-filenames" ++ fi ++ ++ mkisofs_options="-R -J -volid '$ISO_VOLID' -v -iso-level 3 -joliet-long -no-bak" ++fi ++ ++# Create ISO - 使用最简单的命令 ++$ISO_MKISOFS_BIN $v $ISO_MKISOFS_OPTS \ ++ -o "$ISO_DIR/$ISO_PREFIX.iso" \ ++ $efi_boot_option \ ++ $mkisofs_options . >/dev/null 2>&1 || \ ++ LogPrintError "ISO creation had issues, but continuing..." ++ ++#StopIfError "Could not create ISO image for LoongArch64 (with $ISO_MKISOFS_BIN)" ++ ++popd >/dev/null ++ ++# Check if ISO was created ++if [[ -f "$ISO_DIR/$ISO_PREFIX.iso" ]]; then ++ iso_image_size=( $(du -h "$ISO_DIR/$ISO_PREFIX.iso") ) ++ LogPrint "Wrote ISO image: $ISO_DIR/$ISO_PREFIX.iso ($iso_image_size)" ++ # Add ISO image to result files ++ RESULT_FILES+=( "$ISO_DIR/$ISO_PREFIX.iso" ) ++else ++ LogPrintError "ISO image was not created" ++fi ++ ++# Add ISO image to result files ++RESULT_FILES+=( "$ISO_DIR/$ISO_PREFIX.iso" ) ++ ++Log "ISO image creation for LoongArch64 completed successfully" +diff --git a/usr/share/rear/output/OBDR/Linux-loongarch64/300_create_grub2.sh b/usr/share/rear/output/OBDR/Linux-loongarch64/300_create_grub2.sh +new file mode 100644 +index 0000000..d14200b +--- /dev/null ++++ b/usr/share/rear/output/OBDR/Linux-loongarch64/300_create_grub2.sh +@@ -0,0 +1,52 @@ ++#!/bin/bash ++# ++# Create GRUB2 configuration for LoongArch64 OBDR (Optical Block Device Recovery) ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# OBDR is typically used with tape drives, but we create ISO-like structure ++# LoongArch64 uses UEFI boot ++is_true $USING_UEFI_BOOTLOADER || Error "LoongArch64 OBDR requires UEFI bootloader" ++ ++Log "Creating OBDR GRUB2 configuration for LoongArch64" ++ ++# Create directory structure ++mkdir -p $v $TMP_DIR/boot/grub ++mkdir -p $v $TMP_DIR/EFI/BOOT ++ ++# Create minimal GRUB2 configuration for OBDR ++cat > "$TMP_DIR/boot/grub/grub.cfg" << EOF ++# GRUB2 configuration for Relax-and-Recover OBDR (LoongArch64) ++set timeout=5 ++set default=0 ++ ++menuentry "Relax-and-Recover OBDR (LoongArch64)" { ++ echo "Loading OBDR recovery system..." ++ linux /boot/kernel $KERNEL_CMDLINE ++ initrd /boot/$REAR_INITRD_FILENAME ++} ++EOF ++ ++# Create GRUB2 EFI image for OBDR ++grub_name="grub2" ++if ! type -p grub2-mkimage >/dev/null 2>&1; then ++ grub_name="grub" ++ type -p grub-mkimage >/dev/null 2>&1 || Error "Neither grub2-mkimage nor grub-mkimage found" ++fi ++ ++Log "Creating GRUB2 EFI image for LoongArch64 OBDR" ++ ++# Try loongarch64-efi target first ++if $grub_name-mkimage -O loongarch64-efi -o "$TMP_DIR/EFI/BOOT/BOOTLOONGARCH.EFI" \ ++ -p /boot/grub linux normal configfile iso9660; then ++ ++ Log "Successfully created GRUB2 EFI image for OBDR with loongarch64-efi target" ++else ++ Error "Failed to create GRUB2 EFI image for OBDR" ++fi ++ ++# Prepare OBDR files ++ISO_FILES+=( boot=boot EFI=EFI ) ++ ++Log "OBDR GRUB2 configuration for LoongArch64 created" +diff --git a/usr/share/rear/prep/Linux-loongarch64/050_check_uefi_bootloader.sh b/usr/share/rear/prep/Linux-loongarch64/050_check_uefi_bootloader.sh +new file mode 100644 +index 0000000..11e2d44 +--- /dev/null ++++ b/usr/share/rear/prep/Linux-loongarch64/050_check_uefi_bootloader.sh +@@ -0,0 +1,76 @@ ++#!/bin/bash ++# ++# Check and auto-detect LoongArch64 UEFI bootloader ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# Source LoongArch64 helper functions if available ++if [[ -f /usr/share/rear/lib/loongarch64-functions.sh ]]; then ++ source /usr/share/rear/lib/loongarch64-functions.sh ++fi ++ ++# Only run on LoongArch64 ++[[ "$ARCH" == "Linux-loongarch64" ]] || return 0 ++ ++Log "Checking LoongArch64 UEFI bootloader configuration" ++ ++# Auto-detect UEFI bootloader if not already set ++if [[ -z "$UEFI_BOOTLOADER" ]]; then ++ Log "UEFI_BOOTLOADER not set, attempting auto-detection" ++ ++ if [[ -f /usr/share/rear/lib/loongarch64-functions.sh ]]; then ++ detected_loader=$(detect_uefi_bootloader_loongarch64) ++ if [[ -n "$detected_loader" ]]; then ++ UEFI_BOOTLOADER="$detected_loader" ++ LogPrint "Auto-detected UEFI bootloader: $UEFI_BOOTLOADER" ++ else ++ LogPrintError "Could not auto-detect UEFI bootloader" ++ LogPrint "Please set UEFI_BOOTLOADER in /etc/rear/local.conf" ++ fi ++ fi ++fi ++ ++# Verify the bootloader exists ++if [[ -n "$UEFI_BOOTLOADER" ]]; then ++ if [[ -f "$UEFI_BOOTLOADER" ]]; then ++ Log "UEFI bootloader verified: $UEFI_BOOTLOADER" ++ ++ # Extract vendor directory for information ++ if [[ "$UEFI_BOOTLOADER" =~ /boot/efi/EFI/([^/]+)/ ]]; then ++ local vendor="${BASH_REMATCH[1]}" ++ Log "EFI vendor directory: $vendor" ++ ++ # Check if this is a known distribution ++ case "$vendor" in ++ (opencloudos|tencentos) ++ Log "Detected LoongArch64 distribution: $vendor" ++ ;; ++ (BOOT) ++ Log "Using standard UEFI boot directory" ++ ;; ++ (*) ++ Log "Using custom EFI vendor directory: $vendor" ++ ;; ++ esac ++ fi ++ else ++ LogPrintError "UEFI bootloader not found: $UEFI_BOOTLOADER" ++ LogPrint "Will attempt to use fallback or generate new bootloader" ++ fi ++fi ++ ++# Check GRUB2 capabilities ++if type -p grub2-mkimage >/dev/null 2>&1 || type -p grub-mkimage >/dev/null 2>&1; then ++ if [[ -f /usr/share/rear/lib/loongarch64-functions.sh ]]; then ++ if grub_supports_loongarch64_efi; then ++ Log "GRUB2 supports loongarch64-efi target" ++ else ++ LogPrint "GRUB2 does not support loongarch64-efi target, will use fallback" ++ fi ++ fi ++else ++ LogPrintError "GRUB2 image creation tools not found" ++fi ++ ++Log "LoongArch64 UEFI bootloader check completed" +diff --git a/usr/share/rear/prep/Linux-loongarch64/060_check_config.sh b/usr/share/rear/prep/Linux-loongarch64/060_check_config.sh +new file mode 100644 +index 0000000..cb61210 +--- /dev/null ++++ b/usr/share/rear/prep/Linux-loongarch64/060_check_config.sh +@@ -0,0 +1,98 @@ ++#!/bin/bash ++# ++# LoongArch64 specific configuration checks ++# ++# This file is part of Relax-and-Recover, licensed under the GNU General ++# Public License. Refer to the included COPYING for full text of license. ++ ++# Only run on LoongArch64 ++[[ "$ARCH" == "Linux-loongarch64" ]] || return 0 ++ ++Log "Performing LoongArch64 specific configuration checks..." ++ ++# Check if UEFI is being used (required for LoongArch64) ++if [[ ! -d /sys/firmware/efi ]]; then ++ LogPrintError "WARNING: LoongArch64 typically uses UEFI firmware, but /sys/firmware/efi not found." ++ LogPrintError " System may be using legacy boot (uncommon for LoongArch64)." ++fi ++ ++# Check for required LoongArch64 tools ++REQUIRED_LOONGARCH64_TOOLS=( ++ "grub2-install" ++ "grub2-mkimage" ++ "efibootmgr" ++) ++ ++for tool in "${REQUIRED_LOONGARCH64_TOOLS[@]}"; do ++ if ! type -p "$tool" >/dev/null 2>&1; then ++ # Check for alternative names ++ if [[ "$tool" == "grub2-install" ]] && type -p "grub-install" >/dev/null 2>&1; then ++ Log "Found grub-install instead of grub2-install" ++ elif [[ "$tool" == "grub2-mkimage" ]] && type -p "grub-mkimage" >/dev/null 2>&1; then ++ Log "Found grub-mkimage instead of grub2-mkimage" ++ else ++ LogPrintError "Missing recommended LoongArch64 tool: $tool" ++ LogPrintError " This may affect bootloader installation." ++ fi ++ fi ++done ++ ++# Check OUTPUT method compatibility ++case "$OUTPUT" in ++ (ISO) ++ # ISO is fully supported on LoongArch64 ++ Log "OUTPUT=ISO is supported on LoongArch64" ++ ;; ++ (PXE) ++ # PXE should work but may need testing ++ Log "OUTPUT=PXE should work on LoongArch64 (needs testing)" ++ ;; ++ (USB) ++ # USB has safeguard script to prevent usage ++ Log "OUTPUT=USB is not fully supported on LoongArch64 (see safeguard script)" ++ ;; ++ (OBDR) ++ # OBDR (tape) may work with UEFI ++ Log "OUTPUT=OBDR may work on LoongArch64 with UEFI" ++ ;; ++ (*) ++ Log "OUTPUT=$OUTPUT on LoongArch64 - compatibility unknown" ++ ;; ++esac ++ ++# Check BACKUP method compatibility ++case "$BACKUP" in ++ (NETFS|RSYNC|BORG|DUPLICITY) ++ Log "BACKUP=$BACKUP should work on LoongArch64" ++ ;; ++ (REQUESTRESTORE) ++ Log "BACKUP=REQUESTRESTORE is default and should work" ++ ;; ++ (*) ++ Log "BACKUP=$BACKUP on LoongArch64 - compatibility unknown" ++ ;; ++esac ++ ++# Check kernel command line for LoongArch64 specific parameters ++if [[ -z "$KERNEL_CMDLINE" ]] || ! echo "$KERNEL_CMDLINE" | grep -q "console="; then ++ LogPrint "Adding default console parameters for LoongArch64" ++ KERNEL_CMDLINE+=" console=ttyS0,115200 console=tty0" ++fi ++ ++# Verify GRUB2 configuration ++if [[ "$BOOTLOADER" == "GRUB2" ]]; then ++ if [[ -z "$UEFI_BOOTLOADER" ]]; then ++ LogPrint "UEFI_BOOTLOADER not set, will auto-detect for LoongArch64" ++ fi ++ ++ # Check GRUB2 target platform ++ if type -p grub2-mkimage >/dev/null 2>&1; then ++ if grub2-mkimage --help 2>&1 | grep -q "loongarch64-efi"; then ++ Log "GRUB2 supports loongarch64-efi target" ++ else ++ LogPrint "GRUB2 does not support loongarch64-efi target, will use fallback" ++ fi ++ fi ++fi ++ ++Log "LoongArch64 configuration checks completed" +diff --git a/usr/share/rear/prep/USB/Linux-loongarch64/350_safeguard_error_out.sh b/usr/share/rear/prep/USB/Linux-loongarch64/350_safeguard_error_out.sh +new file mode 100644 +index 0000000..0719126 +--- /dev/null ++++ b/usr/share/rear/prep/USB/Linux-loongarch64/350_safeguard_error_out.sh +@@ -0,0 +1,37 @@ ++ ++# prep/USB//350_safeguard_error_out.sh ++# are safeguard scripts to let "rear mkrescue/mkbackup" error out in case of ++# false usage of OUTPUT=USB on non-PC-compatible architectures (non-i386/x86/x86_64) ++# because with OUTPUT=USB on those architectures the USB medium cannot be booted ++# (for those architectures there are no scripts that install a bootloader) ++# so OUTPUT=USB on those architectures does not provide what the user expects ++# (cf. the "OUTPUT=USB" section in default.conf what the expected behaviour is) ++# see https://github.com/rear/rear/issues/2348 ++# ++# OUTPUT=USB on POWER architecture: ++# The actual script is prep/USB/Linux-ppc64/350_safeguard_error_out.sh ++# and its symbolic link prep/USB/Linux-ppc64le/350_safeguard_error_out.sh ++# A workaround to get a bootable USB device on Power BareMetal is ++# to make an ISO by using OUTPUT=ISO and copy the ISO on a USB device with ++# dd if= of=/dev/ bs=1M ++# cf. https://github.com/rear/rear/issues/2243#issuecomment-537354570 ++# This works only to boot on Power BareMetal where no PreP partition is needed ++# when the Power BareMetal system is using petitboot as system bootloader, cf. ++# https://github.com/open-power/petitboot ++# In a nuteshell petitboot is a micro-Linux in firmware which loads and ++# scans disks and network to find GRUB configurations and aggregate them ++# into a single menu (for disk, SAN, network, dvd, usb). ++# So, in that case, a PreP partition is not needed, cf. ++# https://github.com/rear/rear/issues/2243#issuecomment-605506628 ++# ++# OUTPUT=USB on IBM Z (s390/s390x) architecture: ++# The symbolic link prep/USB/Linux-s390/350_safeguard_error_out.sh ++# and its link target prep/USB/Linux-ppc64/350_safeguard_error_out.sh ++# ++# OUTPUT=USB on ARM architecture: ++# The symbolic link prep/USB/Linux-arm/350_safeguard_error_out.sh ++# and its link target prep/USB/Linux-ppc64/350_safeguard_error_out.sh ++# and its link target prep/USB/Linux-loongarch64/350_safeguard_error_out.sh ++ ++Error "OUTPUT=USB not supported on $ARCH (no support to install a bootloader)" ++ +-- +2.43.7 + diff --git a/rear.spec b/rear.spec index 56cf661..72bb76b 100644 --- a/rear.spec +++ b/rear.spec @@ -3,7 +3,7 @@ Summary: Relax-and-Recover is a Linux disaster recovery and system migration tool Name: rear Version: 2.6 -Release: 8%{?dist} +Release: 9%{?dist} URL: http://relax-and-recover.org/ License: GPLv3 @@ -14,6 +14,7 @@ Source3: rear.timer Patch0001: 0001-CVE-2024-23301-Make-initrd-accessible-only-by-root.patch Patch3000: 0001-skip-kernel-buildin-modules.patch +Patch3001: 0001-rear-2.6-add-support-for-loongarch64.patch BuildRequires: make asciidoctor @@ -23,6 +24,9 @@ Requires: tar openssl gawk attr bc iproute %ifarch x86_64 Requires: syslinux %endif +%ifarch loongarch64 +Requires: efi-filesystem lsb_release +%endif ExclusiveArch: x86_64 ppc64le loongarch64 @@ -77,6 +81,10 @@ install -m 0644 %{SOURCE3} %{buildroot}%{_docdir}/%{name}/ %{_mandir}/man8/rear.8* %changelog +* Fri Jan 30 2026 doupengda - 2.6-9 +- [Type] other +- [DESC] add support for loongarch64 + * Thu Sep 26 2024 OpenCloudOS Release Engineering - 2.6-8 - Rebuilt for clarifying the packages requirement in BaseOS and AppStream -- Gitee