# FreeBSD bootloader problem



## polle (Mar 15, 2014)

I have an older PC: MSI motherboard with Athlon 3500+ processor and Geforce 6200TC GPU. I have three harddisks in this system installed: two SATA disks, one with Bodhi Linux and the other one with OS X Leopard.

I decided to install FreeBSD 10,0 on the other hard disk which is an ATA hard disk of 60 GB. I downloaded the 64-bit USB-stick image and after I wrote the image to a stick, booted the PC from USB, no problem at all and installed FreeBSD using the entire ATA disk. The installation finished but when I booted again I had an unbootable system, could not even reach BIOS anymore. I disconnected the FreeBSD disk, booted, connected the harddisk again and reformatted it in OS X, the system booted again.

Now I divided the hard disk again in a 1 GB ext2 partition and the rest free space. Once again I installed FreeBSD in the free space (this time with MBR layout of course). Everything went fine and I was able to boot Leopard and Bodhi (I use F11 at boot to choose the hard disk to boot from).

However if I boot from the hard disk with FreeBSD it does not boot, it just waits forever. But I am capable of booting FreeBSD with GRUB from my Bodhi Linux and also Chameleon (bootloader for Leopard) boots freebsd FreeBSD without problem. both chainload the FreeBSD bootloader. But why does the FreeBSD bootloader hang when I boot directly from the hard disk where FreeBSD is installed? Of course it is not really a problem at the moment, but I prefer each OS to be booted by his own bootloader, thanks*.*


----------



## Juanitou (Mar 15, 2014)

I have already seen something similar. I resolved it by entering the BIOS and configuring IDE Access Mode as Large instead of Auto. If it does not work, try using MBR partitioning instead of GPT for this ATA disk. You could also consult this thread.


----------



## polle (Mar 16, 2014)

Thanks, as I stated I already use MBR partitioning, if not the PC just doesn't boot.

In the BIOS, I changed the IDE access mode to Large from AUTO but that didn't make a difference, thanks anyway for the reply*.*


----------



## Deleted member 3645 (Mar 21, 2014)

polle said:
			
		

> But why does the FreeBSD bootloader hang when I boot directly from the hard disk where FreeBSD is installed? Of course it is not really a problem at the moment, but I prefer each OS to be booted by his own bootloader, thanks*.*



Apparently the automated partition creator in bsdinstall(8) does not handle MBR slices very well. I found that I had to partition my MBR slices manually to create FreeBSD partitions.

The problem seems to be that the bsdinstall(8) starts partition a  right at the beginning of the slice when it should leave at least 8k as room for the  first-second stage boot loader boot/boot.

Instead of letting bsdinstall(8) create the slices, I escaped out to a command line and did it myself.  

My second MBR slice is 20GB so  I created an 18GB root partition and a 2GB swap partition. Then I copied the 1st/2nd stage boot loader to the slice.


```
#gpart add  -b 16 -s 18G  -t freebsd-ufs   ada1s2
   #gpart add                -t freebsd-swap  ada1s2

   #gpart bootcode           -b /boot/boot    ada1s2
```

The *trick* is in the *-b 16* option which starts the ufs partition 16 sectors (8k) from the beginning of the slice.


----------



## polle (Mar 21, 2014)

Thanks for the answer, as far as I can judge this, the explanation sounds posible to me.
But I am not willing to reinstall the system again, so I shall boot FreeBSD from grub or chameleon.

One thing is  not clear to me, why are grub and chameleon capable to chainload the FreeBSD bootloader?


----------



## Deleted member 3645 (Mar 22, 2014)

polle said:
			
		

> Thanks for the answer, as far as I can judge this, the explanation sounds possible to me.
> But I am not willing to reinstall the system again, so I shall boot freebsd from grub or chameleon.
> 
> One thing is  not clear to me, why are grub and chameleon capable to chainload the FreeBSD bootloader?



When working with an MBR disk drive (volume), Grub and Chameleon (and lilo) boot loaders are placed at the very beginning of the first boot sector of the drive.

So when your computer first starts up, the BIOS simply loads code from the very beginning of the drive to start the boot loader.

The boot loader typically presents a list of choices, partitions to boot.  And when a partition is chosen the boot loader loads and runs code from the very beginning of the chosen partition which is the volume boot loader.

The volume boot loader knows enough about the operating system and the filesystem to load the kernel and start it.

In the case of FreeBSD sitting on an MBR partition, the volume boot loader is placed at the very beginning of a partition by using the `gpart bootcode` command.

If the volume boot loader is missing, then the main boot loader will load "code" from the beginning of a partition but nothing good will happen.

If the volume boot loader is there, but the freebsd-ufs partition starts at the very beginning of the partition, then critical header information is erased by  the installation of the volume boot loader and the boot loader will not be able to find the freebsd-ufs partition. 

So if the MBR boot loader is working, but the actual boot is not, then

Be sure to create the first FreeBSD slice  beyond the area where the volume boot loader is stored.  Use the -b option of the "gpart add" command to skip at least 8k (16 sectors)
Be sure to put a volume boot loader at the very beginning of the partition by using the `gpart bootcode` command.


----------

