My purpose is to emulate an USB device locally in a Linux environment. I mean that I want to “mount” a local backing storage file (made with dd) as an USB device inside the root user workspace.
After a Google search, I found the Linux USB Gadget API and the Mass Storage Function : http://www.linux-usb.org/gadget/file_storage.html. But it's not crystal clear : it seems that it can act only as client/server with USB connection between a Linux host and another computer (Linux, Windows or Mac).
I started to set a POC on a Debian Jessie with customized 3.16.7 kernel, but I’m facing the following error "insmod: can't insert 'g_mass_storage.ko': No such device" when I try to load the g_mass_storage module.
Has anyone experienced this kind of stuff ?
Thanks.
Mathieu
Best Answer
Tom Yan,
Thanks for your useful answer. I successfuly loaded the dummy-hcd module. Then, modprobe of the g_mass_storage module :
modprobe g_mass_storage file=/root/myUSBStorage/mass_storage.img stall=0 removable=y iSerialNumber=1234567890
I have now the following dmesg :
FYI, I had to create the partition table and filesystem inside the emulation. I can now successfuly mount the emulated media.
Mathieu