ubuntu 自动安装nv显卡驱动

译文转自:http://forum.ubuntu.org.cn/viewtopic.php?t=141431&start=0&postdays=0&postorder=asc&highlight=

用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
=================================================================================================
原文转自:http://ubuntuforums.org/showthread.php?t=835573


HOWTO: 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


你可能感兴趣的:(Ubuntu)