Enable Ubuntu to automatically compile the official Nvidia driver module when updating the kernel

Source: Internet
Author: User
It is estimated that all those who use the nv video card had to manually install the graphics card driver after the new kernel was upgraded. Although not very difficult, it is quite troublesome. Today, I saw an article on Ubuntuforums.org about how to automatically install the nv driver using scripts. I tried it. I have translated the original text and shared it with you. After the Ubuntu kernel is upgraded, the nvdia driver is automatically installed. If you are using a driver downloaded from the nv official website, you must manually reinstall the nv driver after each kernel upgrade. This guide aims

It is estimated that all those who use the nv video card had to manually install the graphics card driver after the new kernel was upgraded. Although not very difficult, it is quite troublesome. Today, I saw an article on Ubuntuforums.org about how to automatically install the nv driver using scripts. I tried it. I have translated the original text and shared it with you.

After the Ubuntu kernel is upgraded, the nvdia driver is automatically installed.

If you are using a driver downloaded from the official website of nv, you must manually install the nv driver after each kernel upgrade. This guide aims to automatically install the driver after kernel upgrade without manual intervention.

This article assumes that you have correctly installed the nvidia official driver and restarted it at least once after installation (this is very important, because if you have not correctly installed and restarted, ). If you use an unofficial driver, skip this step.

Step 1: Put the driver you are using under/usr/src and generate a link. For example:

Sudo mv NVIDIA-Linux-x86-190.42-pkg0.run/usr/src
Sudo ln-s/usr/src/NVIDIA-Linux-x86-190.42-pkg0.run/usr/src/nvidia-driver

The purpose is to change the driver you use. You only need to delete the original link and specify a new link. You do not need to change the script we will use ).

The script for automatically installing the nv driver is as follows:

#! /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
# Re-compile if nvidia. ko does not 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

Basically, the principle is to check whether the correct nv driver is installed in the newly installed kernel. If not, the script automatically installs the driver module for the new kernel.

Name the above script update-nvidia and run the following command to install it:

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.