In the boot partition there are two kernels, kernel.img and kernel7.img (for the pi 1 vs 2/3). How does the system know which to load?
2 Answers
All the boot magic is in /boot/config.txt
.
kernel: The alternative filename on the boot partition to use when loading the kernel; the default value is kernel.img.
Update: to clear up some confusion and to satisfy my curiosity, I tried the following small experiment.
I DO NOT RECOMMEND YOU TRY THIS!
- On my RPi3 I do not have the kernel entry in config.txt, and the system boots up fine.
- I deleted kernel.img.
- I renamed kernel7.img to foo.bar.
- After rebooting the RPi, the system failed to load. I got the multi-colour screen of death, as expected.
- I added kernel=foo.bar to my config.txt.
- Rebooted the system, and it worked.
This proves two things:
- The system can intelligently select the correct kernel per architecture, within some limits.
- The kernel entry in config.txt works if used.
-
-
@Milliways What do you consider "normal" in this context? There are several sources, for example this raspberrypi.stackexchange.com/q/10489/53481 and several things linked from there, that agree with me.– SiKingCommented Jan 24, 2017 at 0:07
-
By "normal" I mean any of the prebuilt images downloadable from the Foundation site. The post you linked is an earlier version of the link in my answer (before loader.bin was removed). Commented Jan 24, 2017 at 0:20
-
From the linked docs it seems
/boot/config.txt
is passed as an argument to the closed source GPU firmwarestart.elf
which then launches the kernel specified - the confusing bit is that it seems all the boards use the pi 1 kernel image out of the box, but still contain akernel7.img
in/boot
I guess that's what's necessary for one SD card image to work across all the boards. Commented Jan 24, 2017 at 5:44 -
@plasticchris: Indeed. Pi 1 doesn't use the kernel7.img at all (and vice versa, Pi 3 doesn't user kernel.img) , but they're both included (with their dependencies). I suspect that it allows for using the same card in various RPi models automagically. Commented Feb 26, 2019 at 12:56
See http://elinux.org/RPi_Software#Overview which describes the Pi boot process.
Basically bootcode.bin
analyses the hardware and (presumably) decides which kernel to load. (The source is not publicly available).
It is (or was) possible to specify a different kernel, but this is NOT used by normal images.
NOTE With the new USB/Network boot options for the Pi3 the process has changed but the principle remains similar.
For those interested in reading more about the new boot options Raspberry Pi boot modes
-
From your link, I read that completely differently. "Second stage bootloader (bootcode.bin) - This is used to retrieve the GPU firmware from the SD card, program the firmware, then start the GPU." Reading further: "User code - This can be one of any number of binaries. By default, it is the Linux kernel (usually named kernel.img), but it can also be another bootloader (e.g. U-Boot), or a bare-bones application."– SiKingCommented Jan 24, 2017 at 0:09
-
1FYI: I tried a small experiment to verify my answer. See my update.– SiKingCommented Jan 30, 2017 at 5:49
-
@SiKing I don't understand why you are deliberately misinterpreting my answer. I said the
kernel
option "is NOT used by normal images" NOT that it couldn't be done. This is easily verified by looking at config.txt in any standard image. Commented Jan 30, 2017 at 6:40 -
@SiKing You are also NOT answering the actual question "How does the system know which to load" NOT what other methods can be used to load kernels. Commented Jan 30, 2017 at 6:42
-
1I think we are both saying the same thing. I was just trying to clarify my answer. Maybe I failed. Sorry.– SiKingCommented Jan 30, 2017 at 16:54