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.

I'm using both a Bluetooth mouse and keyboard, and frankly it's really annoying having to go grab a physical keyboard in order to boot into another kernel version or into Windows on another partition. Is there a way for me to tell GRUB that when it reboots, to boot directly into a specific kernel or Windows?

Is there a command I can run along the lines of grub-reboot "Windows 7" which would cause my machine to reboot and when starting up, boot into the specified OS or kernel?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

(I'm adapting this answer from http://unix.stackexchange.com/a/11431/73, because it happens to work the same even though the question is different)

First you need to do some prep work in /boot/grub/grub.conf. Change default to saved. In every OS block, add savedefault 0, where 0 is the index of whichever kernel you want it to default to unless told otherwise. Write the value 0 to the file /boot/grub/default, so GRUB will know which default to use on your next reboot (before any of those savedefault directives have executed).

Now at any time before you reboot, you can change the value in /boot/grub/default to change what the default will be on the next boot. If you set it to 1, the second entry in the GRUB list will be the default. As soon as it starts booting, GRUB will execute the savedefault 0 directive and change the default back to 0, so on the subsequent boot you'll switch back to defaulting to 0.

To change the default, you can use grub-set-default, which takes the index number and writes it to that file. So, make an alias/script that does:

grub-set-default 1
shutdown -hr now

And when you run it, GRUB will reboot into the second entry in the list. The next time you reboot, it'll switch back to the first (or whichever you specified)

share|improve this answer
2  
In OSs I use (Debian/Ubuntu-like) /boot/grub/ gets overwritten by Grub scripts running over the user configuration files in /etc/grub and /etc/default/grub. This is triggered often on updates and would make changes non-persistent. –  gertvdijk Dec 6 '12 at 23:14
add comment

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.