OpenWrt Forum Archive

Topic: Is it possible to create full backup or image from a running router?

The content of this topic has been archived on 7 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello!
Actually I have two routers with OpenWRT, TPLink MR3020 and GLiNET 300M with custom modifications, scripts and other stuff.
Is it possible to make a full backup or image of those running routers? I want to clone them to another ones and I was thinking about two different posibilities.

1) Create a image .bin with all the o.s, configuration, files, etc... This would be great because I can flash it directly to the MR3020 in one step, because if not, i have to flash image first, and then do a restore.
2) Make a "full backup" and restore it from webgui.

I've tried to make a normal backup throught web gui but files and scripts manually added are omited.

Thanks!

1.  To "clone" the entire OS and files, first do cat /proc/mtd to find which one is the "firmware" partition.  That partition includes everything that OpenWrt modifies in the flash.  You can create an image of the whole install from it:

root@NanoBeam:/# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00760000 00010000 "firmware"
mtd3: 00140000 00010000 "kernel"
mtd4: 00620000 00010000 "rootfs"
mtd5: 003e0000 00010000 "rootfs_data"
mtd6: 00040000 00010000 "cfg"
mtd7: 00010000 00010000 "EEPROM"
root@NanoBeam:/# cat /dev/mtd2 > /tmp/image.bin

The resulting image.bin can be flashed back to this router or to another router of exactly the same model to clone it.  Treat it as a "sysupgrade" file.
This is for NOR flash only.  It is very unlikely to work on NAND flash.  Also if you only have 32 MB RAM, the image on the RAMdisk may cause the router to run out of RAM.

2.  You can make the "backup" process include your files and scripts by referencing them in a file in /lib/upgrade/keep.d.  Installed packages are by design not backed up, because when you change to a new version most packages need to be replaced with the ones built for the new version.  Someone has written a script that basically formats the output of opkg --list-installed to a form that can be input to opkg install to reinstall upgraded packages.

(Last edited by mk24 on 9 Apr 2018, 16:50)

mk24 wrote:

1.  To "clone" the entire OS and files, first do cat /proc/mtd to find which one is the "firmware" partition.  That partition includes everything that OpenWrt modifies in the flash.  You can create an image of the whole install from it:

root@NanoBeam:/# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00760000 00010000 "firmware"
mtd3: 00140000 00010000 "kernel"
mtd4: 00620000 00010000 "rootfs"
mtd5: 003e0000 00010000 "rootfs_data"
mtd6: 00040000 00010000 "cfg"
mtd7: 00010000 00010000 "EEPROM"
root@NanoBeam:/# cat /dev/mtd2 > /tmp/image.bin

The resulting image.bin can be flashed back to this router or to another router of exactly the same model to clone it.  Treat it as a "sysupgrade" file.
This is for NOR flash only.  It is very unlikely to work on NAND flash.  Also if you only have 32 MB RAM, the image on the RAMdisk may cause the router to run out of RAM.

2.  You can make the "backup" process include your files and scripts by referencing them in a file in /lib/upgrade/keep.d.  Installed packages are by design not backed up, because when you change to a new version most packages need to be replaced with the ones built for the new version.  Someone has written a script that basically formats the output of opkg --list-installed to a form that can be input to opkg install to reinstall upgraded packages.

Thank you so much! I'm going to try and post results! smile

It worked like a charm! I was able to back it up to a *.bin file and then flash it to another one exactly the same.
Thanks!

mk24 wrote:

1.  To "clone" the entire OS and files, first do cat /proc/mtd to find which one is the "firmware" partition.  That partition includes everything that OpenWrt modifies in the flash.  You can create an image of the whole install from it:

root@NanoBeam:/# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00760000 00010000 "firmware"
mtd3: 00140000 00010000 "kernel"
mtd4: 00620000 00010000 "rootfs"
mtd5: 003e0000 00010000 "rootfs_data"
mtd6: 00040000 00010000 "cfg"
mtd7: 00010000 00010000 "EEPROM"
root@NanoBeam:/# cat /dev/mtd2 > /tmp/image.bin

The resulting image.bin can be flashed back to this router or to another router of exactly the same model to clone it.  Treat it as a "sysupgrade" file.
This is for NOR flash only.  It is very unlikely to work on NAND flash.  Also if you only have 32 MB RAM, the image on the RAMdisk may cause the router to run out of RAM.

2.  You can make the "backup" process include your files and scripts by referencing them in a file in /lib/upgrade/keep.d.  Installed packages are by design not backed up, because when you change to a new version most packages need to be replaced with the ones built for the new version.  Someone has written a script that basically formats the output of opkg --list-installed to a form that can be input to opkg install to reinstall upgraded packages.

The discussion might have continued from here.