Skip to content

1.3.2 Autostart X11 via bashrc

PortalMario edited this page Jan 18, 2023 · 2 revisions

Autostart X11 via bashrc

Now we bring two things that we done so far together.

  1. The customized boot sequence with a configured autologin.
  2. The configured X11 start procedure that starts the custom boot animation and emulationstation afterwards.

Emulationstation cannot be run with root-privileges. Therefore, we already configured an autologin for the system's primary user so it can be started by the system's primary user.

Bashrc

Fortunately, when a user starts a new shell/bash a few commands will always be executed during the start of the shell/bash automatically. Those commands are managed within the file: .bashrc which is stored within the home directory of every shell/bash using user. As our primary user automatically starts a new shell/bash right after the login per default, we just have to add one command to our .bashrc at the top that launches X11. Let's take a look at the file and add the startx command to it: (/home/<PIMARY_USER>/.bashrc)

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

startx > /dev/null 2>&1

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
...
  • startx (line 5)
    • Starts the X11-Session for the user that executes it. X11 will then start executing the commands within the xinitrc. Right after the startx command we want to add an output redirection to /dev/null. Startx initializes the x11 server and this will print a bunch of x11 related log messages on the current bash session and therefore the user would see them creating a bad user experience. With startx > /dev/null 2>&1 we redirect the shell output of the startx command into the file /dev/null.

      2>&1 ensures that all output get send into /dev/null even error messages of the corresponding command. By adding this redirection, the user is not going to see uninteresting x11 log messages. The first thing the user would see is the custom boot animation.

Conclusion

If our user now logs into the system, the command startx will be executed automatically and therefore our custom boot animation will be played and emulationstation gets launched. If we reboot the system now, we will have a silent, fast boot that results in an autologin followed by the autostart of the x11 system which will show our custom boot animation and starts emulationstation afterwards.

We can now locate our games at /home/<PRIMARY_USER>/RetroPie/roms/gc/. Don't forget that the file name of the games needs to be exactly the same as they are stated within the corresponding gamelist.xml.

All games and the gamelist itself need to have the right ownership:

$ chown -R <PRIMARY-USER>:<PRIMARY-USER> /home/<PRIMARY_USER>/RetroPie/roms/gc/*

The software part is now done we could now use the system for gaming. The system is now ready to be housed within any case of choice.

Clone this wiki locally