I have a Linux 6.15.2 kernel at /bin/kernel-6-15, built using the stock configuration (which has CONFIG_EFI_STUB=y). When I tried to boot it in legacy BIOS using GRUB, it said error: invalid magic number. I later discovered that my kernel is missing the byte sequence AA 55 at offset 510, which means it will not be bootable in legacy BIOS, no matter what I try. Setting CONFIG_EFI_STUB=n did fix the issue, but CONFIG_EFI_STUB by itself is not the cause.
A valid (bootable in legacy BIOS) Linux kernel from Alpine Linux:
- Bytes at offset 510:
aa55 6aeb 6448 5372 020f 0000 0000 1000
- File format according to
file: Linux kernel x86 boot executable, bzImage, version 6.12.13-0-virt (buildozer@build-3-21-x86_64) #1-Alpine SMP PREEMPT_DYNAMIC 2025-02-10 21:47:33, RO-rootFS, Normal VGA, setup size 512*31, syssize 0xb1540, jump 0x26c 0x8cd88ec0fc8cd239 instruction, protocol 2.15, from protected-mode code at offset 0x2c4 0xb069ea bytes gzip compressed, relocatable, handover offsett 0xb0ec7d, legacy 64-bit entry point, can be above 4G, 64-bit EFI handoff entry point, EFI kexec boot support, xloadflags bit 5, max cmdline size 2047, init_size 0x25b3000
My invalid (not bootable in legacy BIOS) Linux kernel:
- Bytes at offset 510:
0000 0fa4 0000 8566 0fc0 0e84 6701 8d66
- File format according to
file: PE32+ executable for EFI (application), x86-64 (stripped to external PDB), 4 sections
How to reproduce
- Copy the stock configuration to
pkgs/bin/kernel/configs/cfg_6_14
./ix mut system bin/kernel/6/15
hexdump -s 510 /bin/kernel-6-15 | head -n 1 (first two bytes should not be aa55)
file -L /bin/kernel-6-15 (should be PE32+ executable for EFI (application), x86-64 (stripped to external PDB), 4 sections)
See also
https://forums.gentoo.org/viewtopic-p-8815100.html#8815100
I have a Linux 6.15.2 kernel at
/bin/kernel-6-15, built using the stock configuration (which has CONFIG_EFI_STUB=y). When I tried to boot it in legacy BIOS using GRUB, it saiderror: invalid magic number.I later discovered that my kernel is missing the byte sequenceAA 55at offset 510, which means it will not be bootable in legacy BIOS, no matter what I try. Setting CONFIG_EFI_STUB=n did fix the issue, but CONFIG_EFI_STUB by itself is not the cause.A valid (bootable in legacy BIOS) Linux kernel from Alpine Linux:
aa55 6aeb 6448 5372 020f 0000 0000 1000file:Linux kernel x86 boot executable, bzImage, version 6.12.13-0-virt (buildozer@build-3-21-x86_64) #1-Alpine SMP PREEMPT_DYNAMIC 2025-02-10 21:47:33, RO-rootFS, Normal VGA, setup size 512*31, syssize 0xb1540, jump 0x26c 0x8cd88ec0fc8cd239 instruction, protocol 2.15, from protected-mode code at offset 0x2c4 0xb069ea bytes gzip compressed, relocatable, handover offsett 0xb0ec7d, legacy 64-bit entry point, can be above 4G, 64-bit EFI handoff entry point, EFI kexec boot support, xloadflags bit 5, max cmdline size 2047, init_size 0x25b3000My invalid (not bootable in legacy BIOS) Linux kernel:
0000 0fa4 0000 8566 0fc0 0e84 6701 8d66file:PE32+ executable for EFI (application), x86-64 (stripped to external PDB), 4 sectionsHow to reproduce
pkgs/bin/kernel/configs/cfg_6_14./ix mut system bin/kernel/6/15hexdump -s 510 /bin/kernel-6-15 | head -n 1(first two bytes should not beaa55)file -L /bin/kernel-6-15(should bePE32+ executable for EFI (application), x86-64 (stripped to external PDB), 4 sections)See also
https://forums.gentoo.org/viewtopic-p-8815100.html#8815100