How to backup/restore mtd with nanddump/nandwrite

Hello,

Have a mi R3P with NAND flash.

Wanted to backup and restore the mtd using nanddump and nandwrite.

Did some tests but I am doing something wrong.

dump mtd9 with command bellow

# nanddump -n -f /tmp/mtd9bk /dev/mtd9

# flash_erase /dev/mtd9 0 0

# nandwrite /dev/mtd9 /tmp/mtd9bk

however when try to mount I got ECC errors

Out of ecc_threshold!!page: 57537, ecc_threshold: 6, Max_ECN: 16
page 57537: 16, 0, 0, 0
Read page0

Out of ecc_threshold!!page: 57537, ecc_threshold: 6, Max_ECN: 16
page 57537: 16, 0, 0, 0
Read page1

Out of ecc_threshold!!page: 57537, ecc_threshold: 6, Max_ECN: 16
page 57537: 16, 0, 0, 0
Read page2

Some tips are appreciated.

Why not just use the standard system backup feature (which saves your config files in a tar.gz output file)?

I want to "clone" all as I have some customization in areas not covered by the regular backup

In that case, I'd recommend the following options -- both of which are more straightforward and less prone to errors (including the potential to have catastrophic loss of data/functionality if done wrong):

  • add those areas to the backup. Anything you put in /etc/sysupgrade.conf will be included in the backup.
  • copy your custom files/configs and build an image (using image builder) that includes all of your files and even the user-installed packages.

If the only acceptable method for you is still to try to close the actual flash storage, hopefully someone else can help (I would, but I'm not an expert in that particular method).

1 Like

thank you for your tips,

But in this case I am really looking for a way using this method as in my case would be simple/fast for restore.

The custom image is probably the fastest and easiest to restore, actually. It is pretty close to a clone for practical purposes, but requires less work to install.

Anyway, hopefully someone else can chime in about how you can clone your system.

mtd write might be better

1 Like

mtd write works for NAND?

Supposed mtd write works prety much like dd and for nand is not recommended due bad blocks.

Just for reference in case someone else face same issue.

write into NAND is more complicated than when working with NOR.

Depending what you will wanna write to the partition you may need to use diferent approach.

In this case as it is UBI correct way would be something like this

dd if=/tmp/mtd9bk bs=32 | ubiformat /dev/mtd9 -f -

however in others mtd's not using UBI you may need to use nandwrite or others.

Due this will seek for other option, maybe the @psherman idea with some customized image.

thank you all who contributed