Manually reset of modified /etc files to current ostree commit

Dear Toradex Developer Community,
using Torizon and TorizonCore Builder, one can easily build and deploy a Torizon image with customization to a board, let’s call it release 1, and them make further changes to build and deploy a release 2.

The issue is that, if some /etc files on the board are somehow modified with respect to the original release 1, the release 2 is not applied and those files are not overwritten with the content of release 2. I wonder how one could manually force the full application of release 2, including overwrite of all the manual changes done upon release 1.

To provide more information, “ostree admin status” command output shows two releases and “ostree admin config-diff” indicates that some files are modified with respect to current release. Ideally, I am looking for an ostree command to “restore” modified /etc files to the deployed commit.

Thanks for the attention and best regards,
ldvp

Greetings @ldvp,

Let me summarize to make sure I understand the situation here.

  • You start with a base TorizonCore image I assume.
  • You make some modifications then capture these changes with TorizonCore Builder to create a new version. (release 1)
  • With release 1 you make manual changes to /etc. These manual changes are not officially part of any release, 1 or 2, is that right?
  • You then make a new version (release 2). Just to clarify is release 2 based on release 1? Also are the manual changes to /etc included in release 2? I assume based on your wording they are not.
  • Now the problem is that when you deploy release 2 the manual changes done to release 1 are still present and not overwritten by release 2.

Did I get that all correct?

If I did then it sounds like you are falling victim to a fundamental “feature” of OSTree. OSTree treats the /etc directory differently than other directories. The behavior is summarized in this excerpt from the OSTree documentation:

On upgrade, OSTree will perform a basic 3-way diff, and apply any local changes to the new copy, while leaving the old untouched.

So there’s a 3 way merge happening here between release 1’s /etc contents, the manual changes done to /etc, and release 2’s /etc contents. This sounds like what you’re experiencing.

Now if I understand you basically want to to remove the manual changes done to /etc so that the update goes from release 1 to release 2 cleanly. I don’t believe there’s a OSTree command that resets /etc. However there’s another mechanism you can do. In order to do the 3 way merge OSTree needs to know release 1’s original /etc content. But how does it do that if you do manual changes on /etc? The secret is /usr/etc, this directory is a read only default of that release’s /etc.

For your case what this means is that /usr/etc should contain release 1’s original /etc content without any of the changes that occurred after release 1 was deployed. I imagine you can do a kind of magic with rsync to copy/overwrite /usr/etc to /etc to effectively “restore” it, to it’s original state.

Let me know if this helps you.

Best Regards,
Jeremias

1 Like

Hi @jeremias.tx,
thanks a lot for the fast reply, the very clear explaination and the suggestion to use rsync leveraging /usr/etc. I confirm you have exactly understood the case and the command below did the job, I report it here hoping it can be useful to other users with the same need.

rsync -avh /usr/etc/ /etc/ --delete

Cheers,
ldvp

Glad I could help!

Best Regards,
Jeremias