Script before OS starting

1

1

I need to run a script before the operating system starts. The script reads a text file (on file-system FAT32), if the result is "A", then launch OS1, elseif the result is "B", then launches OS2 (another operating system). I thought of Grub, but I do not know how it could be done. Alternatively, I could use EFI Shell, but in the firmware of my computer there is no EFI Shell. How can I do? Thank you all.

Luciano

Posted 2018-05-09T07:48:23.510

Reputation: 33

2Welcome to Super User! An interesting question, but what problem are you trying to solve, if you don't mind my asking? If it's something along "reboot in X/Y on user intervention/programmatically" there might be ways of doing that depening on your setup :) – bertieb – 2018-05-09T08:26:57.563

When the operating system is running, it writes a text file to a FAT32 partition (via a script), depending on whether an event has occurred or not, let's say it writes "A" or "B" (a flag). This can be done by all operating systems installed on the machine. If "A" is written, then on the next reboot (or on re-ignition), OS1 must start, if instead "B" is written, then another operating system must start, say OS2 (not OS2 Warp :-)). That's all. Management must necessarily be pre-boot – Luciano – 2018-05-09T08:45:57.783

1@Luciano UEFI provides this feature out of the box. With Linux you have to run efibootmgr -n <number> (print numbers by running efibootmgr). With Windows you have to figure it out yourself, I haven't used it yet. – gronostaj – 2018-05-09T09:19:28.227

Answers

1

You can download EFI Shell from the TianoCore project. It's an open source release based on the Intel implementation.

Download that binary, place in on the EFI System Partition and add an UEFI boot entry. The easiest way to do that is using Linux: (as root)

cd /efi/boot
wget https://github.com/tianocore/edk2/raw/master/ShellBinPkg/UefiShell/X64/Shell.efi
efibootmgr -c -p 1 -l shell.efi -L "EFI Shell"

Then set it as default boot option through your UEFI configuration interface or using efibootmgr:

efibootmgr -o $(efibootmgr | grep 'EFI Shell' | sed -r -e 's/^Boot0+//' -e 's/\*.*//')

gronostaj

Posted 2018-05-09T07:48:23.510

Reputation: 33 047

Many thanks, now I try. What name of the script for the auto-start? – Luciano – 2018-05-09T09:06:28.973

@Luciano.. For UEFI shells, the name is startup.nsh – fpmurphy – 2018-06-14T14:39:55.433