OpenWRT and Bare Metal BackUps: Difference between revisions

wiki.TerraBase.info
Jump to navigation Jump to search
mNo edit summary
Line 16: Line 16:


====What to do / How to do it / Examples of...====
====What to do / How to do it / Examples of...====
Copy the MBR and "MBR Gap" (Choice of doing it in one or two steps);
Copy the MBR and "MBR Gap" (Choice of doing it in one or two steps, it's also such short process there isn't really a need to add status=progress);


* Syntax in one step;
*Syntax in one step;
** <code>dd if=/dev/sdX of=/dev/sdY bs=512 count=511</code>
**<code>dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img bs=512 count=511</code>
* Syntax in two steps (optional);
*Syntax in two steps (optional);
** MBR: <code>dd if=/dev/sdX of=/dev/sdY bs=512 count=1</code>
**MBR: <code>dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img bs=512 count=1</code>
** "MBR Gap": <code>dd if=/dev/sdX of=/dev/sdY bs=512 skip=1 count=511</code>
**"MBR Gap": <code>dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img bs=512 skip=1 count=511</code>


*Working Example (in one step): <code>dd if=/dev/sdb of=/mnt/sda1/MBR_and_MBR-Gap.img conv=noerror bs=512 count=511 status=progress</code>
*Working Example (in one step): <code>dd if=/dev/sdb of=/mnt/sda1/MBR_and_MBR-Gap.img conv=noerror bs=512 count=511 status=progress</code>
Line 28: Line 28:
Copy the Boot Partition (first partition on a 'stock' / 'standard' OpenWRT x86 installation):
Copy the Boot Partition (first partition on a 'stock' / 'standard' OpenWRT x86 installation):


* Syntax: <code>dd if=/WhatEverPath/WhatEverFileName.img of=/dev/sdX skip=511 conv=noerror bs=512 status=progress</code>
*Syntax: <code>dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img skip=511 conv=noerror bs=512 status=progress</code>


* Working Example: <code>dd if=/run/media/root/NTFS/Boot.img of=/dev/sda skip=511 conv=noerror bs=512 status=progress</code>
*Working Example: <code>dd if=/dev/sda of=/run/media/root/NTFS/Boot.img skip=511 conv=noerror bs=512 status=progress</code>


Copy the Root Partition (second partition on a 'stock' / 'standard' OpenWRT x86 installation):
Copy the Root Partition (second partition on a 'stock' / 'standard' OpenWRT x86 installation):


* Syntax: <code>dd if=/WhatEverPath/WhatEverFileName.img of=/dev/sdX skip=511 conv=noerror bs=512 status=progress</code>
*Syntax: <code>dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img skip=511 conv=noerror bs=512 status=progress</code>


* Working Example: <code>dd if=/run/media/root/NTFS/Boot.img of=/dev/sda skip=511 conv=noerror bs=512 status=progress</code>
*Working Example: <code>dd if=/dev/sda of=/run/media/root/NTFS/Root.img skip=511 conv=noerror bs=512 status=progress</code>


==== Syntax Notes for DD ====
...and finally, issue this command, just to make sure everything is flushed from cache / memory: <code>sync</code>
 
====Syntax Notes for DD====


*if: Input File (or Device)
*if: Input File (or Device)
Line 45: Line 47:
*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)
*conv=sync: Write all buffered blocks to disk (just to be safe, but can cause 'out of space' issues with MBR and "MBR Gap")
*skip: Skips X number of sectors for the ''input ( if= )''
*seek: Skips X number of sectors for the ''output ( of= )''


====Questions About Stuff====
====Questions About Stuff====

Revision as of 23:04, 6 September 2023

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 LVM EXT4 based system.

Backing Up

The "Backing Up" or BackUp Process is the first part of the cloning a system too. In syntax examples, devices are assumed to be in /dev.

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 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.
  • 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)
  • Overlay "Partition" (only for SquashFS, not relevant to EXT4 based installations)

What to do / How to do it / Examples of...

Copy the MBR and "MBR Gap" (Choice of doing it in one or two steps, it's also such short process there isn't really a need to add status=progress);

  • Syntax in one step;
    • dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img bs=512 count=511
  • Syntax in two steps (optional);
    • MBR: dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img bs=512 count=1
    • "MBR Gap": dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img bs=512 skip=1 count=511
  • Working Example (in one step): dd if=/dev/sdb of=/mnt/sda1/MBR_and_MBR-Gap.img conv=noerror bs=512 count=511 status=progress

Copy the Boot Partition (first partition on a 'stock' / 'standard' OpenWRT x86 installation):

  • Syntax: dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img skip=511 conv=noerror bs=512 status=progress
  • Working Example: dd if=/dev/sda of=/run/media/root/NTFS/Boot.img skip=511 conv=noerror bs=512 status=progress

Copy the Root Partition (second partition on a 'stock' / 'standard' OpenWRT x86 installation):

  • Syntax: dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img skip=511 conv=noerror bs=512 status=progress
  • Working Example: dd if=/dev/sda of=/run/media/root/NTFS/Root.img skip=511 conv=noerror bs=512 status=progress

...and finally, issue this command, just to make sure everything is flushed from cache / memory: sync

Syntax Notes for DD

  • if: Input File (or Device)
  • of: Output File (or Device)
  • 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"
  • progress = status: Show the progress of the copy process (only for a certain version of DD and up)
  • conv=sync: Write all buffered blocks to disk (just to be safe, but can cause 'out of space' issues with MBR and "MBR Gap")
  • skip: Skips X number of sectors for the input ( if= )
  • seek: Skips X number of sectors for the output ( of= )

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.


  • Example of saving to a Disk / SSD from an Image File: dd if=/dev/sdb of=/mnt/sda1/MBR_and_MBR-Gap.img conv=noerror bs=512 count=511 status=progress

Copy the Second Partition (/root equivalent): dd if=/dev/sdX2 of=/dev/sdY2 bs=128M conv=noerror progress=status

Flush any buffered information to disk: sync

Other Notes

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'.