4 ms·
Is there a way to write a kernel directly to a boot sector and boot directly from it?
by spease 7y ago
Is there a way to write a kernel directly to a boot sector and boot directly from it?
- kevinoid 7y agoFor EFI systems, the kernel includes a boot stub which allows it to be booted directly by the firmware without an additional bootloader. AFAIK it's not possible to boot directly via BIOS/MBR. https://www.kernel.org/doc/html/latest/admin-guide/efi-stub.html https://www.kernel.org/doc/html/latest/admin-guide/efi-stub....
- grapeli23 7y agoMinimal bootloader can fit in MBR. http://sebastian-plotz.blogspot.com/ http://sebastian-plotz.blogspot.com/
- charlesap 7y agoOr just turn on paging and page in your kernel from the MBR, ignoring the BIOS: https://github.com/charlesap/bootpager https://github.com/charlesap/bootpager EFI eliminates the need for such trickery though, and who doesn't have EFI these days?
- nineteen999 7y ago> who doesn't have EFI these days? VM's hosted on VMware ESX with the default settings comes to mind.
- tsuraan 7y agoSomewhat; if your system boots through EFI (as opposed to the ancient BIOS boot), then you can compile your kernel with the EFI_STUB option[0]. That kernel can be placed in EFI/Boot/bootx64.efi (or whatever you've configured your EFI to boot), and the EFI boot loader will run it without any other boot loader. IME, this goes very well with a built-in initramfs (INITRAMFS_SOURCE[1]), so you have a single-file kernel and ramfs that boots directly from EFI. [0] - https://www.kernel.org/doc/html/latest/admin-guide/efi-stub.html https://www.kernel.org/doc/html/latest/admin-guide/efi-stub.... [1] - https://github.com/torvalds/linux/blob/master/Documentation/driver-api/early-userspace/early_userspace_support.rst https://github.com/torvalds/linux/blob/master/Documentation/...
- Boulth 7y agoThat's right. I'm using this kind of setup on Arch (including Secure Boot signing of the EFI kernel).
- AnIdiotOnTheNet 7y agoI'm curious why there kernel needs to be specially compiled for this. Is it somehow impossible to build an EFI program that boots whatever is concatenated to the end of it? Is it similarly impossible to have the kernel boot an initramfs concatenated to the end of it? This would make it trivial to swap out the individual components without recompilation.
- newnewpdro 7y agoThe Linux kernel used to be a bootable MBR image, but I believe support for this was removed at some point. I used to build custom Linux kernels for rescue floppies that had no boot loader and a bundled rescue initramfs at an ISP back in the late 90s. They booted very quickly despite being 3.5" floppy disks, it was kind of epic for the time. http://tldp.org/HOWTO/Linux-i386-Boot-Code-HOWTO/bootsect.html http://tldp.org/HOWTO/Linux-i386-Boot-Code-HOWTO/bootsect.ht... Edit: It looks like 2.6.23 is when it vanished as part of the arch/i386/* -> arch/x86/* migration: Present @ 2.6.22: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/i386/boot/bootsect.S?h=v2.6.22 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin... Gone in 2.6.23: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/i386/boot/?h=v2.6.23 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...