You have found why you should not use /etc/rc.local
anymore. It has limitations due to Compatibility with SysV. We have seen many problems here on this site using it. Following the recommendation of the developers from systemd you should avoid using it. The right way nowadays is to use a systemd unit file to start a service.
With your requirement we have to execute the command as early as possible on bootup, just after initializing the pseudo filesystem /sys/
. With a look at the System bootup process this seems to be the sysinit.target
with various low-level services and local-fs initialized. Try this unit file with:
rpi ~$ sudo systemctl --force --full edit switch-backlight-off.service
In the empty editor insert these statements, save them and quit the editor:
[Unit]
Description=Switch off backlight of the display
After=sysinit.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
# RemainAfterExit=yes
# ExecStop=/bin/sh -c 'echo "1" > /sys/class/backlight/soc\:backlight/brightness'
[Install]
WantedBy=sysinit.target
Every time you start the service it should switch off the backlight:
rpi ~$ sudo systemctl start switch-backlight-off.service
Enable the new service, so it will run on bootup:
rpi ~$ sudo systemctl enable switch-backlight-off.service
If you like, you can also stop the service and the backlight switches on then. Just uncomment the two commented lines in the [Service]
section.