Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

To clarify, I am wanting to dual boot Windows and a Linux distribution. I already know how to set my laptop up to do that. However, I don't want the grub menu to display on boot. I would like for it to automatically boot Windows by default, unless a modifier key is pressed on boot (ctrl for instance). If the modifier key is pressed, it will boot the Linux distro.

Is this possible?

share|improve this question
    
Are you using grub or grub2? Any specific linux distribution? –  Anthon Apr 12 '13 at 13:06
    
Well currently I don't have a bootloader installed. I was thinking Kali, BackBox, or a similar distribution for pentesting. I manage a Windows domain so I'd prefer to keep Windows as my primary OS. –  bw. Apr 12 '13 at 22:56

3 Answers 3

In Grub2:

set timeout=0
if keystatus --ctrl; then
    set timeout=15
fi

If ctrl is pressed, it will display the menu for 15 seconds before booting the standard entry; if ctrl is not pressed, it will boot the standard entry right away without any menu.

For details refer to info grub on keystatus. There are some caveats, it may not work on all platforms. Alternatively to --ctrl, it also supports --alt and --shift so you may try those should --ctrl not work.

Alternatively you could put Grub on a USB stick. So Windows would boot directly when it's not plugged in. You can also put several Live CDs, and things like memtest or freedos on the USB stick. Very useful thing to have in your wallet :)

share|improve this answer
    
Oooh, nice, a general method! –  SamB Nov 25 at 4:47

As you write in your comment this is for a new installation, so I assume it will come with grub2.

Actually, always booting Windows with grub1 was difficult in my experience. The addition of a new kernel, to the list of kernels versions to select from (e.g. after an kernel upgrade of linux), would change the position of the Windows entry. This caused a hard-coded GRUB_DEFAULT point to something else (most often the memory test inserted by the grub installre between the list of linux kernels and the windows entry in the list). With grub1 I solved this issue by having a script that purged any but the latest 3 kernels, thereby keeping the Windows position fixed.

So make sure you go with grub2 as it makes things easier because of 2 features:

  • grub2 allows submenus, so that the value of GRUB_DEFAULT doesn't become invalid after a kernel-upgrade (which pushes old kernels in the submenu)
  • grub2 generates the menu entries through scripts (in /etc/grub.d on Ubuntu)

I recommend to make the change to the scripts to force Windows to be the first option in the menu: in /etc/grub.d rename 30_os-prober (which generates the windows entry) to something like 09_os-prober. This script is then executed before 10_linux as the scripts are executed sorted by filename and the windows entry will always be on top. And the top is the default if nothing else is specified.

Run update-grub to create the menu in /boot/grub, so that takes care of always booting Windows.

As for not having the menu not to be shown you want to use GRUB_HIDDEN_TIMEOUT and some others in /etc/grub/default:

# wait 5 seconds for a key-press before showing the menu
GRUB_HIDDEN_TIMEOUT=5
# do not show the countdown counter
GRUB_HIDDEN_TIMEOUT_QUIET=true
# after hidden timeout is done wait 0 seconds -> boot without menu
GRUB_TIMEOUT=0

The above combination waits 5 seconds without output (countdown) or a menu and then boots the first entry. (Again: run update-grub after changing that).

share|improve this answer

This thread on AskUbuntu addresses an almost identical issue. Apparently you can hide the grub dialog and bring it up by pressing shift and otherwise let the default operating system boot after the time you defined via the GRUB_TIMEOUT entry in your grub.cfg.

GRUB_DEFAULT= 2 #depends on which entry Windows is
hiddenmenu #this hides the menu
GRUB_TIMEOUT=3 #example for 3 seconds
share|improve this answer
    
IIRC that is for the old grub only. That is why I asked the OP. –  Anthon Apr 12 '13 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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