Ubuntu内核升级导致显卡冲突,升级显卡并禁用自动更新教程
服务器安装的ubuntu 18.04, 4块2080Ti显卡。在无意中升级内核后,导致显卡驱动不匹配,无法进入图形界面。
开机启动后,服务一直卡在ubuntu加载界面,
进入tty终端只是黑屏,没有任何反应。
于是,重启,在开机出现如下画面后,一直按shift (有可能会进不去advanced options for ubuntu选项界面,可以在开机的时候多按几次shift,然后长摁shift。)
进入如下界面:
选择“advanced options for ubuntu”
选择第一个内核,回车启动
通过这个内核启动后,能进入tty终端(按ctrl + alt + F1进入,F1可以换成F2,F3,…F12),接下来按照如下教程升级显卡:
1. 设置默认内核启动
因为后续操作会多次重启,如果不设置默认内核为第一个内核,就需要重新进入advanced options for ubuntu 选择内核。设置默认内核为第一个,为后续操作省事。
进入tty终端,首先找到内核名称:
grep menuentry /boot/grub/grub.cfg
我的服务器显示如下:
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 5.4.0-110-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-110-generic-advanced-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 5.4.0-110-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-110-generic-recovery-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 5.4.0-94-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-94-generic-advanced-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 5.4.0-94-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-94-generic-recovery-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 4.18.0-15-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-15-generic-advanced-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 4.18.0-15-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-15-generic-recovery-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 4.15.0-177-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-177-generic-advanced-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Ubuntu, with Linux 4.15.0-177-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-177-generic-recovery-c7d24c86-c79c-48f6-8b51-0fd1f92f858e' {
menuentry 'Memory test (memtest86+)' {
menuentry 'Memory test (memtest86+, serial console 115200)' {
选择需要默认启动的内核(我需要设置的是5.4.0-110-generic),然后输入如下指令:
sudo gedit /etc/default/grub
然后修改,GRUB_DEFAULT=“Ubuntu,Linux 5.4.0-110-generic”.
然后执行如下命令:
sudo update-grub
然后重启:
sudo reboot
注:我在配置的时候,多次进入tty终端后卡掉。于是我进入内核的recover模型进行默认内核的设置。
进入advanced options for ubuntu后,选择recovery mode 内核启动:
然后选择root,在下方终端中执行默认内核的设置。
2. 禁用nouveau
在终端中输入如下指令,如果没有输出结果,则表明已经禁用。
lsmod | grep nouveau
否则,终端输入如下指令:
sudo gedit /etc/modprobe.d/blacklist.conf
在文件中加入如下内容:
blacklist nouveau
options nouveau modeset=0
更新内容,使其生效:
sudo update-initramfs -u
然后重启设备
sudo reboot
3. 安装gcc与cmake
输入如下指令:
sudo apt-get install build-essential
sudo apt-get install cmake
输入如下指令,检测gcc和cmake是否安装成功,如果有显示版本信息则安装成功:
gcc --version
cmake --version
4. 升级显卡驱动
输入如下指令查看系统推荐的驱动版本:
sudo ubuntu-drivers devices
我的服务器查看驱动版本信息如下:
== /sys/devices/pci0000:3a/0000:3a:00.0/0000:3b:00.0 ==
modalias : pci:v000010DEd00001E04sv00001462sd00003712bc03sc00i00
vendor : NVIDIA Corporation
driver : nvidia-driver-510 - distro non-free
driver : nvidia-driver-470-server - distro non-free
driver : nvidia-driver-470 - distro non-free
driver : nvidia-driver-450-server - distro non-free
driver : nvidia-driver-460 - third-party free
driver : nvidia-driver-510-server - distro non-free recommended
driver : nvidia-driver-418-server - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
于是选择安装510版本驱动。
接着,输入如下命令安装510驱动(跟据系统推荐的驱动版本,修改安装指令驱动版本):
sudo apt install nvidia-driver-510
如果上一个指令没法安装,可采用下面这个指令:
sudo ubuntu-drivers autoinstall
然后输入如下两个指令查看输出,正常输出则表明驱动安装成功:
lsmod | grep nvidia
nvidia-smi
我的输出如下:
nvidia_uvm 1044480 8
nvidia_drm 61440 0
nvidia_modeset 1150976 5 nvidia_drm
nvidia 39104512 604 nvidia_uvm,nvidia_modeset
drm_kms_helper 188416 4 ast,nvidia_drm
drm 491520 8 drm_kms_helper,drm_vram_helper,ast,nvidia,nvidia_drm,ttm
i2c_nvidia_gpu 16384 0
Wed Jun 8 19:22:30 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.73.05 Driver Version: 510.73.05 CUDA Version: 11.6 |
|-------------------------------+----------------------+----------------------+
| 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 ... On | 00000000:18:00.0 Off | N/A |
| 94% 74C P2 238W / 250W | 5719MiB / 11264MiB | 83% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 1 NVIDIA GeForce ... On | 00000000:3B:00.0 Off | N/A |
| 63% 71C P2 161W / 250W | 4283MiB / 11264MiB | 41% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 2 NVIDIA GeForce ... On | 00000000:86:00.0 Off | N/A |
| 22% 46C P8 14W / 250W | 1MiB / 11264MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 3 NVIDIA GeForce ... On | 00000000:AF:00.0 Off | N/A |
| 16% 40C P8 16W / 250W | 1MiB / 11264MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 9010 C python 3569MiB |
| 0 N/A N/A 46633 C python 2147MiB |
| 1 N/A N/A 11682 C python 2335MiB |
| 1 N/A N/A 18183 C python 1945MiB |
+-----------------------------------------------------------------------------+
5. 安装gdm3
显卡升级后,还没有图形界面,通过安装gdm3解决。
指令如下:
sudo apt install gdm3 ubuntu-desktop
systemctl restart gdm
安装成功后,重启:
sudo reboot
重启后成功进入图形界面
6. 设置禁用系统更新
输入如下指令禁止更新内核:
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 "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
启动自动更新内容如下:
APT::Periodic::Update-Package-Lists "2";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "1";
再然后,输入如下指令:
sudo vim /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
启动自动更新内容如下:
APT::Periodic::Update-Package-Lists "2";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "1";
最后,重启:
sudo reboot
— 结束分界线 —
Over~