# reinstall MBR



## Hanzo (Nov 5, 2011)

Hi

I use FreeBSD 8.2 dual boot with winXP under VirtualBOX, I'm just training with basic commands like fdisk :stud . So after deleting my MBR using dd, I used the live CD to recover it (*fdisk -B*) but the FreeBSD partition table haS not been detected; only winXP can boot. Any idea how I can resolve this problem?


----------



## wblock@ (Nov 5, 2011)

/boot/mbr is plain bootcode.  It will boot the active partition.  See boot0cfg(8) about the interactive bootloader /boot/boot0.  Neither of these change the partition table.


----------



## Hanzo (Nov 6, 2011)

wblock@ said:
			
		

> /boot/mbr is plain bootcode.  It will boot the active partition.  See boot0cfg(8) about the interactive bootloader /boot/boot0.  Neither of these change the partition table.







Same result, F1 links to Windows not to FreeBSD :\


----------



## wblock@ (Nov 6, 2011)

Maybe the partition type was changed on the Windows partition.  What is the output of fdisk(8) or gpart(8) on that disk?


----------



## Hanzo (Nov 6, 2011)




----------



## wblock@ (Nov 6, 2011)

`# fdisk ad0`
is enough.  The output shows that the first partition, which appears to be the only partition, is type 0xa5, or FreeBSD.

Just guessing, I think it's actually NTFS and FreeBSD was installed on the second hard disk.  Or possibly, the first disk is FreeBSD but it's not bootable, and the second disk is Windows.


----------



## Hanzo (Nov 7, 2011)

partition 1 for NTFS, 2 for FreeBSD the other disk is just additional free disk


----------



## wblock@ (Nov 7, 2011)

But that output shows partition 2 is unused.  What does fdisk show for the other drive?


----------



## Hanzo (Nov 7, 2011)

wblock@ said:
			
		

> But that output shows partition 2 is unused.


yes and i don't know why ! physically it really exist but fdisk couldn't read it





don't care about this, it's just UFS free disk


----------



## wblock@ (Nov 7, 2011)

Hanzo said:
			
		

> yes and i don't know why ! physically it really exist but fdisk couldn't read it



Does some other program show the second partition being used?  If the data is all there, it would just be a matter of using fdisk(8) to edit the second slice entry and put in the right start and size.  Finding the start shouldn't be difficult, but the size might be.  Unless it goes to the end of the disk.

First, back up at least the MBR (I would back up the whole disk) to someplace safe, then change only the type of the first partition back to NTFS, type 07.  Then test and make sure it still boots Windows.

Once that's fixed, edit the second partition to use the rest of the disk, with type 165 (0xa5) for FreeBSD.


----------



## Hanzo (Nov 7, 2011)

luckily i have backuped my my virtual disk before removing mbr and here is my original fdisk:


----------



## wblock@ (Nov 7, 2011)

Excellent!  Copy just the first 512 bytes from that backup to the first block of the disk:
`# dd if=backupfile of=/dev/ad0 bs=512 count=1`


----------



## Hanzo (Nov 7, 2011)

I know  but the gool of this "exercise" is to reinitialize the boot0 using basic command comparing Grub and other bootmanager and to know the limit of each ones.


----------



## wblock@ (Nov 8, 2011)

See post #10.


----------

