This is for anyone who dual boots Fedora and Windows. Since Fedora is my default in GRUB, when I need to reboot into Windows I normally have to wait for the GRUB menu to come up so I can select Windows. I wanted a command that would let me do this directly from Fedora. And since I couldn't find one, I wrote this. Now I have an icon on the Gnome panel that lets me boot to Windows in one click, while leaving the default boot as Fedora.
If you want to try it, here's how:
Updated March 01, 2007: Installation is now much easier than the instructions below. There is a downloadable rpm available for FC6. To see what bootnext looks like, and for download instructions, click here.
*disclaimer* -- I've run this on my box without problems. It doesn't do anything super smart to tell Gnome to shut down nicely, so make sure you save open files before you run it. Don't sue me, I'm already broke.*/disclaimer*
bootdos - the main program
Below is the python code for the
bootdos program. You'll need to be root (or use sudo) to install it:
$ sudo mv
bootdos /usr/local/sbin/bootdos
$ sudo chmod 0755 /usr/local/sbin/bootdos
Code:
#!/usr/bin/python
# bootdos: Tell GRUB to boot Windows for the next boot only, then reboot
#
# Written by Jack Spaar <jspaar at myrealbox dot com>
# Created Wed Feb 11 20:01:30 PST 2004
# v0.1
import re, os, sys
progName = "bootdos"
WINDOWS_TITLE = "DOS"
GRUB_CONFIG = "/etc/grub.conf"
GRUB_PATH = "/sbin/grub"
def grub_title_to_index(searchTitle):
f = open(GRUB_CONFIG, 'r')
lines = f.readlines()
f.close()
p = re.compile('^\s*title\s*(.*)')
titleNumber = -1
titleCount = 0
for line in lines:
m = p.match(line)
if m :
titleCount += 1
if ( m.group(1) == searchTitle ) :
titleNumber = titleCount - 1
break
return titleNumber
## MAIN
num = grub_title_to_index(WINDOWS_TITLE)
if (num == -1) :
print "%s: %s not found in %s" %(progName, WINDOWS_TITLE, GRUB_CONFIG)
sys.exit(1)
# Now tell GRUB we want that other OS for the next boot only
grubCommands ='savedefault --default=%s --once\nquit\n'%(num)
print "grubCommands =",grubCommands
pipe = os.popen(GRUB_PATH, 'w')
pipe.write(grubCommands)
pipe.close()
# Now reboot
os.system('/sbin/shutdown -r now &')
sys.exit(0)
At this point you could test the program from the command line. Provided that the GRUB menu entry for your Windows partition is entitled "DOS", it will reboot into Windows:
$ sudo /usr/local/sbin/bootdos
Configuring PAM
The next steps allow us to run the program without using sudo. This is good because we want out clicky icon to run without asking for a password. It's a little complicated to set up, but makes it easy to use.
Cut-and-paste the following code to a temp file named 'xx':
Code:
USER=<user>
PROGRAM=/usr/local/sbin/bootdos
Install it like this:
$ sudo mv xx /etc/security/console.apps/bootdos
$ chmod 0644 /etc/security/console.apps/bootdos
Now paste this chunk to another temp file, say 'yy':
Code:
#%PAM-1.0
auth sufficient pam_rootok.so
auth required pam_console.so
#auth required pam_stack.so service=system-auth
account required pam_permit.so
$ sudo mv yy /etc/pam.d/bootdos
$ sudo chmod 0644 /etc/pam.d/bootdos
$ sudo ln -s /usr/bin/consolehelper /usr/local/bin/bootdos
Now when we run /usr/local/bin/bootdos as a normal user it will call consolehelper to run /usr/local/
sbin/bootdos as root. Phew. (Type 'man consolehelper' to understand more about how this works.)
You have these things installed so far:
/usr/local/sbin/bootdos -- the main program
/usr/local/bin/bootdos -- symlink to consolehelper
/etc/security/console.apps/bootdos -- tells consolehelper where the main program is
/etc/pam.d/bootdos -- tells PAM to give us root permissions when we run
bootdos
Last step - make the clicky icon
1) right-click on an empty area of the gnome panel. Doesn't matter where, you can move it later.
2) A menu should appear, select Add to Panel->Launcher...
Now in the Create Launcher dialog,
3) Fill in the name field with something like "Boot to Windows"
4) Fill in the command field with: /usr/local/bin/bootdos
5) Click the "No Icon" after the Icon field to browse for an icon. Pick what you like, and OK.
6) Click OK back on the Create Launcher dialog.
You're done. You now have a one-click boot-to-windows button. W00t!
PS - if you find out there's already some super-easy pre-fabricated way to do all this don't tell me.