:: commit 3baa802ff68a0ed3c834679b49d4cba196ce74b5

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

parents: 98b54eaf25

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

diff --git a/limine-deploy/limine-deploy.c b/limine-deploy/limine-deploy.c
index 10ec90b3..b324e949 100644
--- a/limine-deploy/limine-deploy.c
+++ b/limine-deploy/limine-deploy.c
@@ -506,6 +506,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