From f6ee40326b9c6a110a39722ce924f529369a946c Mon Sep 17 00:00:00 2001 From: Vasilito Date: Fri, 17 Apr 2026 23:46:20 +0100 Subject: [PATCH] Fix grub-install BOOT_PATH, validate grub-mkconfig timeout, add fat_tool sync Fix BOOT_PATH logic in grub-install: non-removable installs now use EFI/${BOOTLOADER_ID} per UEFI spec instead of always EFI/BOOT. Add timeout validation to grub-mkconfig (must be non-negative integer). Add sync() method to fat_tool.py and call os.fsync after cp_in to ensure data reaches disk. Fix misleading block-device error message. --- local/scripts/fat_tool.py | 5 +++++ local/scripts/grub-install | 12 +++++++----- local/scripts/grub-mkconfig | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/local/scripts/fat_tool.py b/local/scripts/fat_tool.py index 1e058fff..b4598e32 100644 --- a/local/scripts/fat_tool.py +++ b/local/scripts/fat_tool.py @@ -105,6 +105,10 @@ class Fat32: self.f.seek(self.fat_start + i * self.fat_size * self.bytes_per_sector) self.f.write(self.fat) + def sync(self): + self.f.flush() + os.fsync(self.f.fileno()) + def _cluster_offset(self, cluster): if not 2 <= cluster <= self.max_cluster: raise RuntimeError(f"FAT32: invalid cluster {cluster}") @@ -570,6 +574,7 @@ class Fat32: else: self._add_dir_entry(parent_cluster, file_name, first_cluster, False, len(data)) self.f.flush() + os.fsync(self.f.fileno()) except Exception: if clusters: self._free_cluster_chain(clusters[0]) diff --git a/local/scripts/grub-install b/local/scripts/grub-install index 1e4a3b50..35b8c5a2 100755 --- a/local/scripts/grub-install +++ b/local/scripts/grub-install @@ -241,9 +241,10 @@ if [ -n "$DISK_IMAGE" ]; then ESP_OFFSET=$((2048 * 512)) # Write GRUB to ESP - BOOT_PATH="EFI/BOOT" - if [ "$REMOVABLE" -eq 0 ] && [ -n "$BOOTLOADER_ID" ]; then + if [ "$REMOVABLE" -eq 1 ]; then BOOT_PATH="EFI/BOOT" + else + BOOT_PATH="EFI/${BOOTLOADER_ID}" fi "$FAT_TOOL" mkdir "$DISK_IMAGE" "$ESP_OFFSET" "EFI" 2>/dev/null || true @@ -265,9 +266,10 @@ fi # Mode 2: Full image build via Red Bear installer (INSTALL_DEVICE given) if [ -n "$INSTALL_DEVICE" ]; then - echo "$PROG: installing to $INSTALL_DEVICE via Red Bear installer..." >&2 - echo "$PROG: for Red Bear OS, use: make all CONFIG_NAME=redbear-full-grub" >&2 - echo "$PROG: or: redox_installer -c redbear-full-grub.toml $INSTALL_DEVICE" >&2 + echo "$PROG: block device installation is not supported by this wrapper." >&2 + echo "$PROG: For Red Bear OS, use one of:" >&2 + echo "$PROG: make all CONFIG_NAME=redbear-full-grub" >&2 + echo "$PROG: redox_installer -c redbear-full-grub.toml $INSTALL_DEVICE" >&2 exit 1 fi diff --git a/local/scripts/grub-mkconfig b/local/scripts/grub-mkconfig index e49e7f06..aa39e7ed 100755 --- a/local/scripts/grub-mkconfig +++ b/local/scripts/grub-mkconfig @@ -85,6 +85,10 @@ while [ $# -gt 0 ]; do esac done +case "$TIMEOUT" in + ''|*[!0-9]*) echo "$PROG: invalid timeout '$TIMEOUT' (must be a non-negative integer)" >&2; exit 1;; +esac + generate_config() { cat </dev/null || date)