LNVHW - Load NVIDIA (driver the) Hard Way from runlevel 3

In my continuing saga to live better through bash scripting, I present my next time saver script for those who like to load the nVidia driver the hard way, but would prefer it be just a little easier. To that end I present LNVHW - Load NVIDIA (driver the) Hard Way from runlevel 3. For this script to work for you, it must be located in the /root/bin folder, marked executable as always.

In KDE, you could start kwrite as:

kdesu kwrite /root/bin/lnvhw

Copy and past the code into your text editor (as root) and save the file.

#!/bin/bash

#: Title       : LNVHW - Load NVIDIA the Hard Way
#: Date Created: Thu Dec 23 21:05:40 CST 2010
#: Last Edit   : Thu Dec 23 21:39:00 CST 2010
#: Author      : J. McDaniel
#: Version     : 1.00
#: Description : Install nVidia Driver the Hard Way
#: Options     : None

#
# Written for the openSUSE forums on Thursday December 23, 2010
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file lnvhw root area bin folder (/root/bin).
# You must be a root user to do this function
# This script must be marked executable to be used.  Please run 
# the following Terminal command: sudo chmod +x /root/bin/lnvhw
# To use lnvhw, you must be in runlevel 3 mode
# When you start your computer, enter a 3 as a kernel option and press enter
# Once your kernel has loaded, log in as root and type the command: lnvhw
#

#
# Please Make Sure this name is correct - Do not include a "/" at the end...
#

nVidia_folder=/home/james/Downloads

# Check to make sure lnvhw was started as Root

if  $UID != 0 ] ; then
  echo "You Must Be A Root User to Run $0"
  exit 1
fi

# Make sure we are in Runlevel 3

RL=$( runlevel )
NUM={#RL}
LEVEL="${RL:2:1}"

if  "$LEVEL" != "3" ]] ; then
  echo "You are not using Runlevel 3 to load the nVidia Driver!"
  exit 1
fi 

  tput clear
  echo "Load nVidia the Hard Way Selection Menu"
  echo

# Determine if the nVidia_folder Exists

if  -d "$nVidia_folder" ]] ; then

  declare -a drivers
  cd "$nVidia_folder"

# Find and display all files that start with linux and end with .bz2

  for i in NVIDIA-* ; do 
    let counter=counter+1
    drivers$counter]=$i 
    echo "$counter) ${drivers$counter]}"
  done

  echo
  echo -n "Please Select the nVidia Driver You wish to use: "
  read CHOICE

  sh ./"${drivers$CHOICE]}"
  exit 0
else
  echo "Folder $nVidia_folder does not exist"
  exit 1
fi

exit 0
# End Of Script


Then mark it executable with the command:

sudo chmod +x /root/bin/lnvhw

To use lnvhw, download the latest nVidia proprietary video driver from:

Welcome to NVIDIA - World Leader in Visual Computing Technologies

Restart your PC and when you select the openSUSE kernel to load, enter a 3 as a kernel load option and press enter. Once you get to the login prompt, enter root and then the password and finally, type in lnvhw and select the nvidia driver you wish to load. Let me know if you have any questions about using lnvhw.

Thank You,

Another valued contribution to the community

Thanks James :slight_smile:

ah7013 said, Another valued contribution to the community, Thanks James :slight_smile:
Thanks ah7013 for those kind works. Also, anyone using the script needs to modify the following line to use your name, unless your name is james as well.

#
# Please Make Sure this name is correct - Do not include a "/" at the end...
#

nVidia_folder=/home/james/Downloads

Thank You,

Hi,

If you replace

nVidia_folder=/home/james/Downloads
with 
nVidia_folder=$HOME/Downloads

there should be no need for a user to change the script.

I’m assuming you are not starting as root.???

there should be no need for a user to change the script.

I’m assuming you are not starting as root.???
Hello there keellambert and Merry Christmas!

As for the folder where you download the NVIDIA drivers to, I assume you are doing this as yourself, and thus the need to change the nVidia_folder to your downloads folder. However, when you run LNVHW, you must do so as root, must be at runlevel 3 and your $HOME would not be equal to where you downloaded the nVidia driver files.

So, you must explicitly specify where those nVidia driver files are located.

Thank You,

Hello jdmcdaniel3,

Thanks, Merry Christmas too.

Is it not possible to log in at runlevel 3 as user (where driver is stored), then su to run your script?

Cheers

Hello jdmcdaniel3,

Thanks, Merry Christmas too.

Is it not possible to log in at runlevel 3 as user (where driver is stored), then su to run your script?

Cheers
keellambert there is more than one way to skin a cat as they say and so I would never say I know all of the ways. However, to switch to runlevel 3 from KDE, I normally open a terminal session, type su -, enter the root password and then** init 3**. This closes X and you must log in again. Since your only duty is to load the nVidia driver as root, I normally just log in as root and now run the lnvhw script. Or, you can reboot, add the kernel run time of 3, login as root and then run lnvhw. But of course, I encourage you to use any procedure that you want which works for you.

Thank You,

Hello jdmcdaniel3,

The variable HOME does not work!!! Sorry for the duff info
As soon as the command ‘su’ or ‘su -’ are used HOME is changed to /root.

However if the sequence; ‘init 3’, logon as user, then ‘su’ is used; USER and LOGNAME stay as user name.
Hence instead of $HOME/Downloads either of the following can be used,
nVidia_folder=/home/$USER/Downloads or nVidia_folder=/home/$LOGNAME/Downloads

Note: if command ‘su -’ is used, both USER and LOGNAME are changed to ‘root’

Hello jdmcdaniel3,

The variable HOME does not work!!! Sorry for the duff info
As soon as the command ‘su’ or ‘su -’ are used HOME is changed to /root.

However if the sequence; ‘init 3’, logon as user, then ‘su’ is used; USER and LOGNAME stay as user name.
Hence instead of $HOME/Downloads either of the following can be used,
nVidia_folder=/home/$USER/Downloads or nVidia_folder=/home/$LOGNAME/Downloads

Note: if command ‘su -’ is used, both USER and LOGNAME are changed to ‘root’
Now that you know how they work, you can select how you want to use lnvhw and the setting of the nVidia_folder value. It is really up to your personnel choice and knowledge of how Linux works. Thanks so much for your comments.

Thank You,

Hi James, and merry Chritsmas to you (and to everyone)!

Why not using something like that (and forget about the Dowload folder part):

drivers=(`find ~ -name "NVIDIA*bz2"`)

or, if you want to follow symlinks as well:

drivers=(`find -L ~ -name "NVIDIA*bz2"`)

You’ll get the drivers fullnames in the array ${drivers*]} and you can do whatever you like with them.

Merry Christmas there please_try_again. I may have already had too much Christmas cheer to be able to anallize (interpret) your suggested command, though the script comment which suggested the files end with .bz2 is wrong as they end with .run. This was a left over comment from its last use in my script klist. I know how to search through directories, but I thought in would be best to direct lnvhw to where you normally download them. I also was using an array for the name to make selection based on its number more easy, if that is the correct way to say that. lol!

Thank You,

I have made a few revisions to lnvhw to validate the existence of the NVIDIA drivers and for user input. If no NVIDIA drivers are found, lnvhw will exit with an error message. If you input a integer number outside the range for NVIDIA drivers found, it will be ignored, if you do not enter a number, it will be ignored and finally, I added a q=quit function should you decide to not load a driver after all. I did play with scanning folders for nVidia driver files, but really, it takes some time to scan many folders and I am betting, you keep all NVIDIA drivers in the same place all of the time and so no multiple folder scaning is being made.

Just as before, you need to change the following line:

#
# Where do you keep your nVidia driver downloads?
# Please Make Sure this name is correct - Do not include a "/" at the end...
#

nVidia_folder=/home/**your_name_here**/Downloads

I have determined that if you prefer, you can keep the lnvhw file in the /usr/local/bin folder. Copy and past the following text into the file lnvhw (as in /usr/local/bin/lnvhw). You MUST be a root user to complete this task.

#!/bin/bash

#: Title       : LNVHW - Load NVIDIA the Hard Way
#: Date Created: Thu Dec 23 21:05:40 CST 2010
#: Last Edit   : Sun Dec 26  8:50:00 CST 2010
#: Author      : J. McDaniel
#: Version     : 1.02
#: Description : Install nVidia Driver the Hard Way
#: Options     : None

TITLE="LNVHW - Load nVidia the Hard Way Selection Menu - Version 1.02"

#
# Written for the openSUSE forums on Sunday December 26, 2010
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file lnvhw usr area bin folder (/usr/local/bin).
# You must be a root user to do this function
# This script must be marked executable to be used.  Please run 
# the following Terminal command: sudo chmod +x /usr/local/bin/lnvhw
# To use lnvhw, you must be in runlevel 3 mode
# When you start your computer, enter a 3 as a kernel option and press enter
#

#
# Where do you keep your nVidia driver downloads?
# Please Make Sure this name is correct - Do not include a "/" at the end...
#

nVidia_folder=/home/your_name_here/Downloads

# Determine the Present Runlevel and Exit if not 3

RL=$( runlevel )
NUM={#RL}
LEVEL="${RL:2:1}"
if  "$LEVEL" != "3" ]] ; then
  echo
  echo "You are NOT using Runlevel 3 to load the nVidia Driver!"
  echo
  exit 1
fi 
gui=true
while $gui ; do
  tput clear
  echo "$TITLE" 
  echo
  echo "Using Video Driver Folder: $nVidia_folder @ Runlevel: $LEVEL"
  echo

# Check to make sure lnvhw was started as Root

  if  $UID != 0 ] ; then
    echo
    echo "You Must Be A Root User to Run $0"
    echo
    exit 1
  fi

# Determine if the nVidia_folder Exists

  if  -d "$nVidia_folder" ]] ; then
    counter=0
    declare -a drivers
    cd $nVidia_folder

# Find and display all files that start with NVIDIA-

    for i in NVIDIA-* ; do 
      if  -f $i ] ; then
        let counter=counter+1
        drivers$counter]=$i 
        echo "$counter) ${drivers$counter]}"
      fi
    done
    if  $counter -eq 0 ]]; then
      echo
      echo "No nVidia Driver Files were found!"
      echo
      exit 1
    fi
    echo
    echo -n "Please Select the nVidia Driver You wish to use (q=Quit): "
    read CHOICE

# Determine if input is an integer number and in range

    if  $CHOICE =~ ^[0-9]+$ ]] ; then
      if  $CHOICE -le $counter ]] &&  $CHOICE -gt 0 ]]; then
        gui=false
      fi
    else
      if  $CHOICE == [Qq] ]] ; then
        exit 0
      fi
    fi
  fi
done
  sh ./"${drivers$CHOICE]}"
  exit 0
else
  echo
  echo "Folder $nVidia_folder does not exist"
  echo
  exit 1
fi
exit 0
# End Of Script


Next, you need to mark the file lnvhw as executable with the following command:

sudo chmod +x /usr/local/bin/lnvhw

To use lnvhw, download the most recent NVIDIA driver to your downloads folder from Welcome to NVIDIA - World Leader in Visual Computing Technologies, restart your PC into runlevel 3, log in as root and run the terminal command:

lnvhw

Since my alternate motive for posting such files is to help learn bash programming, I felt the user input validation was worthy of making a new post and will be useful in your bash scripting tasks. Please enjoy and I want to hear all comments you have.

Thank You,

Just loaded lnvhw today on my 11.3 (2.6.34.7-0.7-default) after updating and having mouse delay problem with Nvidia 256.53 installed. Decided to update to 260.19.29 and use lnvhw to do it. Everything worked great, no problems. After update of Nvidia I did reboot be be sure everything was clean.

Thanks for the great script.

Russ
openSUSE 11.3 (2.6.34.7-0.7-default)|KDE 4.5.4 Release 9|
Intel core2duo 2.5 MHZ,|8GB DDR3|GeForce 8400GS

Just loaded lnvhw today on my 11.3 (2.6.34.7-0.7-default) after updating and having mouse delay problem with Nvidia 256.53 installed. Decided to update to 260.19.29 and use lnvhw to do it. Everything worked great, no problems. After update of Nvidia I did reboot be be sure everything was clean.

Thanks for the great script.

Russ
Russ, thanks so much for the positive feedback! I really never know for sure how well a script might be received. Knowing it is working is good to know.

Thank You,

Just a small comment:

probably using

nVidia_folder=~/Downloads

instead

nVidia_folder=/home/your_name_here/Downloads

in the script would make the beginner`s life much easier.
Thank you and keep up the great work.

Just a small comment:

probably using

      nVidia_folder=~/Downloads 

instead
nVidia_folder=/home/your_name_here/Downloads

in the script would make the beginner`s life much easier.
Thank you and keep up the great work.
If you run the lnvhw script as a root user, which is normal, then

nVidia_folder=~/Downloads <– Not going to work when logged in as root.

Will not point to where you keep your Downloads when you are not root. The thought is you login as root and run lnvhw, so a full folder path is recommended to where you keep your downloads. Again, thanks for your comments.

Thank You,

Sorry I missed that fact that you have to run this as root.
How about

locate NVIDIA-Linux

End of brainstorming :wink:

or simply download the NVIDIA file from script and run it from current directory:

#! /bin/bash

# default driver version (if not specified in the command line)
default_ver="260.19.29"
ver=${1:-$default_ver}

# driver name depends on architecture
arch=$(uname -m)
arch=${arch/i[5-9]/x}
run_file=NVIDIA-Linux-$arch-$ver.run

# nvidia url
url_base=http://us.download.nvidia.com/XFree86/Linux-$arch/$ver
nvidia_url=$url_base/$run_file

# Dowload NVIDIA-Linux run file
wget $nvidia_url

# execute run file from current directory
if  -f ./$run_file ] ; then
  sh ./$run_file
  exit 0
else
  echo $run_file not found
  exit 1 
fi

Is the web crazy or is it just me?
To answer your last question first … The Web is OK.

To the task at hand (loading/reloading the nVidia driver) most often, I am reloading the nVidia driver because I just updated my kernel and I already have the driver I want in my download area and I am loading it just after a reboot and entering runlevel 3 from the grub boot loader.

To your suggestion, I actually wrote something to download from the web, but you (or should I say I) can’t know what the current version might be? I am thinking, I would go see if a new version exists and if it does, download to my home area before I decided to load it. Now I could be loading just a new version in which case I could switch to runlevel three using:

su -
password:
init 3

But my thoughts are even if I do it this way, I already knew about and downloaded the new nVidia driver file.

*What I don’t want to do is, download a driver I already have and I don’t want to enter that long stupid driver name … ever. *

In addition in your script it would be nice to make sure we are in the correct runlevel and that we have root permissions to run the file and give me a list of versions to pick from. It can be downloaded after it has been selected. Now if there was someone that could do this it is you as I could not figure out how to do a directory of the online files to analyze to create the selection to look through.

Of course, what is wrong with my original thoughts on how it could be done? I must say that if you figure out how to present an online driver list to select from for download I will steel it and use it for SAKC, so give it a try and remember that I admire your spirit very much.

Thank You,

Hi James!
Although I have more nvidia than ATI machines around me, I haven’t seen the benefit of installing the latest nvidia driver the way I do for ATI. It looks like the ATI repo is much more outdated than the nvidia one. So I use the nvidia driver from the repo, which doesn’t need to be recompiled. But someone reported the modautocompile service worked well with the nvidia module, which doesn’t surprise me, as this very simple script can basically compile any module.

automatically recompile kernel modules after kernel update

Why don’t you give it a try? All you have to know is the name of the module and the command used to compile it. If I had known this command, I would have added it to my default /etc/modautocompile.conf. Then as the name indicates, you don’t have to worry about manual recompiling any more.

I’m sure that’s something we can find out within a script, using wget, curl, dog and some parsing of the site’s source pages… or even a rss feed or whatever social kind of thing… or just making your mailserver redirect spam from nvidia to your script. :wink:

I wouldn’t. I just avoid the web (it’s crazy).

Of course you can do that. But somehow the purpose of programming - and scripting - is to automate as many things as possible and use the time you save to do … other scripts. Agreed, it is stupid. lol!

I don’t do that either … but I doubt you have a 56K dialup connection. Most of the time it is faster to download an iso image again than figuring out where I did put it on my lan (!).

Yes, yes … But, you know, it was just a quick suggestion. It would save users a lot of time … provided Nvidia doesn’t change its base url. If the run file exists, then you don’t download it again (just a line of code to add).

It’s not difficult … unless you have to parse dozens of java script to get a URL, but even that can be done. Usually when they are more than 5 or 6 java scripts between me an the URL, I would ask my wife - who’s a better programmer in web related stuff.