@sumo and @psherman
Thank you both for your input. I accept that there are other ways to achieve my goal. But none of the options given so far are an easy and automatic solution. That's what I am after.
I looked at the script that can catalog and reinstall user added packages, which seems like a good idea, but it doesn't work on my OpenWrt. I get:
ls: /overlay/usr/lib/opkg/info/*.control: No such file or directory
No user packages found
Likewise I don't want to have to keep track of everything I ever installed by myself. I'll forget things.
I made a full SD card backup already in which I took the SD card out but I don't want to have to keep doing that because it's a pain and I loose internet when I do.
I don't need something as elaborate as building my own image.
Here is what I have got working so far:
Anytime I tried to remount rootfs as readonly I got a "Failed - resource busy" so by following a hint from here I edited /lib/preinit/80_mount_root
and commented out # mount_root (line 19)
and then I edited /lib/preinit/79_move_config
and changed...
mount -t vfat -o rw,noatime $BOOTPART /boot
To
mount -t vfat -o ro,noatime $BOOTPART /boot
Then I rebooted OpenWrt and indeed the boot and root fs were then readonly.
Then running this command to image the first 800MB of the SD card starting from /boot
# dd if=/dev/mmcblk0 bs=4M count=200 | gzip > /mnt/usb/openWrt-backup.img.gz
openWrt-backup.img.gz is 37MB zipped or 820MB when unzipped.
I can make /boot and /root rw again like this:
# mount -o remount,rw /boot
# mount -o remount,rw /dev/root
But the problem is, although I CAN SSH in to OpenWrt… I get no internet connectivity:

So I after editing those /lib/preinit files back to how they were I had to reboot a second time.
Now I checked the .img file with losetup
and I get this:
The boot partition mounts fine but the root does not. I'm guessing that's because my dd command.. I didn't dd the whole sd card. I was hoping I wouldn't have to. It's a 32GB card but only about 500MB is being used!
My questions:
- If I run the dd command on my sd card say, once a week, would that potentially cause the SD card to fail?
- Is it possible to make /dev/root readonly some way other than what I did above so I don't have to reboot?
- If no then is it possible to make the rootfs mount as read only some other way so I can get it back to read/write and normal OpenWrt functioning without having to reboot a second time?
- Here is the partition info on my OpenWrt (on a Pi 4)
Any hint on what dd command I need to image the whole SD card? If I do this then I will just get the /boot partition right? # dd if=/dev/mmcblk0 bs=4M | gzip > /mnt/usb/openWrt-backup.img.gz
- I think I will switch to a smaller card.. e.g: 4 or 8GB.
Thank you!
Flex