Device Drivers, Part 11: USB Drivers in Linux

Let's ride the USB

Let's ride the USB

This article, which is part of the series on Linux device drivers, gets you started with writing your first USB driver in Linux.

Pugs’ pen drive was the device Shweta was playing with, when both of them sat down to explore the world of USB drivers in Linux. The fastest way to get the hang of it, and Pugs’ usual way, was to pick up a USB device, and write a driver for it, to experiment with. So they chose a pen drive (a.k.a. USB stick) that was at hand — a JetFlash from Transcend, with vendor ID 0x058f and product ID 0x6387.

USB device detection in Linux

Whether a driver for a USB device is there or not on a Linux system, a valid USB device will always be detected at the hardware and kernel spaces of a USB-enabled Linux system, since it is designed (and detected) as per the USB protocol specifications. Hardware-space detection is done by the USB host controller — typically a native bus device, like a PCI device on x86 systems. The corresponding host controller driver would pick and translate the low-level physical layer information into higher-level USB protocol-specific information. The USB protocol formatted information about the USB device is then populated into the generic USB core layer (the usbcore driver) in kernel-space, thus enabling the detection of a USB device in kernel-space, even without having its specific driver.

After this, it is up to various drivers, interfaces, and applications (which are dependent on the various Linux distributions), to have the user-space view of the detected devices. Figure 1 shows a top-to-bottom view of the USB subsystem in Linux.

USB subsystem in Linux
Figure 1: USB subsystem in Linux

A basic listing of all detected USB devices can be obtained using the lsusb command, as root. Figure 2 shows this, with and without the pen drive plugged in. A -v option to lsusbprovides detailed information.

Output of lsusb
Figure 2: Output of lsusb

In many Linux distributions like Mandriva, Fedora,… the usbfs driver is loaded as part of the default configuration. This enables the detected USB device details to be viewed in a more techno-friendly way through the /proc window, using cat /proc/bus/usb/devices. Figure 3 shows a typical snippet of the same, clipped around the pen drive-specific section. The listing basically contains one such section for each valid USB device detected on the system.

USB's proc window snippet
Figure 3: USB's proc window snippet

Decoding a USB device section

To further decode these sections, a valid USB device needs to be understood first. All valid USB devices contain one or more configurations. A configuration of a USB device is like a profile, where the default one is the commonly used one. As such, Linux supports only one configuration per device — the default one. For every configuration, the device may have one or more interfaces. An interface corresponds to a function provided by the device.

There would be as many interfaces as the number of functions provided by the device. So, say an MFD (multi-function device) USB printer can do printing, scanning and faxing, then it most likely would have at least three interfaces, one for each of the functions. So, unlike other device drivers, a USB device driver is typically associated/written per interface, rather than the device as a whole — meaning that one USB device may have multiple device drivers, and different device interfaces may have the same driver — though, of course, one interface can have a maximum of one driver only.

It is okay and fairly common to have a single USB device driver for all the interfaces of a USB device. The Driver=... entry in the proc window output (Figure 3) shows the interface to driver mapping — a (none) indicating no associated driver.

For every interface, there would be one or more end-points. An end-point is like a pipe for transferring information either into or from the interface of the device, depending on the functionality. Based on the type of information, the endpoints have four types: Control, Interrupt, Bulk and Isochronous.

As per the USB protocol specification, all valid USB devices have an implicit special control end-point zero, the only bi-directional end-point. Figure 4 shows the complete pictorial representation of a valid USB device, based on the above explanation.

USB device overview
Figure 4: USB device overview

Coming back to the USB device sections (Figure 3), the first letter on each line represents the various parts of the USB device specification just explained. For example, D for device, C for configuration, I for interface, E for endpoint, etc. Details about these and various others are available in the kernel source, in Documentation/usb/proc_usb_info.txt.

The USB pen drive driver registration

“Seems like there are so many things to know about the USB protocol, to be able to write the first USB driver itself — device configuration, interfaces, transfer pipes, their four types, and so many other symbols like T, B, S, … under a USB device specification,” sighed Shweta.

“Yes, but don’t you worry — all of that can be covered in detail later. Let’s do first things first — get the pen drive’s interface associated with our USB device driver (pen_register.ko),” consoled Pugs.

Like any other Linux device driver, here, too, the constructor and the destructor are required — basically the same driver template that has been used for all the drivers. However, the content would vary, as this is a hardware protocol layer driver, i.e., a horizontal driver, unlike a character driver, which was one of the vertical drivers discussed earlier. The difference would be that instead of registering with and unregistering from VFS, here this would be done with the corresponding protocol layer — the USB core in this case; instead of providing a user-space interface like a device file, it would get connected with the actual device in hardware-space.

The USB core APIs for the same are as follows (prototyped in <linux/usb.h>):

int usb_register(struct usb_driver *driver);
void usb_deregister(struct usb_driver *);

As part of the usb_driver structure, the fields to be provided are the driver’s name, ID table for auto-detecting the particular device, and the two callback functions to be invoked by the USB core during a hot plugging and a hot removal of the device, respectively.

Putting it all together, pen_register.c would look like what follows:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>

static int pen_probe(struct usb_interface *interface, const struct usb_device_id *id)
    printk(KERN_INFO "Pen drive (%04X:%04X) plugged\n", id->idVendor, id->idProduct);
    return 0;

static void pen_disconnect(struct usb_interface *interface)
    printk(KERN_INFO "Pen drive removed\n");

static struct usb_device_id pen_table[] =
    { USB_DEVICE(0x058F, 0x6387) },
    {} /* Terminating entry */
MODULE_DEVICE_TABLE (usb, pen_table);

static struct usb_driver pen_driver =
    .name = "pen_driver",
    .id_table = pen_table,
    .probe = pen_probe,
    .disconnect = pen_disconnect,

static int __init pen_init(void)
    return usb_register(&pen_driver);

static void __exit pen_exit(void)


MODULE_AUTHOR("Anil Kumar Pugalia <email_at_sarika-pugs_dot_com>");
MODULE_DESCRIPTION("USB Pen Registration Driver");

Then, the usual steps for any Linux device driver may be repeated:

  • Build the driver (.ko file) by running make.
  • Load the driver using insmod.
  • List the loaded modules using lsmod.
  • Unload the driver using rmmod.

But surprisingly, the results wouldn’t be as expected. Check dmesg and the proc window to see the various logs and details. This is not because a USB driver is different from a character driver — but there’s a catch. Figure 3 shows that the pen drive has one interface (numbered 0), which is already associated with the usual usb-storage driver.

Now, in order to get our driver associated with that interface, we need to unload the usb-storage driver (i.e., rmmod usb-storage) and replug the pen drive. Once that’s done, the results would be as expected. Figure 5 shows a glimpse of the possible logs and a procwindow snippet. Repeat hot-plugging in and hot-plugging out the pen drive to observe the probe and disconnect calls in action.

Pen driver in action
Figure 5: Pen driver in action

Summing up

“Finally! Something in action!” a relieved Shweta said. “But it seems like there are so many things (like the device ID table, probe, disconnect, etc.), yet to be understood to get a complete USB device driver in place.”

“Yes, you are right. Let’s take them up, one by one, with breaks,” replied Pugs, taking a break himself.


  1. I am trying to implement the above module but when i do rmmod usb-storage it shows me following error:
    ERROR: Module usb_storage does not exist in /proc/modules
    could anyone help me out

    • usb_storage might be built into the kernel. You might have to recompile the kernel with usb_storage built as a module.

  2. This is weird. I do not have the ‘usb’ folder within my /proc/bus ! I have folders ‘input’ and ‘pci’ there. Why is there this mismatch? My kernel is 2.6.32-40-generic

    • I tried using older kernel( I used Ubuntu 8.04, with 2.6.24.x ) , but surprisingly it showed me /proc/bus/usb/ , thats all , no device file !!

      Anyway, I found another way out, use command :
      udevadm info –attribute-walk –name
      where : could be /dev/sdb1 etc. It gives a lengthy o/p , try using a pipe & then grep to get what ever u want.

    • i am facing same problm … I do not have the ‘usb’ folder within my /proc/bus ..

      do i need to custumize ma kernel or here is any other way also ..bcos i hv not done this before …m kind of afraid ..

        • root@ubuntu:/home/ayush# sudo apt-get install linux-source-3.2.0 kernel-package libncurses5-dev fakeroot
          Reading package lists… Error!
          E: Encountered a section with no Package: header
          E: Problem with MergeList /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise_main_binary-i386_Packages
          E: The package lists or status file could not be parsed or opened.

          I was trying 1st command mentioned in above link …. can u tell wht is the problm in above cmmnd

          • Not really sure. But looks like something to do with your package management on ubuntu. Check out & resolve by googling for the error.

    • Unfortunately, usbfs has been disabled in Ubuntu for a long time now.

      However, similar information can be found with the following cmd:
      sudo cat /sys/kernel/debug/usb/devices

  3. @twitter-41866709:disqus ,
    Many thanks for sharing the post and everything you explained works like charm, but I might be doing something stupid or probably not aware if some other things need to be tweaked.

    device driver: insmod pen_register.ko triggers probe and I confirmed by dmesg but I’m not able to see the pen drive neither in nautilus nor in file system disk usage( df -h).

    Secondly, issuing #cat /dev/pen1 results in -110 results is connection timeout.

    here is the strace of read

    #strace -e trace=read cat /dev/pen1
    read(3, “177ELF111331000m1004″…, 512) = 512
    read(3, “# Locale name alias data base.n#”…, 4096) = 2570
    read(3, “”, 4096) = 0
    read(3, 0x8d4f000, 32768) = -1 ETIMEDOUT (Connection timed out)
    cat: /dev/pen1: Connection timed out

    Please let know further steps to perform a read/write on the usb drive

    • I believe if you have followed the article – you are anyway not expected to be able to read & write yet. I am doubtful as what is this /dev/pen1 referring to – it might be the one exposed by the usb-storage driver. Read the next articles in series to get the next steps

  4. thank you for the article !
    I think that “lsusb -v” has a sufficient output for those who have usbfs disabled. isn’t it ?

      • my kernel version is new i did lsusb -v ….bt by using this command how can i check which driver is associated with the my pendrive … i want to see that my pendrive is connected to driver = usb-storage ..

        result(partial) of lsusb -v :
        Bus 001 Device 004: ID 0951:1643 Kingston Technology DataTraveler G3 4GB
        Device Descriptor:
        bLength 18
        bDescriptorType 1
        bcdUSB 2.00
        bDeviceClass 0 (Defined at Interface level)
        bDeviceSubClass 0
        bDeviceProtocol 0
        bMaxPacketSize0 64
        idVendor 0x0951 Kingston Technology
        idProduct 0x1643 DataTraveler G3 4GB
        bcdDevice 1.00
        iManufacturer 1 Kingston
        iProduct 2 DataTraveler G3
        iSerial 3 001CC0EC32BCBB611712008E
        bNumConfigurations 1
        Configuration Descriptor:
        bLength 9
        bDescriptorType 2
        wTotalLength 32
        bNumInterfaces 1
        bConfigurationValue 1
        iConfiguration 0
        bmAttributes 0x80
        (Bus Powered)
        MaxPower 200mA
        Interface Descriptor:
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 2
        bInterfaceClass 8 Mass Storage
        bInterfaceSubClass 6 SCSI
        bInterfaceProtocol 80 Bulk-Only
        iInterface 0
        Endpoint Descriptor:
        bLength 7
        bDescriptorType 5
        bEndpointAddress 0x81 EP 1 IN
        bmAttributes 2
        Transfer Type Bulk
        Synch Type None
        Usage Type Data
        wMaxPacketSize 0x0200 1x 512 bytes
        bInterval 0
        Endpoint Descriptor:
        bLength 7
        bDescriptorType 5
        bEndpointAddress 0x02 EP 2 OUT
        bmAttributes 2
        Transfer Type Bulk
        Synch Type None
        Usage Type Data
        wMaxPacketSize 0x0200 1x 512 bytes
        bInterval 0
        Device Qualifier (for other device speed):
        bLength 10
        bDescriptorType 6
        bcdUSB 2.00
        bDeviceClass 0 (Defined at Interface level)
        bDeviceSubClass 0
        bDeviceProtocol 0
        bMaxPacketSize0 64
        bNumConfigurations 1
        Device Status: 0x0000
        (Bus Powered)

        pls reply :)

          • hi .. i hav downloaded this usbview app how to install it on ubuntu ..pls help.. i knw i m asking very silly questions bt i m a begginer pls help

          • i was trying to install using ubuntu software centre bt some erreor : System program problem detected is coming and ubuntu software centre get stopped unexpectedly
            also Could not determine the package or source package name. this error is coming pls help

          • I think you do not need to download or so. As you are on ubuntu, you may just type the following command on the shell: sudo apt-get install usbview

          • i got this error while using : sudo apt-get install usbview

            Reading package lists… Error!
            E: Encountered a section with no Package: header
            E: Problem with MergeList /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_precise_main_binary-i386_Packages
            E: The package lists or status file could not be parsed or open: do apt-get install usbview

  5. it gives me following error when it insert module by writing insmod command

    insmod: error inserting ‘usbstick.ko’: -1 Unknown symbol in module

    • Check out the dmesg output for which symbol in your driver is not yet resolved. And then, fix that. Possibly, you might have got warnings while compilation and have ignored them.

      • i also got the same error … bt in my case it was bcos i hav not included

        MODULE_LICENSE(“GPL”); this line …. can u explain me why it was giving this error insmod: error inserting usb.ko :-1 Unknown symbol in module
        for not including license macro

  6. thanks for this awesome post .. yesterday i tried it and it worked fine … but i have a small doubt if u can help :

    1) when i plugs in my pen drive it is getting detected by my driver . but when i am using another pen drive usb-storage module(which i removed by rmmod usb-storage) get inserted by itself . how it is happening ??

    2) and is there any way so that all the pendrive get detected by my module only not by usb-storage ..

    • 1) module autoload rules under /lib/modules//modules.usbmap, typically get the modules loaded automatically.
      2) Change the above file.

  7. Sir, what is the difference between USB device driver and USB interface driver? because interface is a part of device, so we are writting drivers for interfaces and not for a device . do we writting driver for device or interface ? I am confused in these terminologies . Please guide me .

    • We write a (USB) device driver only. But interesting, you can have one driver per interface of the USB device. Hence, if we have multiple interfaces in a USB device, we technically could have more than one device driver for that same device. That’s what is being highlighted as “… so we are writing drivers for interfaces and not for a device …”.

  8. Hey help me..
    Got everthing right.. and worked like charm….
    Now we did “rmmod usb-driver” after this when i insert my pen drive for the normal usage it does not show me my files. I mean the auto pop up file whioch appear after the insertion of the pendrive
    please help ,how do i revert back.



  9. I would like to add something here.

    In latest Ubuntu and the kernel higher than v3 you will not find the detailed description of the device in “cat /proc/bus/usb/devices”. In fact there is not “/proc/bus/usb/” present. You can find the detailed info in “sys/kernel/debug/usb/devices”. ‘cat’ this particular location for the detailed info of the USB devices which you cannot get from ‘lsusb’ command


  10. Sir, I am doing lsusb -v from the terminal but it didn’t show the detailed information about the vendor id and product id, i also tried /proc/bus/usb/devices but there is no such directory present with this name,i also tried cat “/sys/kernel/debug/usb/devices” but it is showing the error as “permission denied”, so what’s the solution of this problem please tell me.

          • Send the output of the following (as root):
            ls -ld /sys/kernel/debug
            ls -ld /sys/kernel/debug/usb
            ls -ld /sys/kernel/debug/usb/devices

          • Hello Sir,

            The output of the following will be as follows:-

            (1) ls -ld /sys/kernel/debug

            O/p–> drwx—— 17 root root 0 Sep13 13:13 /sys/kernel/debug

            (2) ls -ld/sys/kernel/debug/usb

            O/P—- > ls: cannot access /sys/kerneldebug/usb: Permission denied.

            (3) ls -ld/sys/kernel/debug/usb/devices

            O/P—-> ls: cannot access /sys/kerneldebug/usb: Permission denied.

          • Have you done all these as root? Seems like not – otherwise the second command should not give the mentioned error.

          • Hello Sir,
            I have done all this as a root only but it gives me same error time and again please tell me the solution to it.

  11. Hello Sir,

    When i am using Oracle VM VirtualBox, then it will not show the usb device connected, and will not show any information about it, while when i dual boot the PC and installed Linux Ubuntu separately, then it will show the detailed report of all the usb devices connected just by doing “sudo lsusb”and “lsusb -v” as mentioned above,
    Showing detailed report of vendor id and product id.

    Please, tell me what is the reason behind not showing what sort of usb devices connected when i use VirtualBox.

    • Virtual Boxes typically need various configuring and setting for the real hardware mapping into the virtual box, which is by default not done. And hence, you do not see the real devices, as such, unless specifically configured.

      • So, sir is there a way i can see my usb devices connected to my computer while using VirtualBox. How can i then see all the usb devices connected configuring my VirtualBox??

        • Typically, while setting up virtual box, you need to configure that it should allow/connect the USB devices. Once done, you can see the connected USB devices, as in any normal Linux system.

  12. Hi Anil Sir,

    In this article, you have not used alloc_chrdev_region(..) like in previous articles to register the device, but instead you have used usb defined function.
    Is this function intern typedef with alloc_chrdev_region ?

    If both are not related functions, Can you please explain when to use alloc_chrdev_region and when to not ?


    • The usb-storage driver has already acquired the pen drive’s interface. So, for our driver to take it, we need to get it released from the usb-storage driver – and the easiest way is to remove that.

  13. I removed usb-storage module as mentioned above but it gets automatically inserted when the pendrive is plugged in again. Can anyone tell me how to stop automatic loading of usb-storage module?

    • Easiest way is to plugin the pendrive and then unload the driver. Harder way would be to comment out the auto load settings in the udev configs &/or /lib/modules//modules.usbmap

  14. Hi Anil ,

    I am also facing the same problem what Mayank is facing. usb-storage module gets automatically inserted when the usb is plugged-in again. plz help.

  15. Dear Sir ,

    I have executed the makefile but when I try to insert the module by calling the insmod command – I get the following error :

    root@ubuntu:/home/pranav/Desktop/test# insmod pen_register.ko
    insmod: error inserting ‘pen_register.ko’: -1 Unknown symbol in module

    Sir , Please help me out urgently as I have a project deadline in a few days .

    Looking forward to your reply .

    • After the error, do “dmesg | tail” to check out the details of the “unknown symbol” error. That would help you check which symbol in the pen-driver.ko is unresolved, and that will give a direction to fix that.

      • Thank You Sir .

        Actually the problem was cropping up because I had not added :

        MODULE_LICENSE(“GPL”); which is necessary to load the module in linux kernel 2.6.3 upwards

  16. hi sir,
    i m geting tis msg whem i m trying to insert the module,
    plz let me know the solution.

    root@ubuntu:/home/ajay/modules# insmod usb.ko
    insmod: error inserting ‘usb.ko’: -1 Device or resource busy
    root@ubuntu:/home/ajay/modules# make

  17. Can you please tell me y it shows 3 times ?
    “Pen drive (..) plugged” on insmod
    “Pen drive removed” on rmmod

    i am Using Ubuntu 12.04..

  18. Sir,

    I want to write bare minimum Linux device drivers
    of USB, Ethernet and SATA for my arm board.
    The USB, Ethernet and SATA IP
    cores are developed by us. So it is not possible to download those drivers from
    internet. We have the working full fledged firmware for those.
    The only need
    is to convert those firmware to simple Linux device driver format.
    I just
    want a simple structure of the drivers for doing that. I have read many
    documents; but all those documents are complicated and so I am not getting a
    start to develop those drivers.


    Sreenadh S.

  19. Hi Sir,

    while removing usb_storage am getting it is in use ,please how should i remove .

    sunitha@SUNITHA:~$ sudo rmmod usb_storage
    ERROR: Module usb_storage is in use by ums_realtek

  20. Dear Anil, first of all thank you for having taken the time to spread your knowledge with us. I really appreciate people doing that. Then my question: was is the Terminating entry line ? Why do we have to add and empty {} inside the usb_device_id array ?

    • Lot of discussions are there below, regarding the same. Though in the simplest form, it should happen by doing “rmmod usb-storage”. Otherwise, dig through the discussions below.

      • it is resolved! Under Ubuntu you must as first disconnect the USB-stick, then rmmod usb-storage! Else you get error message from Ubuntu!
        But thank you anyway!

  21. HI,
    I’m trying to insmod/modprobe usb-storage.
    I’m getting the following error:
    FATAL: Module usb_storage not found.

    I dont know why is it not found.
    neither am i able to access any flash drive.

    By using .config, how can u alter usb storage devices settings.. any particular device like sandisk cruzer pop!?


    • 1) Seems like you have renamed / moved the usb_storage.ko* file.

      2) .config is a kernel configuration file and have nothing to do directly with any device.

      • Hi Anil,
        How do you modify a class driver of a particular device.
        For e.g i have a SanDisk flash drive, i want to edit its class driver so that whenever it is attached to the system, a message should appear on the console or something. And by the way where in the tree, can i find the code for the class driver?

        • The corresponding driver is the usb_storage driver – source code of which is available inside the kernel sources under the following folder: drivers/usb/storage

  22. Hi,

    In this post you are installing the module using insmod, is there any way to do the same thing automatically, while I am building my kernel ?

    • I assume you mean to say building the module into the kernel. Yes, it can be done. For that you need to add corresponding entries into the relevant Makefile & Kconfig file of the kernel.

      • So you mean to say it will load automatically ?? And what will happen to usb-storage, as it will also be there? I am asking because i have tried this ..but now luck in auto loading.

        • Once compiled into the kernel, it is no longer a module but part of the kernel and hence gets loaded as part of the kernel itself. Any module, whether it is usb-storage or any other, it should either be compiled into the kernel or as a separate .ko module, not as both.

  23. Hi Anil,
    I wanna know what happens before a USB device is connected.
    1. I mean, what initialization process takes place related to USB?
    2. How the core gets “ready”?
    3. Are all the probe functions in usb set up initially or only when a device is connected?
    4. Is there an array where the core stores all the class drivers (HID, Mass storage etc) so that it can decide which one to load?

    Sorry a long list. Please bear!

    • 1. As per the USB protocol.
      2. Its typically pre-loaded or loaded on first USB request.
      3. probe functions are part of device drivers
      4. auto load is typically achieved using the modules.usbmap &/or udev configurations.

      • Thanks.

        About the last one, I have seen (in the /USB/core/driver.c code) that the core, based on the idVendor, idProduct or class/subClass/protocol will decide which class driver to allocate (rather load) when a particular device is added (eg. USB mass storage). So what does it compare with? There must be some table or array or maybe a list which stores all the data regarding all the class drivers available under USB. I wanted to know, at the code level, what is there? I tried to search, couldn’t find anything.

  24. Hi anil,
    i tried the same code discussed above,one problem i faced is, my driver didnt get probed automatically even after removing usb_storage. then one more thing i found is, im not able to find the file modules.usbmap in the standard directory for modules..can you suggest me some solution.

      • Hi Sir,

        USB connect/disconnect notification in linux

        If any usb mass storage device connected to my board(beagle bone black reff and kernel 3.14) will get asynchronous notifications to application

        how to notify an application when a usb flash drive gets connected and which way follow in linux to get usb device added notifications to application, please could you help me on this.

  25. Hello Sir,
    I am running this module on Ubuntu 14.10, kernel version-3.19.3 and i am unable to unload the usb_storage, it says “it is currently used by uas” and when i am trying to remove the uas is says “operation not permitted” and also there is no file named modules.usbmap in modules directory to comment default loading of usb_register.

  26. Hi Anil,
    I followed the steps above, but still the host usb-storage driver get loaded automatically when I plug-in a usb mass storage device, even when I have removed it using “rmmod usb-storage”. My driver’s name is “usb2”.
    Here’s a snpashot :

    root@esse-VPCEL25EN:/user_dir/drivers/usb# lsmod | grep usb
    usb_storage 62209 0
    usb2 12612 0
    btusb 32412 0
    bluetooth 391196 23 bnep,ath3k,btusb,rfcomm
    root@esse-VPCEL25EN:/user_dir/drivers/usb# rmmod usb-storage
    root@esse-VPCEL25EN:/user_dir/drivers/usb# lsmod | grep usb
    usb2 12612 0
    btusb 32412 0
    bluetooth 391196 23 bnep,ath3k,btusb,rfcomm

    root@esse-VPCEL25EN:/user_dir/drivers/usb# dmesg

    /* after plugging in the usb */
    root@esse-VPCEL25EN:/user_dir/drivers/usb# dmesg
    [13805.894519] usbcore: registered new interface driver pen_driver
    [13833.300733] usb 1-5: new high-speed USB device number 10 using ehci-pci
    [13833.439499] usb 1-5: New USB device found, idVendor=0951, idProduct=1643
    [13833.439516] usb 1-5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    [13833.439525] usb 1-5: Product: DataTraveler G3
    [13833.439533] usb 1-5: Manufacturer: Kingston
    [13833.439540] usb 1-5: SerialNumber: 001CC0EC34E1BBA0471500BF
    [13833.468695] usb-storage 1-5:1.0: USB Mass Storage device detected
    [13833.468884] scsi10 : usb-storage 1-5:1.0
    [13833.469031] usbcore: registered new interface driver usb-storage
    [13834.494740] scsi 10:0:0:0: Direct-Access Kingston DataTraveler G3 PMAP PQ: 0 ANSI: 0 CCS
    [13834.498128] sd 10:0:0:0: Attached scsi generic sg2 type 0
    [13835.269521] sd 10:0:0:0: [sdb] 15646720 512-byte logical blocks: (8.01 GB/7.46 GiB)
    [13835.271614] sd 10:0:0:0: [sdb] Write Protect is off
    [13835.271635] sd 10:0:0:0: [sdb] Mode Sense: 03 41 00 00
    [13835.273844] sd 10:0:0:0: [sdb] No Caching mode page found
    [13835.273866] sd 10:0:0:0: [sdb] Assuming drive cache: write through
    [13835.292591] sd 10:0:0:0: [sdb] No Caching mode page found
    [13835.292611] sd 10:0:0:0: [sdb] Assuming drive cache: write through
    [13835.309357] sdb: sdb1
    [13835.323634] sd 10:0:0:0: [sdb] No Caching mode page found
    [13835.323649] sd 10:0:0:0: [sdb] Assuming drive cache: write through
    [13835.323656] sd 10:0:0:0: [sdb] Attached SCSI removable disk
    [13835.590537] FAT-fs (sdb1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
    [13836.094803] systemd-hostnamed[1297]: Warning: nss-myhostname is not installed. Changing the local hostname might make it unresolveable. Please install nss-myhostname!

    Any help is appreciated.

  27. solved it myself, sorry for bothering with such a long post. I wasn’t changing the the device and the vendor id.

  28. I am getting error while creating .ko file …The make isnt getting completed.

    make -C /lib/modules/4.4.0-45-generic/build SUBDIRS=/home/nikhil modules
    make[1]: Entering directory ‘/usr/src/linux-headers-4.4.0-45-generic’
    CC [M] /home/nikhil/pen_register.o
    Building modules, stage 2.
    MODPOST 1 modules
    FATAL: modpost: GPL-incompatible module pen_register.ko uses GPL-only symbol ‘usb_deregister’
    scripts/Makefile.modpost:91: recipe for target ‘__modpost’ failed
    make[2]: *** [__modpost] Error 1
    Makefile:1406: recipe for target ‘modules’ failed
    make[1]: *** [modules] Error 2
    make[1]: Leaving directory ‘/usr/src/linux-headers-4.4.0-45-generic’
    Makefile:7: recipe for target ‘all’ failed
    make: *** [all] Error 2

  29. hello all
    i have to build a driver according to the below problem statement:
    A process “Pause-Restart” mechanism allows a user to pause an existing process, save its state to disk, copy that state to another machine, and restart that process on the new machine. Build a Linux device driver that implements the process “Pause-Restart” mechanism. Be careful to state your assumptions, if any, about the nature of processes that can be paused and restarted using your mechanism.

    can any body please share the codes for this standard problem of device driver
    please mail it to me at

  30. Hello,
    I am able to remove usb_storage module successfully. But even after replugging the usb stick it takes usb_storage as default driver and not pen_register. Please let me know what am I doing wrong.

  31. Make sure to load the pen_register after removing the usb_storage. Also, ensure that you have updated the vendor & product id of your pen drive in the pen_register driver.


Please enter your comment!
Please enter your name here