How To Dual Boot FreeBSD and Windows XP using GRUB

Ever needed to dual boot Windows XP with FreeBSD and wanted to do it via Grub?

Well, here’s how!

This document assumes that Windows XP is installed on the first partition (i.e. /dev/ad0s1 in freebsd parlance) and that FreeBSD is on the second partition (i.e. /dev/ad1s1), thats the setup on my laptop anyway :)

First install the port:-

cd /usr/ports/sysutils/grub
make install

Now create the “menu.lst” file:-

vi /boot/grub/menu.lst

# For booting FreeBSD

title FreeBSD
root (hd0,1,a)
kernel /boot/loader

# For booting Windows XP

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

NOTE: This will make FreeBSD the default OS

Make MBR writable:-

sysctl kern.geom.debugflags=16

NOTE: if you do not use the above command then you will not be able to run the grub-install script, it will dump out with something like this:-

[zaphod] /boot/grub# grub-install hd0

GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
<code>lists possible command completions.  Anywhere else TAB lists the possible completions of a device/filename. ]

grub>; root (hd0,1,a)
Filesystem type is ufs2, partition type 0xa5
grub>; setup  --stage2=/boot/grub/stage2 --prefix=/boot/grub (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/ufs2_stage1_5" exists... yes
Running "embed /boot/grub/ufs2_stage1_5 (hd0)"... failed (this is not fatal)
Running "embed /boot/grub/ufs2_stage1_5 (hd0,1,a)"... failed (this is not fatal)
Running "install --stage2=/boot/grub/stage2 /boot/grub/stage1 (hd0) /boot/grub/stage2 p /boot/grub/menu.lst "... failed

Error 29: Disk write error
grub>; quit

grub-install script

The grub-install script saves you from having to install the various components manually using the grub command line interface.

grub-install hd0

NOTE: hd0 is listed in the /boot/grub/device.map file to map to the correct device (i.e. /dev/ad0)

More info is available here:-

http://www.gnu.org/software/grub/

Tags: , , ,

3 Responses to “How To Dual Boot FreeBSD and Windows XP using GRUB”

  1. Wirasto S. Karim says on :

    Nice article :)
    Thank’s

  2. Sai Vinoba says on :

    Hi Ubergeek,
    >>
    … that FreeBSD is on the second partition (i.e. /dev/ad1s1)
    >>
    >>
    title FreeBSD
    root (hd0,1,a)
    >>
    Considering you have only one harddisk and two windows style (primary) partitions, if FreeBSD is on second partition or slice of that single harddisk, shouldn’t it be /dev/ad0s2, instead of /dev/ad1s1? Your grub entry is correct. ad1s1 is first slice of second harddisk not second slice of first harddisk.

  3. argv says on :

    If you know what which OS you will boot next… e.g. you work in BSD most of the time and boot to XP occasionally to do some things… there is another way.

    You simply move the boot flag (0×80) to the OS (partion) you want to boot.

    Each OS has it’s own tool(s) to do this safely and quickly.

    e.g.

    BSD –> fdisk -B

    XP –> ‘3parted.exe’ exefrom PLoS Linux site or tools from ‘the starman’ site

    Linux –> GNU fdisk or GNU parted

    This alternative method obviates the need for Grub and allows you to keep the Windows MBR unmolested. :)

Leave a Reply