:: commit 40cbbe5dcba562ce4d810bc81e16e6d568b745ea

mintsuki <mintsuki@protonmail.com> — 2022-04-15 14:40

parents: 18fc320925

limine-deploy: Auto set an MBR partition as active if none found

diff --git a/limine-install/limine-install.c b/limine-install/limine-install.c
index 40ae61b2..1a7dc200 100644
--- a/limine-install/limine-install.c
+++ b/limine-install/limine-install.c
@@ -498,6 +498,25 @@ int main(int argc, char *argv[]) {
         goto cleanup;
     }
 
+    bool any_active = false;
+    uint8_t hint8;
+
+    device_read(&hint8, 446, sizeof(uint8_t));
+    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
+    device_read(&hint8, 462, sizeof(uint8_t));
+    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
+    device_read(&hint8, 478, sizeof(uint8_t));
+    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
+    device_read(&hint8, 494, sizeof(uint8_t));
+    any_active = any_active ? any_active : (hint8 & 0x80) != 0;
+
+    if (!any_active) {
+        fprintf(stderr, "No active MBR partition found, some systems may not boot.\n");
+        fprintf(stderr, "Setting partition 1 as active to work around the issue...\n");
+        hint8 = 0x80;
+        device_write(&hint8, 446, sizeof(uint8_t));
+    }
+
     size_t   stage2_size   = bootloader_file_size - 512;
 
     size_t   stage2_sects  = DIV_ROUNDUP(stage2_size, 512);
tab: 248 wrap: offon