Restoring Boot Sectors in FreeBSD
At work the other day, we had a long power outage, and afterwards one of our FreeBSD 5.2.1 boxes refused to come back up. It'd power up, go through the BIOS stuff, show the FreeBSD boot manager that lets you select which slice to boot, but when you hit F1, the screen would go black and the machine would reset.
Booted off the 5.2.1 install CD, and after entering fixit mode, was able to mount the disk and see
that the files seemed to be intact. Couldn't run fsck
though, the 5.2.1 CD seemed to be missing
fsck_4.2bsd
.
FreeSBIE 1.1 on the other hand, was able to fsck
the
disk, but that didn't solve the problem. Next guess was that something in the /boot
directory was hosed. I'd setup the machine to do weekly dumps of the root partition to another
machine, and was able to extract /boot
from a few days before and pull it back onto
this machine over the network using FreeSBIE, but it still wouldn't boot.
Next theory was that something in the boot sectors was bad. First tried restoring the MBR (Master Boot Record)
from copy that's kept in /boot
- even though it was working well enough to show the F1
prompt to select the slice. Wanted to keep what 5.2.1 had been using, so mounted the
non-booting disk readonly and made sure to have boot0cfg
use the copy there
instead of anything
that might have been on the FreeSBIE disc.
mkdir /foo mount -r /dev/twed0s1a /foo boot0cfg -B -b /foo/boot/boot0 /dev/twed0 reboot
Unfortunately, that didn't help. Each slice (partition in non-BSD terminology) also has boot sectors, and to
restore them, turns out you use the bsdlabel
(a.k.a. disklabel
) utility. Again from
FreeSBIE:
mkdir /foo mount -r /dev/twed0s1a /foo bsdlabel -B -b /foo/boot/boot /dev/twed0s1 reboot
That did it. Apparently something in the slice's boot sectors was messed up.