0

I am trying to implement something which requires me to learn this:- How Raspberry pi NOOBS OS boots in recovery mode while holding SHIFT key?

Can anyone help me regarding this?

2 Answers2

4

This is what I have found out after I checked out noobs code as well as reverse engineering it.

For booting recovery.efi is loaded by bootloader. From here kernel is loaded from recovery.img or some other one for your pi.

Now kernel will load recovery.rfs to the ram. recovery.cmdline contains ram0 as root this means kernel will call sbin/init from ramdisk.

Now init will call /usr/bin/recovery (an ELF 32bit arm program) its source code is in noobs git.

Upon reading main.cpp what I felt is that, after it detects recovery partition, it calls bootmenu function. This function once fixed the partition to boot to, will use SYS_reboot system call to reboot to the new OS.

Now I don't know how it does not invoke the bootloader but I know someone with greater understanding than me will post another how it does not literally reboot.

Also note that recovery.elf is start.elf which will read autoboot.txt to set boot partition to boot.

[edit] I have successfully booted multiple os with this idea. Below given is a system call can be invoked with c or cpp. syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, "1"); Here /dev/mmcblk0p1 will be taken as the boot partition. You can replace that with 2 for /dev/mmcblk0p2 and so on.

1

You are unlikely to get a definitive answer because none of us use NOOBS. (Those who want multi OS use PINN .)

NOOBS is actually an Operating System installer and boot manager.

You CAN NOT "boot in recovery mode while holding SHIFT key" - you need to PRESS SHIFT during the brief period it flashes a message.

It is unclear what you are actually asking; it is simple to detect keypress in a program. If you want a more precise answer about how NOOBS does this you will have to study the code (which is readily available).

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • Hey, thanks for the information :-) Can you please suggest some resources where i can find readily available code? – Preet Patel Oct 17 '20 at 03:33
  • 2
    It is readily found by looking at the Documentation on the Foundation website https://www.raspberrypi.org/documentation/installation/noobs.md or https://github.com/raspberrypi/noobs – Milliways Oct 17 '20 at 03:50