I have an HDD (or SSD, or flash drive) with FreeBSD installed on it, and somehow I broke the bootcode (first 446 bytes of MBR). How could I boot into this FreeBSD?
1 Answer
Assuming that there is 512-byte DOS-like MBR, and you have replaced first 446 bytes of it with some crap (zeros or just /dev/urandom
output), or damaged the bootcode some other way. In this case MBR partition table is on it's place, but system cannot boot from this device.
Idea is to use other BSD-like system's loader to boot with your device and your kernel.
- You should start booting to any BSD-like OS (I have tried with FreeBSD 6.0, 7.0, 8.0, 8.1, 8.2, 8.3, 8.4, 9.2 and Frenzy 1.4) from another HDD, CD, flash drive, PXE, virtual media via BMC/KVM, etc.
- During boot process hit "Escape to loader prompt" option on loader screen (it would be "6" in older FreeBSD systems, "3" in FreeBSD 9, "8" in Frenzy)
- Unload kernel and it's modules by typing
unload
- Find out the device you want to boot your FreeBSD from (usually something like
disk0s1a
) by typinglsdev
- Set this device "current" by typing
set currdev="disk0s1a"
- Re-read
loder.conf
from your device (to be sure that all your kernel tunings and hacks would apply) by typingread-conf boot/loader.conf
- Start OS and enjoy - just type
boot-conf
When your OS starts, you could repair bootcode. I use sysinstall
for it (Custom -> Partition, W, <Yes>
, BootMgr
("Install the FreeBSD Boot Manager"), <OK>
, Q, <Exit>
, <Exit Install>
), but it is deprecated since 9.0-RELEASE and removed from base since 10.0-RELEASE. Other way is to use backup, stored in /boot
, to extract bootcode from it:
# gpart bootcode -b /boot/mbr /dev/yourbootdevice