Update 18/03/2014: I'm sad to announce I no longer have this computer nor any PC with hybrid graphics... My ASUSM51Ta passed away, so I no longer could compile kernels and test things on hybrid graphics. As far as I know this technology is already supported more easily Hybrid Graphics Wiki.

First of all, this HowTo is intended to people like me with almost no knowledge about compiling and patching kernels. Also to people that may want to share their experience using the vga_switcheroo (now included in kernel 2.6.35 onwards) from David Airlie with their own machines with switchable graphics.


If you want to test this HowTo on your computer, please post your experience at the mailing list of https://launchpad.net/%7Ehybrid-graphics-linux

For more info about hybrid graphics consult:
http://linux-hybrid-graphics.blogspot.com/


Notes:





GNU/Linux used: Fedora / Ubuntu
Machine: ASUS M51Ta
Graphic card configuration:
- Integrated: 01:05.0 VGA compatible controller: ATI Technologies Inc RS780M/RS780MN [Radeon HD 3200 Graphics]
- Discrete: 02:00.0 VGA compatible controller: ATI Technologies Inc Mobility Radeon HD 3650



[10/11/2010] Fedora 14 / Ubuntu 10.10 + vga_switcheroo + switch scripts

(0) Install Fedora 14 / Ubuntu 10.10, install needed packages & download icons

(0.1) Burn a CD or make a bootable USB with your fabourite distribution and install it on your laptop.


Fedora 14





Ubuntu 10.10




(0.2) Install the following packages from the command line and download icons:


$ sudo yum update
$ sudo yum install wget gxmessage libnotify-bin
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYqzYlP-BgyTv19LpPlAhqZfODsNZB-eyiNOf6e__FS8AOudy-wIEhyLXMLVnSndIkv9rrii3Sy58mJnx8O3IlrdrY5nr4Rf7CHhbqlaRsH5vLIkr1xB3Kg_TTkWmBHogBu-HOEcGX-8w/s800/hardware_down.png
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgdTtB-ginD408jKwWn5eKv7_Yf1MJ0I2H4yVP-Ot8z633v34txixBOxVh4AoetVM5MJBi80bBMH3D9zdIHdBEtLsIbaLHDHA2RG2YbVcHj_I_VJslyKq9g448x18PjX_JDxuwk4GGvpQ/s800/hardware_up.png
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMiEkJp62CAGJtyiocxgdnnK4_doiE4BvQ15Rpuzo9k3IWw4HHz8cxGmKpmncXAXE0r0w8Nyo4cKmbUbijmwl2rzxgA6j_N061o9kvkv9PKtsc3ZcaZWWTrgxAXfNCj934IBCYdDapqHc/s800/hardware.png
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGcHDeXc2UtTpphrPGhwCabFs-k9Rg_nzwgUO2G-LSOSrvd-oYDK5hNHyDS7F9_yj-7VAEZeFRPhe4TlfmMV68FODmDyEelcLTLG_PUOPgA70p-UTdFDTnCNa3LeHKS-e-5Kox4O9VG3E/s800/switch_before_shutdown.png



$ sudo apt-get update
$ sudo apt-get install wget gxmessage libnotify-bin
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYqzYlP-BgyTv19LpPlAhqZfODsNZB-eyiNOf6e__FS8AOudy-wIEhyLXMLVnSndIkv9rrii3Sy58mJnx8O3IlrdrY5nr4Rf7CHhbqlaRsH5vLIkr1xB3Kg_TTkWmBHogBu-HOEcGX-8w/s800/hardware_down.png
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgdTtB-ginD408jKwWn5eKv7_Yf1MJ0I2H4yVP-Ot8z633v34txixBOxVh4AoetVM5MJBi80bBMH3D9zdIHdBEtLsIbaLHDHA2RG2YbVcHj_I_VJslyKq9g448x18PjX_JDxuwk4GGvpQ/s800/hardware_up.png
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMiEkJp62CAGJtyiocxgdnnK4_doiE4BvQ15Rpuzo9k3IWw4HHz8cxGmKpmncXAXE0r0w8Nyo4cKmbUbijmwl2rzxgA6j_N061o9kvkv9PKtsc3ZcaZWWTrgxAXfNCj934IBCYdDapqHc/s800/hardware.png
$ wget -P /home/"$USER"/.local/share/icons/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGcHDeXc2UtTpphrPGhwCabFs-k9Rg_nzwgUO2G-LSOSrvd-oYDK5hNHyDS7F9_yj-7VAEZeFRPhe4TlfmMV68FODmDyEelcLTLG_PUOPgA70p-UTdFDTnCNa3LeHKS-e-5Kox4O9VG3E/s800/switch_before_shutdown.png


(1) Mount "none" partition on fstab (just on Fedora, Ubuntu does it by default)


$ sudo gedit /etc/fstab
And add the following line:
none                    /sys/kernel/debug debugfs defaults 0 0


(2) Change switch file permissions every time computer initiates


$ sudo gedit /etc/rc.d/rc.local
And add the following lines:

chown "username" /sys/kernel/debug/vgaswitcheroo/switch # change "username" with your user name
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch


$ sudo gedit /etc/rc.local
And add the following lines:

chown "username" /sys/kernel/debug/vgaswitcheroo/switch # change "username" with your user name
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch


(3) Reboot & copy and run script to switch between graphic cards

switch_between_cards.sh

#!/bin/bash
# "switch_between_cards.sh" script by RM, with useful changes from LoLL
# version 20101107

pci_integrated=$(lspci | grep VGA | sed -n '1p' | cut -f 1 -d " ")
pci_discrete=$(lspci | grep VGA | sed -n '2p' | cut -f 1 -d " ")

integrated=$(cat /sys/kernel/debug/vgaswitcheroo/switch | grep $pci_integrated | grep -o -P ':.:...:')
discrete=$(cat /sys/kernel/debug/vgaswitcheroo/switch | grep $pci_discrete | grep -o -P ':.:...:')

name_integrated=$(lspci | grep VGA | sed -n '1p' | sed -e "s/.* VGA compatible controller[ :]*//g" | sed -e "s/ Corporation//g" | sed -e "s/ Technologies Inc//g" | sed -e 's/\[[0-9]*\]: //g' | sed -e 's/\[[0-9:a-z]*\]//g' | sed -e 's/(rev [a-z0-9]*)//g' | sed -e "s/ Integrated Graphics Controller//g")

name_discrete=$(lspci | grep VGA | sed -n '2p' | sed -e "s/.* VGA compatible controller[ :]*//g" | sed -e "s/ Corporation//g" | sed -e "s/ Technologies Inc//g" | sed -e 's/\[[0-9]*\]: //g' | sed -e 's/\[[0-9:a-z]*\]//g' | sed -e 's/(rev [a-z0-9]*)//g' | sed -e "s/ Integrated Graphics Controller//g")

if [ "$integrated" = ":+:Pwr:" ]
then
integrated_condition="(*) - Power ON"
elif [ "$integrated" = ": :Pwr:" ]
then
integrated_condition="( ) - Power ON"
elif [ "$integrated" = ": :Off:" ]
then
integrated_condition="( ) - Power OFF"
fi

if [ "$discrete" = ":+:Pwr:" ]
then
discrete_condition="(*) - Power ON"
elif [ "$discrete" = ": :Pwr:" ]
then
discrete_condition="( ) - Power ON"
elif [ "$discrete" = ": :Off:" ]
then
discrete_condition="( ) - Power OFF"
fi

gxmessage -center \
-buttons "_Cancel":1,"switch to _Integrated":101,"switch to _Discrete":102 \
-wrap \
-title "Choose Hybrid Graphic Card" \
"Choose Hybrid Graphic Card
=================
Integrated: $integrated_condition : $name_integrated
Discrete: $discrete_condition : $name_discrete"


whichCard=$?

case "$whichCard" in

1)
echo "Exit"
;;
101)
if [ "$integrated" == ":+:Pwr:" ] && [ "$discrete" == ": :Pwr:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_down.png" "switching to $name_integrated"
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
elif [ "$integrated" == ": :Pwr:" ] && [ "$discrete" == ":+:Pwr:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_down.png" "switching to $name_integrated"
echo DIGD > /sys/kernel/debug/vgaswitcheroo/switch
if [ "$DESKTOP_SESSION" = "openbox" ]
then
killall -u "$USER"
elif [ "$DESKTOP_SESSION" = "gnome" ]
then
gnome-session-save --logout
fi
elif [ "$integrated" == ": :Off:" ] && [ "$discrete" == ":+:Pwr:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_down.png" "switching to $name_integrated"
echo ON > /sys/kernel/debug/vgaswitcheroo/switch
echo DIGD > /sys/kernel/debug/vgaswitcheroo/switch
if [ "$DESKTOP_SESSION" = "openbox" ]
then
killall -u "$USER"
elif [ "$DESKTOP_SESSION" = "gnome" ]
then
gnome-session-save --logout
fi
elif [ "$integrated" == ":+:Pwr:" ] && [ "$discrete" == ": :Off:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_down.png" "already switched to $name_integrated"
fi
;;
102)
if [ "$integrated" == ":+:Pwr:" ] && [ "$discrete" == ": :Pwr:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_up.png" "switching to $name_discrete"
echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch
if [ "$DESKTOP_SESSION" = "openbox" ]
then
killall -u "$USER"
elif [ "$DESKTOP_SESSION" = "gnome" ]
then
gnome-session-save --logout
fi
elif [ "$integrated" == ": :Pwr:" ] && [ "$discrete" == ":+:Pwr:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_up.png" "switching to $name_discrete"
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
elif [ "$integrated" == ":+:Pwr:" ] && [ "$discrete" == ": :Off:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_up.png" "switching to $name_discrete"
echo ON > /sys/kernel/debug/vgaswitcheroo/switch
echo DDIS > /sys/kernel/debug/vgaswitcheroo/switch
if [ "$DESKTOP_SESSION" = "openbox" ]
then
killall -u "$USER"
elif [ "$DESKTOP_SESSION" = "gnome" ]
then
gnome-session-save --logout
fi
elif [ "$integrated" == ": :Off:" ] && [ "$discrete" == ":+:Pwr:" ]
then
notify-send -t 5000 --icon="/home/$USER/.local/share/icons/hardware_up.png" "already switched to $name_discrete"
fi
;;
esac


(4) OPTIONAL: Script to turn off laptop

This next script is used to turn off the computer. Because, in my case, if I turn off the computer without switching on both cards (specially when the integrated card is on and the discrete card is off), the fan runs at full speed when I turn it on again, stoping only after rebooting. Hence, to avoid this, this other launcher can be used to turn off the computer:

switch_before_shutdown.sh

#!/bin/bash

if [ "$DESKTOP_SESSION" = "openbox" ]
then
gxmessage "Are you sure you want to shut down your computer?" -center -title "Take action" -font "Sans bold 10" -default "Cancel" -buttons "_Cancel":1,"L_ock screen":101,"_Log out":102,"_Reboot":103,"_Shut down":104

case $? in

1)
echo "Exit";;
101)
xscreensaver-command -lock;;
102)
killall openbox;;
103)
echo ON > /sys/kernel/debug/vgaswitcheroo/switch;
gnome-terminal -e 'sudo shutdown -r now';;
104)
echo ON > /sys/kernel/debug/vgaswitcheroo/switch
gnome-terminal -e 'sudo shutdown -h now';;
esac

elif [ "$DESKTOP_SESSION" = "gnome" ]
then

gxmessage "Are you sure you want to shut down your computer?" -center -title "Take action" -font "Sans bold 10" -default "Cancel" -buttons "_Cancel":1,"L_ock screen":101,"_Log out":102,"_Reboot":103,"_Shut down":104

case $? in

1)
echo "Exit";;
101)
gnome-screensaver-command -l;;
102)
gnome-session-save --logout;;
103)
echo ON > /sys/kernel/debug/vgaswitcheroo/switch;
gnome-terminal -e 'sudo shutdown -r now';;
104)
echo ON > /sys/kernel/debug/vgaswitcheroo/switch
gnome-terminal -e 'sudo shutdown -h now';;
esac

fi


I tested this HowTo on my laptop with Fedora 14 (x64) and Ubuntu 10.10 (x32). Please write me if you find any errors or have any sugestion to modify and improve this HowTo.



Followers