Grub one time boot of a different entry

@crazymonkey

I’m splitting this off from

Because it is really a different topic from the question there AND what I guessed about this in that thread before looking made it sound harder than it is AND that thread degenerated into an argument about its original question.

For anyone starting here, what we want to know is the correct commands to reboot one time into a different OS, such that when that OS shuts down or reboots the grub default will be back to what it was before we did all this.

In other words make a one time change to the grub default.
We need to set that by name, not by number, because the numbering of the grub menu is not stable enough for this usage. Most of the documentation on grub defaults is by number. There are two different ways to set the default by name, but I need to relearn them.

I don’t yet have a cookbook answer. I’ll experiment a bit more later if no one jumps in to hand us a cook book answer. The google search I did found only answers that are very much Ubuntu specific.

I’m pretty sure you don’t need to do anything to directly or indirectly change /boot/grub2/grub.cfg. Two different ways to do a one time boot of a different OS are already standard there. You only need to do something with grub2-editenv followed by the sudo shutdown -r now

I need to experiment a bit later to see what exactly you must do with grub2-editenv. The best way to do it may depend on how things are currently set. To find that out I use:

sudo cat /boot/grub2/grubenv

On the (non dual boot) system I’m typing on now, that gives:

# GRUB Environment Block
# WARNING: Do not edit this file by tools other than grub-editenv!!!
save_default=true
boot_success=0
saved_entry=40e2b355e289424b842a998c64d8462d-6.5.8-200.fc38.x86_64
boot_indeterminate=2
#########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

@crazymonkey If you jumped to this new thread with me, what does that command report on your system?

I think to make it cookbook, I also need the output of:
sudo grep -w menuentry /boot/grub2/grub.cfg

Meanwhile if someone else simply knows, please tell us. I also wanted to add that feature to my dual boot system.

The post I marked as the solution contained the key suggestion
sudo grub2-reboot

The actual solution ------------------------------------------------------------
To use that, first I needed:

$ sudo grep -w menuentry /boot/grub2/grub.cfg
menuentry 'Windows Boot Manager (on /dev/nvme0n1p1)' --class windows --class os $menuentry_id_option 'osprober-efi-301F-38B5' {
        menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
               menuentry "$p/$x" --class=uefi {
$

Copying the title from there, I constructed the commands:

sudo grub2-reboot 'Windows Boot Manager (on /dev/nvme0n1p1)'
sudo shutdown -r now

Executing those two commands caused a reboot into Windows, after which the next reboot came back to Fedora.

Putting those two commands into an icon that can be clicked (for easy switch to Windows) is left as an exercise for the reader.
-------------------------------------------------------------------------------------------

Internally, sudo grub2-reboot 'Windows Boot Manager (on /dev/nvme0n1p1)' does just sudo grub2-editenv /boot/grub2/grubenv set next_entry='Windows Boot Manager (on /dev/nvme0n1p1)'
That longer, more basic, version is what I was trying to rediscover enough to suggest when I started this thread. But the shorter command first does some extra checks to rule out some reasons the longer command might be unsound. I don’t have a system on which any of those reasons apply, so the two commands are the same. But the shorter one is easier and on some system may be more robust.

For anyone starting here, what we want to know is the correct commands to reboot one time into a different OS, such that when that OS shuts down or reboots the grub default will be back to what it was before we did all this.

sudo grub2-set-bootflag menu_show_once

… This will let you select what you’d like to boot from grub and then go back to defaults

So you could also:
sudo grubby --info=ALL
using the output from that use grub2-reboot
sudo grub2-reboot 1

would boot selecting index 1

according to the man page you can also use the title.

1 Like

Thankyou, but I guess I was unclear. That isn’t what we want.

So far as I can tell, that only covers the contents of /boot/loader/entries which is not where the entry we want comes from.

That (by title not number) sounds like exactly what we were looking for. I’ll test it.

Edit: That command did work. I marked your post as the solution but edited into the bottom of my first post the extra detail of how you use that solution for the purpose @crazymonkey wanted.

This is done from the grub boot menu by editing the grub command line. Select the kernel to be booted then press e to edit the command line (the line beginning with linux

Changes made this way are only effective for that particular boot and the next boot will revert to the normal command line.

I assumed something would be obvious about the meaning of my question, that apparently wasn’t.

I meant from inside a booted Fedora. Not from the grub menu. That would be a bizarrely stupid question to ask if you meant from inside the grub menu. In the context (that I know I didn’t copy here, just referenced) the problem was the grub menu is on a monitor that isn’t accessible.
But why you want to do this from inside an already booted Fedora isn’t really relevant to simply asking how to do it.

Of course, if you had read the solution part of this already solved thread before making a comment implying the question was asked by an idiot, you might have realized what the question meant.

BTW, I have a different system where the wireless keyboard consistently doesn’t work for enough time after each reboot that I can’t get to either the BIOS or the grub menu unless I get and connect a different keyboard. So it will be very helpful to work from a booted Fedora to give these one time selections to grub, especially the grub selection to go to the BIOS.

I could go directly from Fedora to BIOS settings with

sudo grub2-reboot 'UEFI Firmware Settings'
sudo shutdown -r now

then it would sit in BIOS settings long enough for the keyboard to work again.