OpenBSD how-to: Installing GRUB and dual-booting with Windows

| | Comments (3) |

When I installed OpenBSD 4.4 on my Toshiba Satellite 1100-S101 laptop, I purposefully left Windows XP on the drive. I used the free Linux-based Parted Magic live CD to shrink the Windows partition and leave room for OpenBSD on the hard drive.

The reason I'm so comfortable partitioning a hard drive is because I've done it between 50 and 100 times. For my first three or so OpenBSD installs, however, I gave the whole drive over to OpenBSD since I didn't feel confident setting up a dual- or triple-booting system with it.

So if you ARE comfortable dual-booting lots of Linuxes, Linux and Windows, or what have you, and you have managed to install OpenBSD without killing out your other operating systems, you might want to actually run those other systems, right?

On my most recent OpenBSD install on the Toshiba, I wanted to leave Windows XP on the drive and eventually dual-boot it.

I followed the instructions on the FAQ for installing OpenBSD on a PC with Windows already installed, and I intended NOT to install the OpenBSD bootloader. Well, I didn't do that, but I also managed somehow to kill out the Windows bootloader on the drive's master boot record. That meant I couldn't boot anything.

Luckily the OpenBSD FAQ show me how to boot from the floppy I used for the install (I booted from the floppy because the CD drive isn't working), drop to a shell and install the OpenBSD bootloader. That was easy enough, but I still couldn't dual-boot.

You theoretically can use the Windows bootloader to dual-boot with OpenBSD, but since I had already killed it out and don't have a Windows XP disc to restore it, I turned to GRUB, the bootloader I always use with Linux. It's a package for OpenBSD, and if your system is set up to install packages (with your PKG_PATH in your .profile if you're going to sudo, or in root's .profile if you su to root), you can easily install it.

Since I already added my user account to the sudoers list with visudo, I used sudo at my own shell to install the package. If you su to root instead, use the line with the # prompt:

$ sudo pkg_add -i grub
or
# pkg_add -i grub

After you install grub, you are presented with a path to the Instructions for setting up grub. Those instructions say to do this:

# grub-install --no-floppy hd0

That didn't work for me. The reason is that pkg_add puts all the grub packages in /usr/local/sbin, and either by accident or design, that isn't in my path.

So I instead ran:

# /usr/local/sbin/grub-install --no-floppy hd0

That did work. It installed GRUB in the master boot record as my bootloader.

But unlike in Linux, this GRUB installation didn't create the menu.lst file that GRUB uses to select and boot the various operating systems.

A look through the man and info pages for GRUB plus a little searching on the Web helped me create a menu.lst.

Before I go into that, it's worth pointing out that while most Linux systems store that file as /boot/grub/menu.lst, in OpenBSD it's just /grub/menu.lst. There's no /boot directory. (Instead, boot is an executable in the root directory, the reasons for which both elude me and seem unimportant at this stage.)

Use any text editor you have installed (vi in the base OpenBSD system; or nano or Geany in my system, both of which I've previously added with pkg_add) to create /grub/menu.lst.

Once again, since I have sudo set up, I used it and the nano editor in my shell to create the file. As far as partitions go, on my drive, Windows XP is installed first, followed by OpenBSD. To dual-boot with GRUB, here's how I created menu.lst:

$ sudo nano /grub/menu.lst

That creates the menu.lst file, into which I typed the following:

default 0 timeout 5

title Windows XP
root (hd0,0)
chainloader +1

title OpenBSD
root (hd0,1)
chainloader +1

I saved and closed the file (F3 and then ctrl-X in nano) and then rebooted the PC. As yet another aside, here's how I reboot in OpenBSD:

$ sudo shutdown -r now

Upon reboot, GRUB ran and allowed me to choose between Windows and OpenBSD.

I tested both OSes, and both successfully booted.

I'll probably reverse the order so OpenBSD is in the top spot and will boot automatically if I don't purposefully select it. I could also increase the timeout time to have more of a chance to pick one OS or the other, but right now that doesn't seem necessary.

Observations: While documentation in OpenBSD tends to be extremely detailed, it's not always 100 percent correct. The man pages and info pages didn't tell me, for instance, that the grub executables, including grub-install, couldn't be run from the / directory and that the full path to them was needed. I only found that path by poking around in a file manager. Once I did have the path, I was able to use grub-install successfully with the directions as given. Adding the path to the instructions would certainly help others get GRUB working in OpenBSD.

Since both of the OSes on my laptop — Windows XP and OpenBSD have their own bootloaders on their respective root partitions, all GRUB has to do is chainload to the proper partition, after which time the respective systems' bootloaders take over. After using GRUB to dual- and triple-boot GNU/Linux distributions for more than a year, I've discovered that chainloading as much as possible is a very good thing, especially when dual-booting two Linux distros. That way, "automagic" updates to each distro's menu.lst are just about guaranteed to go smoothly.

This technique made things much easier when dual-booting Debian and Ubuntu. When I didn't chainload to one or the other, one of the two OSes never did get the proper menu.lst updates when a new kernel was installed. But by chainloading to all but one of the distros on the hard drive and installing GRUB in all but one of the distros' root partitions, I've avoided countless problems.

3 Comments

Hmmm... I remember being able to boot specifically the FreeBSD loader with grub, rather than just chainloading. I think I booted loader.conf or something, and it acted as a kernel.

Why the BSDs can't just use grub as default and not their own crappy bootloaders eludes me.

I,too, remember an actual GRUB stanza for FreeBSD that had nothing to do with chainloading.

Re: crappy bootloaders -- I have to agree with you. Why the BSD bootloaders are so unforgiving when it comes to dual-booting is a mystery to me.

I'm going to try again, but when I tried to set up OpenBSD on my Mac G4, I could never get it to boot. I might have missed something (specifically running fdisk -u wd0), but maybe I didn't. Since Debian was so easy to install and run, that's what I still have on that box.

I still can't remember whether it was, in fact, FreeBSD or OpenBSD that I was able to boot via GRUB with an actual stanza rather than simply chainloading to it's own bootloader, but the fact that chainloading is so simple and foolproof means that I'm going to do it every time.

I remember a Slackware install where I tried to load it from the GRUB bootloader controlled by another Linux distro on the box.

No matter what I did, I couldn't manage to get a proper stanza that would load Slackware.

Of course if you let Slackware control the MBR and then install the GRUB package (it's on disc 3, if I remember correctly, or on the ftp), then you automatically get a proper menu.lst file.

But now whenever I install Slackware in a dual-booting situation, I just let the installer put LILO on the root partition (not the MBR) -- I could even make a /boot partition and use that, I imagine -- and proper stanza that would load Slackware.

Of course if you let Slackware control the MBR and then install the GRUB pac then I chainload to it from another distro's GRUB.

Chainloading -- it's your friend!!!

Leave a comment

Tech Talk column

Steven Rosenberg's weekly Tech Talk column, which appears Saturdays in the Los Angeles Daily News, is now available on the Daily News Technology page.

About this blog

New ways to sign in to comment: I just added the ability for prospective commenters on this blog to sign in using their AOL, Yahoo! and Wordpress.com accounts (for the past 200 posts anyway ... more than that will take an extensive, middle-of-the-night rebuild). That's in addition to the other sign-in choices, which include starting a Movable Type account on this blog, Typekey, OpenID, Live Journal and Vox. If you have trouble getting your Movable Type account verified, or any of the other sign-in options are not working properly, please e-mail me. With these added ways of signing in, there's more reason than ever for you to make a comment (or several!).




Steven Rosenberg aims to learn what he does not know. He writes about it here.



About this Entry

This page contains a single entry by Steven Rosenberg published on November 21, 2008 3:00 AM.

My latest project: OpenBSD on the Toshiba Satellite 1100-S101 was the previous entry in this blog.

Ars Technica adds Open Ended, Kit blogs to main journal navigation is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Recent Comments

Steven Rosenberg on OpenBSD how-to: Installing GRUB and dual-booting with Windows: I still can't remember whether it was, in fact, FreeBSD or OpenBSD tha ...

Steven Rosenberg on OpenBSD how-to: Installing GRUB and dual-booting with Windows: I,too, remember an actual GRUB stanza for FreeBSD that had nothing to ...

aronzak.wordpress.com on OpenBSD how-to: Installing GRUB and dual-booting with Windows: Hmmm... I remember being able to boot specifically the FreeBSD loader ...

Powered by Movable Type 4.25

LXer

Links

Daily News technology
LXer
Distrowatch
Linus' Blog
David Pogue
BoingBoing
Linux Today
TuxRadar
Linux.com
Linux Planet
The Open Road
Linux Outlaws podcast
Dan Lynch
Fabian Scherschel
The VAR Guy
Larry the Free Software Guy
Chess Griffin
Linux Reality podcast
Desktop Linux
Practical Technology
Linux Devices
ZDNet
ZDNet U.K.
iTWire
CNet News
TechCrunch
The Register
Ars Technica
Reg Developer
Computerworld
Computerworld blogs
Steven J. Vaughan-Nichols at Computerworld
Debian
Planet Debian
Debian Forums
Debian News
debianHELP
debiantutorials.org
The Debian User
Wolfgang Lonien
Debian-News.net
Debian Administration
Debian Admin
Debian Weather
Ubuntu
Xubuntu
Kubuntu
Edubuntu
Gobuntu
Planet Ubuntu
Ubuntu Forums
Ubuntu Geek
Works With U
Dustin Kirkland
Ubuntu UK Podcast
Popey
gNewSense
CrunchBang Linux
OpenBSD
OpenBSD Journal
OpenBSD Ports
OpenBSD 101
Planet.OpenBSD.nu
jggimi's OpenBSD live CD
DaemonForums
BSDanywhere
Marc Balmer
Denny's OpenBSD blog
Polarwave's OpenBSD Tips and Tricks
Binary Updates for OpenBSD
Puppy Linux
Damn Small Linux
Tiny Core Linux
PCLinuxOS
Mandriva
Red Hat
Red Hat News
Red Hat Blogs
Red Hat: Truth Happens
Red Hat Magazine
CentOS
Planet CentOS
Fedora
Slackware
Slackbuilds
Robby's Slackware Packages
Slackblogs
dropline GNOME for Slackware
GNOME Slackbuild
GWARE - GNOME for Slackware
Wolvix
Zenwalk Linux
Vector Linux
Slax
Splack Linux — Slackware for Sparc
Nonux
How to Forge
marc.info BSD and Linux mailing list archive
FreeBSD
FreeBSD, the Unknown Giant
A Year in the Life of a BSD Guru
NetBSD
PC-BSD
DesktopBSD
DragonFlyBSD
DragonFlyBSD Digest
DesktopBSD
BSD Talk podcast
OpenSolaris
MilaX
BeleniX
DeLi Linux
Linux Loop
Electronista
Engadget
Gizmodo

Advertisement

Other blogs

Johnson Update in Inside USC with Scott Wolf
Has Bynum outgrown Kareem? in Inside the Lakers
Can the Angels just get to the end of this thing without an injury? in Farther Off the Wall
Neuheisel On: in Inside UCLA with Jon Gold
U.S. Roster for Final Two WCQ Announced in 100 Percent Soccer