Northern Mike
Posts: 51
Joined: Mon Oct 31, 2016 11:41 am

HotSwap USB drives

Wed Mar 01, 2017 1:26 pm

Very simple question.... How do I get the PI to acknowledge when a drive is plugged into a USB port (powered hub)?

Here is the setup to explain my simple question;
- Pi3 running 2 external HDDs (sda and sdb) on a 4 port powered USB hub.
- Portable drive plugged into spare USB (on hub) port in order to copy large amounts of data to existing USB HDD (much faster than over the network when dealing with TB's worth of data).
- Use http/php and eventually gpio buttons to initiate mount, bulk copy and dismount drive.

Currently, even using a command prompt over ssh, fdisk -l is unable to locate /dev/sdc or similar when I connect the drive.
Rebooting the pi with the drive connected is not a option.

What am I missing?

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 6138
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: HotSwap USB drives

Wed Mar 01, 2017 1:55 pm

Northern Mike wrote:Very simple question.... How do I get the PI to acknowledge when a drive is plugged into a USB port (powered hub)?
Here is the setup to explain my simple question;
- Pi3 running 2 external HDDs (sda and sdb) on a 4 port powered USB hub.
- Portable drive plugged into spare USB (on hub) port in order to copy large amounts of data to existing USB HDD (much faster than over the network when dealing with TB's worth of data).
- Use http/php and eventually gpio buttons to initiate mount, bulk copy and dismount drive.
Currently, even using a command prompt over ssh, fdisk -l is unable to locate /dev/sdc or similar when I connect the drive.
Rebooting the pi with the drive connected is not a option.
What am I missing?
If you're not using the Pi headless are the auto-detect/auto-mount options enabled in the (GUI) file manager?
If you are (always) running headless, and can identify the portable drive (or drives) uuid or "label" then, maybe, extra entry/entries in fstab** is/are what you could use.
Trev.
** Something like my old (pre-automount capability) discussion here:
http://www.cpmspectrepi.uk/raspberry_pi ... ticks.html
(hopefully to be updated with the file manager auto-mount info soon - PiZeroW page has priority at the mo. :) )
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's & P400. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

Northern Mike
Posts: 51
Joined: Mon Oct 31, 2016 11:41 am

Re: HotSwap USB drives

Wed Mar 01, 2017 3:18 pm

Almost all my PIs are headless.
The make/model of drive (external HDD or jumpdrive) could be one of many.

To give you a mental image of what I have, the production PIs in the house are in a locked cabinet. There is a USB port (USB extension) on the shelf beside the cabinet. You walk up, plug your drive into the port, hit the "Make it GO" button (GPIO pins), and it dumps the contents of the drive to a folder on the PI (mounting and unmounting the drive in the script activated by the GPIO button).

The road block right now is simply, can't find a drive plugged into a USB port if the PI is already running.

User avatar
DougieLawson
Posts: 41046
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: HotSwap USB drives

Wed Mar 01, 2017 3:20 pm

You can trigger short running programs from a udev rule.

Code: Select all

KERNEL=="sd*", SUBSYSTEMS=="scsi", DRIVERS=="sd", SYMLINK+="usb_stick",  RUN+="/usr/local/bin/usb_stick_drive $kernel'"
That one also creates a /dev/usb_stick when one is plugged in.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

fruitoftheloom
Posts: 26283
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: HotSwap USB drives

Wed Mar 01, 2017 3:28 pm

Have you considered power issues powering many drives ???
The information is out there....you just have to let it in.

My other Linux machines: ChromeBox
https://www.aliexpress.com/item/32966393971.html
& Stone Desktop Intel CoreDuo circa 2010

Northern Mike
Posts: 51
Joined: Mon Oct 31, 2016 11:41 am

Re: HotSwap USB drives

Wed Mar 01, 2017 5:08 pm

Power shouldn't be an issue.
Pi is on 2.5A supply
USB hub is 2.1A
Existing external drives are desktop drives with own power supplies.
No other USB devices attached directly to the PI other then the HUB and wifi and bluetooth is off.

User avatar
jojopi
Posts: 3426
Joined: Tue Oct 11, 2011 8:38 pm

Re: HotSwap USB drives

Wed Mar 01, 2017 7:19 pm

Northern Mike wrote:The road block right now is simply, can't find a drive plugged into a USB port if the PI is already running.
You are not seeing the correct behaviour. Linux should detect USB drives when they are plugged in; there is no need to reboot. (The drive may not be automatically mounted, but it should certainly be assigned a /dev/sdX device node and have its partition table inspected.)

Try running "dmesg" to view the kernel messages after plugging the drive in. Are there any errors, or no new messages at all?

Northern Mike
Posts: 51
Joined: Mon Oct 31, 2016 11:41 am

Re: HotSwap USB drives

Thu Mar 02, 2017 1:15 am

jojopi wrote:
Northern Mike wrote:The road block right now is simply, can't find a drive plugged into a USB port if the PI is already running.
You are not seeing the correct behaviour. Linux should detect USB drives when they are plugged in; there is no need to reboot. (The drive may not be automatically mounted, but it should certainly be assigned a /dev/sdX device node and have its partition table inspected.)

Try running "dmesg" to view the kernel messages after plugging the drive in. Are there any errors, or no new messages at all?
I will give that a try in a couple hours. Thanks

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: HotSwap USB drives

Thu Mar 02, 2017 2:39 am

What are the USB IDs of the drives? There are faulty USB interface chips that do exactly what you describe. They mount the first time then fail the next time. I have a USB disk enclosure with a faulty chip. They are common in early and cheap USB 3 devices. I call them USB 2.9. They usually work in Windows but nowhere else because they have an incomplete USB 3 interface. The lsusb command will display the USB ID when the device is first plugged in. For subsequent use, lsusb will not see the device. syslog might contain a message.

Return to “Beginners”