Coder Social home page Coder Social logo

hdd-spindown.sh's Introduction

hdd-spindown.sh

Automatic Disk Standby using Kernel diskstats and hdparm

Summary

hdd-spindown.sh is a rather simple Bash script that enables automatic disk standby for drives that do not support timeout-based spindown by firmware (e.g. -S parameter for hdparm).

Usage, Requirements

hdd-spindown.sh is best run via systemd, using the service unit provided. In order to enable it, simply issue

$ systemctl enable hdd-spindown.service

and adapt configuration file /etc/hdd-spindown.rc to suit your needs.

Apart from coreutils the following is required:

  • smartctl: for detection of drive status and SMART self-checks
  • hdparm for actually initiating drive standby
  • grep for utility output parsing

The following is optional, depending on the features used:

  • logger if syslog interface enabled
  • ping if host monitoring enabled

Configuration

hdd-spindown.sh uses a simple shell-style configuration file for setting the disks to monitor. An example may look like this:

# configuration file for hdd-spindown.sh

CONF_INT=300

CONF_DEV=( "ata-WDC_WD50EFRX-68MYMN1_WD-WX31DA43KKCY|5400" \
           "ata-WDC_WD50EFRX-68MYMN1_WD-WX81DA4HNEH5|5400" \
           "ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5755786|5400" \
           "ata-WDC_WD20EARS-00MVWB0_WD-WMAZA3570471|5400" )

CONF_INT specifies the monitoring interval in seconds while CONF_DEV features a list of devices to monitor, as well as their timeout value in seconds, separated by the pipe symbol '|'.

Note that devices may be specified using their ID (as shown) or device name (e.g. 'sda'). The interval option may be omitted, which sets the default interval of 5 minutes.

For a complete list of options please see the example hdd-spindown.rc.

State of Development

I have replaced all of my rotating disks with flash based storage. I will happily accept pull requests for improvements or bug fixes, but I will not be able to test anything myself.

License

This software is released under the terms of the MIT License, see file LICENSE.

hdd-spindown.sh's People

Contributors

hufman avatar lynix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hdd-spindown.sh's Issues

hdd-spindown.sh doesn't work anymore

Hi!
I've been using hdd-spindown.sh for quite some time now and never had any issues. However, after the recent update, hdd-spindown.sh never puts my HDD to sleep anymore. I've updated the package from AUR last night and noticed issues today.

First issue I've noticed after the update was that the service was disabled. After enabling and starting the service manually, service reports that it's up and running:

$ systemctl status hdd-spindown.service
● hdd-spindown.service - Automatic Disk Standby
   Loaded: loaded (/usr/lib/systemd/system/hdd-spindown.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2017-07-12 21:31:52 EDT; 40min ago
 Main PID: 515 (hdd-spindown.sh)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/hdd-spindown.service
           ├─ 515 /bin/bash /usr/bin/hdd-spindown.sh
           └─7931 sleep 300

Jul 12 21:31:52 exp1 systemd[1]: Started Automatic Disk Standby.
Jul 12 21:31:52 exp1 hdd-spindown.sh[515]: Using 300s interval

But my disk is never put to sleep. If I issue an hdparm request manually, the HDD does spin down (I can hear it spin down).

And then, sometimes later I see this in my journal:

Jul 12 22:21:59 exp1 hdd-spindown.sh[515]: spinning up sdb

so it's spinning up the disk on its own at who knows what interval. Really strange.

My rc file is simple:

$  cat  /etc/hdd-spindown.rc
CONF_INT=300
CONF_DEV=("sdb|300")

What is going on? Thanks in advance!

PS: Using Arch, latest version from AUR.

install question

Sorry newbie here, how do i install the script? Can't find any install instructions in the readme.

Possibly solution for non-working spindown

Hi All,

I've tried this script, and noticed that, if the external enclosure isn't supported officially by smartctl, the script won't work, even the other solutions.

Luckily the bypass trick is very simple. The root cause is that, the smartctl says: "Unknown USB bridge". This can be bypassed with the -d sat parameter.
I've replaced all of smartctl instances in your script like this: smartctl -d sat.
Voilá, the script is working so good.

May I suggest to implement this trick in the next release to stop wasting time by others who have officially unsupported enclosures like me?

Important! This trick will work only that case if sudo hdparm -C /dev/sda command also works, otherwise my suggestion won't get affected.

Spindown fails when one (or more) of the disks in .rc file doesn't exist

Hi,
I have a bunch of HDDs and I've noticed that when one of the disks is disconnected (i.e. missing from the system), hdd-spindown fails to spin down the rest of the disks and reports a failure. For example:

Sep 07 17:51:42 aar systemd[1]: Started Automatic Disk Standby.
Sep 07 17:51:42 aar hdd-spindown.sh[731]: Using 600s interval
Sep 07 17:51:42 aar hdd-spindown.sh[731]: recognized disk: ata-ST4000N00 --> sdd
Sep 07 17:51:42 aar hdd-spindown.sh[731]: error: device not found: 'ata-WDC_WD1001'
Sep 07 17:51:42 aar systemd[1]: hdd-spindown.service: Main process exited, code=exited, status=1/FAILURE
Sep 07 17:51:42 aar systemd[1]: hdd-spindown.service: Failed with result 'exit-code'.

Inside of the .rc file, I have a simple CONF_DEV= declaration that lists all disks by their ATA-ID.

In situations such as this, I'd assume that the program would ignore missing disks and just manage the rest of them. This would be especially useful if you have an external enclosure that might or might not be connected...

Thanks!

Is there any way to identify disks by uuid?

I've tried with sda/sdb etc, but I've noticed that, if I change the USB ports, the device names will change (sda->sdb, sdb->sdc, sdc->sda). One of these devices is HDD but the others are SSDs.
The script won't work if it gets an SSD devicename. This problem should be solved by identifying via uuid.

Thanks!

hdd-spindown doesn't suspend disks anymore

Hi,
I'm not sure if it's just me but hdd-spindown has stopped suspending disks on my machine after a recent Arch update. I have tried to track it down but was unable to figure out what's stopping it. I think it has something to do with the new Linux kernel. After upgrading to 5.5.5, hdd-spindown doesn't suspend anymore. All the logs look normal and there are no errors reported. My .rc file is super simple: an ID for a single disk and a timeout. It has worked fine for over a year so something must have changed in the kernel and the way that hdd-spindown tacks no disk activity.

Question about "dev_isup" function

This script does not work on my machine(Xubuntu 20.04.2). So I checked the shell script. When I comment out line 68,my hard drive can sleep normally.

I manually run smartctl -i -n standby "/dev/sdd" , the "Power mode" is ACTIVE or IDLE. Is this result related to different Linux distributions?

smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.8.0-55-generic] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family: Western Digital Blue
Device Model: WDC WD5000AAKX-75U6AA0
Serial Number: WD-WCC2ELL61791
LU WWN Device Id: 5 0014ee 25e35cee0
Firmware Version: 19.01H19
User Capacity: 500,107,862,016 bytes [500 GB]
Sector Size: 512 bytes logical/physical
Device is: In smartctl database [for details use: -P show]
ATA Version is: ATA8-ACS (minor revision not indicated)
SATA Version is: SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Tue Jun 8 15:36:44 2021 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
Power mode is: ACTIVE or IDLE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.