10

I have a dual boot setup:

  1. Ubuntu 16.04 LTS
  2. Windows

Currently when I want to reboot from Ubuntu into Windows I use grub-reboot with the appropriate number as argument. This works well.

However sometimes Windows needs a reboot so a certain program can install or update and I manually have to select the right grub boot menu entry. Is there a similar way (from Windows UI) to tell grub which entry to boot?

I suppose the grub-reboot command passes the argument to a file which is in turn read by grub upon reboot.

edit (concerning my selected answer): I'm currently looking into mounting the ext4 drive that contains /boot and scripting the edit. this will possibly take quite a while since i'm doing this in my free time beside my 40h/week non-tech job. ^^

  • Comments are not for extended discussion; this conversation has been moved to chat. – terdon Mar 15 '18 at 12:34
  • Please update your question in the future with what you ended up doing to have grub automatically reboot into Windows. I'm keen to know what method worked for you and to see the Window's script (if any) you wrote. I'm sure many other people are interested too. – WinEunuuchs2Unix Mar 16 '18 at 3:10
  • @WinEunuuchs2Unix currently i'm working on it. as Oli said - scripting in windows is a royal PITA. – amon san Mar 20 '18 at 9:01
  • @amonsan I've update my answer with reboot-to-windows function which is a compromise over using ext2fsd that corrupts ext4 superblocks. – WinEunuuchs2Unix Mar 30 '18 at 16:49
  • @amonsan Do you have your system setup now for Windows Update rebooting to go back into Windows automatically? – WinEunuuchs2Unix Mar 30 at 3:26
7

You can replicate what grub-reboot does. It's just a script that eventually calls:

grub-editenv /boot/grub/grubenv set next_entry="Windows"

Where Windows is the name of your grub menu entry. It might not be that

I ran that. All it does it insert next_entry=Windows into /boot/grub/grubenv. On line 2. So if it's just a file, on a filesystem, you can do exactly the same thing from within Windows. It's a Windows problem to solve, but here's the high-level overview:

  • Mount the disk where boot lives. This is probably the hardest bit because this is probably ext4. This might help but it's not inconcievable that you might need Linux running with Windows to edit it.

    As muru points out, it needn't be this hard. You can move /boot to its own FAT32 partition. This makes it trivial to mount in Windows.

  • Insert next_entry=Windows (or whatever) into the file after the comment, before the hashes.

  • Unmount.
  • Reboot.

Scripting that in Windows is well outside my comfort zone and not really what we do here. But that should be all you need to do.

  • 1
    In this method, as I said in a comment now moved to chat, it's best to move to a separate /boot partition, and have it formatted to FAT32 or NTFS, then comfortably edit them on Windows. There's nothing in /boot that particularly requires Unix-y features. Scripting this using Powershell should then be easy. – muru Mar 15 '18 at 13:40
19

Easiest way is with Grub

It is cumbersome controlling grub from Windows. A third party application to access Ubuntu from Windows and some hacking is required. However from the top part of this post: How to change the order on my dual booting distros, you can setup grub to automatically reboot to the last menu option. So when you initially boot with windows, and it wakes up at 2 am to run updates, grub will reload Windows so it can gracefully finish updates.

When you manually reboot and pick Ubuntu from grub all your next reboots automatically load Ubuntu. This feature works equally well if you have bugs in the current kernel and want grub to automatically reboot into an older kernel version you selected.

How to get Grub to repeat last boot selection

This is fairly straight forward. Using sudo powers edit /etc/default/grub and change the following:

#GRUB_DEFAULT=0 # Rather than option #1, we'll always default to last boot choice.
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

The first line you will be commenting out and right below that insert the next two lines.

Save the file and type in the terminal:

sudo update-grub

Ubuntu command line to reboot into Windows

Currently you use something like this:

sudo grub-reboot x # Where x is Windows zero-based grub menu number
sudo reboot now

From this modified Stack Exchange answer you can use the grub default to reboot into Windows. Copy this code into your ~/.bashrc file:

function reboot-to-windows {
    WINDOWS_TITLE=`grep -i "^menuentry 'Windows" /boot/grub/grub.cfg|head -n 1|cut -d"'" -f2`
    sudo grub-set-default "$WINDOWS_TITLE"
    sudo reboot
}
  • Save the ~/.bashrc file with new reboot-to-windows function.
  • Close your current terminal session.
  • Open a new terminal session for changed ~/.bashrc to be loaded.
  • You could type : ~/.bashrc to reload it into the existing terminal session but some people recommend against do this.

To reboot into Windows from the command line use:

reboot-to-windows

If Windows automatically restarts when you aren't looking, Windows is rebooted. This allows Windows automatic updates to be processed normally over multiple-reboot cycles Windows sometimes uses.

  • 1
    This question has nothing to do with boot order. – Jennifer Mar 13 '18 at 18:09
  • 2
    @Jennifer The question is, however, an instance of the XY problem. So this answer is useful. Plus, it is actually about boot order as it is asking for a way to temporarily change the boot order from a Windows UI. – wizzwizz4 Mar 13 '18 at 19:13
2

grub-set-default should do the same as grub-reboot, but make the setting permanent. This is not exactly from Windows UI, as you asked, but maybe it works for you.

  • This question has nothing to do with boot order. – Jennifer Mar 13 '18 at 18:09
  • I don't quite get what you mean with that comment, can you explain? – Sebastian Stark Mar 14 '18 at 7:58
  • Amon San is not asking how do I get grub to default to windows -- ze is asking, if windows is already booted, how to cause a reboot now, and select which OS to boot into. – Jennifer Mar 14 '18 at 8:44
  • @Jennifer OP is not asking "how to reboot now into Windows". If so OP could simply select Windows Restart and then select Windows at the grub menu. OP is asking "When windows automatically reboots when I'm not there, how can I ensure it reboots back into Windows, not the default grub menu option". At least that's the way I see the main problem. – WinEunuuchs2Unix Mar 30 '18 at 15:57
  • Yes, OP could just select Windows Restart and then select Windows at the grub menu. But OP is specifically asking how do I get back into Windows automatically, without having to select Windows in the boot menu -- in other words, how do this without my intervention? Too much X Ying! – Jennifer Apr 2 '18 at 7:28
2

You haven't said which version of Windows or whether you're on UEFI.

If you're using a proper UEFI boot (and not legacy boot), it is possible to temporarily boot to the Windows UEFI boot entry. On Linux, this can be done using tools like efibootmgr. On Windows, I personally use EasyUEFI. It is free for personal, GUI use, but not for enterprise or CLI use. I can't vouch for its safety. It also seems to be somewhat slow, but it does seem to work

In my own setup, which uses Arch Linux (kernel EFI shim, without GRUB), and Windows 10, this is how it looks like, after picking "Manage EFI Boot Option" on the starting screen:

Image showing one-time boot option

If you're using UEFI boot, you should see something similar for Windows, plus a single entry for Ubuntu (which loads GRUB), plus some other device-specific options. The one-time boot option can then be used to set to boot to the UEFI boot entry for Windows once, and then back to GRUB the boot after that. After setting that, you restart as normal.

  • 1
    thanks, but that requires too much manual interaction each time for my taste. – amon san Mar 20 '18 at 9:19
  • 1
    Shrug. At any rate you should move /boot to NTFS or FAT32 instead of editing it as ext4. Write support for ext4 in Windows is iffy, you're risking too much that way. – muru Mar 20 '18 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.