FreeBSD MBR
Appearance
Fighting with FDISK on BSD
While trying to create a second partition on BSD I once typed the wrong key and realized it too late, thus I nuked the partition table of my running FreeBSD box. Because I didn't feel like reinstalling the whole system I had to get back the information about the original partition table. This document describes how this was done because it was a bit nasty sometimes... I really like FreeBSD but I hope one day the whole partition/disk label crap gets replaced by something a bit less clumsy.
Partitions on BSD
- Before we start, create a backup of your partition table: dd if=/dev/da0 of=/tmp/mbr-backup bs=512 count=1
- Run sysinstall, go to Configure->Fdisk
- Create the new partitions. Note that you will just see the number of sectors, to calculate how much space this is simply multiply the sector size with the number of sectors. Typically sector size is something like 512 Bytes.
In case your partition table or MBR is fucked...
- install TestDisk, you will find a port in sysutils/testdisk
- run testdisk, select the media to analyze and select Analyse to check the partition. It will now try to find the boundaries of your partition.
- if testdisk was successful, write the data back to the MBR
In case you get a permission denied while writing the MBR you have to change some GEOM kernel options, see this post for some hints: sysctl kern.geom.debugflags=16. Now try again with writing the MBR, it should work this time.