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
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 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:
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.
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.