參考:https://forums.gentoo.org/viewtopic-p-8312508.html#8312508
我的機(jī)器是rog的gx531银酬,國(guó)內(nèi)叫冰刃3洛姑,無(wú)法使用bumblebee和bbswitch蒜鸡,對(duì)于我來(lái)說(shuō)prime方案是唯一的選擇蜓洪。
1.安裝環(huán)境設(shè)定
安裝nvidia-drivers時(shí)一定要使用kms
和libglvnd
use flag纤勒,以下是我使用的use flag:
~|? equery u nvidia-drivers
[ Legend : U - final flag setting for installation]
[ : I - package is installed with flag ]
[ Colors : set, unset ]
* Found these USE flags for x11-drivers/nvidia-drivers-440.82-r3:
U I
+ + X : Install the X.org driver, OpenGL libraries, XvMC libraries, and VDPAU libraries
+ + abi_x86_32 : 32-bit (x86) libraries
- - compat : Install non-GLVND libGL for backwards compatibility
+ + driver : Install the kernel driver module
+ + gtk3 : Install nvidia-settings with support for GTK+ 3
+ + kms : Enable support for kernel mode setting (KMS)
+ + libglvnd : Use media-libs/libglvnd for dispatch
+ + multilib : On 64bit systems, if you want to be able to compile 32bit and 64bit binaries
- - static-libs : Build static versions of dynamic libraries as well
+ + tools : Install additional tools such as nvidia-settings
- - uvm : Install the Unified Memory kernel module (nvidia-uvm) for sharing memory between CPU and GPU in CUDA programs
- - wayland : Enable dev-libs/wayland backend
我的機(jī)器使用intel 630顯卡和2070 max-q雙顯卡,所以我的VIDEO_CARDS
設(shè)置為intel i965 nvidia nouveau i915
隆檀,也就是在/etc/portage/make.conf
中添加:
VIDEO_CARDS="intel i965 nvidia nouveau i915"
添加nouveau摇天,是為了如果搞砸了還可以使用nvidia的開(kāi)源驅(qū)動(dòng),i965應(yīng)該是支持我的intel 630顯卡恐仑,i915是老款的intel顯卡驅(qū)動(dòng)泉坐,為了謹(jǐn)慎起見(jiàn),我把這個(gè)也加上菊霜。
然后重新編譯@world:
~|? emerge -avN @world @system
2.正常來(lái)說(shuō)nvidia驅(qū)動(dòng)應(yīng)該已經(jīng)裝好了坚冀,如果沒(méi)有,按照gentoo wiki鉴逞,安裝nvidia驅(qū)動(dòng):
emerge -av nvidia-drivers
3.如果你曾經(jīng)安裝過(guò)bumblebee/primusrun/virtualgl等方案记某,必須把所有的這些軟件以及配置文件刪除,刪除X11配置文件构捡,包括/etc/X11/xorg.conf
和/etc/X11/xorg.conf.d/*
里的所有包含"ServerLayout", "Device" 或者 "Screen"的文件或者內(nèi)容液南。
4.根據(jù)你使用的nvidia驅(qū)動(dòng)版本,參考nvidia的文檔設(shè)定xorg.conf文件
比如:https://download.nvidia.com/XFree86/Linux-x86_64/440.82/README/primerenderoffload.html勾徽。
確定nvidia顯卡的BusID
~|? lspci | grep -i vga
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 630 (Mobile)
01:00.0 VGA compatible controller: NVIDIA Corporation TU106M [GeForce RTX 2070 Mobile] (rev a1)
上面我的nvidia 2070顯卡信息開(kāi)頭的數(shù)字就是BusID滑凉,我的是01:00.0
,等一下寫(xiě)入xorg.conf文件中時(shí)就是BusID "PCI:1:0:0"
。
如果配置使用nvidia顯卡:
完整的xorg.conf文件如下(配置使用intel顯卡的xorg內(nèi)容見(jiàn)文章末端)
Section "ServerLayout"
Identifier "layout"
Screen 0 "nvidia"
Inactive "intel"
EndSection
Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:1:0:0"
EndSection
Section "Screen"
Identifier "nvidia"
Device "nvidia"
Option "AllowEmptyInitialConfiguration"
Option "ForceCompositionPipeline" "true"
Option "ForceFullCompositionPipeline" "true"
Option "TripleBuffer" "on"
EndSection
Section "Device"
Identifier "intel"
Driver "modesetting"
Option "AccelMethod" "glamor"
Option "DRI" "3"
Option "TearFree" "true"
EndSection
Section "Screen"
Identifier "intel"
Device "intel"
EndSection
5.修改grub啟動(dòng)參數(shù)
在/etc/default/grub
中找到GRUB_CMDLINE_LINUX=
畅姊,在后面加上nvidia-drm.modeset=1
咒钟,我的是這樣的:
# Append parameters to the linux kernel command line
GRUB_CMDLINE_LINUX="nvidia-drm.modeset=1"
然后重新生成grub配置文件,在我的機(jī)器上這樣操作:
~|? grub-mkconfig -o /boot/grub/grub.cfg
6.請(qǐng)檢查是否安裝了xrandr
若未,如果沒(méi)有請(qǐng)安裝朱嘴。
7.顯示管理配置
如果你沒(méi)有使用gdm、sddm粗合、lightdm等顯示管理器萍嬉,則在~/.xinitrc
中添加
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
比如xfce4桌面用戶(hù),添加后像這樣:
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
exec startxfce4
如果你使用gdm隙疚,創(chuàng)建以下兩個(gè).desktop文件:
/usr/share/gdm/greeter/autostart/optimus.desktop
/etc/xdg/autostart/optimus.desktop
[Desktop Entry]
Type=Application
Name=Optimus
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
NoDisplay=true
X-GNOME-Autostart-Phase=DisplayServer
其它dm請(qǐng)參考:https://wiki.archlinux.org/index.php/NVIDIA_Optimus_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)自行設(shè)定壤追。
8.檢查nvidia KMS是否正確運(yùn)行
重啟后,運(yùn)行以下指令檢查nvidia KMS是否正確運(yùn)行:
~|? cat /sys/module/nvidia_drm/parameters/modeset
如果顯示“Y”供屉,說(shuō)明OK了行冰。
9.startx
或者啟動(dòng)DM
成功了,別忘了給我點(diǎn)個(gè)贊:)
10.切換intel顯卡以省電贯卦。
很多筆記本资柔、游戲本的intel顯卡不支持多臺(tái)顯示器,據(jù)說(shuō)游戲本的主顯示器一般接到intel顯卡撵割,外接顯示器口連接的是nvidia卡贿堰。
如果你使用多臺(tái)顯示器,或者希望使用高性能圖形界面啡彬,那需要使用nvidia顯卡羹与,如果使用單顯示器,并且想延長(zhǎng)筆記本電池的待機(jī)時(shí)間庶灿,則需要切換到intel顯卡纵搁。
把/etc/X11/xorg.conf
的內(nèi)容修改為:
(同樣要注意iGPU那里,BusID要填寫(xiě)正確的intel顯卡的BusID往踢,nvidia那里要填隙正確的N卡的BusID)
Section "ServerLayout"
Identifier "layout"
Screen 0 "iGPU"
Option "AllowNVIDIAGPUScreens"
EndSection
Section "Device"
Identifier "iGPU"
Driver "modesetting"
BusID "PCI:0:2:0"
EndSection
Section "Screen"
Identifier "iGPU"
Device "iGPU"
EndSection
Section "Device"
Identifier "nvidia"
Driver "nvidia"
BusID "PCI:1:0:0"
EndSection
注銷(xiāo)或者重啟后腾誉,就改成intel顯卡了。
11.使用intel顯卡時(shí)峻呕,使用nvidia卡加速特定的程序:
運(yùn)行特定程序利职,在命令行前加參數(shù)"__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia"
比如
~|? __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia google-chrome-stable
~|? __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep "OpenGL renderer"
OpenGL renderer string: GeForce RTX 2070 with Max-Q Design/PCIe/SSE2
我索性在bash的配置文件中加入:
alias nv-run="__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia"
以后只要運(yùn)行以下命令,即可用nvidia卡模式啟動(dòng)google chrome瀏覽器
~|? nv-run google-chrome-stable
12.可以用bbswitch關(guān)閉nvidia顯卡的電源瘦癌,達(dá)到更加省電的目的
(我沒(méi)有測(cè)試成功猪贪,我的筆記本一使用bbswitch就立即死機(jī)):
~|? rmmod nvidia_drm
~|? rmmod nvidia_modeset
~|? rmmod nvidia
~|? modprobe bbswitch
~|? echo "OFF" >> /proc/acpi/bbswitch
如果cat /proc/acpi/bbswitch
顯示:0000:01:00.0 OFF
(前邊的數(shù)字是nvidia顯卡的BusID,不同機(jī)器可能會(huì)有不同)讯私,說(shuō)明成功關(guān)閉了nvidia顯卡的電源热押。
13.后記:
(1)nvidia-settings無(wú)法管理主顯示器西傀,需要用xrandr
管理,
確定你的主顯示器ID桶癣,我的機(jī)器如下拥褂,eDP-1-1是我的主顯示器:
~|? xrandr
Screen 0: minimum 8 x 8, current 2560 x 1440, maximum 32767 x 32767
HDMI-0 disconnected (normal left inverted right x axis y axis)
DP-0 connected primary 2560x1440+0+0 (normal left inverted right x axis y axis) 598mm x 336mm
2560x1440 59.95 + 144.00* 120.00 99.95 84.98 23.97
1024x768 60.00
800x600 60.32
640x480 59.94
DP-1 disconnected (normal left inverted right x axis y axis)
eDP-1-1 connected (normal left inverted right x axis y axis)
1920x1080 240.00 + 60.00
設(shè)置分辨率和刷新率:
~|? xrandr --output eDP-1-1 --mode 1920x1080 --rate 240.00
lxrandr
是lxqt桌面提供的gui設(shè)置工具,也可以使用牙寞。gnome和kde在設(shè)置里可以設(shè)置分辨率和刷新率肿仑。
(2)使用nvidia顯卡,外接顯示器畫(huà)面撕裂問(wèn)題碎税,通過(guò)在xorg.conf中添加如下代碼解決(可以參見(jiàn)我上面貼出來(lái)的完整的xorg.conf文件內(nèi)容:
Option "ForceCompositionPipeline" "true"
Option "ForceFullCompositionPipeline" "true"
Option "TripleBuffer" "on"