I have a Raspberry Pi located in a datacenter. I can reach it only via the network.
When I would want to change the entire SD card image, I could of course send a new card by snailmail and ask the datacenter people to put it in my Pi, but I was thinking about the following:
Would it not be possible to send a new image via the network and have the Pi put it on the card and reboot from it?
There could be a program that you first upload to the Pi, under the existing (and hopefully functional) installation, then run it and it will receive the (compressed) SD card image over a TCP connection. If not too big it could store it in memory first, to be extra secure against network loss during the upload.
Then it would have to unmount the disk partitions, uncompress and write the SD card, and reboot.
Of course the critical part is: would it be possible on a Pi with a single program running to forcibly unmount the root fs without the program crashing (e.g. because it uses demand paging)
I envision it would first stop all "unnecessary" programs to make room in memory and to close open files, turn off the swap, receive the compressed image and put it in RAM, do a check, then stop all remaining programs except itself, unmount the disks and then write the image (uncompressing as it goes) to /dev/mmcblk0.
After that, it should just do a forced reset e.g. using the watchdog.
That should work, shouldn't it?
A slightly more daring approach would be sending the image over the network and having the receiving program uncompress and write it on-the-fly. This of course means end of story when the network goes down during the upload, but that risk is tolerable. Of course it also means the network must remain functional during the phase the disk has been unmounted and the system is in a minimal mode. Not sure if that is possible. But it would mean a larger image can be loaded (which even when compressed is larger than 400MB or so that would be the limit when using RAM).
Is anyone aware of such a program already having been written?