Check/compare current MBR bootcode before updating?

I installed MBR on entire disk, and have these commands:
Code:
gpart bootcode -b '/boot/mbr' 'ada0'
Code:
gpart bootcode -b '/boot/boot' 'ada0s1'

I'd like to do something before those as a check to see if either need updating.



On EFI I have:
Code:
rsync -a --no-times --checksum '/boot/loader.efi' '/boot/efi/EFI/freebsd/loader.efi'
rsync -a --no-times --checksum '/boot/loader.efi' '/boot/efi/EFI/boot/bootx64.efi'

loaders-update looks like it does a compare with something in /dev: https://github.com/Emrion/uploaders/blob/main/loaders-update#L411

Not quite sure what it's checking, but I didn't see anything obvious at root /dev that matched in filesize to mbr or boot. I think I'm looking for something to see if what's on ada0/ada0s1 is the same as /boot/mbr|boot, but I'm not sure how to check something written to low-level disk vs a file on filesystem like EFI.
 
It seems ok what you've done for EFI.

Concerning the legacy BIOS boot:

loaders-update checks the code in the first 446 bytes of the first sector (because after you have the partitions table).

The code would be in your case:
Code:
MD5=$(head -c 446 /dev/ada0 | md5 -q)

You do the same on the file /boot/mbr and compare the two md5 (or whatever checksum you prefer).

Concerning the second stage /boot/boot, I didn't investigate the thing, but I would use the same technique. Instead to take a length of 446 bytes, I would took the length of /boot/boot. And to calculate the md5 of your installed second stage:
Code:
MD5=$(head -c "size of /boot/boot" /dev/ada0s1 | md5 -q)
 
Back
Top