Waking up an external Hard Drive

I have an external hard drive that I want to back up to once a day. The problem is that the unit it plugs into shuts down after non-use for a while and then I can’t mount it.

My understanding is that if I know the port I could perhaps try to read from or write to the port and that could perhaps wake it up.

The problem is I’m not sure how to test this as it doesn’t map to a /dev/ttyUSBn device which some articles make suggestions on how to do this, probably because being a USB3 it’s a PCI SCISI device, well, that’s my guess. When I plug in the external USB cable while running

udevadm monitor

I get the following:

KERNEL[951330.481568] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3 (usb)
KERNEL[951330.481701] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0 (usb)
KERNEL[951330.482018] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14 (scsi)
KERNEL[951330.482039] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/scsi_host/host14 (scsi_host)
KERNEL[951330.555049] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0 (scsi)
KERNEL[951330.555082] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0 (scsi)
KERNEL[951330.555113] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/scsi_disk/14:0:0:0 (scsi_disk)
KERNEL[951330.555134] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/scsi_device/14:0:0:0 (scsi_device)
KERNEL[951330.555183] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/scsi_generic/sg10 (scsi_generic)
KERNEL[951330.555229] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/bsg/14:0:0:0 (bsg)
KERNEL[951330.556964] add      /devices/virtual/bdi/8:128 (bdi)
UDEV  [951330.557581] add      /devices/virtual/bdi/8:128 (bdi)
UDEV  [951330.560146] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3 (usb)
UDEV  [951330.561828] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0 (usb)
UDEV  [951330.562289] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14 (scsi)
UDEV  [951330.562805] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/scsi_host/host14 (scsi_host)
UDEV  [951330.562843] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0 (scsi)
UDEV  [951330.563300] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0 (scsi)
UDEV  [951330.564242] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/scsi_disk/14:0:0:0 (scsi_disk)
UDEV  [951330.564260] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/scsi_device/14:0:0:0 (scsi_device)
UDEV  [951330.564819] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/scsi_generic/sg10 (scsi_generic)
UDEV  [951330.564841] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/bsg/14:0:0:0 (bsg)
KERNEL[951346.243158] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/block/sdi (block)
KERNEL[951346.243183] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/block/sdi/sdi1 (block)
UDEV  [951346.385630] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/block/sdi (block)
UDEV  [951346.479448] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/block/sdi/sdi1 (block)

Does anyone have an idea one what I could do to hopefully wake up the external device so that it can be mounted?

Mounting the HDD is easy with

udisksctl

once it has powered up and can be found.

You could try installing the package “sdparm” and then, use either “sdparm --command=load” or “sdparm --command=start” to attempt to spin up the USB HDD.

The Linux Kernel documentation for this topic is here: <https://www.kernel.org/doc/html/v4.16/driver-api/usb/power-management.html>.
Take note of the section “Changing the default idle-delay time”:

The default autosuspend idle-delay time (in seconds) is controlled by a module parameter in usbcore. You can specify the value when usbcore is loaded. For example, to set it to 5 seconds instead of 2 you would do:

modprobe usbcore autosuspend=5

Equivalently, you could add to a configuration file in /etc/modprobe.d a line saying:

options usbcore autosuspend=5

I think this will work with the start command. Would you happen to know how to get the device identification to use with this command?

I suspect that the device is one of the /dev/ttySnn but I don’t know how to determine which one, if it’s those, it might be somewhere else. Below is my /dev/ directory… actually, looking around the Internet it might be an sg device - still trying to figure it out.

ls /dev/
.blkid.tab       drm_dp_aux0  initctl       mei0                rtc   sdg       sr0     tty21  tty4   tty58   ttyS18  ttyS8    vcsa3
.blkid.tab.old   drm_dp_aux1  input         mem                 rtc0  sdg1      sr1     tty22  tty40  tty59   ttyS19  ttyS9    vcsa4
admmidi          drm_dp_aux2  kfd           memory_bandwidth    sda   sdh       stderr  tty23  tty41  tty6    ttyS2   uhid     vcsa5
amidi            drm_dp_aux3  kmem          midi                sda1  sdh1      stdin   tty24  tty42  tty60   ttyS20  uinput   vcsa6
autofs           drm_dp_aux4  kmsg          mqueue              sdb   sdi       stdout  tty25  tty43  tty61   ttyS21  urandom  vcsa7
block            drm_dp_aux5  lightnvm      net                 sdb1  sdi1      tty     tty26  tty44  tty62   ttyS22  usb      vfio
bsg              dvd          log           network_latency     sdc   sg0       tty0    tty27  tty45  tty63   ttyS23  userio   vga_arbiter
btrfs-control    dvdrw        loop-control  network_throughput  sdc1  sg1       tty1    tty28  tty46  tty7    ttyS24  vcs      vhci
bus              fb0          lp0           null                sdc2  sg10      tty10   tty29  tty47  tty8    ttyS25  vcs1     vhost-net
cdrom            fd           lp1           nvram               sdd   sg2       tty11   tty3   tty48  tty9    ttyS26  vcs10    watchdog
cdrw             full         lp2           port                sdd1  sg3       tty12   tty30  tty49  ttyS0   ttyS27  vcs2     watchdog0
char             fuse         lp3           ppp                 sdd2  sg4       tty13   tty31  tty5   ttyS1   ttyS28  vcs3     xconsole
console          hidraw0      mapper        pps0                sde   sg5       tty14   tty32  tty50  ttyS10  ttyS29  vcs4     zero
core             hidraw1      mcelog        psaux               sde1  sg6       tty15   tty33  tty51  ttyS11  ttyS3   vcs5
cpu              hidraw2      md            ptmx                sde2  sg7       tty16   tty34  tty52  ttyS12  ttyS30  vcs6
cpu_dma_latency  hidraw3      md123         ptp0                sde3  sg8       tty17   tty35  tty53  ttyS13  ttyS31  vcs7
cuse             hidraw4      md124         ptp1                sdf   sg9       tty18   tty36  tty54  ttyS14  ttyS4   vcsa
disk             hpet         md125         pts                 sdf1  shm       tty19   tty37  tty55  ttyS15  ttyS5   vcsa1
dmmidi           hugepages    md126         random              sdf2  snapshot  tty2    tty38  tty56  ttyS16  ttyS6   vcsa10
dri              hwrng        md127         rfkill              sdf3  snd       tty20   tty39  tty57  ttyS17  ttyS7   vcsa2

Below is my /dev/usb/ directory:

ls /dev/usb/
hiddev0  hiddev1

Digging further I found this:

cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: TOSHIBA MD04ACA4 Rev: FP2A
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: TOSHIBA MD04ACA4 Rev: FP2A
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: Samsung SSD 860  Rev: 2B6Q
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: Samsung SSD 860  Rev: 2B6Q
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi4 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: TS512GSSD370     Rev: 4B  
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi5 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: TS512GSSD370     Rev: 4B  
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi6 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: TOSHIBA MD04ACA4 Rev: FP2A
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi7 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: TOSHIBA MD04ACA4 Rev: FP2A
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi8 Channel: 00 Id: 00 Lun: 00
  Vendor: HL-DT-ST Model: DVDRAM GH24NS90  Rev: IN00
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi9 Channel: 00 Id: 00 Lun: 00
  Vendor: ATAPI    Model: iHAS120   6      Rev: 7L0A
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi14 Channel: 00 Id: 00 Lun: 00
  Vendor: ST8000VN Model: 0022-2EL112      Rev: SC61
  Type:   Direct-Access                    ANSI  SCSI revision: 06

With a little luck the

Host: scsi14 Channel: 00 Id: 00 Lun: 00

will relate to the

UDEV  [951330.564242] add      /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.3/3-9.3:1.0/host14/target14:0:0/14:0:0:0/scsi_disk/14:0:0:0 (scsi_disk)

from above.

It seems that knowing the host isn’t going to help much as every example I can find with

sdparm

has a

/dev/sd..

path on it and since the drive is yet to be mounted, I can’t use that.

Late to this thread, but as USB power management is in play, you have a couple of options available to try

  1. Disable power management by using the following boot option
usbcore.autosuspend=-1
  1. Run some code to reset a USB device (this is just one of many examples I seen online)…
    https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line

Another approach that unbinds and rebinds a driver for a given USB controller…

https://davidjb.com/blog/2012/06/restartreset-usb-in-ubuntu-12-04-without-rebooting/
http://www.ubuntubuzz.com/2016/06/reset-usb-20-ehci-usb-30-xhci-without-reboot-linux.html

You can use “udisksctl status” to work out which “/dev/sd?” is related to the USB disk and then, “udisksctl info --block-device /dev/sd?” for more detailed information.
The detailed information provides “Symlinks:” which point to the device in “/sys/bus/usb/devices/” – from there you can use the information in the Linux Kernel documentation.
Otherwise, after the USB drive has been mounted, you can then begin to use the “sdparm” commands on the “/dev/sd??” device.

It will not be a “tty” (Terminal) device – it’ll be a “sd” device …

That’s great. I was already using udisksctl info but I added udisksctl status to the top of my script so now I don’t have to hard code the disk letter. So now the script looks like:

#!/bin/bash                                                                        

. /srv/backups/scripts/header.sh

DISK_SERIAL='000000123AD2' # NEW LINE
DISK=$(udisksctl status | grep "$DISK_SERIAL" | sed 's/ ]*$//' | grep -Po '\w+$') # UPDATED LINE
if  -z "$DISK" ]; then
  echo
  echo "Could not determine disk drive for disk serial # $DISK_SERIAL."
  echo
  udisksctl status
  echo
  exit
fi

DISK_MOUNT_POINT=
function get_mount_point() {
  udisksctl info -b /dev/$DISK| grep MountPoints:|grep -oP '(/|\w)+$'
}

function mount_usb_disk() {
  DISK_MOUNT_POINT=$(get_mount_point)
  if  -z "$DISK_MOUNT_POINT" ]; then
    udisksctl mount -b /dev/$DISK
    DISK_MOUNT_POINT=$(get_mount_point)
    if  -z "$DISK_MOUNT_POINT" ]; then
      echo "Mounting USB disk $DISK failed. Quitting."
      exit
    else
      echo "Mounting USB disk $DISK succeeded at: $DISK_MOUNT_POINT"
    fi
  else
    echo "USB disk $DISK found mounted at: $DISK_MOUNT_POINT"
  fi
}

mount_usb_disk

# ... backup to disk drive.

Not having to hard code the drive letter is one step closer to being perfect. When I run the script I get:

Object /org/freedesktop/UDisks2/block_devices/sdi is not a mountable filesystem.
Mounting USB disk sdi failed. Quitting.

Which is the last problem to solve so now all as I have to do find a way to turn that external device the hard drive sits in on. Perhaps resetting the USB device as @deano_ferrari suggests will do that.

udisksctl info -b /dev/sdi


/org/freedesktop/UDisks2/block_devices/sdi:
  org.freedesktop.UDisks2.Block:
    Configuration:              ]
    CryptoBackingDevice:        '/'
    Device:                     /dev/sdi
    DeviceNumber:               2176
    Drive:                      '/org/freedesktop/UDisks2/drives/ST8000VN_0022_2EL112_000000123AD2'
    HintAuto:                   true
    HintIconName:               
    HintIgnore:                 false
    HintName:                                                                                                                                             
    HintPartitionable:          true                                                                                                                      
    HintSymbolicIconName:                                                                                                                                 
    HintSystem:                 false                                                                                                                     
    Id:                         by-id-scsi-35000c500b032a0ad                                                                                              
    IdLabel:                                                                                                                                              
    IdType:                                                                                         
    IdUUID:                                                                                         
    IdUsage:                                                                                        
    IdVersion:                                                                                      
    MDRaid:                     '/'                                                                 
    MDRaidMember:               '/'                                                                 
    PreferredDevice:            /dev/sdi                                                            
    ReadOnly:                   false
    Size:                       8001563222016
    Symlinks:                   /dev/disk/by-id/scsi-35000c500b032a0ad
                                /dev/disk/by-id/scsi-SST8000VN_0022-2EL112_000000123AD2
                                /dev/disk/by-id/usb-ST8000VN_0022-2EL112_000000123AD2-0:0
                                /dev/disk/by-id/wwn-0x5000c500b032a0ad
                                /dev/disk/by-path/pci-0000:00:14.0-usb-0:9.3:1.0-scsi-0:0:0:0
  org.freedesktop.UDisks2.PartitionTable:
    Type:               gpt