Repacking
The repacking process is mainly taking the reverse path we took for packing, recreating a consistent image with the modifications we want.
I would strongly encourage you to look into the firmware modkit if you need to repack routers and other xx-WRT-based firmware (https://code.google.com/archive/p/firmware-mod-kit/).
Since most of the standard filesystems that are mounted from a file with a -o
loop option will be read-only, a common approach is to work on the files on a normal directory on your computer, create an empty image of the necessary size, recreate an empty filesystem, and copy the files onto it.
Some systems may not implement the filesystems completely and you may need to tailor the filesystem creation (or use specific versions) for it to work with the final target system.