[分享]在内核升级后自动安装nvdia驱动

CPU/显卡/打印机/USB设备等硬件问题
头像
boreascn
帖子: 385
注册时间: 2008-03-26 14:28

[分享]在内核升级后自动安装nvdia驱动

#1

帖子 boreascn » 2008-08-07 0:01

用nv显卡的兄弟们估计都经历过升级新内核后,显卡驱动又得手动安装一次。虽然不怎么难,但是也挺麻烦的。今天在ubuntuforums.org上看到一篇文章介绍用脚本自动安装nv驱动的。试了一下可以。把原文稍微整理翻译了下,跟大家分享一下。

在内核升级后自动安装nvdia驱动

如果你使用的是在nv的官方网站下载的驱动,每当内核升级后,你必须重新手动安装nv驱动。本指南目标是当内核升级后自动进行安装驱动的过程,而不需要手工干预。

本文假定你已经正确的安装了nvidia官方驱动,并在安装后已经重启了至少一次(这非常重要,因为如果你没有正确安装并重启,下述将不能正常工作)。使用非官方驱动的请跳过。

第一步,把你使用的驱动放到/usr/src下,并生成链接。例如:
sudo mv NVIDIA-Linux-x86-173.14.05-pkg1.run /usr/src
sudo ln -s /usr/src/NVIDIA-Linux-x86-173.14.05-pkg1.run /usr/src/nvidia-driver

这样做的目的是当你更换所用的驱动时,只需要删除原来的链接后再指定新的链接即可,不需要改变我们将使用的脚本(script)。
自动安装nv驱动的脚本如下:

代码: 全选

#!/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 -n 2>1 > /dev/null

    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
基本上,原理是检查新安装的内核是否安装了正确的nv驱动,如果没有,脚本将自动为新内核安装驱动模块。

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

sudo mkdir -p /etc/kernel/postinst.d
sudo install update-nvidia /etc/kernel/postinst.d
头像
boreascn
帖子: 385
注册时间: 2008-03-26 14:28

#2

帖子 boreascn » 2008-08-07 0:03

原文:

Automatically update manually installed NVidia drivers after kernel updates

Overview

If you've manually installed the NVidia drivers from the NVidia website, when major kernel releases come out it's necessary to re-install the drivers for the new kernel. This guide aims to automate that process so that it happens when the new kernel is installed and requires no user intervention.



This HOWTO assumes you have correctly installed the NVidia drivers from the website and that you have rebooted after installing them at least once (this is very important because, if you haven't installed them correctly, upon reboot they will not work). This guide is not aimed at users who have installed the drivers using EnvyNG or via the default Ubuntu mechanism.



Implementation



Update: After finding an easier method to this, I've modified the directions slightly. People using the old method can continue to use it or, see this post to revert the changes from the old method.



Another Update: I've changed the script very slightly to provide a status message depending on whether or not building the new driver worked. People can replace nvidia-update with this new script or continue to use the old. I've also changed the testing instructions slightly.



The first thing I recommend doing this is to move the driver you are using to /usr/src and make a symlink to it. For example:



Code:



sudo mv NVIDIA-Linux-x86-173.14.05-pkg1.run /usr/src

sudo ln -s /usr/src/NVIDIA-Linux-x86-173.14.05-pkg1.run /usr/src/nvidia-driver



The reason for doing this is so that if you change the driver you are using, you can simply remove the symlink and point it at the new driver and not have to modify the script we are about to install.



The script we will use to automate this process is here:



Code:



#!/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 -n 2>1 > /dev/null



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



Essentially, what it does is check to see if the kernel we are installing has the proprietary nvidia driver installed. If not, it will build the module for that kernel.



Name the script update-nvidia and install it with:



Code:



sudo mkdir -p /etc/kernel/postinst.d

sudo install update-nvidia /etc/kernel/postinst.d



That's it. The next time you install a kernel that doesn't have the NVidia driver, it will automatically build it for you at installation time.



Testing

You can test it by either waiting for the next kernel release or by temporarily installing the -386 kernel to verify that it really does work properly. If you choose the later method of testing, this is how to do it:



Code:



sudo apt-get install linux-image-386 linux-headers-386



You should see a long pause as it says it's building the nvidia driver for the -386 kernel and then a success message. If it works, you can then remove the -386 kernel we installed for testing with:



Code:



sudo apt-get remove linux-headers-2.6.24-19-386 linux-headers-386 linux-image-2.6.24-19-386 linux-image-386 linux-ubuntu-modules-2.6.24-19-386
头像
kelen
帖子: 734
注册时间: 2008-05-02 19:50

#3

帖子 kelen » 2008-08-07 1:43

这个绝对要支持一下,一直为这事儿烦着哩。。
头像
syrano
帖子: 4313
注册时间: 2007-10-06 18:40

#4

帖子 syrano » 2008-08-09 9:07

太棒了,方法有效。 :lol:
加精 :arrow:
E=m c^2
jqkace
帖子: 32
注册时间: 2007-07-16 13:41

#5

帖子 jqkace » 2008-08-09 19:20

it's really cooooool~~~
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#6

帖子 BigSnake.NET » 2008-08-09 19:38

就是加个hook。。
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
jarryson
帖子: 4002
注册时间: 2005-08-14 19:53

#7

帖子 jarryson » 2008-08-10 1:30

ATI官方驱动也应该这样学学~官方驱动都需要编译一个模块出来,麻烦

不过nv也应该学学ATI开源,开源驱动是完全没有这样的烦恼的。驱动安装后,不需要针对内核编译一个模块出来
uranyang
帖子: 92
注册时间: 2008-08-06 23:30

#8

帖子 uranyang » 2008-08-10 8:34

我看还是难,显卡的驱动程序安装难。
头像
kelen
帖子: 734
注册时间: 2008-05-02 19:50

#9

帖子 kelen » 2008-08-15 8:29

冒似今天升内核21,不能自动更新。
头像
syrano
帖子: 4313
注册时间: 2007-10-06 18:40

#10

帖子 syrano » 2008-08-16 22:39

kelen 写了:冒似今天升内核21,不能自动更新。
我也升级到21,可以自动安装
E=m c^2
头像
ptptptptptpt
帖子: 3711
注册时间: 2006-09-19 18:16

#11

帖子 ptptptptptpt » 2008-08-28 10:51

不错!好主意!
wuyisheng
帖子: 27
注册时间: 2007-06-16 8:38

Re: [分享]在内核升级后自动安装nvdia驱动

#12

帖子 wuyisheng » 2008-10-09 23:14

很奇怪,我更新内核后显卡驱动失效了,但是我删除驱动后重启(想重装驱动)发现竟然又可以了,但是我还没有重装驱动啊,神奇
sfsren
帖子: 167
注册时间: 2008-11-07 21:39

Re: [分享]在内核升级后自动安装nvdia驱动

#13

帖子 sfsren » 2009-01-29 21:47

新手问下,保存后的update-nvidia放在什么地方?是每次升级内核后没有任何操作就自动更新,还是执行sudo mkdir -p /etc/kernel/postinst.d
sudo install update-nvidia /etc/kernel/postinst.d 后才会更新?
liliudd2008
帖子: 51
注册时间: 2008-12-31 21:09

Re: [分享]在内核升级后自动安装nvdia驱动

#14

帖子 liliudd2008 » 2009-01-30 15:22

sfsren 写了:新手问下,保存后的update-nvidia放在什么地方?是每次升级内核后没有任何操作就自动更新,还是执行sudo mkdir -p /etc/kernel/postinst.d
sudo install update-nvidia /etc/kernel/postinst.d 后才会更新?
同上啊 :em06
minechina
帖子: 94
注册时间: 2008-11-19 8:27

Re: [分享]在内核升级后自动安装nvdia驱动

#15

帖子 minechina » 2009-02-05 15:25

我也没看懂,同上。
回复