0

The command I want to run is:

feh -Y -x -q -D 5 -B black -F -Z -z -r /location-to-images

These are the different methods I have tried (and I also tried using fbi instead of feh, but that did not work either):

Firstly, I tried adding the command after @reboot in sudo crontab -e (sudo is probably not necessary). Then I tried creating a bash script in /etc/init.d:

sleep 1m
lxterminal -e "feh -Y -x -q -D 5 -B black _F -Z -z -r /location-to-images"

and made that get run at @reboot, but alas it did nothing. And I did change the permissions to make it executable, and also I could see that the bash file and the command was being run by crontab by running grep CRON /var/log/syslog.

Then I tried following this tutorial (creating a .desktop file), that didn't work either.

Lastly I tried modifying the /etc/rc.local file where I wrote the following:

sleep 5
DISPLAY=:0
lxterminal -e "feh -Y -x -q -D 5 -B black _F -Z -z -r /location-to-images"

And I have run the command which according to some guy on a forum should enable rc-local, sudo systemctl enable rc-local.service although when I run sudo sysv-rc-conf it does not show up in the list, so there might be an issue there.

I will be forever grateful if you can help me with this! I'm planning on gifting my raspberry pi + screen as a cloud-connected digital photo frame for my parents this Christmas, and I don't want them to have to run a command each time they plug it in or the power goes out etc.

1
  • You have tried most of the solutions which don't work or are obsolete. Starting ANY code which displays on boot is not simple (even more so on Bullseye). Why don't you try one of the many photo frame examples. There are dozens, including in MagPi magazine.
    – Milliways
    Commented Dec 6, 2022 at 21:57

1 Answer 1

0

The methodology here will run the command in a single window on an X display as root. There are sort of security implications to that -- it could make it easy for someone to quickly gain superuser access, but since the sudo powers of the Pi user do this anyway, and the fact this person would have to have physical access (at which point security mostly goes out the window -- although it is also considered a risk in relation to possibly malicious apps, but if you are only running one thing that is much less significant), and finally considering the use-case context, this is probably not very important.

First, you want to disable the normal GUI:

sudo systemctl set-default multi-user

This may not work if you started with the full version of RpiOS installed. To check, just reboot. You should go straight to console, no GUI.1

Next, create a file /etc/systemd/system/startx-feh.service. This has to be done as superuser.

[Unit]
Description=Feh on minimal X server
Requires=local-fs.target

[Service]
Type=forking
StandardInput=null
StandardOutput=file:/var/log/local-startx.log
StandardError=inherit
ExecStart=/usr/bin/xinit /usr/bin/feh ...

[Install]
WantedBy=default.target

I'm guessing about the full path to feh, since I don't have it installed on the Pi I've done this with (the original version was used for vlc). You can check that with which feh.

Enable: sudo systemctl enable startx-feh.service. Try rebooting. If it doesn't work, you can check systemctl status startx-feh and have a look in the log (above, /var/log/local-startx.log), which should catch error output from feh.

I presumed invoking it from an lxterminal was just part of an attempt to make it work, and not because you want to catch the actual output etc. If so, you could place that whole command there prefixed with /usr/bin/xinit, or put it all in a script and invoke that.


  1. I normally start with the "lite" version and add GUI stuff if I want it, in which case graphical target starts the GUI at boot and multi-user target does not. However, I remember noticing at some point on a full version system that both of them started the GUI -- hopefully this is not still the case.
5
  • Thanks! The log file is very helpful. I am getting this error, which is weird because the screen is plugged in and displays the terminal as it starts up: (EE) Fatal server error: (EE) no screens found(EE) (EE) Please consult the The X.Org Foundation support at http://wiki.x.org for help. (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information. (EE) (EE) Server terminated with error (1). Closing log file. /usr/bin/xinit: giving up /usr/bin/xinit: unable to connect to X server: Connection refused /usr/bin/xinit: server error Commented Dec 10, 2022 at 11:12
  • Is there a GUI visible before or after that? If so it may be that the normal Xorg service (actually it is the lightdm service that starts it) was not disabled by systemctl set-default multi-user. If there isn't, you could still check systemctl status lightdm to see if both attempts to start it failed by getting in the way of one another somehow (kind of a long shot tho).
    – goldilocks
    Commented Dec 10, 2022 at 15:17
  • Hm so I don't get any GUI, but I see the command line first, then it becomes black for a few seconds before it shows the following on the command line: rc.local[372]: Unable to init server: Could not connect: Connect (...) [FAILED] Failed to start /etc/rc.local Compatibility. (...) [FAILED] Failed to start Feh on a minimal X server.. Running systemctl status lightdm yields lightdm.service - Light Display Manager Loaded: loaded (/lib/systemd/system/lightdm.service; enabled; vendor preset: enabled) Active: inactive (dead) Docs: man:lightdm Commented Dec 16, 2022 at 17:57
  • The momentary black screen is probably symptomatic of a failed X server. Try disabling lightdm: sudo systemctl disable lightdm, but, if things don't happen properly, check again to see if it still runs anyway (a "disabled" service may be run if something else requires it). If so, mask it sudo systemctl mask lightdm. This links it to a sort of dummy (/dev/null) instead of the real service. Do you have anything related to this in /etc/rc.local, BTW? Don't try to do the same thing in two places.
    – goldilocks
    Commented Dec 16, 2022 at 22:00
  • Ah, yes it was still trying to run old code from /etc/rc.local, that's where the errors in the terminal came from. Now I'm getting no errors from the terminal, and only the same error as before in the log file. I tried doing sudo systemctl mask lightdm but to no effect. I have changed to using my touch-screen instead of using an external screen via HDMI, and now my screen flashes white instead of black which is kind of interesting, don't know if that indicates anything Commented Dec 17, 2022 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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