How to override and or modify a file in host OS ( /etc/ )

Hi, I’m in need of modifying the file in /etc/systemd/logind.conf

Specifically what I’m trying to achieve is being able to override the HandlePowerKey property in that file to add custom behaviour to the button event instead of having the device shut off.

I was that hoping modifying the /mnt/state/root-overlay/etc/systemd would mirror changes but it doesn’t appear to do so.

What is the balena way to be able to accomplish what I’m trying to do?

Hey Simon, what you are basically needing is a user space daemon that listens for kernel ACPI events are performs a specific action. On most systems this is handled by systemd-login as you describe, but that is not ideal in this case as you would need to run a container with systemd. Not impossible, but an unrequired complication. A better approach would be to run something like busybox acpi daemon (Busybox acpid - Alpine Linux) and configure it to execute a custom script when it detects the press event.

One thing that confuses me is that you mention that currently the system is powering off when the button is pressed. That means that either there already is something handling the event, in which case you would need to find it and modify it, or it is hardware driven, in which case there is not much you can do about it unless you can disable the hardware action.

It is the actual power button which I am pressing, for further context I am using the iot-gate-imx8 device.

If I were to be able to modify the configuration file for the login-daemon I should be able to prevent the device shutting down when pressing the button for less than 5 seconds.

I am already able to listen to the button press, although it will inevitably trigger a shutdown.

@Simontaga did you manage to abort the shut down after a power button press?

Unfortunately not. From what I could gather I’d have to modify a configuration on the read-only filesystem.

I suppose this might be doable if you build a balena image from scratch, but I never looked into it.

1 Like


It’s important to understand whether the shutdown is actually software or hardware driven. The iot-gate-imx8 by default has a hardware shutdown configured for a long press of the power button. This can be disabled by modifying the LPDR register, which can be done from U-Boot or from an application container with a memory access tool like memtool.

If software driven, as I explained above, you will need to identify what service is intercepting the button event and triggering the shutdown. Nothing in balenaOS is doing this, so it must be something in the application containers.

In general, there are very few use cases left that would require modifications of the hostOS.