OpenWRT and Backing Up: Difference between revisions

mNo edit summary
Line 1: Line 1:
This article is mostly about doing a bare metal backup of an x86 based OpenWRT system.  There are some notes about the additional items that need to be done for a more typical installation on a Router with with Flash based storage (IE, using the
===Rant on Backing Up OpenWRT (Not just the configuration files, but an entire 'Drive' (Flash, SSD, etc.))===
===Rant on Backing Up OpenWRT (Not just the configuration files, but an entire 'Drive' (Flash, SSD, etc.))===
How can the entire OpenWRT installation be backed up in a fashion similar to Acronis products, Clonezilla, etc.?
How can the entire OpenWRT installation be backed up in a fashion similar to Acronis products, Clonezilla, etc.?
Line 34: Line 36:
dd if=/dev/WhatEverSDx of=/mnt/WhatEverSDx/WhatEverImageName.img conv=sync,noerror bs=64K status=progress (Example: dd if=/dev/sdb of=/mnt/sda1/ALL.img conv=noerror,sparse bs=1M status=progress)
dd if=/dev/WhatEverSDx of=/mnt/WhatEverSDx/WhatEverImageName.img conv=sync,noerror bs=64K status=progress (Example: dd if=/dev/sdb of=/mnt/sda1/ALL.img conv=noerror,sparse bs=1M status=progress)


Remember, using DD to clone /dev/WhatEverSDx is not enough.  There's also the /overlay Directory / Loop Device to consider.
Remember, using DD to clone /dev/WhatEverSDx is not enough.  There's also the /overlay Directory / Loop Device to consider.  See the "Overlay" Section below.


====Create a "Device" to Mount, IE Associate a File with a Loop Device Node====
====Create a "Device" to Mount, IE Associate a File with a Loop Device Node====
Line 57: Line 59:
====Note on: LOSETUP -d WhatEverLoopDeviceName====
====Note on: LOSETUP -d WhatEverLoopDeviceName====
Bad news.  The delete command doesn't always work.  After issuing the command on a legitimate Loop Device, and with no errors, the Loop Device will persist.  Checking it with LOSETUP -a shows it is still there.  Accessing it with CFDISK or MOUNT still works.  Oh, well.  Windows solution time.  Reboot.
Bad news.  The delete command doesn't always work.  After issuing the command on a legitimate Loop Device, and with no errors, the Loop Device will persist.  Checking it with LOSETUP -a shows it is still there.  Accessing it with CFDISK or MOUNT still works.  Oh, well.  Windows solution time.  Reboot.
=== Overlay, OverlayFS, Union Mount, SquashFS, F2FS, and more. ===
==== "QuickD" ====
Real quick, here's what's going on with a typical Router based installation of OpenWRT that is stored on Flash Memory Storage.
OpenWRT is essentially installed on devices as if all of it's code were stored in an EPROM and just plugged into the board of a router.  There are a bunch of abstraction layers that make this possible, both in the installation and function of OpenWRT, but that's what is happening.
How is it done?  Using the [[wikipedia:OverlayFS|Overlay]] / [[wikipedia:Union_mount|Union Mount]] capabilities of Linux.  Sorry, not here to explain that fully, hence the above links.
==== Backing up the /overlay Directory ====
Ideally (since LVM isn't typically available to do "Volume Shadow Copies"), one would boot to an alternative OS, use DD to clone the /overlay "Partition" / "Device".  Easy with an x86_64 based install of OpenWRT, but also very possible with a Router based on Flash Memory Storage too.  For the Router scenario, again ideally, if the /overlay "Partition" / "Device" is on an external USB Flash Drive (as it should be if a router has a USB 3.0 port), just pop it into a "Linux Box" (virtual or otherwise) for backing up.  It can also be done "live" without much chance of something being modified during the cloning process.
* While booted to an alternate OS (Rocky Linux, another OpenWRT install on a USB Flash Drive, etc.), in this example, booted to another OS, but first;
** Locate where the /overlay Partition is;
*** LSBLK will show where that is
**** For an OpenWRT install with /overlay on a USB Flash Drive: /overlay will be on /dev/sdXy (where X is a letter and y is a number, example: sda1)
**** For an OpenWRT install with /overlay on a SATA Disk Drive / SSD: /overlay will be on a [[wikipedia:Loop_device|Loop Device]], roughly equivalent to a VHD or VHDX File where a file represents a storage device
***** Use this command: losetup -a (it will display something like this: /dev/loop0: (Some Numbers) (/sda2), offset 3014656  (/dev/loop0 is the device and /sda2 is the "file", actually a real drive))
****
3014656
losetup -o OFFSET_IN_BYTES /dev/loopX /path/to/your/file
losetup -o 3014656 -fP /mnt/sda1/OpenWRT_SDC2.img
mount -t f2fs /dev/loop1 /mnt/loop1


===And More...===
===And More...===
What about taking that RAW Image created by DD and turning it into a VHD File (or just about any other virtual disk format)
What about taking that RAW Image created by DD and turning it into a VHD File (or just about any other virtual disk format)