Configure Linux system as an OTG device

I’m wondering if it’s possible to make a Linux system appear like an USB peripheral.

Like smartphones which can switch from master to slave depending on the device they are connected to, I would like to know if it’s possible to have the same behavior with a Linux system.

For example, I have an embedded Linux on a card with usb connectors, when I plug a usb key to this card, the usb key is detected as a slave device and mounted on the file system.
Now if I connect my card to my computer I would like to have it recognized as usb slave device too.

Do you think it’s possible?

I found a similar question asked but not answered Use a Linux directory as a USB-OTG device to an Android phone?

I finaly chose to try to configure the system as MTP device instead of presenting it as mass storage for those reasons :

  • Protect against concurrent file access
  • Protect system against crash or corruption due to concurrent file access or bad mounting/unmounting
  • Possibility to expose root file system without unmounting or stopping it
  • Possibility to share multiple devices

As I have some problems configuring it I oppened a new question here for those interested.

Asked By: Arkaik


Yes, you can, but it is not easy. You need at least a little work with it.

Working as an USB slave is supported in Linux since around the 2.4 or 2.6 times. You have to find a compatible chip, then a device having it, and then buying one, somewhere (typically, to rent it on the Internet).

Specifically for USB gadgets, there is support for peripherial devices and also for block devices.

Your Google search: Linux USB gadget . You may also have a little dig task in the kernel sources, this slave-side mode is likely not included in most distribution kernels, so you will have to recompile it.

Here is an old, but still actual reference about this. Other may be useful answer.

Extension by @Arkaik:

A userspace MTP responder is available uMTP-Responder, it’s easy to implement and relies on either gadgetfs or functionfs.

Answered By: peterh
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.