内核配置选项

内核参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 支持模块加载
[*] Enable loadable module support --->

# 支持MTTR
Processor type and features --->
[*] MTRR (Memory Type Range Register) support

# 支持VGA仲裁(Arbitration)
Device Drivers --->
PCI support --->
[*] VGA Arbitration

# 支持IPMI消息处理
Device Drivers --->
Character devices --->
[*] IPMI top-level message handler

# 对于AGP显卡,需要激活支持
Device Drivers --->
Graphics support --->
-*- /dev/agpgart (AGP Support) --->

# 注意对于x86和AMD64,内核 framebuffer 驱动和NVIDIA提供的二进制驱动冲突,所以需要从内核中移除支持
Device Drivers --->
Graphics support --->
Frame buffer Devices --->
<*> Support for frame buffer devices --->
< > nVidia Framebuffer Support
< > nVidia Riva support

# 确保nouveau驱动被禁止
Device Drivers --->
Graphics support --->
< > Nouveau (nVidia) cards

# 需要framebuffer驱动来渲染Linux console(TTY),这个功能nvidia驱动不提供,所以需要标记 VGA/VBE/EFI FB作为通用系统framebuffer
Bus options (PCI etc.) --->
[*] Mark VGA/VBE/EFI FB as generic system framebuffer
Device Drivers --->
Graphics support --->
Frame buffer Devices -->
<*> Support for frame buffer devices -->
< > Simple framebuffer support # 这项激活才能看到Device Drivers中的Firmware Drivers配置

# 一定要关闭simple framebuffer,因为 nvidia-driver 提供了模块会产生冲突
Device Drivers --->
Firmware Drivers --->
[ ] Mark VGA/VBE/EFI FB as generic system framebuffer
Graphics support --->
< > Simple framebuffer support

[!TIP]

通常在内核编译之后我们需要重新安装nvidia-driver 详情请见 here 如果你用的是X 那你可以执行emerge @module-rebuild

链接内核

在我们编译完成内核一定要检查好目前的内核是否已经被正确链接 否则安装过程可能就没有那么顺利了

1
2
3
4
5
6
wlmosv$ eselect kernel list 
Available kernel symlink targets:
[1] linux-6.7.9-zen
[2] linux-6.8.7-gentoo *
[3] linux-6.8.7-gentoo-dist
wlmosv$

可以看到我们已经选择了正确的内核来安装它,如果你没有选择好需要的内核安装那么你刚才编译的内核就没用到你的配置选项。正确的选择内核

1
2
3
4
5
6
7
8
wlmosv$ sudo eselect kernel set 2
wlmosv$ eselect kernel list
Available kernel symlink targets:
[1] linux-6.7.9-zen
[2] linux-6.8.7-gentoo *
[3] linux-6.8.7-gentoo-dist
wlmosv$

安装驱动

现在我们就可以安装经典的F*CK Nvidia了 前提是你已经在你的/etc/portage/make.conf 设置了VIDEO_CARDS="nvidia选项。like this:

1
VIDEO_CARDS="nvidia intel i965 iris"

我是双显卡设置intel i965 iris很正常。当然了 本文的目的不再动态切换只在单独使用nvidia驱动

开装!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
wlmosv$ sudo emerge -av x11-drivers/nvidia-drivers 

* IMPORTANT: config file '/etc/portage/package.use/virtual-libcrypt' needs updating.
* See the CONFIGURATION FILES and CONFIGURATION FILES UPDATE TOOLS
* sections of the emerge man page to learn how to update config files.

These are the packages that would be merged, in order:

Calculating dependencies... done!
Dependency resolution took 3.37 s (backtrack: 0/20).

[ebuild R #] x11-drivers/nvidia-drivers-550.76:0/550::gentoo USE="X modules persistenced powerd static-libs strip tools wayland -dist-kernel -kernel-open -modules-compress -modules-sign" ABI_X86="32 (64)" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

Would you like to merge these packages? [Yes/No]

如果你不介意 你可以打开这些use选项:

1
2
3
4
5
6
7
8
9
10
>=media-libs/libglvnd-1.7.0 abi_x86_32
>=x11-libs/libX11-1.8.9 abi_x86_32
>=x11-libs/libXext-1.3.6 abi_x86_32
>=sys-apps/dbus-1.15.8 abi_x86_32
>=x11-libs/libxcb-1.17.0 abi_x86_32
>=x11-libs/libXau-1.0.11 abi_x86_32
>=x11-libs/libXdmcp-1.1.5 abi_x86_32
>=x11-libs/libdrm-2.4.120 video_cards_radeon


具体它们的功能是啥子嘞?请看这里

  1. >=media-libs/libglvnd-1.7.0 abi_x86_32:要求安装的media-libs/libglvnd版本大于等于1.7.0,并且启用了abi_x86_32 USE flag。这表示需要支持32位应用程序的兼容性。
  2. >=x11-libs/libX11-1.8.9 abi_x86_32:要求安装的x11-libs/libX11版本大于等于1.8.9,并且启用了abi_x86_32 USE flag。这表示需要支持32位应用程序的兼容性。
  3. >=x11-libs/libXext-1.3.6 abi_x86_32:要求安装的x11-libs/libXext版本大于等于1.3.6,并且启用了abi_x86_32 USE flag。同样,这表示需要支持32位应用程序的兼容性。
  4. >=sys-apps/dbus-1.15.8 abi_x86_32:要求安装的sys-apps/dbus版本大于等于1.15.8,并且启用了abi_x86_32 USE flag。这表示需要支持32位应用程序的兼容性。
  5. >=x11-libs/libxcb-1.17.0 abi_x86_32:要求安装的x11-libs/libxcb版本大于等于1.17.0,并且启用了abi_x86_32 USE flag。这表示需要支持32位应用程序的兼容性。
  6. >=x11-libs/libXau-1.0.11 abi_x86_32:要求安装的x11-libs/libXau版本大于等于1.0.11,并且启用了abi_x86_32 USE flag。这表示需要支持32位应用程序的兼容性。
  7. >=x11-libs/libXdmcp-1.1.5 abi_x86_32:要求安装的x11-libs/libXdmcp版本大于等于1.1.5,并且启用了abi_x86_32 USE flag。这表示需要支持32位应用程序的兼容性。
  8. >=x11-libs/libdrm-2.4.120 video_cards_radeon:要求安装的x11-libs/libdrm版本大于等于2.4.120,并且启用了video_cards_radeon USE flag。这表示需要支持Radeon显卡的功能。

是的你没看错 如果你想渲染32位的某些好玩的东西 请打开它们。好了这下应该能继续开装了

[!NOTE]

我建议大家把用户添加到用户组中。gpasswd -a 用户名 video

配置sddm

安装Xrander

1
emerge --ask x11-apps/xrandr

xrandr 是一款命令行工具,可以让我们轻松地管理和控制显示器设置。在双显卡环境中,这一工具将发挥至关重要的作用。好吧不扯犊子了。重要的是我们需要他 就像西方不能失去耶路撒冷 –by me

sddm配置文件

具体请看这里 点窝点窝

我们安装完成驱动之后呢 首先需要进行配置的东西就是你的DM了。你是什么DM就设置什么DM 我是SDDM所以我的目录配置如下:

sddm.png

[!IMPORTANT]

这一步非常重要 如果你不设置就会黑屏

Xsetup.png

生成你的nvidia配置文件

1
sudo nvidia-xconfig --prime

他会根据你的显卡来配置 当然了根本不需要配置任何东西 只需要生成 如果生产的配置导致你不能开机 请检查你的DM启动时是否添加了参数 以下是我的xorg文件 仅供参考:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 550.76


Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0" 0 0
Inactive "InactiveDevice1"
Inactive "InactiveDevice1"
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
EndSection

Section "Files"
EndSection

Section "InputDevice"

# generated from data in "/etc/conf.d/gpm"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol"
Option "Device" "/dev/input/mice"
Option "Emulate3Buttons" "no"
Option "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"

# generated from default
Identifier "Keyboard0"
Driver "kbd"
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
Option "DPMS"
EndSection

Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:1:0:0"
EndSection

Section "Device"
Identifier "InactiveDevice1"
Driver "modesetting"
VendorName "Unknown"
EndSection

Section "Device"
Identifier "InactiveDevice1"
Driver "modesetting"
VendorName "Unknown"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
Option "AllowEmptyInitialConfiguration" "True"
SubSection "Display"
Depth 24
EndSubSection
EndSection

生成了配置文件 安装了驱动 现在你可以试试重启 起不动很正常 删除这个文件就可以。

看看效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
nvidia-smi 
Sat Apr 20 22:08:12 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.76 Driver Version: 550.76 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce GTX 1050 Off | 00000000:01:00.0 Off | N/A |
| N/A 44C P3 N/A / ERR! | 704MiB / 4096MiB | 1% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 547 G kate 1MiB |
| 0 N/A N/A 1035 G /usr/lib64/firefox/firefox 6MiB |
| 0 N/A N/A 1268 G ...bin/plasma-browser-integration-host 1MiB |
| 0 N/A N/A 2738 G /usr/bin/X 274MiB |
| 0 N/A N/A 3077 G /usr/lib64/libexec/kf5/klauncher 1MiB |
| 0 N/A N/A 3115 G ...ib64/libexec/xdg-desktop-portal-kde 1MiB |
| 0 N/A N/A 3138 G /usr/bin/kded5 1MiB |
| 0 N/A N/A 3142 G /usr/bin/kwin_x11 117MiB |
| 0 N/A N/A 3184 G /usr/bin/ksmserver 1MiB |
| 0 N/A N/A 3214 G /usr/bin/plasmashell 32MiB |
| 0 N/A N/A 3217 G /usr/bin/kaccess 1MiB |
| 0 N/A N/A 3219 G ...c/polkit-kde-authentication-agent-1 1MiB |
| 0 N/A N/A 3252 G /usr/bin/latte-dock 30MiB |
| 0 N/A N/A 3680 G /usr/bin/flameshot 1MiB |
| 0 N/A N/A 3765 G ...erProcess --variations-seed-version 63MiB |
| 0 N/A N/A 3948 G ...rowser/plugins --ozone-platform=x11 1MiB |
| 0 N/A N/A 3989 G ...39,262144 --variations-seed-version 70MiB |
| 0 N/A N/A 4174 G /usr/lib64/libexec/baloorunner 1MiB |
| 0 N/A N/A 4182 G /usr/bin/telegram-desktop 1MiB |
| 0 N/A N/A 4467 G ...erProcess --variations-seed-version 33MiB |
| 0 N/A N/A 5347 G /usr/bin/konsole 1MiB |
| 0 N/A N/A 6292 G ...ures=SpareRendererForSitePerProcess 37MiB |

嗯 尽管我的显卡电源功率不能正常显示 但是显卡的显存是明显可以正常使用的

以下是我的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
wlmosv$ neofetch 
-/oyddmdhs+:. wlmosv@wlmosv
-odNMMMMMMMMNNmhy+-` -------------
-yNMMMMMMMMMMMNNNmmdhy+- OS: Gentoo Linux x86_64
`omMMMMMMMMMMMMNmdmmmmddhhy/` Host: 81FW Lenovo Legion Y7000
omMMMMMMMMMMMNhhyyyohmdddhhhdo` Kernel: 6.8.7-gentoo-x86_64
.ydMMMMMMMMMMdhs++so/smdddhhhhdm+` Uptime: 2 hours, 25 mins
oyhdmNMMMMMMMNdyooydmddddhhhhyhNd. Packages: 1 (dpkg), 1240 (emerge)
:oyhhdNNMMMMMMMNNNmmdddhhhhhyymMh Shell: bash 5.2.26
.:+sydNMMMMMNNNmmmdddhhhhhhmMmy Resolution: 1920x1080
/mMMMMMMNNNmmmdddhhhhhmMNhs: DE: Plasma 5.27.11
`oNMMMMMMMNNNmmmddddhhdmMNhs+` WM: KWin
`sNMMMMMMMMNNNmmmdddddmNMmhs/. Theme: [Plasma], Adwaita-dark [GTK2/3]
/NMMMMMMMMNNNNmmmdddmNMNdso:` Icons: [Plasma], Papirus [GTK2/3]
+MMMMMMMNNNNNmmmmdmNMNdso/- Terminal: konsole
yMMNNNNNNNmmmmmNNMmhs+/-` Terminal Font: JetBrains Mono 11
/hMMNNNNNNNNMNdhs++/-` CPU: Intel i5-8300H (8) @ 4.000GHz
`/ohdmmddhys+++/:.` GPU: NVIDIA GeForce GTX 1050 Mobile
`-//////:--. GPU: Intel CoffeeLake-H GT2 [UHD Graphics 630]
Memory: 3734MiB / 15877MiB

疑难杂症

  • 如果不能启动桌面 请删除xorg配置文件位于/etc/X11/xorg.conf
  • 也可以看这里
  • 请添加你的用户到video组 一定要 另外不要使用bumblebee相关的任何服务和组
  • 当你配置完成更新的内核后请执行merge @module-rebuild(只对x11的nvidia-driver管用)
  • 检查你的make.conf 是否添加了nvidia 就像这样:

make.conf

后记

如果需要我补丁的请在评论区畅所欲言。其实安装nvidia显卡不难 难得是内核配置以及各种配置文件的问题 当然了,三天的折腾也是有效果的 现在全局渲染起来是真的好 虽然我只有垃圾1050 但是这阻止不了我从失败中爬起来再次战斗 fating!!!(——)我知道我打错了

参考网站: