Tuesday, August 2, 2016

How to install driver in Linux – (Patching)

How to install driver in Linux – (Patching)

This is one the essential and important task

Following steps are required to compile driver as module:

Install and uninstall Commands (manage driver with help of below cmd) its call Patching

# lspci   -------- list pci -display hardware information
# insmod  -----Install module stand to load the drivers into memory (on the flight-running)
# modprobe  ---install module with dependencies
# modinfo   ----- get the information of driver
# rmmod -- remove ext2 and raid driver from memory
# depmod –a  - For reread modile.dep or modprobe.conf
# lsmod    -----list module – to check load driver into ram
# dmesg   ----- check all installed driver information
----------------------------------------------------------------------------------------------------------------
The entire Driver installed below location in Linux. (Driver Path)

[root@Tusharjahdav ~]# ls /lib/modules/2.6.32-431.el6.x86_64/kernel/   -----driver location
arch  crypto  drivers  fs  kernel  lib  mm  net  sound
----------------------------------------------------------------------------------------------------------------
Kernel doesn’t have NTFS not supported in Centos-5 and FAT is supported.

Check in config.conf file and search for support hardware

[root@Tusharjahdav boot]# pwd
/boot     ----------------------------------config.conf file location

[root@Tusharjahdav boot]# vi config-2.6.32-431.el6.x86_64

:set ic  ----ignore case sensitivity
/ntfs    ------search driver

CONFIG_FAT_FS=m --------------------------Fat is enable
# CONFIG_NTFS_FS is not set --------------ntfs not supported.

How to installed NTFS drivers in Linux.
# yum install –y ntfs-3q
# yum install –y fuse
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# lspci –vvv   (-vvv – verbosity) -  display hardware information
The above opt put shows the details information of all the pci device

00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
02:00.0 USB controller: VMware USB1.1 UHCI Controller
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

---------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# lspci -vvv | grep -i < driver name>  --check specific hardware
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# lspci -vvv | grep -i audio  -- check specific hardware support
02:02.0 Multimedia audio controller: Ensoniq ES1371 [AudioPCI-97] (rev 02)
        Subsystem: Ensoniq Creative Sound Blaster AudioPCI64V, AudioPCI128

[root@Tusharjahdav ~]# lspci -vvv | grep -i eth -- check specific hardware support
02:01.0 Ethernet controller: Intel mCorporation 82545EM Gigabit Ethernet Controller (Copper)
----------------------------------------------------------------------------------------------------------------
Bus means – flat wired in motherboard
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# dmesg                 ------ check all installed driver information
[root@Tusharjahdav ~]# dmesg | less         ------check installed driver information page wise

parport_pc 00:09: reported by Plug and Play ACPI
parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE]
ENS1371 0000:02:02.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# dmesg | grep -i eth  ------ check specific driver information

e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:0c:29:ec:46:4e
e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection
ADDRCONF(NETDEV_UP): eth0: link is not ready
e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
eth0: no IPv6 routers present
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# dmesg | grep -i VGA -----driver information
Console: colour VGA+ 80x25
vgaarb: device added: PCI:0000:00:0f.0,decodes=io+mem,owns=io+mem,locks=none
vgaarb: loaded
vgaarb: bridge control possible 0000:00:0f.0
Download audio driver from net and Untar audio source code (tar ball) in /usr/src using tar command:

[root@Tusharjahdav boot]# dmesg | grep -i memory

[root@Tusharjahdav boot]# dmesg | grep -i tty

[root@Tusharjahdav boot]# dmesg | grep -i dma

[root@Tusharjahdav boot]# cat /var/log/dmesg | less
----------------------------------------------------------------------------------------------------------------
It’s not show hardware support lspci command and its show in installed driver  dmeg command,
It’s  rare case to face such issue         
----------------------------------------------------------------------------------------------------------------
$ tar -zxvf ati.src.tar.gz -----download Linux driver found in source code format package
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav software]# tar -zxvf ati.src.tar.gz -----untar package called autoconfig / tarball installation and after compile to get the .ko file

[root@Tusharjahdav ~]# cd /var/local/ati - (after extract above command its create ati (DIR) in this path (cd /usr/local/ati)  ------after source code compile create ati folder 
[root@Tusharjahdav software]#  vi read me and  view install

[root@Tusharjahdav software]# ./configure

[root@Tusharjahdav software]# Make

[root@Tusharjahdav software]# Makelnstall

[root@Tusharjahdav software]# cd /usr/local/ati/  --------after run above 3 cmd installed driver and go /usr/local/ati/ folder

[root@Tusharjahdav software]# ls

[root@Tusharjahdav software]#  ati.ko  ------------------kernel driver file extension

Become a root user (use su or sudo) and load the module:
$ su -
$ insmod hello.ko
Note you can see message on screen if you are logged in as root under run
level 3
----------------------------------------------------------------------------------------------------------------
How to load .ko file or drivers

[root@Tusharjahdav drivers]# insmod ext2.ko -----to load the drivers into the Memory (on the flight – running ) & (installed without dependencies)

[root@Tusharjahdav software]# echo $?   ---check command run successfully or not
0

[root@Tusharjahdav software]# modprobe ati.ko   -----to load the drivers into the Memory.
(Load with dependencies)(It’s load to temporary in RAM)
----------------------------------------------------------------------------------------------------------------
How to Check loaded Kernel Module Drivers into the (KLM) in RAM
Verify that module loaded:
[root@Tusharjahdav software]#  lsmod | less   -------to show loaded driver in ram
                                                    (Display from /proc/modules) to show the kernel drivers 

Module                  Size         Used by
garp                      7152            1            8021q
stp                       2218              1            garp
llc                       5546              2            garp,stp
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav drivers]# lsmod | grep -i ext –list module-check load driver into the ram
                                                 #/proc/sys/ ---to search driver from this path.
ext2                   68236  0
ext3                  240013  1
jbd2                   93427  1 ext4
mbcache                 8193  3 ext2,ext3,ext4   -----loaded ext2 driver in ram for temporary

Module   -------driver name
Size         -------size of driver in hdd (bites)
Used by  -------used by program (how many programs used )
Description ---- description of driver    
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav software]#   insmod          }    load the kernel driver
[root@Tusharjahdav software]#   modprobe     }    load the driver with dependencies
----------------------------------------------------------------------------------------------------------------
  
If you unload same unused drivers, used below commands for unload

[root@Tusharjahdav software]# rmmod ext2 / raid  -------remove ext2 and raid driver from memory (remove for temporary after reboot driver automatic load because of (*) selected)
ext2 driver no used so we will unload from ram (cd /lib/module/2.28/kernel/)

* ---- always load in ram  ---MONOLITHIC
M ----whenever is required   ---MODULE

Unload the module:
$ rmmod hello
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav software]# lsmod | less  -----to verify (it’s done)

[root@centoshost kernel]# lsmod | wc –l  ---total count in auto loaded driver into ram
43 ------43 driver select * that’s why they loaded in ram while booting.
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav drivers]# modprobe -c | grep -i VGA  ----- check installed driver configurations  information

blacklist vga16fb
alias usb:v182Dp0269d*dc*dsc*dp*ic*isc*ip* sisusbvga
alias usb:v182Dp021Cd*dc*dsc*dp*ic*isc*ip* sisusbvga
alias symbol:restore_vga vgastate
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav kernel]#  yum install tree –y  ---installed for tree command
----------------------------------------------------------------------------------------------------------------
[root@Tushar software]# tree –f | grep –i raid - to search drivers & delete for permanently

│   │   ├── ./crypto/async_tx/async_raid6_recov.ko
│   │   └── ./crypto/async_tx/raid6test.ko
│   │   ├── ./drivers/md/dm-raid45.ko
│   │   ├── ./drivers/md/dm-raid.ko
│   │   ├── ./drivers/md/raid0.ko
│   │   ├── ./drivers/md/raid10.ko
│   │   ├── ./drivers/md/raid1.ko
│   │   └── ./drivers/md/raid456.ko
│   │   ├── ./drivers/scsi/aacraid

 [root@Tus kernel]# tree -f | grep sg -- to search drivers , driver path  & delete for permanently
To view directory structure of a directory in tree format, use tree command as
First go to directly and search from that directory files.
 
│   │       ├── ./drivers/media/video/videobuf-dma-sg.ko
│   │   ├── ./drivers/misc/sgi-gru
│   │   │   ├── ./drivers/misc/sgi-xp/xp.ko
│   │   │   └── ./drivers/misc/sgi-xp/xpnet.ko
│   │   ├── ./drivers/scsi/sg.ko -------------------driver path


[root@Tusharjahdav etc]# tree –a  - Show all files including hidden dot files:
├── yum
│   ── vars


[root@Tusharjahdav etc]# tree -L 2  ---Limit the level or depth of recursion

└── yum.repos.d
    ├── CentOS-Base.repo

[root@Tusharjahdav etc]# tree –d   ----Show only the directories:

├── xdg
│   ├── autostart


[root@Tusharjahdav etc]# man tree  -Run man tree for more on how to use tree.
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav kernel]# #rm -rf /drivers/scsi/sg.ko -----search and delate permanently
----------------------------------------------------------------------------------------------------------------
Kernel Compilation Time we select the below option

[      ]  ------  black means ---disable
[  *  ] -------Always run in RAM   (used consistency)    ---enable
[ M ]  ------  whenever we required driver                      ---enable

[  *  ] ---Monolithic-----}
[ M ] --- Modules   ------}its means  ---enable

----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav kernel]# lsmod | wc –l  ---check loaded driver count
64----------------------------loaded driver count

64 driver given (*)  that’s way they loaded in memory at the time of booting os.

----------------------------------------------------------------------------------------------------------------
NOTE : IF any issue with VMware driver ---Installed VMware Tools
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav software]# insmod ati.ko   -----To lead temporally
----------------------------------------------------------------------------------------------------------------
HOW TO PERSISTENT KERNEL DRIVERS
----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav kernel]# vi /etc/rc.local ------before login

modprob /user/local/ati/ati.ko ----- Add this command in rc.local (vi /etc/rc.local/)
But for drivers no need to add in rc.local because of kernel have separate driver file.
----------------------------------------------------------------------------------------------------------------
http://www.tecmint.com/15-basic-ls-command-examples-in-linux/

HOW TO PERSISTENT KERNEL DRIVERS

root@Tusharjahdav kernel]# vi /etc/modprobe.conf  -----add entry in this file for run persistent kernel driver in Linux

but before this entry ati.ko driver copy from /user/locat/ati/ to /lib/module/2.2.21/kernel/sound/
----------------------------------------------------------------------------------------------------------------
cp /usr/local/ati/ati.ko /lib/module/2.2.21/kernel/sound/  ----move ati.ko file at actual path.
----------------------------------------------------------------------------------------------------------------
root@Tusharjahdav kernel]# vi /etc/modprobe.conf  - to persistent the kernel drive (to load the driver while booting)    THIS FILE FOR USER MODE

Alice    audi  ati    ----audi  --(any think u like), (ati ----driver name) (this entry load from    
                                                                                                                       actual driver path)
wq!
----------------------------------------------------------------------------------------------------------------
root@Tusharjahdav kernel]#  cd /lib/modules/2.6.32-504.23.4.el6.x86_64

[root@centoshost 2.6.32-504.23.4.el6.x86_64]# ls

build   modules.alias      modules.ccwmap   modules.drm          modules.isapnpmap    modules.ofmap   modules.seriomap  modules.symbols.bin  updates
extra   modules.alias.bin  modules.dep      modules.ieee1394map  modules.modesetting  modules.order   modules.softdep   modules.usbmap       vdso
kernel  modules.block      modules.dep.bin  modules.inputmap     modules.networking   modules.pcimap  modules.symbols   source               weak-updates

[root@centoshost 2.6.32-504.23.4.el6.x86_64]# vi modules.dep  ----this file for kernel mode and we can also use this file 

kernel/arch/x86/kernel/test_nx.ko:
kernel/arch/x86/kernel/microcode.ko:
kernel/arch/x86/crypto/ablk_helper.ko: kernel/crypto/cryptd.ko
kernel/arch/x86/crypto/glue_helper.ko:
kernel/arch/x86/crypto/aes-x86_64.ko: kernel/crypto/aes_generic.ko
kernel/arch/x86/crypto/twofish-x86_64.ko: kernel/crypto/twofish_common.ko
kernel/arch/x86/crypto/salsa20-x86_64.ko:
kernel/drivers/video/vgastate.ko:
kernel/sound/ati.ko  ------add entry
----------------------------------------------------------------------------------------------------------------
[root@centoshost 2.6.32-504.23.4.el6.x86_64]# depmod –a  ---This command used for after adding driver entry in module.dep or modprobe.conf file
For reread modile.dep or modprobe.conf
----------------------------------------------------------------------------------------------------------------
[root@centoshost ~]# modinfo  --- get the information of driver

----------------------------------------------------------------------------------------------------------------
All above commands call patching

Insmod, yum update, yum update kernel, modprob,modinfo, installing new packages, compilaing, tarball, souce code , patch -d
----------------------------------------------------------------------------------------------------------------
See message in /var/log/message file:                   
$ tail -f /var/log/message

Load module when Linux system comes up. File /etc/modules use to load
kernel boot time. This file should contain the names of kernel modules that
are to be loaded at boot time, one per line. First copy your module to
/lib/modules/$(uname -r)/kernel/drivers. Following are suggested steps:

Create directory for hello module:
$ mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
(b) Copy module:
$ cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
(c) Edit /etc/modules file under Debian Linux:
$ vi /etc/modules
(d) Add following line to it:
hello
(e) Reboot to see changes. Use lsmod or dmesg command to verify module
loaded or not.
$ cat /proc/modules
OR
$ lsmod | less

http://www.tldp.org/HOWTO/html_single/Module-HOWTO/

LKM Utilities

The programs you need to load and unload and otherwise work with LKMs are in the package modutils. You can find this package in this directory.
This package contains the following programs to help you use LKMs:
Insmod  -  Insert an LKM into the kernel.
Rmmod  - Remove an LKM from the kernel.
Depmod  - Determine interdependencies between LKMs.
Kerneld  - Kerneld daemon program
Ksyms  -  Display symbols that are exported by the kernel for use by new LKMs.
Lsmod - List currently loaded LKMs.
Modinfo - Display contents of .modinfo section in an LKM object file.
Modprobe -Insert or remove an LKM or set of LKMs intelligently. For example, if you must load A before loading B, Modprobe will automatically load A when you tell it to load B.
Changes to the kernel often require changes to modutils, so be sure you're using a current version of modutils whenever you upgrade your kernel. modutils is always backward compatible (it works with older kernels), so there's no such thing as having too new a modutils.
Warning: modprobe invokes insmod and has its location hardcoded as /sbin/insmod. There may be other instances in modutils of the PATH not being used to find programs. So either modify the source code of modutils before you build it, or make sure you install the programs in their conventional directories.

--------------------------------------------------------------------------------------------------------------------

We can black list the drivers, How to block drivers in Linux????

[root@centoshost Desktop]# cd /etc/modprobe.d/  ------Go to modprobe.d
[root@centoshost modprobe.d]# ls
anaconda.conf   dist-alsa.conf  dist-oss.conf  vmware-tools.conf
blacklist.conf  dist.conf       openfwwf.conf

[root@centoshost modprobe.d]# vi blacklist.conf  ----edit blacklist file for black the drivers

###### file system ####
blacklist ext3  -------------------black list ext2 file system driver

# sound drivers
blacklist snd-pcsp  -------------------block sound drivers

wq!
--------------------------------------------------------------------------------------------------------------------
KERNEL PATCHING

Kernel patch file available on net and patch file extension is .patch

How can installed patch file in Linux?

Example:  zyx….patch  ----------------file driver

[root@centoshost ~]#  patch zyx....patch  ----installed patch driver
[root@centoshost ~]# patch -d zyx....patch ----installed patch driver

No comments:

Post a Comment