1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple dual-boot Windows and FreeBSD 9 under MBR

Discussion in 'Howtos and FAQs (Moderated)' started by nsth, Jan 15, 2012.

  1. nsth

    nsth New Member

    Messages:
    1
    Likes Received:
    0
    Since bsdinstall is geared towards GPT installations, it's not so easy to dual-boot a fresh install of FreeBSD with an existing install of Windows on the same drive. I'm assuming here that you have an existing installation of Windows under an MBR structure. If you're running 64-bit Windows 7 under a UEFI motherboard, there's a fair chance your drive is operating under GPT. You can check this with GParted (under drive information, partition style should read 'msdos' if it is MBR-structured).

    This tutorial will result in a FreeBSD installation with a UFS root partition. This does not cover ZFS.

    The bootselect code will be the minimalist boot0 code as installed by previous versions of FreeBSD. Sorry, fancy bootselect fans.

    The following only applies under MBR!
    Back up anything you don't want to lose!
    This worked for me but it may not work for you!


    Assuming you have Windows installed, start your already-prepared FreeBSD installer from CD or USB. Follow the prompts as per the Handbook's instructions for bsdinstall until you come to the first partitioning prompt.

    You are given the choice of Guided, Manual or Shell partition setup. Select Manual. You should see a hierarchy of your storage devices. From here I will assume that your installation target drive is ada0. If it is ad0 or otherwise, be sure to substitute. You may want to note the name of the storage device for later on.

    On ada0, you should see an NTFS or FAT partition, named ada0s1 or similar. Select the parent (ada0) and Create and hit Enter to create your FreeBSD MBR partition. Change Type to "freebsd". Change size to the total intended size of all your FreeBSD slices, including Swap space. Don't enter a mountpoint. Select OK.

    From here, make sure the first slice you create is your root slice, otherwise your install will not boot. bsdinstall does not appear to modify the order of slices from how you enter them, so you have to make the root slice first to ensure your installation is bootable.

    To do this, select ada0s2 (the partition you created before) and select create. Then enter
    Code:
    Type: freebsd-ufs
    Size: <desired size postfixed with MB or GB>
    Mountpoint: /
    Label: <whatever pleases you>
    Note that for an MBR partition, you do not create a 'freebsd-boot' partition as you would for a GPT installation.

    Then, again by selecting ada0s2 and selecting Create, make a swap slice:
    Code:
    Type: freebsd-swap
    Size: <whatever you like, I prefer 2x RAM>
    Mountpoint and Label are greyed out. Select OK.
    Feel free to make any other freebsd-ufs partitions (just not /boot) to fill out your freebsd partiton, then select Finish. The Handbook picks up from here, until you've committed, installed, rebooted. You'll notice bsdinstall has overwritten the MBR without asking any questions during the install, so for a scary few minutes you won't be able to access Windows.

    Login to root (or login with a user and su to root), and then bearing in mind you should replace 'ada0' with your HDD's device if different, execute
    Code:
    boot0cfg -B ada0
    to install the bootselect code to the MBR.

    Rebooting, you should now be able to boot into Windows and FreeBSD.
     
  2. rafaelbsd

    rafaelbsd New Member

    Messages:
    1
    Likes Received:
    0
    Thanks for the excelent article!

    Just want to make a small contribution:

    I erased my Notebook, to correctly create the sizes of the partitions.

    Then I installed firts Windows 7.

    After that, with FreeBSD 9.0 DVD, when I started the Manual in the partition part, the system didn´t show me Windows 7 partition.

    So I created it, using type NTFS, and then created the rest of the partitions as you told in the article.

    The final partition schema was:
    Code:
    ada0
      ada0s1 nfts
      ada0s2 BSD
        ada0s2a  /
        ada0s2b  swap
    
    After install FreeBSD, I did reboot the system to install Windows 7, choosing the partition created with FreeBSD. Windows recognized it and the installations was successful.

    After the Windows installation, I rebooted again with the FreeBSD 9 DVD, entered the LiveCD and executed the boot0cfg -B ada0.

    Everything is working just fine!!!

    PS: sorry about my poor english... ;-)
     
  3. shix

    shix New Member

    Messages:
    6
    Likes Received:
    0
    Sorry for grave digging, but how would someone remove FreeBSD without having to mess up Windows?
     
  4. wblock@

    wblock@ Administrator Staff Member Administrator Moderator Developer

    Messages:
    11,202
    Likes Received:
    14
    Back up the entire disk first. The FreeBSD boot selector can be overwritten with Windows' fixboot command. Or fixmbr; I've never been clear on the difference. Windows should be able to see the FreeBSD slice, and eager to format it. It will then show up as another drive.
     
  5. rhish

    rhish New Member

    Messages:
    86
    Likes Received:
    0
    I had the same idea, thinking FOXBOOT and FIXMBR were basically the same. Then i discovered somethign interesting this morning.
    During my dual install issues i went into WinXP recovery and got the following results.

    C:\>FIXBOOT
    FIXBOOT cannot find the system drive, or the drive specified is not valid.

    so I then ran the other

    C:\>FIXMBR
    ** CAUTION **
    This computer appears to have a non-standard or invalid master boot record.
    FIXMBR may damage your partition tables if you proceed.
    Are you sure you want to write a new MBR?

    So, it would seem, FIXBOOT stops because it doesnt find a valid MBR, but FIXMBR wants to fix the situations?
     
  6. htutt

    htutt New Member

    Messages:
    46
    Likes Received:
    0
    I think that C:\> fixboot doesn't need for Windows XP to fix master boot record, and just need C:\> fixmbr.
    But for Windows 7, it needs both commands;
    C:\>bootrec /fixboot
    C:\>bootrec /fixmbr
     
  7. scottro

    scottro Member

    Messages:
    238
    Likes Received:
    0
    Having been away from FreeBSD for awhile, I was having a lot of trouble with BSD install and partitioning under an MBR when not using the same disk. This was the first thing I came across that fixed it for me, thank you. I did it under Linux, but it didn't (using 9.1) install the bootloader--not sure what step I missed. However, I was able to easily boot by adding it to a Linux grub2.

    Most of what I found prior to this assumed that either one was using the whole disk or at least wanted to use GPT.
     
  8. ShelLuser

    ShelLuser Member

    Messages:
    1,047
    Likes Received:
    7
    Very nice article. Strict, to the point and still very usable.

    Today I was trying to help a family member out with an Linux (Debian-like, I think it was Ubuntu) environment which had gone awol. It was a bit of a geek problem, but he was using his own (plain) boot manager he once wrote, which worked perfect with Lilo (which used 1 sector in the boot record due to it's 2 stage boot process) whereas the now commonly used Grub takes up a whole lot more.

    Long story cut a little bit shorter: I was looking at a Linux environment which had to be bootstrapped, but with a preference for Lilo which was also hard to satisfy. Not sure what went wrong; but Lilo did not like the partition table for some reason.

    And because he mostly used the Linux environment to clean up his windows environment (temporary internet files for example, which often have extremely long file names) I figured that FreeBSD should be able to cope just as well. # pkg_add -r should be perfectly usable.

    The only problem was booting, and your article nailed it perfectly.

    It even turned into a double win. Not only did this approach work flawlessly; the new boot menu (I think this is /boot/boot0) is also exactly 1 sector in size; just like Lilo used to be.

    Which means so much that my relative can now probably copy the new boot sector and implement it in his own boot menu so that he can continue to boot happily ever after ;)

    Alas, thanks again for a very straight to the point howto.