Menu
blog.headdesk.me
blog.headdesk.me

Backup to USB drive and power it off when not in use

Posted on 2015/07/022015/07/02

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.

Loading

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Full text search

Recent Posts

  • Generate secure password
  • AWS Compute Savings Plans
  • AWS Zonal Shift
  • Coffee break…
  • Prevent private key from being committed to git
  • aws (14)
  • coffee (2)
  • headfi (1)
  • linux (9)
  • others (61)
  • security (2)
  • tech (41)
  • terraform (3)
  • wordpress (2)

Loading

apache aws awscli azure backup boot cloud coffee docker ec2 EL8 ElasticBeanstalk espresso featured git kernel lelit linux lvm meltdown MFA nat gateway php power proliant python rdp Redhat RHEL rpm Ryzen scp security smartarray smart switch snapshot spectre tech terraform ubuntu ubuntu upgrade vpn windows wordpress workspace

©2026 blog.headdesk.me | Powered by SuperbThemes