Can a USB hub be used to access a drive from two devices?

30

So let's say, I get a USB hub, and I plug it into a hard drive for example (as in, I plug the USB cable that typically goes in a PC, into a hard drive) and then I plug for example two PCs into it (as in, I plug it into the part where there are multiple USB slots), can the two PCs both read and write data to it?

human

Posted 2019-07-02T17:38:51.477

Reputation: 311

Not an answer, but SCSI could do this, with some caveats. From 2004 https://criggie.org.nz/scsi/

– Criggie – 2019-07-05T13:09:36.973

Answers

67

No. USB by design can only have a single host (one PC).

What you can get is a kind of "switch", often combined with a USB hub. Then you can connect two PCs to it and manually switch between them. But only one PC can be the USB host at a time.

If you want to share a harddisk between two PCs, then there are other ways to do that (e.g. NAS = network attached storage).

dirkt

Posted 2019-07-02T17:38:51.477

Reputation: 11 627

11If you want to share a USB mass storage device with multiple devices, connect it to a router with the ability to share a USB storage device connected to it, allowing access to the storage. – Ramhound – 2019-07-02T19:10:30.010

As an alternative to having a full NAS, some ISP-provided routers have an USB port to act as a NAS, to share the contents in the network. This is NOT a very good option, as one can just buy a Raspberry Pi for relativelly cheap, and use it as a low-powered Linux NAS. – Ismael Miguel – 2019-07-03T15:27:31.713

It would be theoretically possible to create a device which allowed both computers to access the drive at the same time, right? Each computer would see itself as the host to a drive, but the device in the middle would be parsing the commands sent, reinterpreting them to send to the real drive, and parsing the response on the way back. I don't know if such a device exists -- I'd be surprised if it did, to be honest -- but is there any technical limitation on its existence, or do people just not make them? – Fund Monica's Lawsuit – 2019-07-03T19:34:15.157

8@NicHartley: The USB protocol is stateful, so not easily: The intermediate device would have to remember various states of the devices, and either do workarounds if the two hosts expect them to be in different states, or just plainly fail in this case. It would also have to decide which host to send back the answer to. For simple USB devices, it could probably be made to work, and for USB storage devices probably too. However, just for USB storage devices, it would probably be easier for the intermediate device to simulate two distinct USB slaves, and pass on the SCSI commands to the drive. – dirkt – 2019-07-03T20:00:20.993

@dirkt I was specifically thinking about USB storage, yes, not arbitrary USB. That... doesn't actually sound as bad as I was thinking. Also, I didn't know what SCSI was until just now. Thanks! – Fund Monica's Lawsuit – 2019-07-03T20:02:16.500

3@NicHartley The other limitations are the drives' native command sets and filesystems are generally not designed to allow simultaneous access from multiple hosts, even if you get past the USB hurdle. You'd have to start/end a new session every time, at which point you're little better than just manually switching the drive (there'll be a huge latency while waiting for the switch from the other host). – Bob – 2019-07-04T01:12:16.680

12Not only would the SCSI session be a problem. OSes aggressively cache access to the file system, for two OSes to have concurrent access to the same block device/filesystem, they would need to synchronize access to the file system metadata, which would be insanely slow, if at all possible. – Aron – 2019-07-04T01:38:39.703

3@Aron: Actually, that's definitely possible and not too horrendous. It's been used in High-Availability systems so that a pair of computers would share the same disks. This allowed for uninterrupted operation even if one of the pair crashed.But this requires OS cooperation. – MSalters – 2019-07-04T07:10:20.573

26

No. You cannot share USB devices between different hosts. USB switches allow you to disconnect USB devices from one computer and connect them to another by pressing a button. The primary use is (most probably) to connect a keyboard-mouse-set to two PCs and switch as needed.

But even if USB would allow the setup you have in mind, you'll run into trouble. Most filesystems will be damaged/become inconsistent/corrupt if data is written simultaneously by two computers. Please don't confuse this with special protocols like Samba/Windows Shares, NFS etc. In these cases, only the computer that shares the data will continue to read and write to disk for the other computers. So although multiple computers have access, a single computer controls all read and write accesses.

If you want to share a harddisk between two PCs you can use sharing options in the OS of one of the PCs (e.g., Windows Shares, NFS). Moreover, today's home routers and NAS allow to easily share attached storage in the network.

user3422070

Posted 2019-07-02T17:38:51.477

Reputation: 501

5

It's physically impossible to plug a hub into two PCs using standard USB cables. Hubs and PCs both have A-type sockets on downstream ports, and there are no standard cables connecting two A-sockets together.

The same issue will arise when you'll try to connect your hub's upstream port to a hard drive, as they will both have B-type sockets . There are exceptions to this case, as upstream ports are allowed to have AB or C-type sockets, but it won't work nevertheless, as USB is dysfunctional without a host on the bus.

Dmitry Grigoryev

Posted 2019-07-02T17:38:51.477

Reputation: 7 505

Male A-male A cables are readily available, despite not being covered in the standard. I have one somewhere, I think it came with a SATA adapter. – Pete Kirkham – 2019-07-06T01:12:29.220

1@PeteKirkham That's why I say "there are no standard cables". – Dmitry Grigoryev – 2019-07-08T08:12:34.433

5

No, you cannot, but there are other similar solutions.

If you were to set up a NAS (Network Attached Storage) on the network, then both PC's could read off of the network storage device. This would work over the entire network, as it is connected to the network. You then could even map the drive or subdirectory on the USB as a drive, if you want.

Alternately, you can plug the USB into another PC and map one PC read another PC by manually setting ip addreses (if they are not already mapped), set the sharing settings, and you connect them with via ethernet, but I'm pretty sure that you can't automatically access external drives (anything plugged into USB) using this method unless they are specifically mapped. In this case the drive would be plugged into only 1 computer and the other PC would read the drive through the other PC, over ethernet.

rtyocum

Posted 2019-07-02T17:38:51.477

Reputation: 139

2

It should be possible using USB-C that supports the Thunderbolt interface:

Apple’s Thunderbolt can support up to six devices in a daisy chain, on a single port. So an example of this would be if your MacBook Pro (device 1) is connected to an iMac (device 2), which is connected to an external hard drive (device 3), which is connected to another external hard drive (device 4), which is connected to RAID storage (device 5), which is connected to an Apple Thunderbolt Display (device 6).

In this daisy chain, your MacBook Pro and your iMac will be able to read the data from all the hard drives and the RAID, as well as talk to each other. Pretty cool, huh?

Cees Timmerman

Posted 2019-07-02T17:38:51.477

Reputation: 1 240

1

I have a KVM that is able to share a single USB2 port between up to 4 computers along with the keyboard mouse.

You can drop a file from a Windows PC onto it and read it from a Mac connected to the same KVM. It's pretty cool.

Cost about $100 on Amazon for the 4Port version with 4K support. I have a MacMini + Windows + RaspberryPI + Nintendo Switch connected.

The trick is that normal KVM's disconnect the ports as you switch between hosts, but this model keeps the ports alive so the O/S doesn't lose / rediscover the keyboard/mouse/usb each time you switch.

I've tested the port with a USB2 stick, PS4 controller and a Logitech mechanical keyboard which needed more power than the dedicated keyboard usb port on the KVM.

Don't want to break any advertising rules, but if you google the product, it's red.

My first answer, so YMMV.

Ian Stoffberg

Posted 2019-07-02T17:38:51.477

Reputation: 27

Out of curiosity: What happens if you plug a USB harddisk or USB stick into this port (to be safe, not one with valuable data)? Will it be detected on all four computers? What happens if you try to write to the same file on all four computers at the same time, every time with different contents? Or do you have to manually switch? In this case, what happens when you read/write from a computer where it hasn't been switched to? – dirkt – 2019-07-04T13:24:04.317

1What does KVM mean in this context? – Marc.2377 – 2019-07-05T02:01:41.140

1Sorry if I was unclear. KVM in this case is "keyboard, video, mouse" switch. The initials have since become more commonly reused for the linux vm technology. The original KVM was a rackmount thing to allow multiple servers to share the same mouse/keyboard and monitor. I use one to share my limited space between a pc, mac + random smaller boxes. classic psone, c64 mini, raspberry pi, psmini, etc. – Ian Stoffberg – 2019-07-05T15:51:06.910

@dirkt It looks like you can't write simultaneously. I plugged in a usb drive on the windows pc and when I went to the mac it was there. I could read/write on either machine, but not at the same time. it seems like the switch preserves a connected state that a drive is present, but doesn't really permit IO. The switch didn't power up my external 2.5" drive. If I get a 3.5" one with external power, I'll give that a try sometime. – Ian Stoffberg – 2019-07-05T16:07:43.260

So it automatically switches, after some kind of timeout? When you try to write on the "wrong" machine, you don't get an error message? Interesting solution. – dirkt – 2019-07-05T17:27:34.443

Well, the moment you switch to the second pc, your monitor swaps to that O/S. When you return to the first, there will be a error. I think hitting retry worked once, but I wouldn't trust the file. – Ian Stoffberg – 2019-07-05T19:34:26.800

Note that you're allowed to post a link to amazon and what not. What is considered spammy is (1) posting links to products not related to the question and (2) posting links to your own products without disclosing your affiliation. – Dmitry Grigoryev – 2019-07-08T08:10:52.847