How to disable or block device driver like USB & CD in Linux ?

Linux Block device driver or Blacklisting Drive:

Into this article we will learn block device driver in Linux…

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 disabled a USB/CD-ROM drive, first check whether a driver, first check whether a driver is loaded or not

 #lsmod | grep –i usb

[root@linuxelearn ~]# lsmod | grep -l usb

[root@linuxelearn ~]#

 

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

[root@linuxelearn ~]# lsmod | grep -i usb

usb_storage            49386  1

 

Also check where it is mounted

#mount

 

/dev/sr0 on /media/RHEL_6.0 i386 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

/dev/sr1 on /media/XIAOMI type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

 

You can navigate through /media/XIAOMI …… and verify whether it is correct device or not.

Now as we know the module name just remove the module.

#modprobe  -r usb_storage

[root@linuxelearn ~]# modprobe -r usb_storage

FATAL: Module usb_storage is in use.

[root@linuxelearn ~]#

 

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

[root@linuxelearn ~]# umount /media/XIAOMI

[root@linuxelearn ~]# lsmod | grep -i usb

usb_storage            49386  0

[root@linuxelearn ~]# modprobe -r usb_storage

[root@linuxelearn ~]# lsmod | grep -i usb

[root@linuxelearn ~]#

 

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

#

# Listing a module here prevents the hotplug scripts from loading it.

# Usually that’d be so that some other driver will bind it instead,

# no matter which driver happens to get probed first.  Sometimes user

# mode tools can also control driver binding.

#

# Syntax: see modprobe.conf(5).

#

#usb

blacklist usb_storage

# watchdog drivers

blacklist i8xx_tco

# framebuffer drivers

blacklist aty128fb

blacklist atyfb

blacklist radeonfb

blacklist i810fb

blacklist cirrusfb

blacklist intelfb

blacklist kyrofb

blacklist i2c-matroxfb

:wq!

Now save the file and quit the vim editor.

 

Now again try connecting the drive and check whether the USB is loading or not

[root@linuxelearn ~]# lsmod | grep -i usb

[root@linuxelearn ~]#

 

Note:- The procedure for black listing CD-ROM is exactly same. Try it yourselves

 

How to Remove the USB/CD-ROM from blacklist.

Remove the entry from /etc/modprobe.d/blacklist.conf

Connect the drive and install the module for USB and check whether it is mounting or not.

[root@linuxelearn ~]# lsmod | grep -i usb

[root@linuxelearn ~]# modprobe  usb_storage

[root@linuxelearn ~]# mount

/dev/sda2 on / type ext4 (rw)

oproc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)

/dev/sr0 on /media/RHEL_6.0 i386 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

/dev/sr1 on /media/XIAOMI type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)

[root@linuxelearn ~]#

 

I hope you enjoyed reading this article. Please make comments if you like this………..$

 

Leave a Reply

Your email address will not be published. Required fields are marked *