Mastering Linux Kernel Configuration: lsmod, modprobe, modinfo

Опубликовано: 28 Сентябрь 2024
на канале: ARN Tech Trainings
281
11

KERNEL PARAMETER:

Listing out the Modules (Drivers) and blacklisting the USB and CDROM Driver:
• The drivers in Linux are known as Modules or Kernel Modules.

• These modules are assigned by kernel basing upon the hardware.

• Hardware can only be communicated and can work efficiently when the proper module is loaded in the kernel.

To find all the kernel Modules:
• All the kernel modules will be residing in /lib/modules directory

• Navigate to the directory /lib/modules and check it with uname –r

#cd /lib/modules/
#ls
#uname -r

To search all the kernel modules in the system using find command:
• All the kernel modules in the system will be ending with .ko extension, so let’s search it
using find command

#find / -name *.ko

Note:- Observe that all the modules listed are in /lib/modules only.
All modules may be supported or currently loaded modules.

To list all the currently loaded modules:
#lsmod

To check whether a particular module is loaded or not:
• To see the particular module use
#lsmod |grep –i module name
#lsmod |grep –i cdrom
#lsmod |grep –i sound

To install/re-install a module:
• To install a module use the following command
#modprobe mod name
#modprobe vfat

#lsmod | grep - i fat
#modprobe vfat
#lsmod | grep -i fat

#lsmod | grep - i vmhgfs
#modprobe vmhgfs

To remove the loaded module:
• There might be a situation where your module is not working properly, in that case we need
to remove the module and reinstall it. Let’s see how to remove a module first

• From previous task we know that vfat module is installed let’s remove it
#modprobe –r mod name
#modprobe –r vfat

#lsmod | grep -i fat
#lsmod | grep - i vfat

To see the information about the module:
• To see the information about a module the syntax is
#modinfo mod name
#modinfo cdrom

Disabling or Blacklisting a USB/CD-ROM driver:
To disable a USB/CD-ROM drive driver, first check whether a driver is loaded or not

• #lsmod |grep –i usb

If it is not loaded, connect the USB drive to the system and wait for it to get loaded, then
check it again whether the module is loaded or not

#lsmod |grep –i usb

Also check where it is mounted
#mount

You can navigate through /media/E817….. and verify whether it is correct device or not.
• Now as we know the module name just remove the module

#modprobe –r usb_storage

The error showing above is because the drive is mounted, unmount it and try removing
module again

As we have successfully removed the module, now place the module name in
/etc/modprobe.d/blacklist.conf file so that it may not be loaded in future.

#vim /etc/modprobe.d/blacklist.conf

Now save the file and quit the vim editor
• Now again try connecting the drive and check whether the USB is loading or not

#lsmod | grep -i usb

Note: -
The procedure for black listing CD-ROM is exactly same. Try it yourselves
To remove the USB/CD-ROM from black list

1. Remove the entry from /etc/modprobe.d/blacklist.conf
2. Connect the drive and install the module for USB and check whether it is mounting or not

Repairing the corrupted boot loader and recovering it:
• There might be a situation where your boot loader i.e., GRub might got corrupted and you want to recover it or in other word repair it.

Basically the repairing of GRub means installing a new grub on the existing one from RHEL 6 DVD.

• To recover the grub the steps are:

• Insert the RHEL 6 DVD and make the system boot from CD/DVD

• Boot the system in Rescue installed system Mode

• Select the language with which you want to continue and move cursor on OK, press Enter

• Select the keyboard Type and move cursor to OK and press Enter to continue.Select Local CD/DVD to make the sytem boot from it. As the system’s bootloader is corrupt.

• Move cursor to NO to ignore the networking and also to continue

• Move the curor to Continue tab, to mount the ‘root’ from CD/DVD. Press Enter

• Observe from above pic, that now your system has been mounted on /mnt/sysimage. It means where our system root is residing

• Move the cursor to OK and press Enter to continue.

• Press Enter to continue.

• Select ‘shell start shell’ and move cursor to OK to start the shell

• You can observe that a shell prompt is displayed

• Change the DVD root to system root by using following command
#chroot /mnt/sysimage

• Check that on which partition does your ‘/boot’ is using #fdisk –l or parted –l command

• Install the grub on the /boot device i.e. /dev/vda2 by using following command
#grub-install device name
#grub-install /dev/vda2

• If it shows no error reported, that means we have successfully recovered the grub.

• Type “exit” to exit from system root

• Againg type “exit” or “reboot” to reboot the system.

#arn
#arntech
#arntraining
#arntrainings
#arntechtrainings

linux kernel modules explained,kernel modules in linux,linux kernel manager,mastering Linux Kernel Configuration: lsmod,linux kernel module,linux modules