一:環境
系統:ubuntu16.04
顯卡類型:Nvidia 940M
二:出現的問題:
屏幕黑屏,但顯卡驅動安裝成功
判斷是不是顯卡驅動安裝成功步驟:
1.進入登陸界面黑屏,盲輸入用戶名,密碼,盲進系統,(注意:有沒有進入系統,通過其他機器ssh到當前機器,用命令w查看,如果有”tty7“關鍵字出現,說明進入系統)
2.盲打開一個終端,在終端中輸入#glxinfo | grep rendering > log,其他機器ssh到當前機器,查看log文件,如何顯示“direct rendering: Yes“,則顯卡安裝成功,其他都是失敗,許重裝顯卡
三:聲明,首先我要說,有人和我的問題狀況一模一樣的話,再使用下面方法,如果自己遇到黑屏但驅動沒裝好,請忽視下面內容,對症下藥,希望大家明白。
四:解決方法
1.編輯文件(沒有就新建),/etc/lightdm/display_setup.sh
#!/bin/sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
2.執行命令:# chmod +x /etc/lightdm/display_setup.sh
3..編輯文件(沒有就新建),/etc/lightdm/lightdm.conf
[Seat:*]
display-setup-script=/etc/lightdm/display_setup.sh
五:腳本解決方法(上面步驟可直接通過下面腳本執行)
#!/bin/sh
if [ ! -f "/etc/lightdm/display_setup.sh" ]; then
sudo touch /etc/lightdm/display_setup.sh
sudo echo -e "#!/bin/sh\nxrandr --setprovideroutputsource modesetting NVIDIA-0\nxrandr --auto" >> /etc/lightdm/display_setup.sh
sudo chmod +x /etc/lightdm/display_setup.sh
elif cat /etc/lightdm/display_setup.sh|grep 'xrandr --setprovideroutputsource modesetting NVIDIA-0'>/dev/null && cat /etc/lightdm/display_setup.sh|grep 'xrandr --auto'>/dev/null
then
echo "File /etc/lightdm/display_setup.sh had the Content!"
else
sudo echo -e "#!/bin/sh\nxrandr --setprovideroutputsource modesetting NVIDIA-0\nxrandr --auto" >> /etc/lightdm/display_setup.sh
fi
if [ ! -f "/etc/lightdm/lightdm.conf" ]; then
sudo touch /etc/lightdm/lightdm.conf
sudo echo -e "[Seat:*]\ndisplay-setup-script=/etc/lightdm/display_setup.sh" >> /etc/lightdm/lightdm.conf
elif cat /etc/lightdm/lightdm.conf|grep '[Seat:*]'>/dev/null && cat /etc/lightdm/lightdm.conf|grep 'display-setup-script=/etc/lightdm/display_setup.sh'>/dev/null
then
echo "File /etc/lightdm/lightdm.conf had the Content"
else
sudo echo -e "[Seat:*]\ndisplay-setup-script=/etc/lightdm/display_setup.sh" >> /etc/lightdm/lightdm.conf
fi
echo "Finished,Restart Lightdm------------------------"
sudo /etc/init.d/lightdm restart