1

I have an power-managed USB drive that powers down when not in use, and wakes up automatically when accessed. It's used as a backup drive from a root script which mounts it when necessary. Sometimes the mount command fails because I suspect that it doesn't always wait for the drive to spin up (although this is a guess).

I'd like to put a command in the script that will probe the drive and cause it to spin up so it's ready when the mount is issued. I've tried lsusb but that doesn't work, and file system commands don't either as it's not mounted yet. fdisk -l does appear to work, but is there something better I could use?

UPDATE

As suggested by @vidarlo I checked out dmesg after the next time the mount failed:

[Sun Aug 5 01:30:04 2018] usb 1-1: reset high-speed USB device number 2 using xhci_hcd [Sun Aug 5 01:30:04 2018] usb 1-1: device firmware changed [Sun Aug 5 01:30:04 2018] usb 1-1: USB disconnect, device number 2 [Sun Aug 5 01:30:04 2018] sd 2:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK [Sun Aug 5 01:30:04 2018] sd 2:0:0:0: [sdb] tag#0 CDB: Read(10) 28 00 00 00 00 41 00 00 02 00 [Sun Aug 5 01:30:04 2018] print_req_error: I/O error, dev sdb, sector 65 [Sun Aug 5 01:30:04 2018] EXT4-fs (sdb1): unable to read superblock [Sun Aug 5 01:30:04 2018] usb 1-1: new high-speed USB device number 4 using xhci_hcd [Sun Aug 5 01:30:05 2018] usb 1-1: New USB device found, idVendor=152d, idProduct=2339 [Sun Aug 5 01:30:05 2018] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=5 [Sun Aug 5 01:30:05 2018] usb 1-1: Product: USB to ATA/ATAPI Bridge [Sun Aug 5 01:30:05 2018] usb 1-1: Manufacturer: JMicron [Sun Aug 5 01:30:05 2018] usb 1-1: SerialNumber: 152D203380B6 [Sun Aug 5 01:30:05 2018] usb-storage 1-1:1.0: USB Mass Storage device detected [Sun Aug 5 01:30:05 2018] scsi host2: usb-storage 1-1:1.0 [Sun Aug 5 01:30:07 2018] scsi 2:0:0:0: Direct-Access SAMSUNG HD321KJ PQ: 0 ANSI: 2 CCS [Sun Aug 5 01:30:07 2018] sd 2:0:0:0: Attached scsi generic sg1 type 0 [Sun Aug 5 01:30:07 2018] sd 2:0:0:0: [sdb] 625142448 512-byte logical blocks: (320 GB/298 GiB) [Sun Aug 5 01:30:07 2018] sd 2:0:0:0: [sdb] Write Protect is off [Sun Aug 5 01:30:07 2018] sd 2:0:0:0: [sdb] Mode Sense: 00 38 00 00 [Sun Aug 5 01:30:07 2018] sd 2:0:0:0: [sdb] Asking for cache data failed [Sun Aug 5 01:30:07 2018] sd 2:0:0:0: [sdb] Assuming drive cache: write through [Sun Aug 5 01:30:08 2018] sdb: sdb1 [Sun Aug 5 01:30:08 2018] sd 2:0:0:0: [sdb] Attached SCSI disk

Regardless of the error the drive appears to end up becoming available. I believe that if I'd rerun the backup script at this point it would have worked.

2 Answers 2

2

Any read should trigger it:

sudo dd if=/dev/sdx1 bs=1k count=1 of=/dev/zero

will attempt to read from it and should wake it up.

Note that I somewhat doubt that this is the reason mount does not work. Do you get any error messages? What does dmesg | tail -n 25 show after a failed mount attempt?

7
  • I'm not assuming I know the device name, so I couldn't use that. However, if you doubt my guess at the reason for the error (yes, mea culpa, I should have done this already) then perhaps I should just wait for it to happen again and investigate properly.
    – ceperman
    Jul 30, 2018 at 11:47
  • 1
    Use /dev/disk-by-uuid/UUID in place of /dev/sdx1 if you go by UUID when mounting.
    – vidarlo
    Jul 30, 2018 at 11:50
  • 1
    Write unwanted output to /dev/null, not /dev/zero.
    – waltinator
    Jul 30, 2018 at 12:48
  • @waltinator Why? Both accept and discard any input.
    – vidarlo
    Jul 30, 2018 at 13:01
  • 3
    /dev/null is designed to discard any input and produce EOF as output. /dev/zero is designed to discard any input and produce NULL as output. For reading it makes a difference. For discarding data it makes zero (pun intended) difference.
    – vidarlo
    Jul 30, 2018 at 13:16
1

Sleeping power-managed USB drive

Your power-managed USB drive powers down when not in use, and wakes up automatically when accessed, but sometimes too slowly. In this case it it neither unmounted nor ejected, and I think the command

sudo partprobe

should wake it up.


Sleep

Not in this case but in some related cases

sleep 5

would help by giving the operating system 5 seconds to get ready for the next command (the backup).

Unmount

If you have unmounted all partitions on a USB drive with sudo umount ..., it is still powered on and connected to a /dev/sdx (where x is the drive letter, for example b or c), and you can mount the partitions on it again with sudo mount ....

Eject

If you have ejected a USB pendrive, which is the typical action from the file browser, when you click on the eject icon, all partitions on it are unmounted and it is powered off and no longer connected to /dev/sdx. I means that you cannot wake it up with any command by pointing to /dev/sdx.

Unplug and plug in again

When you unplug and plug an ejected USB drive in again, it will be powered on and connected to /dev/sdx.

Warning: never unplug a USB drive that has a mounted partition

Never unplug a USB drive, that has a mounted partition, because there is a high risk, that the file system in the partition will be corrupted.

So you must unmount or eject (or shutdown the computer) before unplugging.

2
  • partprobe looks useful thanks (actually partprobe -d better in my case) and is simple to use, although perhaps no more so than fdisk -l > /dev/null. Since the command doesn't complete until the disk is spun up and read I don't see why the sleep command is needed.
    – ceperman
    Jul 30, 2018 at 16:51
  • @ceperman, I see, and I will modify the answer (put less emphasis on sleep).
    – sudodus
    Jul 30, 2018 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.