dglt1 / optimus-switch

*installer finished* installs nvidia prime and makes switching to intel only and back again easy as one command. intel mode fully disables the nvidia gpu to extend battery life.
71 stars 9 forks source link

LightDM fails in Intel mode #12

Closed samsapti closed 4 years ago

samsapti commented 4 years ago

I had an issue with LightDM failing in Intel mode, whenever I would lock the screen or logout (basically everytime I needed to access LightDM for the second time after reboot), so I began to troubleshoot, and here's what I found:

After LightDM failing after logout, I was able to switch to another TTY. From there I tried to run sudo lightdm and from there I got the error in this photo. I took a look at /usr/local/bin/optimus.sh. It turned out, that on line 12 and 27, the directory /sys/bus/pci/devices/0000:01:00.0 doesn't exist, since the dGPU is allready powered down, so LightDM stalls and the system requires a reboot. I applied a simple fix, and everything works perfectly now.

Here's my fix: Before: /etc/switch/intel/no-optimus.sh

#!/bin/sh

#this script is run as a display setup script
#that replaces the one used by nvidia/prime.
##
#this powers-down/disables the nvidia dGPU and
#removes it from /sys/bus/pce/devices
#for the current boot. this is reset after reboot.
# PLEASE READ BELOW TO ENABLE THIS

xrandr --auto
echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control'  #adjust busid if needed

#############
##make sure the line below is the correct acpi_call to disable your nvidia gpu. 
#to find out what call disables your nvidia gpu,
#run this (not while using nvidia gpu, this is why i left it commented out.
#
#` sudo /usr/share/acpi_call/examples/turn_off_gpu.sh ` 
#
#and see which acpi_call is returned as "works!" and then uncomment and edit this file to match.
#same goes for the the BusID of nvidia card, 
#default is set to 0000:01:00.0 (syntax is important) 
#if your nvidia gpu has a 1:0:0 busID, just uncomment the line, no change needed.

echo '\_SB.PCI0.GFX0._DSM' > /proc/acpi/call
echo -n 1 > '/sys/bus/pci/devices/0000:01:00.0/remove'

After: /etc/switch/intel/no-optimus.sh

#!/bin/sh

#this script is run as a display setup script
#that replaces the one used by nvidia/prime.
##
#this powers-down/disables the nvidia dGPU and
#removes it from /sys/bus/pce/devices
#for the current boot. this is reset after reboot.
# PLEASE READ BELOW TO ENABLE THIS

xrandr --auto

#This ensures that LightDM doesn't fail after locking the screen or logging out, because since the system isn't rebooting, the dGPU is already turned off, so it's already removed from /sys/bus/pci/devices.
if [ -d "/sys/bus/pci/devices/0000:01:00.0" ]
then

    echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control'  #adjust busid if needed

fi

#############
##make sure the line below is the correct acpi_call to disable your nvidia gpu. 
#to find out what call disables your nvidia gpu,
#run this (not while using nvidia gpu, this is why i left it commented out.
#
#` sudo /usr/share/acpi_call/examples/turn_off_gpu.sh ` 
#
#and see which acpi_call is returned as "works!" and then uncomment and edit this file to match.
#same goes for the the BusID of nvidia card, 
#default is set to 0000:01:00.0 (syntax is important) 
#if your nvidia gpu has a 1:0:0 busID, just uncomment the line, no change needed.

echo '\_SB.PCI0.GFX0._DSM' > /proc/acpi/call

#Same as previous if statement.
if [ -d "/sys/bus/pci/devices/0000:01:00.0" ]
then

    echo -n 1 > '/sys/bus/pci/devices/0000:01:00.0/remove'

fi

Edit: I also created a pull request.

dglt1 commented 4 years ago

i'm surprised i didnt come across this already myself but it definitely makes sense. i'll test it out in the next day or two and add it in, thanks for contributing. :+1:

dglt1 commented 4 years ago

thanks again, i merged your modified no-optimus.sh