3

I successfully installed a dual-boot (Ubuntu 18.04 and win10) on my notebook.

Unfortunately I'm still new to the Linux world and my terminal skills and Linux knowledge are close to bad. But I'm willing to learn.

My concern: Every time my machine restarts or I want to switch the OS I have to wait for the grub bootloader and then choose the OS. Normally I will not change my running OS for example if I worked in Ubuntu, I would like to boot back into it or the other way.

Now I want to write a little program that automatically changes the default boot entry to the other OS and then reboots the system.
I guess the problem is not writing this little script for Ubuntu. But how should I realize this for windows?

My To do list based on my knowledge.

  • Somehow move the /etc/default/grub file to a small fat32 partition so windows is able to read it and make changes. ~probably easy
  • Run the sudo update-grub equivalent command in windows? ~this one is way beyond my knowledge and maybe totally stupid - like running an file.exe on Ubuntu.

I already searched for similar question but without finding a reasonable good solution for me.

  • Some recommended to teach windows to read/write on the Ubuntu drive. I think that my precious Ubuntu drive should not be violated by windows.
  • Or to install another bootloader. I would like to stay with GRUB, because its working and the default?
  • Make changes to the /boot/grub/grub.cfg or /boot/grub/grubenv I'm not 100% sure about it, but most users don't recommend messing with the grub.cfg file because its generated from other files?

I know that I can probably just use a function in GRUB to run the last booted OS as default. But when I want to switch from one OS to the other I like the idea of just running a little own program instead of waiting for the reboot then hitting a key before the timer runs out... and if you miss this opportunity - reboot again -

Thanks for your help

Hysteria
  • 31
  • 1
  • 3
  • 1
    If you have UEFI installs, you can just choose what system to boot from UEFI boot menu. Often f12 but varies by vendor. – oldfred Dec 25 '18 at 22:47
  • @Hysteria when you are in windows you want to tell the system that next boot should be Ubuntu or Windows...this is what are you trying to achieve?? suppose if you achieve this and next boot is Ubuntu..means now you are in Ubuntu.. after restart are you expecting Windows or Ubuntu? – PRATAP Dec 26 '18 at 03:49
  • @PRATAP this depends. I have to set a default OS and a short timer (that's not the problem). At this point If I set Win10 as default and run an update I easily came back to Win10. But when I'm done in win10 and want to go back to Ubuntu my Idea takes place: I'm still in win10 and want to tell Grub that now the default boot OS is Ubuntu and reboot the system. So I don't need to sit in front of my system to tell GRUB during startup I want to change the OS. – Hysteria Dec 26 '18 at 09:58
  • i have tried since morning.. from windows 10..seems its not possible.. bcoz any changes we make.. update-grub is the task which is not possible.. i have seen a similar question.. little different.. OP added USB to achieve what you are looking for.. – PRATAP Dec 26 '18 at 10:03
  • https://askubuntu.com/a/1075943/739431 – PRATAP Dec 26 '18 at 10:05

2 Answers2

4

This will do almost what you want...

Making this change will allow you to choose which OS to boot, and it'll reboot to that same OS until you make a different selection.

Edit /etc/default/grub and change/add this:

sudo -H gedit /etc/default/grub # edit the file


GRUB_DEFAULT=saved # change this line

GRUB_SAVEDEFAULT=true # add this line


Then:

sudo update-grub

heynnema
  • 70,711
0

For those of us on other flavors of Ubuntu, gedit may not be available; no matter, just about any text editor will do, and @heynnema has it right otherwise...

Edit the file /etc/default/grub with your favorite editor under sudo

  • Edit GRUB_DEFAULT to be "saved" (it probably is "0" when you see it first)
  • Add a new line "GRUB_SAVEDEFAULT=true"

Now

  • sudo update-grub