On Linux, it is possible to power off a USB device using command line. It’s perfect for my USB backup drive. I can power it off after backup every night, and power it on before the job starts. This saves power, reduce heat, and more importantly, prevent accidental or unexpected changes as the device is completely offline.
The command to turn off/on a USB device requires the USB address. To find it, I look for “Toshiba” in dmesg and 2-1 is the address.
# dmesg | grep -i toshiba [ 2.401262] usb 2-1: Manufacturer: TOSHIBA
Now I have the address, I can power off the device with the following command
$ echo 2-1 > /sys/bus/usb/drivers/usb/unbind
To bring it back on
$ echo 2-1 > /sys/bus/usb/drivers/usb/bind
And when it’s powered on, the kernel reported the device as if it’s just plugged in:
[605419.258985] usb-storage 2-1:1.0: USB Mass Storage device detected [605419.259151] scsi host11: usb-storage 2-1:1.0 [605420.263369] scsi 11:0:0:0: Direct-Access TOSHIBA External USB 3.0 5438 PQ: 0 ANSI: 6 [605420.264876] sd 11:0:0:0: Attached scsi generic sg4 type 0 [605420.267811] sd 11:0:0:0: [sdd] 3907029164 512-byte logical blocks: (2.00 TB/1.81 TiB) [605420.268293] sd 11:0:0:0: [sdd] Write Protect is off [605420.268302] sd 11:0:0:0: [sdd] Mode Sense: 23 00 00 00 [605420.268783] sd 11:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA [605425.980615] sdd: sdd1 [605425.983234] sd 11:0:0:0: [sdd] Attached SCSI disk
Now if you run a Linux desktop like I do and you don’t want the system to automatically mount the drive under a generated path, simply add a “noauto” option to fstab and mount it in the backup script.
337 total views, 2 views today