分页: 1 / 2
[分享]在内核升级后自动安装nvdia驱动
发表于 : 2008-08-07 0:01
由 boreascn
用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
发表于 : 2008-08-07 0:03
由 boreascn
原文:
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
发表于 : 2008-08-07 1:43
由 kelen
这个绝对要支持一下,一直为这事儿烦着哩。。
发表于 : 2008-08-09 9:07
由 syrano
太棒了,方法有效。

加精

发表于 : 2008-08-09 19:20
由 jqkace
it's really cooooool~~~
发表于 : 2008-08-09 19:38
由 BigSnake.NET
就是加个hook。。
发表于 : 2008-08-10 1:30
由 jarryson
ATI官方驱动也应该这样学学~官方驱动都需要编译一个模块出来,麻烦
不过nv也应该学学ATI开源,开源驱动是完全没有这样的烦恼的。驱动安装后,不需要针对内核编译一个模块出来
发表于 : 2008-08-10 8:34
由 uranyang
我看还是难,显卡的驱动程序安装难。
发表于 : 2008-08-15 8:29
由 kelen
冒似今天升内核21,不能自动更新。
发表于 : 2008-08-16 22:39
由 syrano
kelen 写了:冒似今天升内核21,不能自动更新。
我也升级到21,可以自动安装
发表于 : 2008-08-28 10:51
由 ptptptptptpt
不错!好主意!
Re: [分享]在内核升级后自动安装nvdia驱动
发表于 : 2008-10-09 23:14
由 wuyisheng
很奇怪,我更新内核后显卡驱动失效了,但是我删除驱动后重启(想重装驱动)发现竟然又可以了,但是我还没有重装驱动啊,神奇
Re: [分享]在内核升级后自动安装nvdia驱动
发表于 : 2009-01-29 21:47
由 sfsren
新手问下,保存后的update-nvidia放在什么地方?是每次升级内核后没有任何操作就自动更新,还是执行sudo mkdir -p /etc/kernel/postinst.d
sudo install update-nvidia /etc/kernel/postinst.d 后才会更新?
Re: [分享]在内核升级后自动安装nvdia驱动
发表于 : 2009-01-30 15:22
由 liliudd2008
sfsren 写了:新手问下,保存后的update-nvidia放在什么地方?是每次升级内核后没有任何操作就自动更新,还是执行sudo mkdir -p /etc/kernel/postinst.d
sudo install update-nvidia /etc/kernel/postinst.d 后才会更新?
同上啊

Re: [分享]在内核升级后自动安装nvdia驱动
发表于 : 2009-02-05 15:25
由 minechina
我也没看懂,同上。