Improve output and README for BootOrder problems

Report own entry status (missing, disabled, after windows, enabled).
Also improve README instructions on the topic.
This commit is contained in:
Lauri Kenttä
2025-04-12 09:13:12 +03:00
parent ffa3e335ea
commit 611ab30db3
4 changed files with 70 additions and 27 deletions

View File

@@ -99,11 +99,11 @@ Sometimes the first boot is very slow (multiple minutes) for an unknown reason.
### Image is not visible, "nothing happens" ### Image is not visible, "nothing happens"
Run the setup again and select the option to check the boot log. Continue troubleshooting according to the log contents: Run the setup again and select the option to check the boot log, marked with `BOOT LOG START` in the log file. Continue troubleshooting according to the log contents:
#### Log is empty #### Boot log is empty
If the log is empty, then HackBGRT is not in use. Many computers now have a security feature which causes this problem: the computer resets some settings on reboot and skips the newly-installed HackBGRT. If the log is empty, then HackBGRT is not in use. Many computers now have a security feature which causes this problem: the computer prevents enabling HackBGRT automatically, instead it resets a certain setting (BootOrder) on reboot and skips the newly-installed HackBGRT.
You have to fix this manually. (After all, the security feature is specifically designed to prevent automatic changes.) You have to fix this manually. (After all, the security feature is specifically designed to prevent automatic changes.)
@@ -119,13 +119,15 @@ Some people report that HackBGRT is not visible in the computer settings. That's
If all else fails and you are sure about your computer skills, you can try the legacy installation method. The method bypasses this particular problem but may cause very serious problems if configured incorrectly. If all else fails and you are sure about your computer skills, you can try the legacy installation method. The method bypasses this particular problem but may cause very serious problems if configured incorrectly.
#### Log is not empty #### Boot log is not empty
Try to reinstall HackBGRT with the default configuration and image. If the log shows that HackBGRT has been run during boot, the problem is usually in your configuration file or image. Try to reinstall HackBGRT with the default configuration and image.
If the default logo works, try again with your custom image. Make sure that the image has a reasonable size and position and that you haven't messed up `config.txt`. If the default logo works, try again with your custom image. Make sure that the image has a reasonable size and position so that it fits the resolution which HackBGRT reports during boot. The resolution may be lower than your desktop resolution.
If the default logo does not work, check the boot log again. When you get your image working with the default configuration, you can do any other necessary changes to `config.txt`.
If the default logo does not work, check the boot log again to see if there is some obvious error.
You may report an issue and attach the `setup.log` file. You may report an issue and attach the `setup.log` file.
### Impossible to boot at all ### Impossible to boot at all

View File

@@ -264,13 +264,13 @@ public class Efi {
try { try {
var log = GetVariable("HackBGRTLog", EFI_HACKBGRT_GUID); var log = GetVariable("HackBGRTLog", EFI_HACKBGRT_GUID);
if (log.Data == null) { if (log.Data == null) {
return "Log is empty."; return "Boot log is empty.";
} }
return new string(BytesToUInt16s(log.Data).Select(i => (char)i).ToArray()); return new string(BytesToUInt16s(log.Data).Select(i => (char)i).ToArray());
} catch (NotImplementedException e) { } catch (NotImplementedException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
return $"Log not found: {e.ToString()}"; return $"Boot log not found: {e.ToString()}";
} }
} }

View File

@@ -90,6 +90,16 @@ public class EfiBootEntries {
} }
} }
/**
* Status of the own boot entry.
*/
public enum OwnEntryStatus {
NotFound,
Disabled,
EnabledAfterWindows,
Enabled
}
/** /**
* Path to the Windows boot loader. * Path to the Windows boot loader.
*/ */
@@ -173,6 +183,26 @@ public class EfiBootEntries {
get { return FindEntry(null); } get { return FindEntry(null); }
} }
/**
* Check if the own entry is enabled.
*/
public OwnEntryStatus GetOwnEntryStatus() {
var (ownNum, ownVar, _) = OwnEntry;
if (ownVar == null) {
return OwnEntryStatus.NotFound;
}
var (msNum, _, _) = WindowsEntry;
var msPos = BootOrderInts.IndexOf(msNum);
var ownPos = BootOrderInts.IndexOf(ownNum);
if (ownPos < 0) {
return OwnEntryStatus.Disabled;
}
if (ownPos < msPos || msPos < 0) {
return OwnEntryStatus.Enabled;
}
return OwnEntryStatus.EnabledAfterWindows;
}
/** /**
* Disable the said boot entry from BootOrder. * Disable the said boot entry from BootOrder.
* *
@@ -295,15 +325,4 @@ public class EfiBootEntries {
} }
} }
} }
/**
* Try to log the boot entries.
*/
public static void TryLogEntries() {
try {
new EfiBootEntries().LogEntries();
} catch (Exception e) {
Setup.Log($"LogEntries failed: {e.ToString()}");
}
}
} }

View File

@@ -482,13 +482,12 @@ public class Setup {
var fwbootmgr = "{fwbootmgr}"; var fwbootmgr = "{fwbootmgr}";
Execute("bcdedit", $"/set {fwbootmgr} displayorder {guid} /addfirst", true); Execute("bcdedit", $"/set {fwbootmgr} displayorder {guid} /addfirst", true);
WriteLine("Enabled NVRAM entry for HackBGRT with BCDEdit."); WriteLine("Enabled NVRAM entry for HackBGRT with BCDEdit.");
// Verify that the entry was created.
Execute("bcdedit", "/enum firmware", true); Execute("bcdedit", $"/enum {guid}", true);
var e = new EfiBootEntries(); var e = new EfiBootEntries();
e.MakeOwnEntry(false, DryRun); // Fix load options for shim. e.MakeOwnEntry(false, DryRun); // Fix load options for shim.
e.EnableOwnEntry(DryRun); e.EnableOwnEntry(DryRun);
Execute("bcdedit", $"/enum {guid}", true); Execute("bcdedit", $"/enum {guid}", true);
e.LogEntries();
} catch (Exception e) { } catch (Exception e) {
Log($"EnableBCDEdit failed: {e.ToString()}"); Log($"EnableBCDEdit failed: {e.ToString()}");
throw new SetupException("Failed to enable HackBGRT with BCDEdit!"); throw new SetupException("Failed to enable HackBGRT with BCDEdit!");
@@ -536,9 +535,6 @@ public class Setup {
e.MakeOwnEntry(true, DryRun); e.MakeOwnEntry(true, DryRun);
e.EnableOwnEntry(DryRun); e.EnableOwnEntry(DryRun);
WriteLine("Enabled NVRAM entry for HackBGRT."); WriteLine("Enabled NVRAM entry for HackBGRT.");
// Verify that the entry was created.
e.LogEntries();
Execute("bcdedit", "/enum firmware", true);
} }
/** /**
@@ -549,6 +545,27 @@ public class Setup {
WriteLine("Disabled NVRAM entry for HackBGRT."); WriteLine("Disabled NVRAM entry for HackBGRT.");
} }
/**
* Log boot entries and report the status of HackBGRT boot entry.
*/
public void CheckEntries() {
try {
var efiBootEntries = new EfiBootEntries();
efiBootEntries.LogEntries();
var entryStatusText = efiBootEntries.GetOwnEntryStatus() switch {
EfiBootEntries.OwnEntryStatus.NotFound => "missing",
EfiBootEntries.OwnEntryStatus.Disabled => "disabled (not in BootOrder)",
EfiBootEntries.OwnEntryStatus.EnabledAfterWindows => "disabled (after Windows in BootOrder)",
EfiBootEntries.OwnEntryStatus.Enabled => "enabled correctly",
_ => throw new SetupException("Unknown HackBGRT boot entry status!")
};
WriteLine($"HackBGRT boot entry is {entryStatusText}.");
} catch (Exception e) {
WriteLine($"Failed to check EFI boot entries: {e.Message}");
Setup.Log(e.ToString());
}
}
/** /**
* Get paths related to MS boot loader. * Get paths related to MS boot loader.
*/ */
@@ -975,8 +992,10 @@ public class Setup {
}; };
var bootLog = tryGetBootLog(); var bootLog = tryGetBootLog();
Setup.Log(bootLog); Setup.Log(bootLog);
Efi.LogBGRT(); Efi.LogBGRT();
EfiBootEntries.TryLogEntries(); CheckEntries();
if (GetBootTime() is DateTime bootTime) { if (GetBootTime() is DateTime bootTime) {
var configTime = new[] { File.GetCreationTime("config.txt"), File.GetLastWriteTime("config.txt") }.Max(); var configTime = new[] { File.GetCreationTime("config.txt"), File.GetLastWriteTime("config.txt") }.Max();
Log($"Boot time = {bootTime}, config.txt changed = {configTime}"); Log($"Boot time = {bootTime}, config.txt changed = {configTime}");
@@ -1008,6 +1027,8 @@ public class Setup {
HandleBitLocker(); HandleBitLocker();
enable(); enable();
verify(revert); verify(revert);
CheckEntries();
Execute("bcdedit", "/enum firmware", true);
}; };
foreach (var arg in actions) { foreach (var arg in actions) {
Log($"Running action '{arg}'."); Log($"Running action '{arg}'.");
@@ -1033,6 +1054,7 @@ public class Setup {
BootToFW(); BootToFW();
} else if (arg == "show-boot-log") { } else if (arg == "show-boot-log") {
WriteLine(bootLog); WriteLine(bootLog);
CheckEntries();
} else { } else {
throw new SetupException($"Invalid action: '{arg}'!"); throw new SetupException($"Invalid action: '{arg}'!");
} }