OpenWRT and Bare Metal BackUps: Difference between revisions
Created page with "For this article, the x86_64 (referred to as just x86 in this article) version of OpenWRT on an EXT 4 installed on a BIOS / MBR / DOS partitioned Disk / SSD will be the main focus. SquashFS will be addressed too. All of the below information was tested on an OpenWRT 19.07.10 EXT4 "Combined" (as in MBR, GRUB, Boot, and Root Partition (no Overlay)) based system. The overall objective beyond a bare metal backup is to eventually move an x86_64 SquashFS based system to an..." |
mNo edit summary |
||
Line 3: | Line 3: | ||
The overall objective beyond a bare metal backup is to eventually move an x86_64 SquashFS based system to an LVM EXT4 based system. | The overall objective beyond a bare metal backup is to eventually move an x86_64 SquashFS based system to an LVM EXT4 based system. | ||
=== Backing Up === | ===Backing Up=== | ||
The "Backing Up" or BackUp Process is the first part of the cloning a system too. | The "Backing Up" or BackUp Process is the first part of the cloning a system too. | ||
==== Relevant "Partitions" of an OpenWRT x86 ==== | ====Relevant "Partitions" of an OpenWRT x86==== | ||
* MBR (first Sector, 512 Bytes in size, Sector Number 0 (zero), contains stage 1.0 of GRUB and Partition table) | *MBR (first Sector, 512 Bytes in size, Sector Number 0 (zero), contains stage 1.0 of GRUB and Partition table) | ||
* "[[wikipedia:BIOS_boot_partition#Overview|MBR Gap]]" (contains stage 1.5 of GRUB) | *"[[wikipedia:BIOS_boot_partition#Overview|MBR Gap]]" (contains stage 1.5 of GRUB and a file named core.img, but the image can't be seen because there is no file system there, it's just a 'gap') | ||
** Notes on "MBR Gap": Research indicates this "MBR Gap" can vary quite a bit depending on the OS. Even different versions of Windows have different size "Gaps". IE, the size is arbitrary and not set in stone. Lesson? Use a Partition Utility to look and see how things are arranged for an OS. It also seems that the GRUB 1.5 Stage is made to fit in 32K so it will fit into the MBR Gap. | **Notes on "MBR Gap": Research indicates this "MBR Gap" can vary quite a bit depending on the OS. Even different versions of Windows have different size "Gaps". IE, the size is arbitrary and not set in stone. Lesson? Use a Partition Utility to look and see how things are arranged for an OS. It also seems that the GRUB 1.5 Stage is made to fit in 32K so it will fit into the MBR Gap. | ||
* Boot Partition (contains grub.cfg file with settings and VMLINUZ (a compressed Kernel Image in "Boot Executable bzImage" format) | *Boot Partition (contains grub.cfg file with settings and VMLINUZ (a compressed Kernel Image in "Boot Executable bzImage" format) | ||
* Root Partition (all the files that comprise an OpenWRT installation, plus user added files, packages, settings, etc. on an EXT4 installation) | *Root Partition (all the files that comprise an OpenWRT installation, plus user added files, packages, settings, etc. on an EXT4 installation) | ||
* Overlay "Partition" (only for SquashFS, not relevant to EXT4 based installations) | *Overlay "Partition" (only for SquashFS, not relevant to EXT4 based installations) | ||
==== What to do / How to do it / Examples of... ==== | ====What to do / How to do it / Examples of...==== | ||
Copy the MBR and "MBR Gap" | Copy the MBR and "MBR Gap" in one step; | ||
* | * <code>dd if=/dev/sdX of=/dev/sdY bs=512 count=511</code> | ||
Copy the MBR and "MBR Gap" in two steps; | |||
* | |||
* Example | *Syntax for MBR: <code>dd if=/dev/sdX of=/dev/sdY bs=512 count=1</code> | ||
* Why 511 sectors? Use CFDISK (or any other Partitioning Utility) and you'll see that the first Sector of the first Partition starts at Sector 512. That is just the arrangement the OpenWRT developers chose. Research indicates this "MBR Gap" can vary quite a bit depending on the OS. Even different versions of Windows have different size "Gaps". IE, the size is arbitrary and not set in stone. | *Syntax for "MBR Gap": <code>dd if=/dev/sdX of=/dev/sdY bs=512 skip=1 count=511</code> | ||
*Working Example: <code>dd if=/dev/sdb of=/mnt/sda1/MBR_and_MBR-Gap.img conv=noerror bs=512 count=511 status=progres</code> | |||
==== Questions About Stuff ==== | |||
*Why 511 sectors? | |||
**Use CFDISK (or any other Partitioning Utility) and you'll see that the first Sector of the first Partition starts at Sector 512. That is just the arrangement the OpenWRT developers chose. Research indicates this "MBR Gap" can vary quite a bit depending on the OS. Even different versions of Windows have different size "Gaps". IE, the size is arbitrary and not set in stone. | |||
*Lessons about "MBR Gap"? | |||
**Use a Partition Utility to look and see how things are arranged. Research seems to indicate that the GRUB 1.5 Stage is made to fit in 32K. | |||
*Why did the OpenWRT developers that focus so much on refinement and minimization use a whopping 256K for the MBR Gap? | |||
**The answer appears to be known only to them as there is no direct way to ask them. ChatGPT was asked and the answer was so bad, it was way worse than not knowing. | |||
Copy the First Partition (/boot Directory): <code>dd if=/run/media/root/NTFS/Boot.img of=/dev/sdc skip=511 conv=noerror bs=512 status=progress</code> | Copy the First Partition (/boot Directory): <code>dd if=/run/media/root/NTFS/Boot.img of=/dev/sdc skip=511 conv=noerror bs=512 status=progress</code> | ||
* Example of saving to a Disk / SSD from an Image File: <code>dd if=/dev/sdb of=/mnt/sda1/MBR_and_MBR-Gap.img conv=noerror bs=512 count=511 status=progress</code> | *Example of saving to a Disk / SSD from an Image File: <code>dd if=/dev/sdb of=/mnt/sda1/MBR_and_MBR-Gap.img conv=noerror bs=512 count=511 status=progress</code> | ||
Copy the Second Partition (/root equivalent): <code>dd if=/dev/sdX2 of=/dev/sdY2 bs=128M conv=noerror progress=status</code> | Copy the Second Partition (/root equivalent): <code>dd if=/dev/sdX2 of=/dev/sdY2 bs=128M conv=noerror progress=status</code> | ||
Line 35: | Line 46: | ||
Syntax Notes; | Syntax Notes; | ||
* if: Input File (or Device) | *if: Input File (or Device) | ||
* of: Output File (or Device) | *of: Output File (or Device) | ||
* bs: "How much to copy from one device to another at a time" | *bs: "How much to copy from one device to another at a time" | ||
* conv=noerror: "Don't stop, just do what I told you to do, and don't give an excuse" | *conv=noerror: "Don't stop, just do what I told you to do, and don't give an excuse" | ||
* progress = status: Show the progress of the copy process (only for a certain version of DD and up) | *progress = status: Show the progress of the copy process (only for a certain version of DD and up) | ||
* sync: Write all buffered blocks to disk (just to be safe) | *sync: Write all buffered blocks to disk (just to be safe) | ||
=== Other Notes === | ===Other Notes=== | ||
==== GRUB ==== | ====GRUB==== | ||
OpenWRT specifically mentions GRUB 2 in their documentation. But the way it works on an x86_64 EXT4 installation of OpenWRT would convince anyone that it is Legacy GRUB (except for the GNU GRUB version 2.02 heading at the top of the screen). The way it is configured via /etc/grub/grub.cfg would also convince anyone that Legacy GRUB was being used. So, the conclusion is that GRUB 2.02 is indeed being used, but since it is backwards compatible, it is in 'Legacy Mode'. | OpenWRT specifically mentions GRUB 2 in their documentation. But the way it works on an x86_64 EXT4 installation of OpenWRT would convince anyone that it is Legacy GRUB (except for the GNU GRUB version 2.02 heading at the top of the screen). The way it is configured via /etc/grub/grub.cfg would also convince anyone that Legacy GRUB was being used. So, the conclusion is that GRUB 2.02 is indeed being used, but since it is backwards compatible, it is in 'Legacy Mode'. |