11

I have a use case where I want a virtual hard disk (particularly, on a freeNAS installation) to act as a USB mass storage peripheral for an external device, such as a phone or video game console. My idea is to do away with all the USB storage devices in my setup and move to virtualizing them as part of my NAS and have them be a painless part of my regular backup routine.

I realize that USB is not a symmetric setup, so I'd need a slave port on my NAS. I also realize this is something done on the actual USB controller card, so there's no real way to just "use" a USB port as a slave port.

My question is, is there any sort of method of emulation or conversion, through hardware, software, or some combination thereof, to achieve this functionality? It seems like I can use the linux usb-gadget api in mass storage mode if I can get a slave port to work. However, I can't seem to find any sort of expansion card with USB slave or USB-OTG support, and I know of no other hardware solutions that I could use in the middle of this setup.

Does anyone have any pointers?

Edit: Would a device like this work?

http://www1.plxtech.com/products/usbcontrollers/usb3382

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
AJ Quad
  • 111

2 Answers2

3

Look into the "Mass Storage Gadget" documentation. This might be one place to start: https://www.kernel.org/doc/html/latest/usb/mass-storage.html

You should not need anything too far out of the ordinary for hardware in the computer that is hosting the virtual USB devices. I'm looking into this as well and it appears that most every USB-C controller on the market has the ability to enter a USB device (as opposed to host) mode. Apple computers with USB-C ports have the right kind of chip in order to support "Target Disk Mode". This is demonstrated by the "hackintosh" (non-Apple computers running macOS) crowd that such chips are common. A hackintosh cannot enter Target Disk Mode because this function is not part of the operating system, Apple put this function in the firmware as this allows a computer to go in this mode for repairing a non-booting computer.

I don't have too much to add here. About all I know so far is that there is a project called "USB gadget" that is developing this function of Linux computers acting as virtual USB devices, and that I know that the hardware needed to make this work is fairly common now that more and more laptops are using USB-C as a power input port. For USB Power Delivery to work there has to be a "host" supplying the power and a "device" receiving power. Every USB-PD power brick is a USB host that will negotiate power delivery to any device connected, devices such as a laptop using USB-C as a power input port.

MacGuffin
  • 416
1

If a linux based OS would be an option, maybe you could take a look at LIO with usb frontend:

"The USB Gadget fabric module enables Linux to export local storage devices via the Universal Serial Bus (USB), so that other systems can mount them as an ordinary storage device. " (https://en.wikipedia.org/wiki/LIO_(SCSI_target))

What I can't tell you by now is:

  1. Which cabling is required: Please don't make a simple 1 to 1 connection as this could kill your machine!
  2. How to configure this for a particular USB port

I'll do further research when I have more time!

EDIT: I tried and I failed. Sounds much easier than it might to be. Maybe someone else has more information about that?

B-LechCode
  • 308
  • 1
  • 2
  • 10
  • 1
    USB C connector would be a simple 1 to 1. They scrapped host / client in that standard to allow two similar devices to connect. – Philip Couling Jan 03 '20 at 13:24
  • From @PhilipCouling above: "USB C connector would be a simple 1 to 1." This is true that USB-C can provide 1 to 1 but this "They scrapped host / client in that standard to allow two similar devices to connect." is not necessarily true. As I understand it USB is still host/client but the state of either device can switch based on a handing over who is host to the other end of the connection. Whether using LIO-target or USB-gadget for the communications the computer acting as a mass storage device will need to be capable of device mode. Laptops that charge by USB-C must support device mode. – MacGuffin Sep 01 '20 at 22:07