I would like to emulate an USB from an image file.

I am using Centos7 with the Kernel 4.11.7 installed through kernel-ml and kernel-ml-devel elrepo 4.11.7-1.el7.elrepo.x86_64 (actually I tried with 3.10.* 4.10.* 4.11.1 too)

We have 2 solutions:

  1. with insmod

    sudo insmod /link/to/g_mass_storage.ko file=/tmp/filebin.img stall=0 removable=y

In dmesg: udc-core: couldn't find an available UDC - added [g_mass_storage] to list of pending drivers

  1. with modprobe

    $ sudo modprobe g_mass_storage file=/tmp/testusb.img stall=0 removable=y modprobe: FATAL: Module g_mass_storage not found. Nothing in dmesg.

  2. I have also tried with dummy_hcd:

    $ sudo modprobe dummy_hcd modprobe: FATAL: Module dummy_hcd not found.

How can I fix this problem ?

I tried many things like recompiling the Kernel 4.11.1 by enabling everything with gadget etc...

/usr/src/kernels/4.11.7-1.el7.elrepo.x86_64 $ cat .config | grep CONFIG_USB_DUMMY_HCD

Result: After compiling the kernel, I was able to modprobe dummy_hcd and to emulate an usb with a binary file.

1 Answer 1


You need the dummy_hcd dummy (loopback) host controller device. The gadget USB drivers are meant for real USB hardware, and on normal PCs this hardware doesn't exist. The loopback controller provides both the framework for the gadget controller, and a USB host controller to access them. So:

$ sudo modprobe dummy_hcd

gives you a new root hub

$ lsusb
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Now you can modprobe the gadget driver

$ sudo modprobe g_mass_storage file=/path/to/backing_file idVendor=0x1d6b idProduct=0x0104 iManufacturer=Myself iProduct=VirtualBlockDevice iSerialNumber=123

and it will show up under the new root hub

$ lsusb
Bus 005 Device 002: ID 0525:a4a5 Netchip Technology, Inc. Pocketbook Pro 903
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Note that you don't need to simulate a USB mass storage device if you are just interested in the contents of the file, you can mount that directly (via the loop device, but that happens automatically).

  • 2
    I forgot to say I tried dummy_hcd too. But : modprobe: FATAL: Module dummy_hcd not found. I don't know why I don't have this module.
    – None
    Commented Jun 27, 2017 at 6:38
  • Verify that CONFIG_USB_DUMMY_HCD=m, and set and recompile if it isn't.
    – dirkt
    Commented Jun 27, 2017 at 6:41
  • It's not, Im gonna recompile. I'll let you keep informed. Thanks.
    – None
    Commented Jun 27, 2017 at 6:50
  • It's working, thank you ! Btw how to "eject" the usb without rebooting ?
    – None
    Commented Jun 27, 2017 at 23:24
  • 2
    sudo modprobe -r g_mass_storage works.
    – None
    Commented Jun 28, 2017 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .