User avatar
BorbingoBoy
Posts: 12
Joined: Sun Apr 09, 2017 6:24 am
Location: Croatia
Contact: Website

Toggling GL and Boot Mode w/o raspi-config

Sat Jan 20, 2018 4:13 pm

Do you use RetroPie and PIXEL at the same time? Do you not want to to use raspi-config to toggle GL and boot mode every time? Do you prefer to save time and sanity? Well, fear not, this script is for you!
BorbingoBoy wrote:
Thu Jan 25, 2018 4:23 pm
Thank you, DougieLawson, for making it happen! :)

How to use: Copy the code below and paste it in a new empty file with the name of your choice (for example, 'gl'), the sh extension isn't necessary. Open terminal and enter sudo cp [file name] /usr/bin/. Finally, enter sudo chmod -rwxr-xr-x /usr/bin/[file name]. You are done!

To run it, just enter sudo [file name]. I made it option-based, the menus should be self-explanatory. That's it!

Code: Select all

#!/bin/bash

if [ $(id -u) -ne 0 ]; then
  printf "Reminder: use sudo!\n"
  exit 1
fi

echo GL toggler for Raspbian.
echo Code is mainly copied from raspi-config. BorbingoBoy 2018
echo Special thanks to DougieLawson


# Start of functions

# Enable GL driver
do_G1() {
        if ! grep -q -E "^dtoverlay=vc4-kms-v3d" /boot/config.txt; then
          ASK_TO_REBOOT=1
        fi
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
        sed /boot/config.txt -i -e "s/^#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/"
        if ! grep -q -E "^dtoverlay=vc4-kms-v3d" /boot/config.txt; then
          printf "dtoverlay=vc4-kms-v3d\n" >> /boot/config.txt
        fi
        STATUS="The full KMS GL driver is enabled."
        }

# Disable GL driver
do_G3() {
        if grep -q -E "^dtoverlay=vc4-f?kms-v3d" /boot/config.txt; then
          ASK_TO_REBOOT=1
        fi
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/"
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
        STATUS="The GL driver is disabled."
        }

# Boot to CLI
do_CLI() {
         systemctl set-default multi-user.target
         ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
         }

# Boot to desktop
do_DSKTP() {
           systemctl set-default graphical.target
           ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
           }

# End of functions


# Dialog enable/disable

echo What would you like to do?
 
PS3='Choice: '
options=("Enable GL" "Disable GL" "Cancel and Reboot" "Cancel")
select opt in "${options[@]}"
do
    case $opt in
        "Enable GL")
            do_G1
            break
            ;;
        "Disable GL")
            do_G3
            break
            ;;
        "Cancel and Reboot")
            reboot
            break
            ;;
        "Cancel")
            break
            ;;
        *) echo invalid option;;
    esac
done


# Dialog for changing boot mode

echo Where would you like to boot next?

PS3='Choice: '
options=("To Desktop" "To CLI" "Cancel and Reboot" "Cancel")
select opt in "${options[@]}"
do
    case $opt in
        "To Desktop")
            do_DSKTP
            break
            ;;
        "To CLI")
            do_CLI
            break
            ;;
        "Cancel and Reboot")
            reboot
            break
            ;;
        "Cancel")
            break
            ;;
        *) echo invalid option;;
    esac
done


# Dialog for confirming final reboot

echo Reboot?

PS3='Choice: '
options=("Yes" "No")
select opt in "${options[@]}"
do
    case $opt in
        "Yes")
            reboot
            break
            ;;
        "No")
            break
            ;;
        *) echo invalid option;;
    esac
done

Original post

Hello,

I have ExaGear and RetroPie installed on my Raspberry Pi 3, Raspbian Jessie. In order to play 3D games and such, GL driver must be on (and booting to desktop is, of course, required), but in order to use RetroPie, the GL driver must be off, and booting to CLI is required.

Which commands should I use instead of using raspi-config to toggle (full) GL driver and to change boot mode (desktop/CLI)?

By the way, I am planning to create two shell scripts to toggle GL driver, change boot mode and restart, so that I wouldn't have to enter all of the commands every time.

Thank you!
Last edited by BorbingoBoy on Sat Dec 22, 2018 6:16 pm, edited 5 times in total.
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456

User avatar
DougieLawson
Posts: 39562
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Toggling OpenGL Driver w/o raspi-config?

Sat Jan 20, 2018 4:42 pm

Read /usr/bin/raspi-config it's a bash shell script, you should be able to see how it makes the change.

You can also "source" /usr/bin/raspi-config and use the functions in it in your own programs (without using the menus).
https://bash.cyberciti.biz/guide/Source_command
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
BorbingoBoy
Posts: 12
Joined: Sun Apr 09, 2017 6:24 am
Location: Croatia
Contact: Website

Re: Toggling OpenGL Driver w/o raspi-config?

Sat Jan 20, 2018 6:23 pm

DougieLawson wrote:
Sat Jan 20, 2018 4:42 pm
Read /usr/bin/raspi-config it's a bash shell script, you should be able to see how it makes the change.

You can also "source" /usr/bin/raspi-config and use the functions in it in your own programs (without using the menus).
https://bash.cyberciti.biz/guide/Source_command

Code: Select all

#!/bin/sh

# Enable
#       if ! grep -q -E "^dtoverlay=vc4-kms-v3d" $CONFIG; then
#         ASK_TO_REBOOT=1
#       fi
		sed $CONFIG -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
		sed $CONFIG -i -e "s/^#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/"
		if ! grep -q -E "^dtoverlay=vc4-kms-v3d" $CONFIG; then
			printf "dtoverlay=vc4-kms-v3d\n" >> $CONFIG
		fi
#       STATUS="The full KMS GL driver is enabled."
        ;;

# Disable
#       if grep -q -E "^dtoverlay=vc4-f?kms-v3d" $CONFIG; then
#         ASK_TO_REBOOT=1
#       fi
        sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/"
        sed $CONFIG -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
#       STATUS="The GL driver is disabled."
        ;;
I should use this, right?
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456

User avatar
DougieLawson
Posts: 39562
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Toggling OpenGL Driver w/o raspi-config?

Sat Jan 20, 2018 6:27 pm

Probably, I've never looked because that OpenGL stuff doesn't interest me.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
BorbingoBoy
Posts: 12
Joined: Sun Apr 09, 2017 6:24 am
Location: Croatia
Contact: Website

Re: Toggling OpenGL Driver w/o raspi-config?

Sat Jan 20, 2018 6:54 pm

To CLI, GL off:

Code: Select all

#!/bin/sh

# Disable GL driver
#       if grep -q -E "^dtoverlay=vc4-f?kms-v3d" $CONFIG; then
#         ASK_TO_REBOOT=1
#       fi
        sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/"
        sed $CONFIG -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
#       STATUS="The GL driver is disabled."
        ;;

# Boot to CLI
        if [ $SYSTEMD -eq 1 ]; then
          systemctl set-default multi-user.target
          ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
        else
          [ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
          sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
        fi
        ;;

reboot
I get:

Code: Select all

sed: no input files
sed: no input files
./nogl_cli_test.sh: 10: ./nogl_cli_test.sh: Syntax error: ";;" unexpected
--
To desktop, GL on:

Code: Select all

#!/bin/sh

# Enable GL driver
#       if ! grep -q -E "^dtoverlay=vc4-kms-v3d" $CONFIG; then
#         ASK_TO_REBOOT=1
#       fi
		sed $CONFIG -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
		sed $CONFIG -i -e "s/^#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/"
		if ! grep -q -E "^dtoverlay=vc4-kms-v3d" $CONFIG; then
			printf "dtoverlay=vc4-kms-v3d\n" >> $CONFIG
		fi
#       STATUS="The full KMS GL driver is enabled."
        ;;

# Boot to desktop
        if [ -e /etc/init.d/lightdm ]; then
          if id -u pi > /dev/null 2>&1; then
            if [ $SYSTEMD -eq 1 ]; then
              systemctl set-default graphical.target
              ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
            else
              update-rc.d lightdm enable 2
            fi
            sed /etc/lightdm/lightdm.conf -i -e "s/^\(#\|\)autologin-user=.*/autologin-user=pi/"
            disable_raspi_config_at_boot
#         else
#            whiptail --msgbox "The pi user has been removed, can't set up boot to desktop" 20 60 2
          fi
#       else
#         whiptail --msgbox "Do sudo apt-get install lightdm to allow configuration of boot to desktop" 20 60 2
#         return 1
        fi
        ;;

reboot
I get:

Code: Select all

sed: no input files
sed: no input files
And the prompt wouldn't appear.

Could you help me, please?
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456

User avatar
DougieLawson
Posts: 39562
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Toggling OpenGL Driver w/o raspi-config?

Sat Jan 20, 2018 8:52 pm

Turn the code from /usr/bin/raspi-config into three functions

Code: Select all

do_G1() {
        if ! grep -q -E "^dtoverlay=vc4-kms-v3d" /boot/config.txt; then
          ASK_TO_REBOOT=1
        fi
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
        sed /boot/config.txt -i -e "s/^#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/"
        if ! grep -q -E "^dtoverlay=vc4-kms-v3d" /boot/config.txt; then
          printf "dtoverlay=vc4-kms-v3d\n" >> /boot/config.txt
        fi
        STATUS="The full KMS GL driver is enabled."
        }
  do_G2() {
        if ! grep -q -E "^dtoverlay=vc4-fkms-v3d" /boot/config.txt; then
          ASK_TO_REBOOT=1
        fi
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/"
        sed /boot/config.txt -i -e "s/^#dtoverlay=vc4-fkms-v3d/dtoverlay=vc4-fkms-v3d/"
        if ! grep -q -E "^dtoverlay=vc4-fkms-v3d" /boot/config.txt; then
          printf "dtoverlay=vc4-fkms-v3d\n" >> /boot/config.txt
        fi
        STATUS="The fake KMS GL driver is enabled."
        }
  do_G3() {
        if grep -q -E "^dtoverlay=vc4-f?kms-v3d" /boot/config.txt; then
          ASK_TO_REBOOT=1
        fi
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/"
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
        STATUS="The GL driver is disabled."
        }
You can then call any one of those to set full vc4-kms-v3d call do_G1(), fake vc4-fkms-v3d call do_G2() or legacy call do_G3() from your main line code. Since you're editing /boot/config.txt you'll need to run as root (sudo)
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
BorbingoBoy
Posts: 12
Joined: Sun Apr 09, 2017 6:24 am
Location: Croatia
Contact: Website

Re: Toggling OpenGL Driver w/o raspi-config?

Tue Jan 23, 2018 4:05 pm

DougieLawson wrote:
Sat Jan 20, 2018 8:52 pm
Turn the code from /usr/bin/raspi-config into three functions

Code: Select all

...
You can then call any one of those to set full vc4-kms-v3d call do_G1(), fake vc4-fkms-v3d call do_G2() or legacy call do_G3() from your main line code. Since you're editing /boot/config.txt you'll need to run as root (sudo)
Thank you, it worked! What should I replace $SYSTEMD with, though?

Thanks again!
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456

User avatar
DougieLawson
Posts: 39562
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Toggling OpenGL Driver w/o raspi-config?

Wed Jan 24, 2018 9:23 am

Sorry I have no idea what you're asking.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
BorbingoBoy
Posts: 12
Joined: Sun Apr 09, 2017 6:24 am
Location: Croatia
Contact: Website

Re: Toggling OpenGL Driver w/o raspi-config?

Wed Jan 24, 2018 1:49 pm

DougieLawson wrote:
Wed Jan 24, 2018 9:23 am
Sorry I have no idea what you're asking.
I'm sorry if I wasn't clear. I'm trying to find what I should replace $SYSTEMD with here (also code from raspi-config):

Code: Select all

# Boot to CLI
        if [ $SYSTEMD -eq 1 ]; then
          systemctl set-default multi-user.target
          ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
        else
          [ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
          sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
        fi
        ;;
It doesn't appear to work if the string isn't defined.
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456

User avatar
DougieLawson
Posts: 39562
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Toggling OpenGL Driver w/o raspi-config?

Thu Jan 25, 2018 7:43 am

BorbingoBoy wrote:
Wed Jan 24, 2018 1:49 pm

Code: Select all

# Boot to CLI
        if [ $SYSTEMD -eq 1 ]; then
          systemctl set-default multi-user.target
          ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
        else
          [ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
          sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
        fi
        ;;
Change that to

Code: Select all

# Boot to CLI
        
          systemctl set-default multi-user.target
          ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
        
 
 
        
        
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
BorbingoBoy
Posts: 12
Joined: Sun Apr 09, 2017 6:24 am
Location: Croatia
Contact: Website

Re: Toggling OpenGL Driver w/o raspi-config?

Thu Jan 25, 2018 4:23 pm

Yaay, I finally made it! Thank you, DougieLawson, for making it happen! :)

How to use: Copy the code below and paste it in a new empty file with the name of your choice (for example, 'gl'), the sh extension isn't necessary. Open terminal and enter sudo cp [file name] /usr/bin/. Finally, enter sudo chmod -rwxr-xr-x /usr/bin/[file name]. I made it option-based, the menus should be self-explanatory. You are done!

To run it, just enter sudo [file name]. That's it!

Code: Select all

#!/bin/bash

if [ $(id -u) -ne 0 ]; then
  printf "Reminder: use sudo!\n"
  exit 1
fi

echo GL toggler for Raspbian.
echo Code is mainly copied from raspi-config. BorbingoBoy 2018
echo Special thanks to DougieLawson


# Start of functions

# Enable GL driver
do_G1() {
        if ! grep -q -E "^dtoverlay=vc4-kms-v3d" /boot/config.txt; then
          ASK_TO_REBOOT=1
        fi
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
        sed /boot/config.txt -i -e "s/^#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/"
        if ! grep -q -E "^dtoverlay=vc4-kms-v3d" /boot/config.txt; then
          printf "dtoverlay=vc4-kms-v3d\n" >> /boot/config.txt
        fi
        STATUS="The full KMS GL driver is enabled."
        }

# Disable GL driver
do_G3() {
        if grep -q -E "^dtoverlay=vc4-f?kms-v3d" /boot/config.txt; then
          ASK_TO_REBOOT=1
        fi
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/"
        sed /boot/config.txt -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/"
        STATUS="The GL driver is disabled."
        }

# Boot to CLI
do_CLI() {
         systemctl set-default multi-user.target
         ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
         }

# Boot to desktop
do_DSKTP() {
           systemctl set-default graphical.target
           ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
           }

# End of functions


# Dialog enable/disable

echo What would you like to do?
 
PS3='Choice: '
options=("Enable GL" "Disable GL" "Cancel and Reboot" "Cancel")
select opt in "${options[@]}"
do
    case $opt in
        "Enable GL")
            do_G1
            break
            ;;
        "Disable GL")
            do_G3
            break
            ;;
        "Cancel and Reboot")
            reboot
            break
            ;;
        "Cancel")
            break
            ;;
        *) echo invalid option;;
    esac
done


# Dialog for changing boot mode

echo Where would you like to boot next?

PS3='Choice: '
options=("To Desktop" "To CLI" "Cancel and Reboot" "Cancel")
select opt in "${options[@]}"
do
    case $opt in
        "To Desktop")
            do_DSKTP
            break
            ;;
        "To CLI")
            do_CLI
            break
            ;;
        "Cancel and Reboot")
            reboot
            break
            ;;
        "Cancel")
            break
            ;;
        *) echo invalid option;;
    esac
done


# Dialog for confirming final reboot

echo Reboot?

PS3='Choice: '
options=("Yes" "No")
select opt in "${options[@]}"
do
    case $opt in
        "Yes")
            reboot
            break
            ;;
        "No")
            break
            ;;
        *) echo invalid option;;
    esac
done
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456

Return to “Raspberry Pi OS”