Best Practice MTD Restore Procedures


#1

I've been using the following back up all script for scheduled full MTD backups: https://openwrt.org/docs/guide-user/installation/generic.backup

My current restore procedure is with SSH access as such:
dd if=./mtd_backup/mtd0_routerboot.backup | ssh root@192.168.169.1 "dd of=/dev/mtd0"
dd if=./mtd_backup/mtd1_factory.backup | ssh root@192.168.169.1 "dd of=/dev/mtd1"
dd if=./mtd_backup/mtd2_firmware.backup | ssh root@192.168.169.1 "dd of=/dev/mtd2"
dd if=./mtd_backup/mtd3_kernel.backup | ssh root@192.168.169.1 "dd of=/dev/mtd3"
dd if=./mtd_backup/mtd4_rootfs.backup | ssh root@192.168.169.1 "dd of=/dev/mtd4"
dd if=./mtd_backup/mtd5_rootfs_data.backup | ssh root@192.168.169.1 "dd of=/dev/mtd5"

mtd0 & mtd1 failed as expected, the rest were successful.

However, the second time I tried this restore method, my RBM33G board ended up being stuck in a boot loop and I had to factory reset it. Any ideas? Is this restore method ok?


#2

Is this restore method ok?

Its certainly interesting :slight_smile: ive never seen dd piped around like that.

I would suspect that something else was writing to the mtd at the point you wrote to it. Im not sure off the top of my head how to do it better. On a traditional system, youd unmount everything before writing dd , but i dont know how openwrt would react to that (or if its possible)

Is there an ftp or tftp method of getting to your bootloader? If so id keep the backups (unless someone more knowledgeable says even that is risky) and move the restore step to apply the backups with the boatloader (if it supports it , and if you have serial)

Edit: ive seen it mentioned in a few other places that its a good idea to make 4-5 backups of each mtd partition and use binary diff tools to verify they are all the same before considering each partition backup file is safe to use.


#3

Thanks for the feedback @Sparks ... after reading up on MTD, off the top of my head I thought to use dd via ssh, however, don't know if its best practice. Ideally, I'd like to combine the backup partitions or know what the best practice is for restoring a full MTD backup.


#4

Note that "firmware" is a meta-partition that is the union of kernel, rootfs, and rootfs_data. This is the only partition that you need to save and restore. It will contain the entire state of the flash that is altered by OpenWrt.

Keep backups of the bootloader and factory data offline, but do not attempt to routinely rewrite them. The OpenWrt kernel should be enforcing a write-protect on those partitions.

The best way to write a firmware is to use sysupgrade -n.


#5

Thank you @mk24 , just so I'm crystal clear: ./mtd_backup/mtd2_firmware.backup is the only partition that needs to really be restored in a light disaster scenario or point in time recovery, correct? No need to restore ./mtd_backup/mtd4_rootfs.backup and ./mtd_backup/mtd5_rootfs_data.backup.

Also, use the sysupgrade -n method to restore this partition. Or if I continue to use the dd method, figure out a way to first go into a maintenance mode before execution.


#6

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.