# Pre-installation questions - Backing up the MBR/BIOS disk boot sectors - how to? [Solved]



## neogeo (Oct 6, 2021)

Hello,

My main question centers on error messages seen when using each of 'dd' and 'ddpt' when I was booted to a local FreeBSD 12.1 boot disk, on a Panasonic CF-19 laptop.


```
dd if=/dev/ada0 of=/root/boot.img bs=446 count=1
dd: /dev/ada0: Invalid argument
0+0 records in
0+0 records out
0 bytes transferred in 0.001164 secs (0 bytes/sec)
```

I'd seen a similar error message when trying to create the boot.img file using ddpt.

I'd picked up the initial 'dd' shell command from some Linux documentation (DualBoot/Mbr - Ubuntu Wiki). Maybe GNU/Linux differs in how it implements DD?

My main question: Using dd in FreeBSD or ddpt from FreeBSD ports, is it possible to create a backup of the MBR/BIOS disk boot sectors, minus the disk partition information? I'd like to be able to restore the disk's present bootloader (Windows 10 afaict) if other bootloaders (e.g Grub) may not work out

If it may help to describe any of the context to this question, as to how this question has occurred, I'm trying to back up the boot sector for the laptop's internal hard disk, minus the MBR partition data. This backup would be saved on an external boot disk I've created, such that presently has FreeBSD 12.1 installed on it (UFS root partition) from a local FreeBSD 12.1 build. This would be before installing Grub to the laptop's internal hard disk, from within a third OS, in one intermediate step before installing FreeBSD on the disk. In this installation:

This laptop has BIOS firmware
This is for a new installation of FreeBSD 12.2, which I've built under local build config, along with ports  built for the 12.2 build under Poudriere
This will be for a multi-boot installation on a Panasonic CF-19 laptop. Windows 10 is installed on another MBR partition on the same internal hard disk.
I've tried using GPT on the internal hard disk. It appears that Windows 10 is wholly unable to boot from a GPT disk on a machine using BIOS firmware. This limitation may have been passingly denoted in some Microsoft documentation.
The laptop is presently using an MBR disk partition layout. Three of the existing partitions on the disk are somehow in use by Windows, each of those being a primary MBR partition.
The FreeBSD installation will be created under an EBR (extended) partition. As well as a FreeBSD ZFS partition, this EBR partition will also contain a partition for FreeBSD swap and crash dumps, and may contain partitions for Linux boot and Linux root filesystems.  The swap partition may be shared with that Linux installation.
If the conventional FreeBSD bootloader may not be able to load FreeBSD from within an EBR partition, I've begun looking at other options for a bootloader - such as in managing a Grub install with a third OS installation, namely Alpine Linux. Ideally, this would be where the Grub install would originate, for the final disk configuration
Ideally, the FreeBSD installation will be produced with a ZFS on Root configuration for FreeBSD. I'm not certain of whether and how this may affect the availability of the FreeBSD installation to the FreeBSD bootloader, if using zfsboot. So, I'm looking at Grub - hoping that that may work out for this installation.
Ideally, the Linux boot and root partitions would also use ZFS - not affecting the FreeBSD install, albeit. The Grub system available with Alpine Linux may provide some support for this. Albeit, I'm not certain of whether and how it may integrate with FreeBSD ZFS support and grub.
As long as the main bootloader on the disk can at least boot Windows 10, I can try to adjust the installation requirements if this present config may not work out
I don't consider it an option, at this time, to abandon the Windows 10 installation on the laptop. Up to the point of discovering some of the limitations on this installation, I'd thought it would be a pretty nice idea to have a FreeBSD installation on the laptop, too.  I'm willing to manage a separate Alpine Linux install for this, if simply to have something to manage a Grub bootloader on the disk.

While my main question is focusing on dd, I believe I'm largely on my own with the rest of that. I'm OK with that - right now, only wondering about how to back up the boot sectors on the internal hard disk, before installing Grub?

TY for any help to this effect.
Health,
- Sean


----------



## SirDice (Oct 6, 2021)

It's the block size you used.


```
root@molly:~ # dd if=/dev/ada0 of=boot.img bs=446 count=1
dd: /dev/ada0: Invalid argument
0+0 records in
0+0 records out
0 bytes transferred in 0.000050 secs (0 bytes/sec)
root@molly:~ # dd if=/dev/ada0 of=boot.img bs=512 count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.000186 secs (2748964 bytes/sec)
```


----------



## neogeo (Oct 6, 2021)

Thx! 

If I try to restore the full 512 byte logical block to the disk, I believe that would also restore the partition layout of the disk at the time when the backup was produced? I understand that gpart(8) can be used to address that. I was hoping to back up and restore only the bootloader bytes. If the geometry of the disk may provide some limitations here, can work around that though? 

Short of writing new code for this one-off task, could there be any way to restore only the bootloader bytes? 

Health, all


----------



## neogeo (Oct 6, 2021)

I've made a backup of all the disk's logical sectors up to the start of the first partition. Notwithstanding the initial shlell cmd from Linux Wiki, it was actually 2048 bytes on the disk. Under hexdump, it ends with the magic bytes 0x55 0xAA (NeoSmart - The BIOS/MBR Boot Process).

Along with 'gpart backup' files for the MBR and EBR layouts at the time, hopefully it will be enough for some possible rollback of the disk configuration, subsequent of the Alpine Linux install, then Grub, and then FreeBSD. Hopefully Grub can load FreeBSD root on ZFS under an EBR partition and/or hand over to zfsboot from there?

[solved]  in the dd question. Thx


----------



## SirDice (Oct 6, 2021)

neogeo said:


> I was hoping to back up and restore only the bootloader bytes.


Honestly I wouldn't use it like that, I'd much rather use a Windows recovery to restore the Windows MBR. 








						Fix the MBR – Guide for Windows 10, 11, XP, Vista, 7, 8
					

This guide shows you how to fix the Master boot record (MBR) in any of the Windows versions: Windows 10, Windows 11, Windows XP, Vista, 7, or Windows 8. What is the MBR The MBR (stands for “M…



					neosmart.net


----------



## neogeo (Oct 22, 2021)

TY for the ref. 

I have a Windows rescue disk installed on a thumb drive (used rufus) with which I was able to use bootrec in recovering the laptop's Windows 10 boot manager. This was after a botched usage of the Windows mbr2gpt tool (subsequently discovering that Windows will not boot from a GPT disk on a BIOS machine). If it gets botched again, can probably use the same rescue disk. The laptop's internal rescue partition may not be of use to Windows, after the botched mbr2gpt call. I was able to recover the filesystems at least - it was a failed decision before installing an SSD on the laptop. I had a second disk available. iirc FreeBSD's gpart was really useful during the rescue session.

I've read of there being some ways to get the Windows 10 boot loader to boot FreeBSD. I'm not certain if that may work out with ZFS under an EBR partition, however. I've got Arch Linux successfully installed under a VM now, will have to build a new Grub from Arch's AUR for the ZFS support but I think I've got the grub config worked out for it, along with some local scripting for the ZFS filesystem creation. 

I'm afraid it's not a very straightforward setup, have begun managing the scripting in a local repository though. I believe it may be possible to boot Linux and FreeBSD from the same set of boot (i.e grub-compatible) and root pools. I think Grub might be the only boot manager that would support this - testing it out in a VM environment first, though, albeit without a Windows 10 install alongside the ZFS under EBR fun.

tgf gpart

Health, all
- Sean


----------

