T400实现双显卡切换

声卡/显卡/打印机/USB设备等硬件问题(网卡问题请发上面的网卡板块)
回复
squall724
帖子: 126
注册时间: 2007-06-13 9:36
送出感谢: 0
接收感谢: 5 次

T400实现双显卡切换

#1

帖子 squall724 » 2011-03-13 23:09

原贴(需和谐上网):http://asusm51ta-with-linux.blogspot.com/
系统环境:ubuntu10.04 + happyaron的2.6.38-5内核

1、检查系统是否支持双卡切换
进bios打开双卡切换,启动后输入下面命令
su
cat /sys/kernel/debug/vgaswitcheroo/switch
如果有以下输出
0:IGD: :Off:0000:00:02.0
1:DIS:+:Pwr:0000:01:00.0
恭喜你,可以实现双卡切换

2、每次重启都要重新输入,可以加入rc.local自动执行
chown "你的登录用户名" /sys/kernel/debug/vgaswitcheroo/switch
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

3、下载脚本所用的图片资源
wget -P /home/"$USER"/.local/share/icons/ http://lh4.ggpht.com/_Dw3SC8gD9Jk/S-MGV ... e_down.png
wget -P /home/"$USER"/.local/share/icons/ http://lh5.ggpht.com/_Dw3SC8gD9Jk/S-MGV ... are_up.png
wget -P /home/"$USER"/.local/share/icons/ http://lh4.ggpht.com/_Dw3SC8gD9Jk/TNbQX ... rdware.png
wget -P /home/"$USER"/.local/share/icons/ http://lh5.ggpht.com/_Dw3SC8gD9Jk/S41Dj ... utdown.png

4、保存下面的脚本到switch-between-cards文件

代码: 全选

#!/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
5、chmod +x switch-between-cards

6、sudo apt-get install gxmessage

7、执行switch-between-cards脚本,会弹出对话框先择显卡(有时会卡住,强行重启X就ok了)

缺点:需要重启桌面
jtshs256
论坛版主
帖子: 22322
注册时间: 2010-07-19 21:41
系统: OS X
送出感谢: 2 次
接收感谢: 27 次

Re: T400实现双显卡切换

#2

帖子 jtshs256 » 2011-03-13 23:41

单卡路过……
NO DO NO DIE
http://a/%%30%30
回复

回到 “常用硬件支持”