# Windows/FreeBSD attempted dual boot; only Windows will boot.



## protondonor (Mar 12, 2013)

The short version: I have an attempted dual-boot of Windows 7 and FreeBSD 9.1, but only Windows 7 will boot.

What happens when I start up:
Shows manufacturer's screen

Then goes into boot0 showing

```
F1 FreeBSD
F2 Win

F6 PXE
```
Pressing F2 starts Windows BCD, pressing F1 causes # to appear and then does nothing.

Windows BCD (modified by EasyBCD) shows

```
Windows 7
FreeBSD 9.1
```
Selecting Windows 7 boots into Windows, selecting FreeBSD shows a blank screen with a blinking cursor, out of which the only escape is pressing control+alt+delete.

Prior state was with boot0 only (I was following nsth's instructions from this thread); F2 would launch Windows BCD, which would boot Windows without offering a choice. F1 still wouldn't work. After reading a lot more threads, it seemed that EasyBCD was the preferred method of doing this, so I installed EasyBCD, with results as shown above.

Both Windows and FreeBSD are installed on the same hard drive; if I remember my installation correctly Windows occupies partition ada0s2 (approximately 675 GB; no separate recovery partition) and FreeBSD occupies partition ada0s1 (25 GB). Both of these are primary partitions, the partition format is MBR, and there are no other hard drive partitions. (Windows insists that ada0s1 is 100% free, but I'm guessing that's only because ada0s1 is not using a NTFS or FAT file system, is that correct?)

So I'm trying to figure out how to get this to boot FreeBSD, without messing with my Windows data. (There's a lot of important stuff there.) What steps should I take? Do I need to use fixmbr to override boot0 in the MBR, or should I instead try to use boot0 as my boot manager as I was originally planning?


----------



## SirDice (Mar 12, 2013)

Use the Windows fixmbr to fix the boot and let EasyBCD take care of the dual booting.


----------



## protondonor (Mar 12, 2013)

fixmbr ran but after restarting I just got a "Missing Operating System" error. Running fixboot or rebuildbcd results in an error message, namely "The volume does not contain a recognized file system." Startup Repair claimed it could not repair the problem automatically.

Furthermore the Windows disk doesn't actually recognize any Windows OS installed, although scanos says there is one. I haven't been able to add my SATA controller or hard drive drivers using the Load Drivers button (it just gives "The installation has failed"), although the Load Drivers tool can browse my hard drive. I ran chkdsk and it only found 4KB of bad sectors, and before starting this, my hard drive was working fine.


----------



## protondonor (Mar 12, 2013)

Never mind my previous post. I got Windows to boot properly, without going through boot0, through the following steps:


run [cmd=]fixmbr[/cmd]
boot from FreeBSD 9.1 Live CD
run [cmd=]boot0cfg -B ada0[/cmd]
the Windows disk now recognizes that I have a damaged install of Windows 7; repair it using the suggested options
boot Windows 7; boot0 is still installed
shut down, boot from Windows disk
run this series of commands, including [cmd=]bootrec /rebuildbcd[/cmd], from Windows disk
boot Windows 7; boot0 is now uninstalled!

After doing this, I added a boot option for FreeBSD in EasyBCD, but the boot screen for FreeBSD is still a single blinking cursor.


----------



## jgrim (Mar 13, 2013)

Doesn't EasyBCD install something on the Windows file system?  I think it's a file that contains the first stage bootloader for FreeBSD.  Perhaps this file does not work with 9.x BSD?  The articles and posts I've seen regarding EasyBCD and FreeBSD all refer to the 8.x versions.  There may be a way to update that boot file by copying something from FreeBSD, but I don't know what that would be.

I was having a similar problem when I tried EasyBCD, but with Windows on ada0 and FreeBSD on ada1.  For my install I just use the BIOS boot menu to select the disk.  I've used EasyBCD successfully on Linux systems, but haven't got it to work with FreeBSD (yet).


----------



## kpa (Mar 13, 2013)

EasyBCD makes a copy of the boot sector, if it does not work when chain loaded by EasyBCD it's very likely it does not work on its own either.


----------



## protondonor (Mar 13, 2013)

kpa: That's what I was suspecting. Is it likely that my installation failed? If so, how would I go about reinstalling it without overriding the boot sector and having to retrace my steps again?


----------



## boyans (Mar 14, 2013)

See if this manual can help
Dual boot Windows 7 and Linux/UNIX


----------



## jgrim (Mar 14, 2013)

How is your partition table formatted?  MBR or GUID?  From what I have read in (old) forum posts, EasyBCD may not do well with GUID formatted partition tables. I checked the EasyBCD documentation, but could not find anything either for or against GUID partitions.


----------



## larryvc (Mar 15, 2013)

boyans said:
			
		

> See if this manual can help
> Dual boot Windows 7 and Linux/UNIX



I followed that procedure and got a "Boot error" message.  I suppose this is a little bit better than a blinking cursor.


----------



## wblock@ (Mar 15, 2013)

The hard part of this is getting FreeBSD installed to a second slice without it overwriting the bootcode in the MBR.  After that, boot Windows, install EasyBCD, and use it to add an entry to the boot menu for the FreeBSD slice.  That's really all EasyBCD is, an editor for the Windows setup.

Potential complications:
bsdinstall(8) may have no way to avoid writing the bootcode to the MBR.  I don't know, I usually do not use it.
There is secondary bootcode in the FreeBSD slice, which must also be installed.


----------



## larryvc (Mar 15, 2013)

wblock@ said:
			
		

> There is secondary bootcode in the FreeBSD slice, which must also be installed.



The procedure, outlined at that link, creates a Windows boot manager menu entry "FreeBSD" and this is termed a "boot sector loader" entry.  This entry can be made bcdedit, EasyBCD, Visual BCD Editor, and others. 

The FreeBSD /boot/boot1 code is copied as a partition boot record file, in this case "FreeBSD.pbr", to the root folder of the Windows drive.  The procedure calls this file a "boot sector file". EDIT: EasyBCD creates this file in the NST folder of the Windows drive.

When a user selects the FreeBSD entry in the Windows boot manager menu, the "boot sector file" specified in the "boot sector loader" object is loaded and the Windows boot manager transfers control to it.

The code in the "boot sector file" is then supposed to launch the next FreeBSD boot sequence, /boot/boot2.

At this point we can see that the Windows boot manager has transferred control to FreeBSD.pbr as the error message that I received, "Boot error", is embedded in FreeBSD.pbr (/boot/boot1).

I am stuck at this point. Can anyone provide us with further insight into the intricate workings of the FreeBSD boot loader?  How does /boot/boot1 find /boot/boot2?


----------



## larryvc (Mar 16, 2013)

wblock@ said:
			
		

> Potential complications:
> bsdinstall(8) may have no way to avoid writing the bootcode to the MBR.  I don't know, I usually do not use it.



*CAUTION: *If you select `auto` in `Guided` partitioning mode, it will write the boot code to the MBR. I tried this on a test machine, it overwrote the MBR, FreeBSD still would not dual boot, Windows was unreachable. Fortunately just a three minute restore to get back to normal in this case. It could have been much worse. 

I believe that there is just to much risk involved in trying to set up a dual boot environment for FreeBSD using the Windows boot manager. It is so easy to use a virtual environment instead.  With todays faster hardware I hardly notice any performance hits with any of the virtualized OSes that I run.

If anyone comes up with a stable, working solution, let us know.


----------



## wblock@ (Mar 16, 2013)

It can be done through the shell.  But I agree, a VM is far safer, shares space with the host filesystem, and runs at the same time as the host.  So, for example, the host can be used to look up help on the web while installing a VM guest.


----------



## boyans (Mar 17, 2013)

larryvc said:
			
		

> How does /boot/boot1 find /boot/boot2?



The code in boot1 "knows" the partition/slice where to look for /boot/boot2, loads it and transfers control to it.

If in the meantime some partitions where moved, resized, deleted it can no longer find the file boot2. Partitions are usually addressed by offset on MBR disks. The solution in this case is to reinstall/repair the boot loader/manager in FreeBSD and then to repeat the procedure for creating the dual-boot.

For every installed OS a recovery/live CD/DVD/USB should be present to be used for fixing MBR and boot loader.


----------



## kpa (Mar 17, 2013)

Actually both boot loaders are combined into one boot loader /boot/boot that  is usually written on the first sectors of the slice (e.g. da0s1) that contains the FreeBSD partitions. 

Unlike in some other systems none of the locations (LBA sectors etc) of the boot loader(s) have to be known in advance, the only file that is actually located from the filesystem and loaded is /boot/loader and it can reside anywhere on the disk, the blocks it is stored at do not need to be known by the boot blocks.

This means that rewriting of the boot blocks is very rarely needed. Fixing the MBR is a different and slightly unrelated issue.

Source: boot(8)


----------

