Install the driver and shell basic commands

Source: Internet
Author: User

Lnsmod r8168.ko

Sh ~~ Jiaoben ~~~ Autorun ~~

#! /Bin/sh

# Invoke insmod with all arguments we got
# And use a pathname, as insmod doesn't look in. By default

# 'Uname-R' to list the current version number

Target_path =/lib/modules/'uname-R'/kernel/Drivers/Net
Echo
Echo "check old driver and unload it ."
Check = 'lsmod | grep r8169'
# Query the Currently mountedProgramWhether there is r8169 --- this is another version of the driver

If ["$ check "! = ""]; Then
Echo "rmmod r8169"

# Remove the driver of this version
/Sbin/rmmod r8169
Fi

Check = 'lsmod | grep r8168'
If ["$ check "! = ""]; Then
Echo "rmmod r8168"

# If it is already installed, reinstall it.
/Sbin/rmmod r8168
Fi

Echo "build the module and install"
Echo "-------------------------------"> log.txt
The worker outputs the current time information to log.txt.

Date 1> log.txt

The handler outputs the compilation process information to log.txt. If an error occurs, 1 is returned.
Make all 1> log.txt | Exit 1

# Who can help me explain the three below?
Module = 'ls src/*. Ko'
Module =$ {Module # src /}
Module =$ {module %. Ko}

If ["$ module" = ""]; then
Echo "no driver exists !!! "
Exit 1
Elif ["$ module "! = "R8169"]; then

# Why? If test-e
If test-e $ target_path/r8169.ko; then
Echo "backup r8169.ko"
If test-e $ target_path/r8169.bak; then
I = 0
While test-e $ target_path/r8169.bak $ I
Do
I = $ ($ I + 1 ))
Done
Echo "RENAME r8169.ko to r8169.bak $ I"
MV $ target_path/r8169.ko $ target_path/r8169.bak $ I
Else
Echo "RENAME r8169.ko to r8169.bak"
MV $ target_path/r8169.ko $ target_path/r8169.bak
Fi
Fi
Fi

Echo "Depending module. Please wait ."

# Key 1
Depmod-
Echo "load module $ module"
# Key 2

Modprobe $ Module

Echo "completed ."
Exit 0

 

### Note

Both insmod and modprobe load the kernel module, but the difference is that modprobe can handle the dependency issue of module loading.

For example, if you want to load module A, but module A requires the system to load Module B first, an error message is usually reported when you directly use insmod to mount module, however, modprobe can know that loading Module B before loading module A will satisfy the dependency.

However, modprobe is not a great idea, and it won't be so powerful as to know the dependency between modules. This program reads the/lib/modules/2.6.xx/modules. Dep file to know the dependency. This file is created through the depmod program. 

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.