Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

LILO had a simple feature that allowed one to select the boot menu entry that should be used on the next reboot while in Linux, thus one could select the OS to be booted into on shutdown and didn't had to wait till the computer rebooted to the boot menu and select the next entry manually.

For Grub that feature has existed as unofficial patch as well.

This was quite some years ago. Has that feature made it into mainline Grub in the meantime? Is it available under Ubuntu and is there any way to integrate it with the GUI (i.e. have not only a "Reboot" entry, but a "Reboot into Windows" entry in the shutdown menu)?

share|improve this question

4 Answers

up vote 6 down vote accepted

There is a grub command just to do so, it is grub-reboot.

It seems to only work when you have grub configured to start with the last saved entry. So if you have not already done so, modify /etc/default/grub and set

GRUB_DEFAULT=saved

then update grub configuration file:

sudo update-grub

From now on, at each boot grub will start the last used entry.

Now, if you want to set in advance what should be the system to boot the next time, use

sudo grub-reboot ENTRY

where ENTRY could be a number relative to a menu entry (numbered starting from 0), or an exact menu entry title, for example

sudo grub-reboot "Microsoft Windows XP Professional (on /dev/sda1)"

This command can easily be make available as a launcher

#!/usr/bin/env xdg-open
#
# save as ~/Desktop/reboot-into-windows.desktop
#

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=sh -c 'gksu "grub-reboot 2" && gnome-session-save --shutdown-dialog'
Name=Reboot into Windows
Icon=gnome-panel-launcher

but I don't know how it could be integrated into the system menu.

You can obtain the available menu entry title with

sed -n '/menuentry/s/.*\(["'\''].*["'\'']\).*/\1/p' /boot/grub/grub.cfg 
share|improve this answer

As far as I understood this will not be exactly what you want but I guess pretty close. Just follow the link webupdate article.

share|improve this answer
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Marco Ceppi Sep 26 '11 at 20:22

I'm not sure if this will 100% also work in ubuntu, but I once made this work on a centos machine

basically you'll have to tell grub which id # from grub.conf it should run next. The id # can be found out by

echo `sudo grep ^title /boot/grub/grub.conf | grep -n Windows | cut -f 1 -d:`-1

so in my case this would e.g. output "4-1" as the fourth entry in my grub.conf contains the text "Windows". (Replace this with the actual entry name (also partially) you want to use. Then you can feed this to grub like:

echo "savedefault --stage2=/boot/grub/stage2 --default=4-1 --once" | sudo /sbin/grub

and at the next reboot it should automatically boot the entry you've told it to.

this all can be put together in a script like the following:

#!/bin/sh
let NEWBOOT=`sudo grep ^title /boot/grub/grub.conf | grep -n Windows | cut -f 1 -d:`-1
echo Booting $NEWBOOT - `sudo grep ^title.\*Windows /boot/grub/grub.conf`
echo "savedefault --stage2=/boot/grub/stage2 --default=$NEWBOOT --once" | sudo /sbin/grub
sudo reboot

the script will automatically determine which entry from your grub.conf corresponds to the text "Windows", will feed this to grub to tell what should be loaded on next boot and will reboot your pc.

for a gui you could e.g. add a shortcut icon to your desktop to achive this.

share|improve this answer
The config file for grub-legacy is menu.lst, not grub.conf. For grub2, it is grub.cfg, but your second command is only for grub-legacy. – psusi Sep 26 '11 at 15:46

Simply edit /boot/grub/grub.cfg and change the default entry to point to the entry you want to boot. The value can either be the ordinal number of the entry (starting from zero for the first one) or you can place the full title of the entry you want in quotes.

share|improve this answer
Don't advice to modify boot.cfg, it will be restored at each manual or automatic update-grub. User should modify /etc/default/grub, instead. – enzotib Sep 26 '11 at 16:46
@enzotib, since the change is only meant to pertain to the next boot, there is no reason to do it that way. – psusi Sep 26 '11 at 17:14
you forget that a wrong editing on that file could lead to an unbootable system – enzotib Sep 26 '11 at 18:08
@enzotib, not really; one of the beautiful things about grub2 is that you can always recover manually at the prompt. Also the danger of screwing up other parts of the file is a specious argument, and if you get the default line wrong, the worst that happens is that it defaults to the first entry. – psusi Sep 26 '11 at 18:11

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.