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?
Not an answer, but SCSI could do this, with some caveats. From 2004 criggie.org.nz/scsi– CriggieJul 5, 2019 at 13:09
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).
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.– RamhoundJul 2, 2019 at 19:10
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. Jul 3, 2019 at 20:00
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).– BobJul 4, 2019 at 1:12
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.– AronJul 4, 2019 at 1:38
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.– MSaltersJul 4, 2019 at 7:10
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.
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.
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. Jul 6, 2019 at 1:12
1@PeteKirkham That's why I say "there are no standard cables". Jul 8, 2019 at 8:12
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.
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.
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? Jul 4, 2019 at 13:24
1What does KVM mean in this context? Jul 5, 2019 at 2:01
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. Jul 5, 2019 at 15:51
@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. Jul 5, 2019 at 16:07
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. Jul 5, 2019 at 17:27
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?