RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Script to start ES or Desktop on boot

    Scheduled Pinned Locked Moved Help and Support
    boot config
    26 Posts 4 Posters 5.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • FrazattoF
      Frazatto @mitu
      last edited by

      @mitu it works as intended in rc.local to load the lcd driver when no HDMI is detected.
      Unless it is miss understanding the commas, I'm not finding any mismatch.

      Maybe if I set both ES and Raspbian to load to prompt and decide with to start in rc.local, hum....seams a good idea.

      I will test later, thanks o/

      1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator
        last edited by

        @Frazatto said in Script to start ES or Desktop on boot:

        @mitu it works as intended in rc.local to load the lcd driver when no HDMI is detected.

        Are you running this from rc.local or from autostart.sh ?

        Unless it is miss understanding the commas, I'm not finding any mismatch.

        I'm just posting what I get when running the script.

        FrazattoF 1 Reply Last reply Reply Quote 0
        • FrazattoF
          Frazatto @mitu
          last edited by

          @mitu said in Script to start ES or Desktop on boot:

          Are you running this from rc.local or from autostart.sh ?

          I already have a similar code running in rc.local to switch between lcd or hdmi on the fly and it has been working as intended.
          Now I'm trying to choose ES or Desktop depending if HDMI cable is connected or not.

          My previous idea won't work.....rc.local is not the last script to run during boot and trying to bring up a GUI before end of boot is probably a bad idea.....hum.....

          One thing I noticed, autostart.sh doesn't have the #!/bin/bash header, is it really a bash script??? Or is it just a flag for what ever ES is doing to start after boot?

          mituM 1 Reply Last reply Reply Quote 0
          • mituM
            mitu Global Moderator @Frazatto
            last edited by

            @Frazatto said in Script to start ES or Desktop on boot:

            One thing I noticed, autostart.sh doesn't have the #!/bin/bash header, is it really a bash script??? Or is it just a flag for what ever ES is doing to start after boot?

            It's a Bash script. This is how EmulationStation is started automatically on boot.

            FrazattoF 1 Reply Last reply Reply Quote 0
            • FrazattoF
              Frazatto @mitu
              last edited by

              @mitu Okkk....I researched a little more and tried this script:

              #if HDMI connected, go to desktop
              video="$(tvservice -s)"
              
              if [[ $video =~ "HDMI" ]];
              then
                startx
              else
                emulationstation #auto
              fi
              

              And I tested just with strings and bash before truing to boot and I'm 100% sure it does what I expect.
              But black screen is confirmed if you try to startx inside autostart.sh!!!!!

              I will have to find another way of doing this.

              BuZzB 1 Reply Last reply Reply Quote 0
              • BuZzB
                BuZz administrators @Frazatto
                last edited by

                @Frazatto do you have splash screen enabled? Try disabling

                To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                FrazattoF 1 Reply Last reply Reply Quote 0
                • FrazattoF
                  Frazatto @BuZz
                  last edited by

                  @BuZz all splash screens are disabled.

                  1 Reply Last reply Reply Quote 0
                  • FrazattoF
                    Frazatto
                    last edited by

                    Some more info...
                    Adding & after startx let the terminal keep running and showed me the real errors occurring.
                    You will get an permission denied as tty1 is occupied by the original user, Xorg can't start since the display is already in use and I don't want to run Desktop as root all the time and adding Pi to tty group only cascade into other access errors.

                    So I think this is a definitive answer that it is not possible to startx conveniently on ES autostart.sh

                    1 Reply Last reply Reply Quote 0
                    • mituM
                      mitu Global Moderator
                      last edited by

                      @Frazatto said in Script to start ES or Desktop on boot:

                      So I think this is a definitive answer that it is not possible to startx conveniently on ES autostart.sh

                      No, it's not - I actually tested and it works. I'm on the latest RetroPie version (Raspbian Buster) and I have no problem starting the desktop from autostart.sh.

                      Maybe you should give more details about your system, as detailed in https://retropie.org.uk/forum/topic/3/read-this-first.

                      1 Reply Last reply Reply Quote 0
                      • FrazattoF
                        Frazatto
                        last edited by

                        That is unexpected.......
                        Yes I did read that, didn't seam pertinent till now.

                        raspberry pi 3B+
                        Raspbian Buster
                        Retropie 4.6.2

                        1 Reply Last reply Reply Quote 0
                        • mituM
                          mitu Global Moderator
                          last edited by

                          Try this - disable any programs in autostart.sh. On boot, you should be presented with a command line prompt. Run startx from there and see if it works. If it doesn't, post the X.org log file to pastebin.com, from $HOME/.local/share/xorg/.

                          FrazattoF 1 Reply Last reply Reply Quote 0
                          • FrazattoF
                            Frazatto @mitu
                            last edited by

                            @mitu now I'm just confused :D

                            If I try what you asked, it works just fine.
                            So I went ahead and tried just startx & in autostart.sh and I get the same error.
                            This is the log you asked for when the desktop fails to start:
                            (the line about xf86OpenConsole used to be an access error to tty1 that I "fixed")

                            [    20.335] 
                            X.Org X Server 1.20.4
                            X Protocol Version 11, Revision 0
                            [    20.342] Build Operating System: Linux 4.15.0-48-generic armv8l Raspbian
                            [    20.345] Current Operating System: Linux BMO.local 4.19.118-v7+ #1311 SMP Mon Apr 27 14:21:24 BST 2020 armv7l
                            [    20.345] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_headphones=1 bcm2708_fb.fbwidth=1280 bcm2708_fb.fbheight=720 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  dwc_otg.lpm_enable=0 console=tty1 console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo
                            [    20.356] Build Date: 05 June 2019  12:49:54PM
                            [    20.359] xorg-server 2:1.20.4-1+rpt1 (https://www.debian.org/support) 
                            [    20.362] Current version of pixman: 0.36.0
                            [    20.368] 	Before reporting problems, check http://wiki.x.org
                            	to make sure that you have the latest version.
                            [    20.368] Markers: (--) probed, (**) from config file, (==) default setting,
                            	(++) from command line, (!!) notice, (II) informational,
                            	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
                            [    20.380] (==) Log file: "/home/pi/.local/share/xorg/Xorg.0.log", Time: Sat Jul  4 15:48:27 2020
                            [    20.394] (==) Using system config directory "/usr/share/X11/xorg.conf.d"
                            [    20.406] (==) No Layout section.  Using the first Screen section.
                            [    20.406] (==) No screen section available. Using defaults.
                            [    20.406] (**) |-->Screen "Default Screen Section" (0)
                            [    20.406] (**) |   |-->Monitor "<default monitor>"
                            [    20.425] (==) No device specified for screen "Default Screen Section".
                            	Using the first device section listed.
                            [    20.425] (**) |   |-->Device "Allwinner A10/A13 FBDEV"
                            [    20.425] (==) No monitor specified for screen "Default Screen Section".
                            	Using a default monitor configuration.
                            [    20.425] (==) Automatically adding devices
                            [    20.425] (==) Automatically enabling devices
                            [    20.425] (==) Automatically adding GPU devices
                            [    20.426] (==) Max clients allowed: 256, resource mask: 0x1fffff
                            [    20.482] (WW) The directory "/usr/share/fonts/X11/cyrillic" does not exist.
                            [    20.482] 	Entry deleted from font path.
                            [    20.482] (WW) The directory "/usr/share/fonts/X11/100dpi/" does not exist.
                            [    20.482] 	Entry deleted from font path.
                            [    20.482] (WW) The directory "/usr/share/fonts/X11/75dpi/" does not exist.
                            [    20.482] 	Entry deleted from font path.
                            [    20.482] (WW) The directory "/usr/share/fonts/X11/Type1" does not exist.
                            [    20.482] 	Entry deleted from font path.
                            [    20.483] (WW) The directory "/usr/share/fonts/X11/100dpi" does not exist.
                            [    20.483] 	Entry deleted from font path.
                            [    20.483] (WW) The directory "/usr/share/fonts/X11/75dpi" does not exist.
                            [    20.483] 	Entry deleted from font path.
                            [    20.483] (==) FontPath set to:
                            	/usr/share/fonts/X11/misc,
                            	built-ins
                            [    20.483] (==) ModulePath set to "/usr/lib/xorg/modules"
                            [    20.483] (II) The server relies on udev to provide the list of input devices.
                            	If no devices become available, reconfigure udev or disable AutoAddDevices.
                            [    20.483] (II) Loader magic: 0x1fcf80
                            [    20.483] (II) Module ABI versions:
                            [    20.483] 	X.Org ANSI C Emulation: 0.4
                            [    20.483] 	X.Org Video Driver: 24.0
                            [    20.483] 	X.Org XInput driver : 24.1
                            [    20.483] 	X.Org Server Extension : 10.0
                            [    20.487] (--) using VT number 2
                            
                            [    20.487] (II) systemd-logind: logind integration requires -keeptty and -keeptty was not provided, disabling logind integration
                            [    20.488] (II) no primary bus or device found
                            [    20.488] (II) LoadModule: "glx"
                            [    20.534] (II) Loading /usr/lib/xorg/modules/extensions/libglx.so
                            [    20.712] (II) Module glx: vendor="X.Org Foundation"
                            [    20.712] 	compiled for 1.20.4, module version = 1.0.0
                            [    20.712] 	ABI class: X.Org Server Extension, version 10.0
                            [    20.713] (II) LoadModule: "fbturbo"
                            [    20.713] (II) Loading /usr/lib/xorg/modules/drivers/fbturbo_drv.so
                            [    20.736] (II) Module fbturbo: vendor="X.Org Foundation"
                            [    20.736] 	compiled for 1.20.3, module version = 0.5.1
                            [    20.736] 	Module class: X.Org Video Driver
                            [    20.736] 	ABI class: X.Org Video Driver, version 24.0
                            [    20.737] (II) FBTURBO: driver for framebuffer: fbturbo
                            [    20.737] (EE) 
                            Fatal server error:
                            [    20.751] (EE) xf86OpenConsole: Cannot open virtual console 2 (Permission denied)
                            [    20.758] (EE) 
                            [    20.764] (EE) 
                            Please consult the The X.Org Foundation support 
                            	 at http://wiki.x.org
                             for help. 
                            [    20.791] (EE) Please also check the log file at "/home/pi/.local/share/xorg/Xorg.0.log" for additional information.
                            [    20.799] (EE) 
                            [    20.806] (WW) xf86CloseConsole: KDSETMODE failed: Bad file descriptor
                            [    20.806] (WW) xf86CloseConsole: VT_GETMODE failed: Bad file descriptor
                            [    20.806] (EE) Server terminated with error (1). Closing log file.
                            
                            1 Reply Last reply Reply Quote 0
                            • mituM
                              mitu Global Moderator
                              last edited by

                              @Frazatto said in Script to start ES or Desktop on boot:

                              [ 20.751] (EE) xf86OpenConsole: Cannot open virtual console 2 (Permission denied)

                              The error shows you're trying to run X on the 2nd text console, not the first. When running on the 1st one, it should show something like

                              [420164.968] (++) using VT number 1
                              

                              Do you have other configuration added to the default image ? Did you add something to /boot/cmdline.txt ?

                              FrazattoF 1 Reply Last reply Reply Quote 0
                              • FrazattoF
                                Frazatto @mitu
                                last edited by

                                @mitu manually? Never touched this file before.
                                This is it's content:

                                dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo
                                
                                1 Reply Last reply Reply Quote 0
                                • mituM
                                  mitu Global Moderator
                                  last edited by

                                  That's strange, doesn't look like a standard cmdline.ext. Did you install from a Raspbian Lite image or from a RetroPie image ?

                                  FrazattoF 1 Reply Last reply Reply Quote 0
                                  • FrazattoF
                                    Frazatto @mitu
                                    last edited by

                                    @mitu
                                    https://www.raspberrypi.org/downloads/raspberry-pi-os/
                                    "Raspberry Pi OS (32-bit) with desktop and recommended software"
                                    Than Retropie flowing the GIT guide.

                                    How does your look like?
                                    What does this file do?

                                    mituM 1 Reply Last reply Reply Quote 0
                                    • mituM
                                      mitu Global Moderator @Frazatto
                                      last edited by

                                      @Frazatto Not sure if that file is the culprit, but I've seen configuration when the default tty was modified via that file. Sorry, I have no ideas why it's not working, I just tested on a stock RetroPie install and couldn't get any errors.

                                      FrazattoF 1 Reply Last reply Reply Quote 0
                                      • FrazattoF
                                        Frazatto @mitu
                                        last edited by

                                        @mitu don't worry, you tried to the very end and I thank you!
                                        On the Raspberry forum nobody even bothered to answer me :P

                                        1 Reply Last reply Reply Quote 0
                                        • mituM
                                          mitu Global Moderator
                                          last edited by

                                          @Frazatto said in Script to start ES or Desktop on boot:

                                          On the Raspberry forum nobody even bothered to answer me :P

                                          That's probably because your problem is specific to the RetroPie auto-start configuration and not something Raspbian/Raspberry Pi related.

                                          1 Reply Last reply Reply Quote 0
                                          • FrazattoF
                                            Frazatto
                                            last edited by

                                            Just for future reference, I was messing around with this problem again and it just worked now........

                                            So to recap, if you want to change between X and EmulationStation depending on what output is connected, change /opt/retropie/configs/all/autostart.sh to something like the code below and it should work.

                                            #if HDMI connected, go to desktop
                                            video="$(tvservice -s)"

                                            if [[ $video =~ "HDMI" ]];
                                            then
                                            startx
                                            else
                                            emulationstation #auto
                                            fi

                                            I believe my Pi had some inconsistency in which user had ownership over the display, I manually set up ES and Rapibian to start on cmd, than in raspconfig set it to start X and lastly changed it back to ES to start by default. (yes, sounds complicated, but it was an accident really)

                                            After that, the code snippet should work as intended.

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.