Can I change the grub default choice from Windows?
Solution 1
The default menu choice is (or can be) stored in the GRUB "environment block", a little 1024 byte file that lives in /boot/grub/grubenv by default. You could easily put that on a drive accessible from both Windows and Linux (e.g. a FAT or NTFS partition) and modify it accordingly. I've done this already one-way (Linux -> Windows) for my mother's laptop using a little script:
#! /bin/bash
sudo /usr/sbin/grub-set-default 0
nohup bash -c "sleep 15s && sudo /sbin/reboot" &
gnome-session-quit --no-prompt --logout
Also added the following to /etc/sudoers to make the necessary commands execute without prompting:
%adm ALL=(root) NOPASSWD: /usr/sbin/grub-set-default, /sbin/reboot
Alternatively, it looks like someone may already have done the heavy lifting:
http://de.mcbf.net/david/grubchoosedefault/
Haven't tried this yet though ..
Solution 2
About 20 years ago my OS/2 did that. Knowing a bit more about boot processes, I do not know exactly how it did that. It may have had boot loaders in PBR - partition boot sector and just moved boot flag. Or it may have just dd'd the boot sector/MBR with a different version. Those might work now.
But it might be easier just to install grub2 to a separate NTFS grub2 only boot partition. Then you can edit grub.cfg directly from both Windows and Linux. While you could edit the grub.cfg, I might just make 3 grub configs, working, Windows boot & Linux boot. And just have scripts to copy either Windows boot or Linux boot to the working copy. Then no update grub required.
On one of my flash drives that I originally created as a Windows 7 repair flash drive, I over-installed grub2 so from same flash drive I could directly boot other Linux repair ISO via loopmount. The only issue with grub installed in Windows is making sure you do not create /Boot & /boot as then you have major issues. I had /BCD & /grub in one /Boot folder. So you might not even have to have a separate grub only partition, but have to be careful not to damage Windows.
Related videos on Youtube
Marco A.
Updated on September 18, 2022Comments
-
Marco A. over 1 year
This is a weird question. I read how to set the default OS choice for GRUB (How do I set the grub timeout and the grub default boot entry?) and I did that, but since I often work from home, I'd like to switch from Windows 7 to Ubuntu 13 and from Ubuntu 13 to Windows 7 automatically by VNC.
I can edit manually the file
/etc/default/grub
, but I can't do thesudo update-grub
from inside the Windows environment.My question is: is there any way to do this from inside a Windows environment or to use a workaround to be able to change the default bootloader choice and boot into another operating system remotely ?
-
sancho.s ReinstateMonicaCellio over 7 yearsNote also this question and its answers. unix.stackexchange.com/questions/11423/…
-
sancho.s ReinstateMonicaCellio over 7 yearsAnd this askubuntu.com/questions/514513/…
-
-
jawtheshark over 7 yearsIf I recall correctly, the OS/2 boot manager had its own partition. That way it wasn't limited to the code size restrictions imposed by the MBR. Basically, the MBR launched the OS/2 boot manager (on a partition), which then chainloaded the desired OS. It also set the hidden flag on the other OSes, that you didn't boot into. The OS/2 boot manager was awesome...
-
4dummies almost 4 yearsThis is great, but one thing is unclear: if grubenv must be moved to make it accessable, how do change grub so it knows the new location? I'm on a System 76 laptop where they put it in under / in /boot/grub and not even in a separate /boot partition.
-
Steve Dee almost 4 yearsHuh, after 6 years I had to go back to grub docs! Turns out the "load_env" command can take a --file argument. There should be a call to it from your grub config. Different distros may construct the grub config in different ways, on my Ubuntu system /etc/grub.d/00_header contains the load_env call which would need to be changed..