1

I have a couple of Raspberry Pis running at different sites. I can access all of them over SSH and all of them are running read only file system.

I need to fully replace the software on some of this and I would like to do this over SSH. I know it is a bit dangerous, but it will save me some time and if it fails I can always go there and replace the SD card by hand.

So I figure what I should do is:

  1. Create a RAM disk
  2. Copy commands to RAM disk: dd, reboot
  3. From my remote computer issue something like:

    dd if=software.img bs=1m | ssh root@raspberrypi /mnt/ram/dd of=/dev/mmcblk0 bs=1m
    

I have two questions. Would this work if we have ...

  • With a couple of RasPis and your requirements, have you considered to use Netbooting multiple “workers” RPi from a “master” RPi? – Ingo Sep 27 '18 at 10:13
  • 1
    @Ingo thank you for the suggestion, allthough the raspberries are located in different networks so I don't think network boot would work? Also I think the amount of data would be a bit too much if it works since I need to put the central server on the Internet in this case. – www.jensolsson.se Sep 27 '18 at 14:23
  • You are right. Netbooting is not a possibility for you. You need a stable network. It was just a quick idea. – Ingo Sep 27 '18 at 16:15
3

First, if you have a spare Raspberry, you should set it up as similar as possible to the ones you have remote and use it to test until you have it working, while you can see error messages and refine your process.

If your file system is read only, you don't have to worry about corruption be writes from the running system.

You don't just need dd and reboot, you also need all the libraries that are needed to run the programs. Use ldd to see the required libraries.

You don't have to copy the files to a ram disk. You just need the content in place before the disk is wiped. You ca do that by just reading the contents with cat.

ldd $(type -p dd reboot) | while read name rest; do cat ${rest%:} > /dev/null; done

This should read all the files mentioned by ldd, including dd and reboot. It will complain about missing linux-vdso, just ignore it or add code to avoid the message. After that, both programs and the libraries will be in memory, unless they don't fit into the available memory.

You should use reboot -f to reboot. With a read only system, you have no need for a proper shutdown, and a regular reboot might cause systemd to load pages from files that are no linger present.

  • Thanks this sounds like a great plan. So I don't have to worry that the system would purge data from the cache randomly? – www.jensolsson.se Sep 27 '18 at 22:05
  • It's a good idea to stop all processes that you don't need. Basically everything except sshd and your login shell, network related stuff, and so on. – RalfFriedl Sep 27 '18 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.