• Re: Switch boot entry by power-on reason

    From Thomas Schmitt@21:1/5 to hede on Sun Jul 21 11:50:01 2024
    Hi,

    hede wrote:
    Technically it should be possible, as dmidecode can show the reason:
    Handle 0x0001, DMI type 1, 27 bytes
    System Information
    ...
    Wake-up Type: LAN Remote
    vs.
    Wake-up Type: Power Switch

    The statement in man dmidecode "DMI (some say SMBIOS)" caused me to search
    for "GRUB SMBIOS" which yields:
    https://www.gnu.org/software/grub/manual/grub/html_node/smbios.html

    This looks like a low-level user interface to
    https://en.wikipedia.org/wiki/System_Management_BIOS

    Diving into
    https://codesearch.debian.net/search?q=package%3Admidecode+Wake-up+Type
    leads me to
    https://sources.debian.org/src/dmidecode/3.6-1/dmidecode.c/?hl=4498#L4498 which lets me guess that your answer is in
    smbios --type 1 --get-byte 24
    with the possible values told by function dmi_system_wake_up_type()
    https://sources.debian.org/src/dmidecode/3.6-1/dmidecode.c/?hl=513#L513

    Consider to explore this in the GRUB shell and (if needed) to find
    somebody who can help to develop a smart configuration which makes use of
    the result to offer different boot menus.
    (I am not sure whether we have the expertise here. As last resort, i'd
    ask at mailinglist grub-devel@gnu.org in the hope that the experts are
    in helpful mood. It's not a very harsh environment there.)


    Have a nice day :)

    Thomas

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hede@21:1/5 to All on Sun Jul 21 11:20:01 2024
    Hi list,

    does anybody know if it's possible to switch the boot menu entry to boot based on the reason the PC was powered on?

    Say for example the following challenge:

    - start Windows if someone powers it on via the power button
    - start Linux if the system was powered on via LAN or a bios timer event

    This would enable some general PC to also function as a remote backup PC. The user of the PC wants to start Windows if he powers it on via the Power Button. But additionally to that there is a timer event starting the PC at night for remote backups
    running at that time and the backup solution is for Linux.

    I tried to find a solution using grub, systemd-boot, rEFInd and even the Windows Boot Manager with no success. It seems none of the famous boot managers is able to switch the boot entry based on the power up reason given by the UEFI.

    Technically it should be possible, as dmidecode can show the reason:
    Handle 0x0001, DMI type 1, 27 bytes
    System Information
    ...
    Wake-up Type: LAN Remote
    vs.
    Wake-up Type: Power Switch

    (the first one was powered on via Intel AMT, the second one by the power switch, as an example)

    It seems still no one has implemented that?

    (the next problem would be to have a working Secure Boot + TPM hard disk decrypt operation for both systems... but this one is of no interest if there is no reason)

    best regards
    hede

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Schmitt@21:1/5 to David and Thomas collaboratingly on Mon Jul 29 18:50:01 2024
    Hi,

    David and Thomas collaboratingly wrote:
    smbios --type 1 --get-byte 24 --set result

    hede wrote:
    Many thanks, it works :-)

    \o/\o/ So the community and its resources are not that useless \o/\o/


    Have a nice day :)

    Thomas

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hede@21:1/5 to bouncingcats@gmail.com on Mon Jul 29 18:30:04 2024
    Hello David and Thomas,

    On Sun, 21 Jul 2024 10:45:59 +0000 David <bouncingcats@gmail.com> wrote:

    On Sun, 21 Jul 2024 at 09:46, Thomas Schmitt <scdbackup@gmx.net> wrote:
    ...

    So your manually written grub.cfg. would contain something like the below lines
    in addition to whatever other content you need to boot the machine.

    smbios --type 1 --get-byte 24 --set result
    if [ "${result}" == "REPLACEME" ] ; then
    default=1
    else
    default=2
    fi


    Many thanks, it works :-)

    Here for me the result is either 5 or 6 and I can switch between the boot entries by manipulating the default entry via this smbios command. The best thing with this solution is, that it only sets the default value so the user can override it manually by
    choosing some other entry. The timeout remains.

    Btw: This computer is one of those where Windows is constantly kicking out Grub from the EFI Boot Manager. After booting Windows there is no longer any grub in the EFI Boot Manager and the PC starts Windows only.

    But that's not Microsofts fault here, it's the BIOS vendors fault (HP/AMI) as this UEFI removes all EFI Boot Manager entries except the Default one. I tried to add several additional entries and they all get removed on next boot. So if Grub adds itself,
    the Windows boot entry gets removed. So Windows adds itself again on next boot (which I think is quite reasonable to do). So then Grub gets removed again.

    The solution is to force Windows to add Grub as its own Bootloader with (in a Windows Admin Shell):

    bcdedit /set {bootmgr} path \EFI\debian\shimx64.efi

    There are plenty of articles in the Internet how to do so correctly. Afterwards Windows wants to install Grub if Grub gets removed from UEFI. ;-)

    Hopefully all that remains is to use the above information to figure out
    the actual value needed to replace my REPLACEME placeholder.

    Boot the PC via all the different methods and for every one run in the Grub shell:
    smbios --type 1 --get-byte 24
    This returns the value of the current startup type / boot reason.

    Many thanks
    hede

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)