Make Grub Load Last Used OS (SOLVED)

willyum

Member
Joined
Apr 28, 2020
Messages
55
Reaction score
12
Credits
515
I dual boot Windows and Fedora. Currently Fedora is the default, but I would like GRUB to load the last one used. I have poked around the internet for the answer, but it appears that Fedora has a different process than some others. Can someone instruct me.
 


I dual boot Windows and Fedora. Currently Fedora is the default, but I would like GRUB to load the last one used. I have poked around the internet for the answer, but it appears that Fedora has a different process than some others. Can someone instruct me.
Have you tried looking into how to edit a windows boot file in a windows/linux setting? I've never done that before, you might be able to increase the time on the windows boot menu for choosing between the two.
 
Long ago, I was using a different distro that was using legacy grub and non-eufi and there was a relatively simple way to make grub change the default ( I think that is what it does) in the menu to the last OS used. I think I'm finding those same commands now for some other distros, but it doesn't work for my current Fedora installation. I have no problem with the time available to manually select the OS and it is really not a big deal. It is just a nicety I would like to have back, if possible.
 
@willyum , hi.

Can you provide here the content of your grub file

Code:
cat /etc/default/grub

Thanks

Chris Turner
wizardfromoz
 
GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" #GRUB_DEFAULT=0 GRUB_DEFAULT=saved GRUB_SAVEDEFAULT=true GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="resume=/dev/mapper/fedora_localhost--live-swap rd.lvm.lv=fedora_localhost-live/root rd.lvm.lv=fedora_localhost-live/swap rhgb quiet" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true
 
OK, you have 2/3 of it right with the lines 4 and 5

Code:
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

That is all that is needed for most Distros.

Fedora however provides one additional curve ball.

So change it from

Code:
GRUB_ENABLE_BLSCFG=true

to

GRUB_ENABLE_BLSCFG=false

Save and exit the file, then run

Code:
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

Then reboot and see how you go.

Cheers
Wizard
 
OK. Did that. Now making a selection from the menu results in an error message that ends with .../EFI/fedora/grubenv not found.
I checked with Nemo and, indeed, grubenv is not in the path /boot/efi/EFI/fedora/grubenv, but is located in /boot/grub2/grubenv.

Follow up:
I fixed it by copying the grubenv file to the /boot/efi/EFI/fedora directory. Works as it should.
Thanks for the help.
 
Last edited:
I understand. Fedora Wiki has this, in part

(Source https://fedoraproject.org/wiki/GRUB_2 )

Updating the GRUB configuration file​


The GRUB configuration file is located at /boot/grub2/grub.cfg and is intended to be a static file that does not need updating. In case of disk replacement, or installation of another Linux distribution, /boot/grub2/grub.cfg should be updated. Use the following commands:

sudo grub2-mkconfig -o /etc/grub2.cfg

sudo grub2-mkconfig -o /etc/grub2-efi.cfg

sudo grub2-mkconfig -o /boot/grub2/grub.cfg - Legacy boot method for grub update.

These commands use information provided by the os-prober utility to add entries for other Linux distributions and Windows.


Note.png
Refrain from using grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg going forward. This is a valid location on Fedora 33 and earlier. However on Fedora 34 and later, it is a small stub file that merely forwards to /boot/grub2/grub.cfg. See the Reinstalling GRUB section if you have accidentally overwritten this file.

The stub described in the last lines is what I still use and it works on my Fedora 36, but configurations differ from computer to computer.

By the looks of it we are better advised to be using

Code:
sudo grub2-mkconfig -o /etc/grub2.cfg

OR

sudo grub2-mkconfig -o /etc/grub2-efi.cfg

The BLS line that was in your /etc/default/grub was the curve ball I was talking about, and it negates the effect of

GRUB_SAVEDEFAULT=true

Changing the BLS from true to false remedies that.

Glad you found a working solution, anyway.

Cheers

Wizard
 
Thanks for the follow-up.
Even a monkey at the keyboard can occasionally write a complete sentence.
I just ignorantly copied the file grub was looking for into the place it was looking and it worked. Monkey see monkey do.
So. even though it works, is it the correct way to do it? Should it be done differently to keep from screwing up something down the road? Should I go through the process again replacing the code you provided in msg #6 to what you provided in msg #8?
 
I just love the monkey at a keyboard analogy ... now why do I feel an urge to hang from a tree branch and peel a banana with my toes?
I just ignorantly copied the file grub was looking for into the place it was looking and it worked.

Sounds like enterprise to me, in practising your troubleshooting skills. :)

In terms of repeating the process with the recommended command - your computer, your decision.

If the way you went is producing the desired result, I would stay with it, but that's me.

A test of the setup will be when the next kernel upgrade goes through, as there are occasions when the upgrade can alter your /etc/default/grub

I would certainly take a snapshot of the system as it works now. If you installed under BTRFS, perhaps install Snapper and use it, if EXT4 then Timeshift.

Cheers

Wizard
 
I just love the monkey at a keyboard analogy ... now why do I feel an urge to hang from a tree branch and peel a banana with my toes?


Sounds like enterprise to me, in practising your troubleshooting skills. :)

In terms of repeating the process with the recommended command - your computer, your decision.

If the way you went is producing the desired result, I would stay with it, but that's me.

A test of the setup will be when the next kernel upgrade goes through, as there are occasions when the upgrade can alter your /etc/default/grub

I would certainly take a snapshot of the system as it works now. If you installed under BTRFS, perhaps install Snapper and use it, if EXT4 then Timeshift.

Cheers

Wizard
If it ain't broke, don't fix it. So, I'll leave it til it gets broke. Then I'll call on you to help me fix it. :)
But, I will do a backup.
Thanks.
 

Members online


Latest posts

Top