Hello, I am trying to set up a safe shutdown for EmonPi using upsd - I have an uninterruptible power supply which lasts an hour or two. A script runs when the power has been out for x minutes, and I want that to shutdown the EmonPi. However the script need rw access. Is it possible to change the root file system permanently to rw? What are the disadvantages of doing so? Thanks.
Why does it need write access? If it’s for a log you should point the log to /var/log (in RAM) or if it needs to set a flag or pid lock etc, that should be done in /tmp (also in ram).
I assume you are running a emonSD (but not the latest?). Yes it is possible, or you could look at the rpi-rw and rpi-ro commands (or the ntp-backup service) to establish how to get your script to set the os to rw as and when it needs to.
A read only filesystem is both less likely to get altered randomly as the user (or a script) must put the OS in rw mode to purposely make changes, the RO mode also reduces writes to disk to lower the disk wear and hopefully extend the sdcard life. Plus it offers a level of protection against failures due to power interruptions eg power cuts or pulling the power lead, many sdcard failures are due to the power being removed whilst the OS is writing to disk, causing a corrupted file.
Thank you Paul. I have looked at the scripts for rpi-ro and rpi-rw and they are straightforward. However, there is something making the EmonPi default to ro. Is it in /etc/fstab, or is it in the kernel? When I log out and back in again it reverts to ro. Or is it perhaps timed in some way?
I see the advantages of a ro file system, thanks. I do have the latest version of emon SD. I’ll look into why it needs rw access.
To boot up to a rw filesystem you need to edit fstab and the hourly to command is part of the ntp_update script previously mentioned and can be edited or disabled (if os is always rw). But there are many update scripts and utilities that will try and recount the os ro, unless it’s the very last image, which I strongly suspect you are not using as that is NOT ro.
Hi Paul, You are quite right. My SD version was Oct 2017 - surprising since I bought the EmonPi in Nov 2018. I will try the latest version. My UPS tries to write to /var/lib/upsd, and of course cannot in a ro file system.
Thanks again, Tim
You could just manually mount the FS as RW using
rpi-rw long enough to add a symlink so that your ups can write to a RW partition eg
rpi-rw sudo mv /var/lib/upsd /home/pi/data/upsd sudo ln -s /home/pi/data/upsd /var/lib/upsd rpi-ro
or something along those lines . . .
Excellent, thank you Paul. That did the trick. Should I upgrade to the latest SD card image anyway?
I’m not the best person to answer that I’m afraid, but I would say not unless you need to, that’s why I tried to remove the necessity, now you have a choice rather than having to do it just for your ups.