202300704更新,黑屏问题主要由linux内核更新导致
# 一定要保持当前的内核,也就是安装 NVIDIA 驱动时用的内核
sudo apt-mark hold linux-image-generic linux-headers-generic
20230706 22:46 更新:好像这一步也没有用!!!
sudo gedit /etc/modprobe.d/blacklist.conf
# 在文件末尾输入
blacklist nouveau
options nouveau modeset=0
# 更新
sudo update-initramfs -u
# 重启
reboot
# 重启后验证是否完成屏蔽
lsmod | grep nouveau
# 无输出则屏蔽成功
# 查看nvidia显卡型号
lspci | grep -i nvidia
# 输出
01:00.0 3D controller: NVIDIA Corporation Device 25a0 (rev a1)
# 查看集成显卡型号
lspci | grep -i vga
The PCI ID Repository可以按照十六进制数字代码找到相应的显卡型号。
按照显卡型号下载驱动 (ctrl+鼠标点击-》跳转)下载官网建议的.run文件,下载完成后移动到主目录。
推荐直接在ubuntu自带的软件和更新-附加驱动
里面直接安装驱动
# 添加权限
sudo chmod a+x NVIDIA-Linux-x86_64-*.run
# 安装
sudo ./NVIDIA-Linux-x86_64-*.run -no-x-check -no-nouveau-check
// -no-opengl-files 只安装驱动文件,不安装OpenGL文件(据说台式机需要,否则会循环登录)
// -no-x-check 安装驱动时不检查X服务(for:you appear to be running an x server pleaseexit x before installing)
// -no-nouveau-check 安装驱动时不检查nouveau
// 安装过程中会询问是否安装32位的,选择 NO
// 安装过程或询问是否执行 nvidia-xconfig 选择 NO
# 安装完成后挂载nvidia
modprobe nvidia
# 验证是否安装成功
nvidia-smi
// 会显示显卡温度,风扇转数等信息
# 安装选择显卡的工具
sudo apt install nvidia-prime
# 选择使用nvidia
sudo prime-select nvidia
// nvidia 使用nivdia显卡
// intel 使用intel集成显卡
// on-demand 使用混合显卡
// query 查看当前使用的显卡
# 按照上述教程安装的
sudo ./NVIDIA-Linux-x86_64-*.run --uninstall
# 使用sudo安装或者ubuntu软件更新器里面安装的
sudo apt remove --purge nvidia*
sudo apt autoremove
20230706更新:这一步不需要了,没有用,保持内核不更新就行了。
问题描述:在进行prime-select nvidia后,重启电脑,左上角光标闪烁,无法进入登录页面。如果你恰巧执行了 nvidia-xconfig
命令,生成 /etc/X11/xorg.conf
之后,系统也还是进不去,**但是不会再一直循环登陆,而是登陆之后直接就卡住了。**问题出现在 X11 的配置文件上。相关参考链接如下:
稍微深入分析Ubuntu环境下安装NVIDIA驱动导致黑屏的原因
Why black screen after run sudo nvidia-xconfig
ubuntu安装nvidia驱动后循环登陆/登陆界面卡住
解决思路:
解决步骤:
# 终端执行
sudo nvidia-xconfig
# 此时会在/etc/X11中生成xorg.conf文件,打开进行编辑 --20230704 删除了这个文件还是可以进入图形界面
sudo gedit /etc/X11/xorg.conf
将其替换为以下内容,手动在 nvidia-xconfig 生成的文件中添加对 intel 显卡的支持
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 535.54.03
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0"
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
EndSection
Section "Files"
EndSection
Section "InputDevice"
# generated from default
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/psaux"
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"
BoardName "NVIDIA GeForce RTX3050TI"
BusID "PCI:1:0:0"
EndSection
Section "Device"
Identifier "intel"
Driver "modesetting"
BusID "PCI:0:2:0"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
EndSubSection
EndSection
其中BusID可以用以下命令查看
xxxxxx:~$ lspci -k | grep -EA3 'VGA|3D|Display'
00:02.0 VGA compatible controller: Intel Corporation Device 46a6 (rev 0c)
DeviceName: Onboard IGD
Subsystem: Hewlett-Packard Company Device 89c0
Kernel driver in use: i915
--
01:00.0 3D controller: NVIDIA Corporation Device 25a0 (rev a1)
Subsystem: Hewlett-Packard Company Device 89c1
Kernel driver in use: nvidia
Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia
# 安装图形界面管理器
sudo apt install lightdm
# 切换
sudo dpkg-reconfigure lightdm // 登录在左边
sudo dpkg-reconfigure gdm3 // 登录在中间
# 查看当前已安装内核
dpkg --get-selections | grep linux-image
linux-image-5.15.0-67-generic install
linux-image-5.15.0-76-generic install
linux-image-generic-hwe-20.04 install
# 保持当前内核
sudo apt-mark hold linux-image-generic linux-headers-generic
# 解除保持
sudo apt-mark unhold linux-image-generic linux-headers-generic
# 修改配置
sudo vim /etc/apt/apt.conf.d/10periodic
# 原来是这样的
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "1";
# 改成这样的
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
# 修改配置
sudo vim /etc/apt/apt.conf.d/20auto-upgrades
# 原来是这样的
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "1";
# 改成这样的
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
# 查看当前使用内核(绝对不能删除这个内核)
uname -r
# 查看内核列表
sudo dpkg --get-selections |grep linux-image
linux-image-5.15.0-67-generic deinstall
linux-image-5.15.0-76-generic install
linux-image-generic-hwe-20.04 install
linux-image-unsigned-5.15.0-67-generic deinstall
# or
sudo dpkg --get-selections |grep linux
binutils-x86-64-linux-gnu install
console-setup-linux install
libselinux1:amd64 install
libselinux1-dev:amd64 install
linux-base install
linux-firmware install
linux-generic-hwe-20.04 install
linux-headers-5.15.0-76-generic install
linux-headers-generic-hwe-20.04 install
linux-hwe-5.15-headers-5.15.0-76 install
linux-image-5.15.0-67-generic deinstall
linux-image-5.15.0-76-generic install
linux-image-generic-hwe-20.04 install
linux-image-unsigned-5.15.0-67-generic deinstall
linux-libc-dev:amd64 install
linux-modules-5.15.0-67-generic deinstall
linux-modules-5.15.0-76-generic install
linux-modules-extra-5.15.0-67-generic deinstall
linux-modules-extra-5.15.0-76-generic install
linux-sound-base install
pptp-linux install
syslinux install
syslinux-common install
syslinux-legacy install
util-linux install
# 删除内核
sudo apt remove linux-image-5.15.0-67-generic .. # 所有带5.15.0-67的