Ubuntu – Can I change the grub default choice from Windows

bootdual-bootgrub2windowswindows 7

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 the sudo 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 ?

Best Answer

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 ..