Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 24/04/2014, à 15:57

Nytrilik

[Tuto] Asus N56VZ Ubuntu gnome 14.04 : nvidia-prime+gdm+bbswitch

Hello,

I finally found a solution about black or white screen (depends of computer's mood) when you switch from power saving mode to performance mode (and reverse) on Optimus laptop + gdm.

Config :
Asus N56VZ
Ubuntu 14.04 Gnome amd64
kernel > 3.13.0-45-generic
Nvidia GT 650M  > Drivers nvidia-346
nvidia-prime > 0.6.2
bbswitch-dkms > 0.7-2ubuntu1
gdm > 3.10.0.1-0ubuntu4~trusty2

This tutorial will help you to fix the use of gdm with nvidia-prime and bbswitch by making an easy script for automatically switching from a card to an other.

--Dont reboot you're computer until the end of the procedure--

Start open terminal and delete nvidia previous version

sudo apt-get purge nvidia*
sudo apt-get autoremove

Install nvidia and intel free drivers (I didn't try but nvidia-current drivers probably work too).

sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
sudo apt-get install xserver-xorg-video-intel nvidia-331 ppa-purge

Then go in x11 folder : '/etc/x11'. Drivers installation change 'xorg.conf' name to 'xorg.conf.mmddyyyy' (mmddyyyy = date of nvidia driver installation). So take this file, make a copy (you can keep it, there's no incidence on procedure) and rename the new created file in 'xorg.conf-nvidia'. Open it (you have to make these changes in root mode $ sudo gedit). And replace the lines :

Section "ServerLayout"
  Identifier "layout"
  Screen 0 "nvidia"
  Inactive "intel"
EndSection

Section "Device"
  Identifier "intel"
  Driver "modesetting"
  BusID "PCI:0:2:0"
EndSection

Section "Screen"
  Identifier "intel"
  Device "intel"
EndSection

Section "Device"
  Identifier "nvidia"
  Driver "nvidia"
  BusID "PCI:1:0:0"
EndSection

Section "Screen"
  Identifier "nvidia"
  Device "nvidia"
  Option "UseDisplayDevice" "None"
EndSection

Section "Monitor"
    Identifier "VGA-0"
    Option "Ignore" "True"
EndSection

Please check that you have the corrects BusID for both cards.

lspci -vnn | grep '\''[030[02]\]'

The BusID is on the left.

Ok, now we're gonna make a executable script for switching from a config to an other, just create an empty file and paste the following commands into it. I named it 'optimus'. Don't forget to change its properties > “automatically execute as a program” (chmod +x '/folder/optimus').

#!/bin/bash

if [ $# = 0 ]; then
	echo "Use the one of following commands:"
	echo
	echo "1) sudo nohup $0 nvidia"
	echo "2) sudo nohup $0 intel"
	echo
	
	read command
	
	if [ "$command" = "1" ]; then
		sudo nohup "$0" nvidia
	fi
	
	if [ "$command" = "2" ]; then
		sudo nohup "$0" intel
	fi
	
	exit
fi


if [ `whoami` != "root" ]; then 
	echo "You must run it as root";
	exit
fi


if [ "$1" = "nvidia" ]; then
	NVIDIA_MODULE="`ls /usr/lib | grep -o nvidia\-[1-9][1-9][1-9]\-updates | head -n1`"
	if [ -z "$NVIDIA_MODULE" ]; then
		NVIDIA_MODULE="`ls /usr/lib | grep -o nvidia\-[1-9][1-9][1-9] | head -n1`"
	fi
	if [ -z "$NVIDIA_MODULE" ]; then
		echo "Error! Cannot find nvidia module name. You should modify this script to make it work."
		exit
	fi

	gnome-session-quit
	service gdm stop

	tee /proc/acpi/bbswitch <<<ON
	prime-select nvidia
	cp '/etc/X11/xorg.conf-nvidia' '/etc/X11/xorg.conf'
	sleep 2
	modprobe $NVIDIA_MODULE
	xrandr --setprovideroutputsource modesetting NVIDIA-0
	xrandr --auto
	sleep 2
	service gdm start
	service gdm restart
fi


if [ "$1" = "intel" ]; then
	gnome-session-quit
	service gdm stop

	rm '/etc/X11/xorg.conf'
	prime-select intel
	sleep 2
	rmmod nvidia
	sleep 2
	tee /proc/acpi/bbswitch <<<OFF

	service gdm start
	service gdm restart
fi

Then move it to '/usr/bin' folder (as root : sudo nautilus).

Next, create a new empty file, I named it 'xorg-delete' and paste the few lines below :

#!/bin/bash 
### BEGIN INIT INFO 
# Provides:          xorg-delete 
# Required-Start:    $remote_fs $syslog 
# Required-Stop:     $remote_fs $syslog 
# Default-Start:      
# Default-Stop:      0 1 6 
# X-Interactive:     true 
# Short-Description: remove xorg.conf 
# Description:       remove file '/etc/X11/xorg.conf'
#                    placed in /etc/init.d. 
### END INIT INFO 

prime-select intel
sleep 2
rm '/etc/X11/xorg.conf'
exit 0

Make it automatically executable (chmod +x '/folder/xorg-delete') and place it in 'etc/init.d'. I know it sounds weird to create a script just for remove a simple config file (prime-select is reset to intel mode at every boot session. So the line is useless but I keep it just in case) but if you reboot or shutdown you're computer in nvidia mode without remove 'xorg.conf', the intel card can't be properly used at start and you gonna get a black screen.

Enter this command in a terminal :

sudo update-rc.d xorg-delete stop 99 0 1 6 .

We finally finished with gdm and nvidia. To call the optimus script, enter 'optimus' in a terminal and follow instructions.
BUT don't do it now, we need to fix bbswitch before ! The following steps will help you to only launch intel card at start. Nvidia card will remain shutdown by default until you decide to activate it with the optimus script.

Open (root mode) 'etc/modules' and paste this line :

bbswitch load_state=0

You should have something like this :

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

lp
rtc
bbswitch load_state=0

Open gnome startup applications list :

gnome-session-properties

Remove : "Nvidia-x-server-settings" (if you installed it)

Ok, last step... Open (root) '/etc/rc.local' and paste just before the line "exit 0", the command

rmmod nvidia

And we're done !!

Reboot you're computer and be sure the nvidia card is 'OFF' at start and when you switch on the intel profile, then 'ON' on nvidia profile. Use this command.

cat /procc/acpi/bbswitch

NB : if you get a black screen at start after following this tutorial, don't panic, open a console tty (ctrl+f1) and call the 'optimus' script in intel mode. Then go back on this tutorial and check every steps. (I often bring some updates so keep an eye on it).

Hope, this tutorial will help many of you, stuck with nvidia-prime + gdm + bbswitch on optimus laptop. I'm a beginner on ubuntu and I couldn't be able to find those solutions without the help of Deve, Tim and ubuntu-fr's tutorials. Thanks to them.

Ciao

Dernière modification par Nytrilik (Le 05/05/2015, à 09:09)

Hors ligne

#2 Le 24/04/2014, à 16:19

Korak

Re : [Tuto] Asus N56VZ Ubuntu gnome 14.04 : nvidia-prime+gdm+bbswitch

Bonjour,

Je ne sais pas trop comment t'aider mais il faudrait un truc du genre:

Lancer ton fichier Optimus avec un paramètre.

Le paramètre sera (par exemple) on ou off.

Et suivant ce paramètre, tu actives une carte graphique ou l'autre.

Il faut donc que ton script récupère le paramètre donné en entrée de commande.


OS: Ubuntu 22.04 64 bits + Windows 11 64 bits en dualboot (BIOS UEFI, Secure Boot activé et table de partitions GPT)
PC portable HP 17-CP0308NF   Processeur: AMD Ryzen 7 5700U avec carte graphique AMD Lucienne intégrée au processeur.   Mémoire vive: 16 Go RAM
Quand vous ne trouvez pas la solution à un problème, cherchez des pistes menant à la solution !

Hors ligne