Ubuntu安装NVIDIA驱动导致黑屏的详细解决方案
<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>Ubuntu 安装 NVIDIA 驱动后无法进入图形界面的解决方法<ul class="second_class_ul"><li>问题描述</li><li>可能原因</li><li>解决步骤</li><ul class="third_class_ul"><li>1. 卸载 NVIDIA 驱动和清理残留文件</li><li>2. 安装开源驱动 nouveau</li><li>3. 重新安装图形界面环境</li><li>4. 重置 Xorg 配置</li><li>5. 更换显示管理器(可选)</li><li>6. 重启显示管理器</li><li>7. 重启系统</li><li>8. 检查硬件配置(可选)</li></ul><li>常见错误信息解析</li><ul class="third_class_ul"></ul><li>总结</li><ul class="third_class_ul"></ul></ul></li></ul></div><p>最近向了解使用Marker这个项目学习和进行一些pdf文档书籍的转换拆分工作,其中用到了cuda加速,但是本项目对windows环境似乎不太友好,在windows折腾无果,那就在linux环境下搞一下吧,不搞不知道,一搞在第一步就可谓是一波九折。。。</p><p class="maodian"></p><h2>Ubuntu 安装 NVIDIA 驱动后无法进入图形界面的解决方法</h2>
<p>在使用 Ubuntu 系统时,安装 NVIDIA 显卡驱动后,遇到了启动黑屏的情况,本文将总结可能的原因和详细的解决步骤,帮助您恢复系统的正常运行。</p>
<p class="maodian"></p><h3>问题描述</h3>
<p>安装命令:<code>sudo ubuntu-drivers autoinstall</code> (正是使用这个命令安装后黑屏)<br />命令解释:自动安装最合适的专有驱动程序。该命令会扫描你的硬件,并尝试从 Ubuntu 仓库中安装最匹配的闭源驱动程序,通常是最新版本的驱动程序。<br />也有的教程使用的这个命令: <code>sudo ubuntu-drivers install</code>: 安装 Ubuntu 推荐的驱动程序。该命令会安装 Ubuntu 官方推荐的驱动程序,通常是经过测试且较为稳定的版本,但不一定是最新版本。<br />安装 NVIDIA 驱动后,重启系统时可能出现以下症状:<br />(因这个问题重装了好几次系统。。)</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="ubuntu启动日志" src="https://zhuji.jb51.net/uploads/allimg/20250822/2-250R21A43LG.png" /></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250822/2-250R21A43NP.png" /></p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250822/2-250R21A43JY.png" /></p>
<p>也可能是黑屏就显示一个光标。</p>
<p>ps:其实这里已经启动成功了,只不过驱动程序冲突没有进入图形界面。</p>
<ul><li>启动日志中出现错误信息,例如:<ul><li><code>block nvme0n1: No UUID available providing old NGUID</code></li><li><code>iwlwifi 0000:00:14.3 WRT: Invalid buffer destination</code></li><li><code>Bluetooth: hci0: Malformed MSFT vendor event: 0x02</code></li><li><code> Dependency failed for sssd-nss.socket</code></li></ul></li></ul>
<p>这些错误提示可能与存储设备、无线网卡、蓝牙驱动或系统服务依赖有关,但未必是导致黑屏的直接原因。</p>
<p class="maodian"></p><h3>可能原因</h3>
<p><strong>驱动冲突</strong>:新安装的 NVIDIA 驱动可能与系统现有的驱动或库文件产生冲突。 <strong>配置错误</strong>:Xorg 配置文件或显示管理器(如 GDM3、LightDM)配置不当。 <strong>兼容性问题</strong>:NVIDIA 驱动与当前内核版本或其他硬件(如集成显卡)存在兼容性问题。</p>
<p class="maodian"></p><h3>解决步骤</h3>
<p class="maodian"></p><h4>1. 卸载 NVIDIA 驱动和清理残留文件</h4>
<p>首先,彻底卸载 NVIDIA 驱动和相关库文件,防止冲突:</p>
<p>屏幕黑屏,无法进入图形界面,在当前界面下,进入 tty 终端模式(<code>crtl</code>+<code>alt</code>+F2-F6任意按键)。<br />进入tty后依次输入用户名和密码,之后执行以下指令</p>
<div class="dxycode"><pre class="brush:bash;">sudoapt-get remove --purge *nvidia*
sudoapt-get autoremove
sudoapt-get autoclean</pre></div>
<p><code>sudo apt-get remove --purge '^nvidia-.*'</code>或<code>sudo apt-get remove --purge nvidia*</code>等命令都会导致卸载不全,这个坑真的排查了好久。</p>
<p>如果担心<code>*nvidia*</code>有风险,可以使用以下命令进行查找匹配</p>
<div class="dxycode"><pre class="brush:bash;">dpkg -l |grep nvidia
lsmod |grep nvidia</pre></div>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://i-blog.csdnimg.cn/direct/8730b273b04a437198c67e7706e0e708.jpeg" /></p>
<p>之后使用如<code>sudo apt remove --purge nvidia* libnvidia*</code>的前后缀匹配来卸载删除。</p>
<p>重新加载配置:</p>
<div class="dxycode"><pre class="brush:bash;">sudo ldconfig
sudoupdate-grubsudo update-initramfs -u -k all # 用于更新 initramfs (initial RAM filesystem),也称为初始内存盘。-u: 这个选项表示更新所有已存在的 initramfs 映像。-k all: 这个选项指定要更新哪些内核的 initramfs。 all 表示更新所有已安装内核的 initramfs 映像。</pre></div>
<p>在进入tty界面时如果安装系统时选择的时中文可能会存在乱码:</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250822/2-250R21A439414.png" /></p>
<p>方案1:临时修改为英文:<code>export LANG=en_US.UTF-8</code></p>
<p>方案2:永久生效:</p>
<div class="dxycode"><pre class="brush:bash;">sudo dpkg-reconfigure locales
sudonano /etc/default/locale</pre></div>
<p>将内容修改为:</p>
<div class="dxycode"><pre class="brush:bash;">LANG="en_US.UTF-8"
LANGUAGE="en_US:en"</pre></div>
<p>并重启<code>sudo reboot</code>。</p>
<p class="maodian"></p><h4>2. 安装开源驱动 nouveau</h4>
<p>安装适用于 NVIDIA 显卡的开源驱动 nouveau:</p>
<div class="dxycode"><pre class="brush:bash;">sudoapt-getinstall xserver-xorg-video-nouveau</pre></div>
<p>一般第一次安装时就是安装的这个驱动,为了防止被卸载执行一下更放心</p>
<p class="maodian"></p><h4>3. 重新安装图形界面环境</h4>
<p>确保系统的图形界面组件完整,重新安装 Ubuntu 桌面环境:<br />确保你安装了图形环境(如 GNOME、KDE 等)。<br />安装 GNOME 桌面:</p>
<div class="dxycode"><pre class="brush:bash;">sudoapt-getinstall ubuntu-desktop</pre></div>
<p>看了很多教程正是缺少这一步导致仍然停留在启动日志界面。(想不到安装驱动程序竟然把图形桌面干没了。。)<br />缺少这一步再次启动可能:</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250822/2-250R21A439644.png" /></p>
<p>崩溃不?</p>
<p class="maodian"></p><h4>4. 重置 Xorg 配置</h4>
<p>重置 Xorg 配置以恢复默认设置:</p>
<div class="dxycode"><pre class="brush:bash;">sudo dpkg-reconfigure xserver-xorg</pre></div>
<p>到这里一般就解决了,再次重启 <code>sudo reboot</code>。</p>
<p class="maodian"></p><h4>5. 更换显示管理器(可选)</h4>
<p>如果问题仍未解决,可以尝试安装并切换到 LightDM 显示管理器:</p>
<div class="dxycode"><pre class="brush:bash;">sudoapt-getinstall lightdm
sudo dpkg-reconfigure lightdm</pre></div>
<p>在配置过程中,选择 <strong>LightDM</strong> 作为默认显示管理器。</p>
<p class="maodian"></p><h4>6. 重启显示管理器</h4>
<p>根据您使用的显示管理器,重启对应的服务:</p>
<p>重启 GDM3:</p>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl restart gdm3</pre></div>
<p>重启 LightDM:</p>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl restart lightdm</pre></div>
<p class="maodian"></p><h4>7. 重启系统</h4>
<p>执行重启命令,使所有更改生效:</p>
<div class="dxycode"><pre class="brush:bash;">sudo reboot</pre></div>
<p class="maodian"></p><h4>8. 检查硬件配置(可选)</h4>
<p>查看系统中是否存在其他显卡(如 Intel 集成显卡):</p>
<div class="dxycode"><pre class="brush:bash;">lspci |grep -i vga</pre></div>
<p>如果输出包含 <code>Intel Corporation</code>,说明系统有集成显卡。可能需要针对多显卡配置进行额外的设置。</p>
<p class="maodian"></p><h3>常见错误信息解析</h3>
<p><strong>NVMe 和 UUID 问题</strong>:与存储设备的识别有关,可能是 BIOS 设置或分区表的问题,通常不影响图形界面启动。</p>
<p><strong>iwlwifi 驱动问题</strong>:涉及无线网卡驱动,若网络功能正常,可暂时忽略。</p>
<p><strong>Bluetooth 问题</strong>:与蓝牙驱动相关,一般不会导致系统无法进入图形界面。</p>
<p><strong>SSSD 服务失败</strong>:表示某个系统服务启动失败,可通过禁用该服务来排除影响:</p>
<div class="dxycode"><pre class="brush:bash;">sudo systemctl disable sssd.service</pre></div>
<p>这里贴个我踩过的巨坑:</p>
<p>当我第一次ubuntu系统黑屏时,始终解决不了我就把它给卸了重装,但是我卸载的方式简单粗暴:直接找出ubuntu所占的所有分区然后直接删除。这里没有清除BIOS的ubuntu启动项,注意这个启动项并不是在ubuntu的EFI分区中也就是就算你删干净了ubuntu的分区也没被清除,这还好,但是当我启动windows时:</p>
<p style="text-align:center"><img style="max-width:100%!important;height:auto!important;"alt="" src="https://zhuji.jb51.net/uploads/allimg/20250822/2-250R21A4392X.png" /></p>
<p>然后我就很蠢的把windows也卸载了重装发现还是不行,接着又重新分区重装:(</p>
<p>好不容易装了2个系统一安装驱动又干到黑屏了!</p>
<p>一整个人崩溃了有木有。</p>
<p class="maodian"></p><h3>总结</h3>
<p>在 Ubuntu 系统上,安装 NVIDIA 驱动后出现黑屏或无法进入图形界面的情况,可能由驱动冲突、配置错误或兼容性问题引起。通过卸载 NVIDIA 驱动、安装开源驱动 nouveau、重新安装图形界面环境、重置 Xorg 配置和更换显示管理器等步骤,通常可以解决问题。遇到类似问题时,建议按照上述步骤逐一排查,恢复系统的正常运行。</p>
<p><strong>提示</strong>:在进行系统级别的操作时,务必确保命令的正确性,并在必要时备份重要数据。</p>
<p>以上就是Ubuntu 安装 NVIDIA 驱动导致黑屏详细解决方案的详细内容,更多相关资料请阅读琼殿技术社区其它文章!</p>
頁:
[1]