TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Resources for learning about boot loaders?

102 pointsby rayascottover 7 years ago
I’m trying to find the best resources I can for learning about boot loaders. I recently installed Fedora dual boot on my MacBook Air and want to understand what is happening during the boot process, and why, for example, I’m now staring at a Grub console after resizing my APFS partition.

12 comments

mindcrashover 7 years ago
Realmode assembly - writing bootable stuff:<p><a href="https:&#x2F;&#x2F;0x00sec.org&#x2F;t&#x2F;realmode-assembly-writing-bootable-stuff-part-2&#x2F;2992" rel="nofollow">https:&#x2F;&#x2F;0x00sec.org&#x2F;t&#x2F;realmode-assembly-writing-bootable-stu...</a><p>Writing a bootloader:<p><a href="http:&#x2F;&#x2F;3zanders.co.uk&#x2F;2017&#x2F;10&#x2F;13&#x2F;writing-a-bootloader&#x2F;" rel="nofollow">http:&#x2F;&#x2F;3zanders.co.uk&#x2F;2017&#x2F;10&#x2F;13&#x2F;writing-a-bootloader&#x2F;</a><p>(Both from my HN archive, posted somewhere this year)
yjftsjthsd-hover 7 years ago
Obligatory: <a href="http:&#x2F;&#x2F;wiki.osdev.org&#x2F;Main_Page" rel="nofollow">http:&#x2F;&#x2F;wiki.osdev.org&#x2F;Main_Page</a>
feelin_googleyover 7 years ago
I think looking at the bootloader source is an excellent way to learn. However the more complex the bootloader, IME the less rewarding the time spent reading its source.<p>While Grub is highly well-known, popular, sometimes innovative and of course very flexible, it is also more complicated than I would like and so I am not a user. The primary reason is because of its strategy to locate parts of the bootloader on the media in a way that can vary from one installation to another. The alternative, &quot;standard&quot; approach being to locate all parts of the bootloader in some pre-defined area, usually near the start of the &quot;disk&quot;.<p>The Grub approach obviously has its justifications and advantages. Maybe some see the Grub approach as an advantage because e.g. if one accidentally loses access to an area near the start of the media where most bootloaders historically reside, then one can still potentially recover.<p>However, if understanding the boot process is a goal, I see the Grub approach as a disadvantage. It makes locating and verifying the bootloader more complex when it is fragmented into parts that are potentially scattered around the media instead of located in a pre-defined area near the start of the disk. If one makes changes such as the formatting or partitioning of the disk, are all the fragments from a prior Grub install accounted for? I would prefer not to have to consider that question. Whereas I know how to completely remove&#x2F;reinstall the bootloader if I always know where it will be located.<p>If the goal is to understand the bootloader one is using on a lower level than simply using it, e.g., verifying it is there on the media, I think there are more simple alternatives than Grub.<p>Alas, last time I checked the Linux kernel is still not compliant with the &quot;Multiboot Specification&quot;. This is unfortunate for me because the non-Grub alternative I prefer supports it and it really works well for multibooting. I would love to use it to try booting a Linux kernel. I suspect there is probably a workaround but making the easy choice to use Grub probably obstructs people from experimenting with alternatives.<p>While experimenting years ago, if I remember correctly, I booted a NetBSD kernel using the FreeBSD bootloader (the part written in Forth). I seem to remember this was possible because of compliance with the Multiboot Specification.<p>&quot;One bootloader, many kernels.&quot; (Without chainloading.)
hawskiover 7 years ago
The one I&#x27;m using at the moment: <a href="https:&#x2F;&#x2F;www.rodsbooks.com&#x2F;efi-bootloaders&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;www.rodsbooks.com&#x2F;efi-bootloaders&#x2F;index.html</a><p>It is still maintained and updated. It covers most not loaders out there in context of Linux. It is also very practical.
评论 #15983879 未加载
评论 #15982416 未加载
评论 #15983016 未加载
peterkellyover 7 years ago
This is what first got me started, and I highly recommend it:<p><a href="http:&#x2F;&#x2F;www.brokenthorn.com&#x2F;Resources&#x2F;OSDevIndex.html" rel="nofollow">http:&#x2F;&#x2F;www.brokenthorn.com&#x2F;Resources&#x2F;OSDevIndex.html</a>
评论 #15983005 未加载
cmurfover 7 years ago
General purpose understanding probably won&#x27;t help you with the specific problem you&#x27;re having. I know quite a bit about the user space foils of your situation with Apple&#x27;s EFI firmware, the NVRAM boot entries that point to the bootloader, GRUB2, and the peculiarities of Fedora&#x27;s installer. And there is really nothing standard about it..<p>a. Fedora&#x27;s installer, only on Macs, creates a 2nd &quot;EFI System partition&quot; that&#x27;s HFS+ formatted. And that&#x27;s because Apple&#x27;s EFI firmware can read HFS+ directly, and it enables showing Fedora as a boot option when you boot with the option key held down. This doesn&#x27;t happen if the bootloader is on the &quot;real&quot; FAT32 EFI system partition, which hilariously Apple doesn&#x27;t use for booting either, they only use it for staging firmware updates.<p>Right out of the gate you&#x27;re in the weeds of super esoteric stuff...<p>b. That you get a GRUB prompt means the firmware found the GRUB EFI OS Loader binary, which is on that HFS+ faux-EFI System partition. In that same directory should be the grub.cfg, which it should read automatically and display a menu of kernels to boot. Therefore, the GRUB prompt also means the OS Loader isn&#x27;t finding the grub.cfg.<p>So you have something of a mystery on your hands and it&#x27;ll take an autopsy to find out what&#x27;s going on. First thing would be to use one of the netinstallers (any Fedora edition netinstall image) put onto a USB stick, boot that with the option key, choose Troubleshooting, then Rescue a Fedora system, wait for boot process, pick the first option to find and assemble the system. And then you&#x27;ll<p><pre><code> chroot &#x2F;mnt&#x2F;sysimage grub2-mkconfig -o &#x2F;boot&#x2F;efi&#x2F;EFI&#x2F;fedora&#x2F;grub.cfg exit reboot </code></pre> That should work unless there are extenuating circumstances (some other distro&#x27;s GRUB is somewhere on this system). But I still don&#x27;t really understand how APFS resize can affect the grub.cfg alone, without nerfing the entire HFS+ faux-ESP as well, in which case you wouldn&#x27;t have a GRUB prompt.
评论 #15982982 未加载
评论 #15989528 未加载
评论 #15983912 未加载
评论 #15983285 未加载
josefbacikover 7 years ago
I spent an unreasonable amount of time working on grub2. The stuff I looked at the most where the uefi spec<p><a href="http:&#x2F;&#x2F;wiki.phoenix.com&#x2F;wiki&#x2F;index.php&#x2F;Category:UEFI" rel="nofollow">http:&#x2F;&#x2F;wiki.phoenix.com&#x2F;wiki&#x2F;index.php&#x2F;Category:UEFI</a><p>And then the uefi stub code in the Linux kernel, as well as the grub2 source code. It’s not too hard to figure out the flow in grub2, just figure out where it does EXIT_BOOT_SERVICES and work from there.
colejohnson66over 7 years ago
For some reverse engineered versions of the Windows bootloaders: <a href="http:&#x2F;&#x2F;thestarman.pcministry.com&#x2F;asm&#x2F;mbr&#x2F;" rel="nofollow">http:&#x2F;&#x2F;thestarman.pcministry.com&#x2F;asm&#x2F;mbr&#x2F;</a>
gbugniotover 7 years ago
You should take a look at U-Boot implementation.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;u-boot&#x2F;u-boot" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;u-boot&#x2F;u-boot</a>
amorphidover 7 years ago
I learned by playing around with the Grub bootloader in Linux VMs launched with Vagrant. I deleted every non-essential line of code in the bootloader config, and then stared at it &amp; the Grub docs until it made sense. My ultimate goal was learning how to turn a Linux container into a bootable VM.
评论 #15984456 未加载
fao_over 7 years ago
PoC || GTFO has a series of articles about the bootloader and operating systems all written in under 512 bytes. It&#x27;s quite adorable. I also recommend the website wiki.osdev.org -- it saw me through harsh undocumented times.
fuzzfactorover 7 years ago
<a href="http:&#x2F;&#x2F;reboot.pro&#x2F;" rel="nofollow">http:&#x2F;&#x2F;reboot.pro&#x2F;</a>