Create full backup .bin

hi,

i'm noob for openwrt, and need help for rassure me.
i try to create tutorial ( for me and for you if you want ^^ ) for create full backup on my system.
is possible for you approuve or decline my "tuto" ?

my hardware is linksys EA8300 with dual boot.

create backup .bin

1/ show actual parted 

cat /sys/devices/virtual/ubi/ubi0/mtd_num

## 11 = kernel
## 13 = alt_kernel

go on http://10.0.0.1/cgi-bin/luci/admin/system/flash

Save mtdblock contents
11 or 13 

place file on new folder whit text document for explain detail ( version openwrt and kernel or alt_kernel important).

_________________________________________________________

restore firmware :

before, install clean same version of you backup ( use sysupgrade )

1/ show parted 
cat /sys/devices/virtual/ubi/ubi0/mtd_num

restore only on the same parted on backup file 11 or 13

go on http://10.0.0.1/cgi-bin/luci/admin/system/flash

use the uploader file for restore backup  

is good or wrong and big risk brick ?

1 Like

Hello fellow EA8300 user,

If you overwrite the wrong partition you could brick the device.

NOTE: THIS FEATURE IS FOR PROFESSIONALS!

I reassure you.

DISCLAIMER:

I don't know how to do this safely. But it would be nice to have a "easy button" config save. I don't really need it though - but it would be nice.

yes, i know, i explain on my "tuto" ( tuto for me ^^ )
BUT
i don't know if possible for exemple save mtd11 ( main firmware )

and restore on the mtd13 ( alt_kernel )

if not possible, no probleme

and

i don't know if my tutorial is good ...

is a mix on the "restore original firmware linksys EA8300" and this topic : https://forum.archive.openwrt.org/viewtopic.php?id=73770

I own both EA8300 and MR8300 and I would like to understand what is being asked here ?

If it's about not bricking the EA8300, I'm not sure I understand ?

Please explain if it's about backup or not bricking...

héllo @oneil4
you can look at my topic about backup/flash espressobin uboot from OpenWrt, here :

just adapt it to your needs...

mainly, you have to :

  1. list mtd partitions
    cat /proc/mtd
  2. backup a partition
    dd if=/dev/mtd11 of=/media/usb/backup_mtd11.bin
  3. restore a partition
    mtd -r /media/usb/backup_mtd11.bin /dev/mtd11

note: 1&2 can be done with luci

be sure that this is NOT supported !
be sure that this is a power user only merhod... and you may brick your hatdware...
so take it at your own risk !!!

but this is how I will answer your request.

TheONLY supported method is to :

  1. save opkg installed in a list by user with the script opkg backup ( from the wiki )
    https://openwrt.org/docs/guide-user/advanced/opkg_extras

  2. backup your setting ( including opkg script and lists of opkg installed )

  3. flash a new firmware

  4. restore the users' opkg list with the script opkg restore ( same script from wiki )

for a full backup, you may also use a more linux friendly merhod with a tar archive...
you may also compress it...
and you may also put it remotly to a NAS for sample...
and, why not, do it planned at recurrent time like with a cron
like this ; https://openwrt.org/docs/guide-user/troubleshooting/backup_restore
this is a backup plan style ! :wink:

edited: add wiki links and some text fixes
edited (2) : fixed the mtdwrite -> mtd -r

1 Like

for beginners, it should be easy to create a complete backup, currently, it is still a bit complicated with openwrt.

and i think that even if there is some risk, this solution, if it is well applied, could be an easy solution

BUT

I'm not sure if we should take the "kernel" or "rootfs" mtd......

I understand the risks of touching this, that's why I ask a lot of information to the forum before trying.

to try it, I saved mtd11 on my computer, via the luci interface ( step 1 and 2 )

and I put back in the /TMP folder, the file goes in the TMP folder, so, I think I don't need to restore via a partition stored on a disk or usb key.

(whit mtd11.bin inside tmp folder )
2

Translated with www.DeepL.com/Translator (free version)

1 Like

The ea8300/ mr8300 has NAND flash, meaning the bad block table is in-band on the flash, by using dd on the raw flash you copy not just the data, but also the bad block table - restoring it to another device (or even the same one later on!) would overwrite wear-levelling and bad block information, permanently damaging the NAND.

Don't ever do this on a device using NAND!

1 Like

with nand flash, is not possible use mtd backup / restore ?

or possible just don't use "dd" fuction ?

1 Like

The idea itself is deeply flawed and dangerous (even more so on NAND), but not using NAND-aware tools all the way through makes it a guaranteed wrecker.

2 Likes

I said to use dd for backup ! never said it for flashing, but expressly said to use mtd tools to write !
Do not understand your advertise ?!
You can backup also with cat...

1 Like

It is the official method of the wiki of OpenWrt, (also) : https://openwrt.org/docs/guide-user/installation/generic.backup

my apologize if I have been confused about it, (but still not seen where !!!???)

The forum already talk about this here : Best Practice MTD Restore Procedures

And it is also the method used by luci (the only method... I think)

edit: add luci source reference

First of all, anything with the right intend is good by nature. So that is a great starting point for sure. Thank you for your efforts.

I to have been thinking of creating/updating tutorials. The more I think of it the more I realize that it is best to first get myself a deep understanding of a particular subject before I write it to be used by others.

For example I think to myself. Is the language I use easy to understand. Are the terms I use correct in the given context. And the most important aspect. Is the solution I offer actually a solid one.

I for one am not known for any public tutorials, let alone good ones.

I think the moral of the story is this. Even though you deserve praise for your intend. The community is best served with tutorials with a strong background.

Respect

1 Like

thank you for the answer,

the tutorial is especially for me ^^ when I want to restore the backup in 2 or 3 years for example.

a solution of tutorial would be to make videos so that the user can watch the other make ( that reassures )

another difficulty is the language... I'm not an expert in english, I use deepl to translate, and sometimes the translations are not understandable.

for me, openwrt should allow to make a backup without using any application, or script.

why in luci backups there is the option to backup mtd if it is not possible to restore them as easily as to backup them?

for me, the part "security" of my tuto, it is to remetre the sysupgrade of the version which one wants to restore, (one restarts on a clean insalation, of the same version as the backup, then one takes the same partition if there are 2 partitions, and finally one restores)

but, I do not know if it is well, and there are full of method, of which that which gives erdoukki which helped me well several times, but for him it is easy, but for me, it is hard...

Translated with www.DeepL.com/Translator (free version)

1 Like

It's just as harmful for backing up, as you are not querying a block device (the mtd subsystem as a whole isn't that, but for NAND this is actively harmful) but a character device, which -in case of NAND- does include the in-band wear-leveling/ bad block information. Meaning your backup is already corrupted, in the best of all cases the mtd tools would bail out for 'restoring' this data (larger than fitting into the target mtd, as you haven't just copied the data, but also the in-band meta-data as well), but I'm not going to put that at a test.

The wiki being incorrect or imprecise wouldn't surprise me, after all it's user created content - and at least early supported devices tended to use spi-nor instead of NAND (while not exactly a new concept, it was mostly reserved to more expensive devices (with larger flash) until 'recently'.

1 Like

As said, use mtd to write to nand.
Use dd to read and backup but never to write back !

edit : okay with SPI not with NAND !!

1 Like

In luci it is a power user tool, because it is more a dump access than a save/backup !
So, normal that there is no easy restore access that will mainly broke the device…

1 Like

The advice is ok about nand, but nandwrite take care of the flash…
The better way will be to use nandump to backup instead of dd, as adviced in linux ; https://www.kernel.org/doc/html/latest/driver-api/mtdnand.html#tools
But it is not available on OpenWrt, as far that I now…
It will be preferable to use uboot nand read/write, when available, but more complicated also…

I partly agree with you, because dd may take more informations than needed, but mtd will only restore the necessary and take care about badblocks…
am I wrong ?

edit :

Is it true for NAND ? or is because I was testing on SPI ???

1 Like

and this :

I tried your suggestion

  • Old unit: tar -cvzf /tmp/overlay.tar.gz /overlay
  • Copy the tar file from old to new unit
  • New unit: cd /; tar -xvzf /tmp/overlay.tar.gz

by : Using "Save mtdblock contents" to clone a unit - #3 by rob.clark56

is possible use for backup ?

1 Like

my apologize... nand tools are available in OpenWrt !

root@ultra:~# opkg install nand-utils
Installing nand-utils (2.1.2-1) to root...
Downloading https://downloads.openwrt.org/releases/21.02.0-rc3/targets/mvebu/cortexa53/packages/nand-utils_2.1.2-1_aarch64_cortex-a53.ipk
Configuring nand-utils.

nanddump nandtest nandwrite

Usage: nanddump [OPTIONS] MTD-device
Dumps the contents of a nand mtd partition.

-h         --help               Display this help and exit
           --version            Output version information and exit
           --bb=METHOD          Choose bad block handling method (see below).
-a         --forcebinary        Force printing of binary data to tty
-c         --canonicalprint     Print canonical Hex+ASCII dump
-f file    --file=file          Dump to file
-l length  --length=length      Length
-n         --noecc              Read without error correction
           --omitoob            Omit OOB data (default)
-o         --oob                Dump OOB data
-p         --prettyprint        Print nice (hexdump)
-q         --quiet              Don't display progress and status messages
-s addr    --startaddress=addr  Start address
           --skip-bad-blocks-to-start
                                Skip bad blocks when seeking to the start address

--bb=METHOD, where METHOD can be `padbad', `dumpbad', or `skipbad':
    padbad:  dump flash data, substituting 0xFF for any bad blocks
    dumpbad: dump flash data, including any bad blocks
    skipbad: dump good data, completely skipping any bad blocks (default)


root@ultra:~# nandtest 
usage: nandtest [OPTIONS] <device>

  -h, --help           Display this help output
  -V, --version        Display version information and exit
  -m, --markbad        Mark blocks bad if they appear so
  -s, --seed           Supply random seed
  -p, --passes         Number of passes
  -r <n>, --reads=<n>  Read & check <n> times per pass
  -o, --offset         Start offset on flash
  -l, --length         Length of flash to test
  -k, --keep           Restore existing contents after test
root@ultra:~# nandwrite 
Usage: nandwrite [OPTION] MTD_DEVICE [INPUTFILE|-]
Writes to the specified MTD device.

  -a, --autoplace         Use auto OOB layout
  -k, --skip-all-ffs      Skip pages that contain only 0xff bytes
  -m, --markbad           Mark blocks bad if write fails
  -n, --noecc             Write without ecc
  -N, --noskipbad         Write without bad block skipping
  -o, --oob               Input contains oob data
  -O, --onlyoob           Input contains oob data and only write the oob part
  -s addr, --start=addr   Set output start address (default is 0)
  --skip-bad-blocks-to-start                          Skip bad blocks when seeking to the start address
  -p, --pad               Pad writes to page size
  -b, --blockalign=1|2|4  Set multiple of eraseblocks to align to
      --input-skip=length Skip |length| bytes of the input file
      --input-size=length Only read |length| bytes of the input file
  -q, --quiet             Don't display progress messages
  -h, --help              Display this help and exit
  -V, --version           Output version information and exit

so, as said in linux MTD :

It is better to use nanddump and nandwrite...
for backup and restore nand (MTD) partitions !

1 Like

thanks @slh to point me on this !

1 Like