geerlingguy / backup-pi

Use a Raspberry Pi for backups.
MIT License
32 stars 3 forks source link

Configure USB drive to spin down automatically #2

Open geerlingguy opened 8 years ago

geerlingguy commented 8 years ago

Mostly for power consumption, but basically—make this a configurable option (e.g. either enable it or disable it via a bool), and also allow configuration of the time before the drive spins down after inactivity.

Some people might use an SSD here, but most people would likely toss an old spinning rust drive at the Pi for backups (since it's expendable... and since the Pi's USB 2.0 bust can't sustain super fast transfer, at least not in the current generation). So it's nice to conserve energy. Just don't use too quick a frequency for the default spindown as frequent toggles can cause the drive to wear faster.

For some references:

geerlingguy commented 8 years ago

I've added a new geerlingguy.hdparm role on Ansible Galaxy for control over this parameter. I will also need to see about setting it on-the-fly or if I can get hdparm to read from its conf file... also need to verify things are working. Right now it looks like it'll take at least 30 min to an hour to format the 2 TB USB drive. It would take 4-6 hours if I formatted allowing the initialization to happen in the background!

geerlingguy commented 8 years ago

To set spin-down on the fly:

# Enable power management on USB HDD.
sudo hdparm -B 127 /dev/sda
# Set spindown time to 10 minutes.
sudo hdparm -S120 /dev/sda

You can check the status of the drive using:

sudo hdparm -C /dev/sda

(Outputs something like active/idle or standby if it's spun down).

geerlingguy commented 8 years ago

Looks like this works nicely with the following in /etc/hdparm.conf:

/dev/sda {
    spindown_time = 120
}