[linux]-ubuntu在内核升级时自动更新显卡驱动

导语:显卡驱动在内核升级之后重启显卡就无法使用。结合了大佬的脚本,使显卡驱动能在内核升级之后同步更新。

内核升级后显卡驱动报错如下。

执行如下命令

wget -c http://tech-pkg.oss-cn-hangzhou-internal.aliyuncs.com/00-SoftwareTools/NVIDIA-Linux-x86_64-535.104.05.run
chmod +x NVIDIA-Linux-x86_64-535.104.05.run
mv NVIDIA-Linux-x86_64-535.104.05.run /usr/src
ln -sf /usr/src/NVIDIA-Linux-x86_64-535.104.05.run /usr/src/nvidia-driver
cat > update-nvidia <<EOF
#!/bin/bash
#

# Set this to the exact path of the nvidia driver you plan to use
# It is recommended to use a symlink here so that this script doesn't
# have to be modified when you change driver versions.

DRIVER=/usr/src/nvidia-driver

# Build new driver if it doesn't exist

if [ -e /lib/modules/\$1/kernel/drivers/video/nvidia.ko ] ; then

    echo "NVIDIA driver already exists for this kernel." >&2

else

    echo "Building NVIDIA driver for kernel $1" >&2

    sh \$DRIVER -K -k \$1 -s --no-x-check --no-nouveau-check --install-libglvnd --dkms |tee  /var/log/nvidia-ker.log
    nvidia-smi --query-gpu=name,driver_version,uuid --format=csv  |tee -a /var/log/nvidia-ker.log
    if [ -e /lib/modules/\$1/kernel/drivers/video/nvidia.ko ] ; then

        echo "   SUCCESS: Driver installed for kernel $1" >&2

    else

        echo "   FAILURE: See /var/log/nvidia-installer.log" >&2

    fi
fi


exit 0
EOF

把上面的脚本命名为update-nvidia,并通过如下命令安装:

mkdir -p /etc/kernel/postinst.d
install update-nvidia /etc/kernel/postinst.d
cd /etc/kernel/postinst.d

install update-nvidia /etc/kernel/postinst.d 是用来将 update-nvidia 脚本安装到 /etc/kernel/postinst.d 目录下,这是一个用于在每次内核更新后自动运行的目录。

install命令和cp命令类似,只是自动把文件权限改成rwxr-xr-x 罢了。

apt安装软件的时候可能会升级内核版本

image-20240112112345234

参考:

https://forum.ubuntu.org.cn/viewtopic.php?t=141431&start=15

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爷来辣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值