How to set up a machine to dual-boot OpenBSD and Windows XP

There are many ways to set up a dual-boot. This method uses Windows' NTLDR, however you should know there are both free and commercial alternatives. One that I have successfully used is GNU GRUB. The following configuration is easier to get going than GRUB, although it is certainly less configurable. My method also requires Windows to be present, so if you delete your Windows partition someday, you'll need to get another bootloader.

I cover two ways of achieving the same setup: the easy way and the harder way. In both cases, you'll want both Windows and OpenBSD installed ahead of time. I suggest that you install Windows before you install OpenBSD. Unless my memory fails me, the Windows installer of yore was unkind enough to actually erase your other partitions. Out of laziness, I assume that current versions of the Windows installer are equally thoughtless. To prevent this from happening, install Windows first. OpenBSD's FAQ has a good writeup on preparing your disk for multiple operating systems. You should follow it.

By the way, if you find errors, omissions, or outright lies in this how-to, please let me know.


The easy method

Software required:

Windows XP, installed
OpenBSD, installed
BootPart

I'm going to assume that your 1st partition is Windows, and that your 2nd partition is OpenBSD. Note that OpenBSD's fdisk partition IDs start counting from zero. This means that the first partition is fdisk partition #0, the second partition is fdisk partition #1, and so on. I'm also going to assume that you followed OpenBSD's instructions and marked your OpenBSD partition as the active one. Good, now we're going to undo some of your work.

$ sudo fdisk wd0
Disk: wd0       geometry: 9729/255/63 [156296385 Sectors]
Offset: 0       Signature: 0xAA55
â         Starting       Ending       LBA Info:
 #: id    C   H  S -    C   H  S [       start:      size   ]
------------------------------------------------------------------------
*0: 07    0   1  1 - 1911 254 63 [          63:    30716217 ] HPFS/QNX/AUX
 1: A6 1912   0  1 - 9728 254 63 [    30716280:   125580105 ] OpenBSD     
 2: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
 3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused   

Here I have a 60GB disk that has two partitions. Partition 0 is a ~15GB NTFS partition, and partition 1 is a ~45GB OpenBSD ffs partition. fdisk recognizes our NTFS partition as "HPFS/QNX/AUX" because the partition type ("7") is the same. We're now going to mark the Windows partition as active. I like to use the interactive editor.

$ sudo fdisk -e wd0
Enter 'help' for information
fdisk: 1> f 0
Partition 0 marked active.
fdisk:*1> w
Writing MBR at offset 0.
fdisk: 1> q

Now, reboot your machine so that you can get into the Windows side.

$ sudo reboot
When Windows comes up, download BootPart with your favorite web browser. As of the writing of this document, BootPart is at version 2.60.

We need to fetch OpenBSD's partition boot record, store it on disk (in the Windows partition), and then configure our boot.ini to recognize OpenBSD as one of our choices when the boot selection menu comes up. BootPart makes this trivially easy.

Drop into a Windows shell by going to the "Run..." menu under the "Start" menu and typing "cmd", then hitting OK. If bootpart.exe is not installed in your $PATH environment variable, or if you're not in bootpart.exe's installation directory, 'cd' there. In my case, I added bootpart.exe to my $PATH. Let's start by running bootpart.exe without any options so we can see what BootPart thinks of our disk.

C:\>bootpart.exe
ˆBoot Partition 2.60 for WinNT/2K/XP (c)1995-2005 G. Vollant (info@winimage.com)
WEB : http://www.winimage.com and http://www.winimage.com/bootpart.htm
Add partition in the Windows NT/2000/XP Multi-boot loader
Run "bootpart /?" for more information

Physical number of disk 0 : e93782fc
 0 : C:* type=7  (HPFS/NTFS), size= 15358108 KB, Lba Pos=63
 1 : C:  type=a6 , size= 62790052 KB, Lba Pos=30716280

You can see here that BootPart sees that same information that OpenBSD's fdisk did. OpenBSD's partitions are of type "a6". For the record, FreeBSD's type is "a5" and NetBSD's is "a9".

Now we simply need to tell BootPart to dump OpenBSD's partition boot record, and add partition 1 to NTLDR's boot.ini file. This is achieved by running the following command:

C:\>bootpart.exe 1 C:\openbsd.pbr "OpenBSD"

If you are successful, BootPart will report something like the following:

Writing a boot sector using LBA position 30716280 (0x1d4b178)
C:\openbsd.pbr written
C:\BOOT.INI updated

Now, if you're paranoid, you can go and check your C:\BOOT.INI file yourself. Go have a look. You should see something like this:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
C:\openbsd.pbr="OpenBSD"

You may be wondering why the BOOT.INI file lists Windows as the 1st partition. Didn't fdisk/BootPart list it as 0? This isn't a mistake-- Windows starts counting from 1. fdisk starts counting from 0. This will be important later on.

Of course, we won't really be satisfied until OpenBSD is the default OS to boot. We just need to run one more command:

C:\>bootcfg /default /ID 2

If successful, you should see the following:

SUCCESS: Changed the default OS in the BOOT.INI.

Why ID 2? Well, remember what I said about Windows counting from 1 and not 0? Your OpenBSD partition will be partition 2 in NTLDR parlance.

At this point, your BOOT.INI should look something like this:

[boot loader]
timeout=30
default=C:\openbsd.pbr
[operating systems]
C:\openbsd.pbr="OpenBSD"
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

I also like to change that "timeout=30" to read "timeout=10" or something shorter, where the number is in seconds. Who wants to wait around for 30 seconds? That spyware ain't downloading itself!

Next, reboot your machine, and voila!, you should have a nifty boot menu.


The harder method

Have one of these, and then follow the instructions ;^) Kidding.

Software required:

Windows XP, installed
OpenBSD, installed

Again, I'm going to assume that your 1st partition is Windows, and that your 2nd partition is OpenBSD. I'm also going to assume-- again-- that you followed OpenBSD's instructions and marked your OpenBSD partition as the active one.

We need to dump OpenBSD's boot record to disk. As it is mentioned in OpenBSD's FAQ, if you don't understand this command, you won't get the results you want. The FAQ is "nice" enough to assume that your hard disk is a SCSI device, apparently to make sure that you were really listening. I'll be a little nicer. This assumes you're using an EIDE disk. Note that we're accessing the character device here. The following command dumps the first 512 bytes of the / (root) partition, which contains the partition boot record.

NOTE: If you really want to trash a disk, dd is your friend. Be careful!

$ sudo dd if=/dev/rwd0a of=openbsd.pbr bs=512 count=1

You'll need to copy this file somewhere that you can get at it later from Windows. As far as I am aware, there is no way to read an ffs partition from Windows, so your best bet is to copy it to another machine. I use scp, like so:

$ scp openbsd.pbr dbarowy@boojum:.

I'm going to leave it up to you to figure out how to use SSH/SCP if you don't know already. Try starting with the man page.

Now we need to mark our Windows partition as bootable in fdisk.

$ sudo fdisk wd0
Disk: wd0       geometry: 9729/255/63 [156296385 Sectors]
Offset: 0       Signature: 0xAA55
â         Starting       Ending       LBA Info:
 #: id    C   H  S -    C   H  S [       start:      size   ]
------------------------------------------------------------------------
*0: 07    0   1  1 - 1911 254 63 [          63:    30716217 ] HPFS/QNX/AUX
 1: A6 1912   0  1 - 9728 254 63 [    30716280:   125580105 ] OpenBSD     
 2: 00    0   0  0 -    0   0  0 [           0:           0 ] unused      
 3: 00    0   0  0 -    0   0  0 [           0:           0 ] unused   

Here I have a 60GB disk that has two partitions. Partition 0 is a ~15GB NTFS partition, and partition 1 is a ~45GB OpenBSD ffs partition. Again, fdisk's interactive editor:

$ sudo fdisk -e wd0
Enter 'help' for information
fdisk: 1> f 0
Partition 0 marked active.
fdisk:*1> w
Writing MBR at offset 0.
fdisk: 1> q

Now, reboot your machine so that you can get into the Windows side.

$ sudo reboot

When you are booted into Windows, copy the openbsd.pbr file you made before to your root directory on C:\. We're now going to hand-edit our C:\BOOT.INI file. Notepad does the trick for me.

Append the following line to your BOOT.INI:

C:\openbsd.pbr="OpenBSD"

Your modified BOOT.INI should look something like this.

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
C:\openbsd.pbr="OpenBSD"

It's really that simple. If you want to make OpenBSD the default, change the default line to read:

default=C:\openbsd.pbr

You may have noticed in the easy method that BootPart also switched the order of the OpenBSD and Windows entries (OpenBSD first) in the [operating systems] section of the file, but I don't think this is strictly necessary. Feel free to change the timeout here as well. "timeout=30" represents 30 seconds. Also note that Windows numbers its partitions starting with 1, instead of 0 like fdisk. If you work with any Windows tools (like bootcfg), you'll need to keep that in mind.

When you're done, save the file and reboot. Now you have a basic boot selection menu. For reference, my BOOT.INI looks like this:

[boot loader]
timeout=10
default=C:\openbsd.pbr
[operating systems]
C:\openbsd.pbr="OpenBSD"
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

Just remember that this boot setup requires Windows to work, since NTLDR is an NT program. If you delete your Windows partition, you will need a new bootloader.

If you want more information about NTLDR hacking check out these two pages:

How to edit the Boot.ini file in Windows XP, and The NTLDR Hacking Guide.



This page is already printer-friendly.

Valid XHTML 1.1! Get Firefox
©2003 danwuzheer design
This page is valid XHTML 1.1.
If you want all of your traffic to fall into a deep, dark hole, please email me at devnull@barowy.net.