Solved How to restore boot loader?

aimeec1995

Active Member

Reaction score: 18
Messages: 232

In the event that the boot loader were wiped out, how would one restore it?
Thanks.
 
OP
A

aimeec1995

Active Member

Reaction score: 18
Messages: 232

Note i did not wipe out my boot loader. But I feel this would be useful knowledge
 

k.jacker

Aspiring Daemon

Reaction score: 467
Messages: 740

It's important to know if your bootcode is UEFI or BIOS.

Code:
% gpart show ada0
=>       40  937703008  ada0  GPT  (447G)
         40     409600     1  efi  (200M)
     409640  928628736     2  freebsd-ufs  (443G)
  929038376    8388608     3  freebsd-swap  (4.0G)
  937426984     276064        - free -  (135M)

If the first partition is 'efi', like above, you have UEFI bootcode in first partition and MBR is clear/not used.
If it were 'freebsd-boot', than it is BIOS bootcode inside that partition and an entry inside the Master Boot Record/sector 0 as well.
Size of first partition doesn't really matter.
Examples assume you use GPT partitioning.

Create UEFI bootcode:
gpart bootcode -p /boot/boot1.efi -i1 ada0

Create BIOS bootcode:
gpart bootcode -b /boot/pmbr -p /boot/gptboot-i1 ada0
 
OP
A

aimeec1995

Active Member

Reaction score: 18
Messages: 232

It's important to know if your bootcode is UEFI or BIOS.

Code:
% gpart show ada0
=>       40  937703008  ada0  GPT  (447G)
         40     409600     1  efi  (200M)
     409640  928628736     2  freebsd-ufs  (443G)
  929038376    8388608     3  freebsd-swap  (4.0G)
  937426984     276064        - free -  (135M)

If the first partition is 'efi', like above, you have UEFI bootcode in first partition and MBR is clear/not used.
If it were 'freebsd-boot', than it is BIOS bootcode inside that partition and an entry inside the Master Boot Record/sector 0 as well.
Size of first partition doesn't really matter.
Examples assume you use GPT partitioning.

Create UEFI bootcode:
gpart bootcode -p /boot/boot1.efi -i1 ada0

Create BIOS bootcode:
gpart bootcode -b /boot/pmbr -p /boot/gptboot-i1 ada0

Thank you friend.
So this would be done from a live disk?
What about zfs with raid?
 

k.jacker

Aspiring Daemon

Reaction score: 467
Messages: 740

No, you can modify bootcode at all time, no need for a live disk or single user mode.

For zfs:
To create UEFI bootcode to boot zfs, you use the same bootcode/command as above:
gpart bootcode -p /boot/boot1.efi -i1 ada0

To create BIOS bootcode to boot zfs:
gpart bootcode -b pmbr -p /boot/gptzfsboot -i1 ada0

Remember it is allways a good idea to install bootcode on every disk in a pool.
 

phoenix

Administrator
Staff member
Administrator
Moderator

Reaction score: 1,285
Messages: 4,099

Remember it is allways a good idea to install bootcode on every disk in a pool.

Slight correction / adding specificity. It's important to install bootcode on every disk in a bootable pool (aka root-on-zfs setups). There's no need to have bootcode installed on drives that are never, ever meant to be booted from.

For example, all our storage servers at work have 2 ZFS pools:
  1. a system pool that's bootable (usually just a mirrored vdev on SSDs)
  2. a storage pool made up of dozens (90 in the biggest ones) of drives
The SSDs in the system pool include bootcode; the harddrives in the storage pool don't.
 
Top