I am setting up a dual booting headless Linux / Windows machine. I mostly want the machine to always boot up to Ubuntu, except for occasionally when I need to test something in windows.
I've installed Windows and Ubuntu, and currently it boots up to Ubuntu every time. I would like to be able to tell it to boot to Windows on the next boot only and then when I restart from Windows have the system return to booting Ubuntu.
I found Grub Legacy - section 4.3.1 - Booting once-only but I am using Ubuntu 14.04 server which has the newer version of grub. From what I've read, I need to make some changes to /etc/default/grub
and use sudo grub-set-default
when I want to boot to Windows.
I think those changes start with adding this to /etc/default/grub
:
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=false
Anytime changes are made to /etc/default/grub
I know that I need to then run
sudo update-grub
and which results in:
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.13.0-43-generic
Found initrd image: /boot/initrd.img-3.13.0-43-generic
Found linux image: /boot/vmlinuz-3.13.0-32-generic
Found initrd image: /boot/initrd.img-3.13.0-32-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
done
Since Windows is the 7th option in that list I believe I would run sudo grub-set-default 6
(0 based counting) - is this correct and is there a different method to get a numbered list of boot choices after the system is already booted?
Also, are the lines in /etc/default/grub
sufficient to achieve this behavior or do I need to add additional configuration?
GRUB_DEFAULT=saved
, you have to do this manually later like explained here in the second paragraph for Grub2 and thengrub-set-default 0; grub-reboot 0
– rubo77 Feb 09 '16 at 00:35grep -i "menuentry '" /boot/grub/grub.cfg|sed -r "s|--class .*$||g"|nl -v 0
– rubo77 Feb 09 '16 at 01:25menuentry
s under asubmenu
in/boot/grub/grub.cfg
must be passed togrub-reboot
asSUBMENU>MENUENTRY
. So, for instance, using some bash-fu similar to @rubo77's, I wanted to bootmenuentry
7, however this entry was under asubmenu
which was the second entry in the top-level menu, so I needed to pass'1>6'
instead (single quotes to avoid the shell interpreting >). – trent.sol Oct 19 '17 at 18:26sudo grub-reboot 2; reboot
– rubo77 Feb 27 '21 at 20:25