Giter VIP home page Giter VIP logo

hd-idle's People

Contributors

adam5wu avatar adelolmo avatar benengele avatar grayxu avatar medarion avatar mothlyme avatar paulwebster avatar rabelux avatar spasche 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  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  avatar  avatar  avatar  avatar  avatar

hd-idle's Issues

Extend guidance on `ata` vs `scsi` command types

I have misunderstood the "command type" parameter.

For some USB drives (including those with /dev/disk/by-id entries starting, interestingly, ata-) the default scsi command does not work.

I've seen this with Seagate USB drives such as the Seagate Backup Plus Hub, which looks like /dev/disk/by-id/ata-ST6000DM003-2CY186-....

Though when hd-idle logs no errors with scsi as the command type, it appears that doesn't actually work. With ata, errors are logged, but it does actually work!

Perhaps some extended guidance on when to select ata vs scsi would help? I'll take a look and see if I can proffer a PR.

Hard drive doesn't spin down after certain uptime

I am running hd-idle on a Pi v4 and it works really well. What I have noticed though is that if my pi hasn't been rebooted for a while (3 weeks for example) the hard drive doesn't spin down anymore. If I restart the hd-idle service it works for a short period again but then doesn't spin down again.
Are there any logs I can look at to see why this is happening and if it is hd-idle? I appreciate it could be something else causing it too.
Thanks.

Scripting feature within hd-idle

I have a usbrelay module to control the cooling fan through a simple script command. Is there any way to provide the scripting capability so the scripts could be invoked when disk spin down/up?

Shutdown 1 disk

How can I shutdown 1 disk only?

the -a options doesn't seem to work

~ # hd-idle -a /dev/sda -i 5 -d
symlinkPolicy=0, defaultIdle=600, defaultCommand=scsi, debug=true, logFile=, devices={name=sda, givenName=/dev/sda, idle=5, commandType=scsi}
disk=sdb command=scsi spunDown=false reads=5265 writes=99 idleTime=600 idleDuration=2 spindown=0001-01-01T00:00:00 spinup=2020-07-01T15:57:39 lastIO=2020-07-01T15:57:39
disk=sdc command=scsi spunDown=false reads=4488 writes=127 idleTime=600 idleDuration=2 spindown=0001-01-01T00:00:00 spinup=2020-07-01T15:57:39 lastIO=2020-07-01T15:57:39
disk=sda command=scsi spunDown=false reads=5221 writes=102 idleTime=5 idleDuration=2 spindown=0001-01-01T00:00:00 spinup=2020-07-01T15:57:39 lastIO=2020-07-01T15:57:39
disk=sdd command=scsi spunDown=false reads=14362 writes=0 idleTime=600 idleDuration=2 spindown=0001-01-01T00:00:00 spinup=2020-07-01T15:57:39 lastIO=2020-07-01T15:57:39
disk=sde command=scsi spunDown=false reads=4153 writes=64 idleTime=600 idleDuration=2 spindown=0001-01-01T00:00:00 spinup=2020-07-01T15:57:39 lastIO=2020-07-01T15:57:39

Is the -i idle time persistant?

Just a simple question as I can't tell if I change anything with the config file, but, are the changes made with the cli -i option persistent through reboot?

getting error during building

github.com/adelolmo/hd-idle/io
encoding/hex
github.com/benmcclelland/sgio
github.com/adelolmo/hd-idle/sgio
github.com/adelolmo/hd-idle
##
# From git-lfs/git-lfs repo:
# dh_golang doesn't do anything here in deb 8, and it's needed in both
##
if [ "arm-linux-gnueabihf" != "x86_64-linux-gnu" ]; then\
        cp -rf obj-arm-linux-gnueabihf/bin/*/* obj-arm-linux-gnueabihf/bin/; \
fi
make[1]: Leaving directory '/home/mirek190/hd-idle'
   dh_auto_test -O--buildsystem=golang
        go test -v -p 1 github.com/adelolmo/hd-idle github.com/adelolmo/hd-idle/diskstats github.com/adelolmo/hd-idle/io github.com/adelolmo/hd-idle/sgio
?       github.com/adelolmo/hd-idle     [no test files]
fork/exec /tmp/go-build466280710/b045/diskstats.test: exec format error
FAIL    github.com/adelolmo/hd-idle/diskstats   0.155s
fork/exec /tmp/go-build466280710/b062/io.test: exec format error
FAIL    github.com/adelolmo/hd-idle/io  0.002s
?       github.com/adelolmo/hd-idle/sgio        [no test files]
FAIL
dh_auto_test: go test -v -p 1 github.com/adelolmo/hd-idle github.com/adelolmo/hd-idle/diskstats github.com/adelolmo/hd-idle/io github.com/adelolmo/hd-idle/sgio returned exit code 1
debian/rules:43: recipe for target 'build' failed
make: *** [build] Error 1
dpkg-buildpackage: error: debian/rules build gave error exit status 2

I also tried install from the deb package under my debian ...but also got error.

sudo dpkg -i hd-idle_1.12_amd64.deb
dpkg-deb: error: 'hd-idle_1.12_amd64.deb' is not a debian format archive
dpkg: error processing archive hd-idle_1.12_amd64.deb (--install):
subprocess dpkg-deb --control returned error exit status 2
Errors were encountered while processing:
hd-idle_1.12_amd64.deb

Set copyright on license

The license has still some placeholders that have to be replaced.

<program> Copyright (C) <year> <name of author>

Are logs (actually) reliable?

Hi!
Thanks for making hd-idle a better utility.

I have noticed a strange behavior on my Debian 10 (openmediavault 5) server. I am using hd-idle 1.9.
Firts: your hd-idle seems to work fine, because I monitor the power consumption of my server with an external device and the power consumption matches drives spinning down as expected.

However, logs are saying something different.
Here's an example from syslog:

Aug  6 20:39:38 nas hd-idle[4314]: sdc spinup
Aug  6 20:45:44 nas hd-idle[4314]: sdb spindown
Aug  6 20:45:44 nas hd-idle[4314]: sda spindown
Aug  6 20:46:45 nas hd-idle[4314]: sdb spinup
Aug  6 20:46:45 nas hd-idle[4314]: sda spinup
Aug  6 20:49:48 nas hd-idle[4314]: sdc spindown
Aug  6 20:50:49 nas hd-idle[4314]: sdc spinup 

However, at 21:11 I have checked my drives with hdparm and they were in standby as expected.
2020-08-06 21_11-

It doesn't match what this log says. At 21:11 what you see above was the last event, I doublechecked it.

I also have the actual hd-idle log which I don't really understand. Does it write only when disks are spun-up?

date: 2020-08-06, time: 20:39:38, disk: sdc, running: 609, stopped: 60
date: 2020-08-06, time: 20:46:45, disk: sdb, running: 1220, stopped: 61
date: 2020-08-06, time: 20:46:45, disk: sda, running: 1220, stopped: 61
date: 2020-08-06, time: 20:50:49, disk: sdc, running: 610, stopped: 61

TL;DR Your utility seems to work fine but logs are saying the opposite.

SystemV init script

Hi, first of all thanks for your work.

I'd like to suggest adding a SystemV init script, like the version included in Debian repo. It would make things easier for people who likes SystemV.

If you want I can send you a copy of the script.

Regards!

Arm64 - Failure (SCSI response not ok)

I'm facing an issue which I'm not sure why I'm encountering as everything worked perfectly with armhf (hd-idle v.1.5 though). The difference is the device (server), so I'm using arm64 instead of armhf.

/etc/default/hd-idle

START_HD_IDLE=true
HD_IDLE_OPTS="-i 0 -c ata -s 0 -a /dev/disk/by-id/ata-ST4000DM004-ID -i 600 -a /dev/disk/by-id/ata-ST6000DM003-ID -i 600"

systemctl status hd-idle

* hd-idle.service - hd-idle - spin down idle hard disks
   Loaded: loaded (/lib/systemd/system/hd-idle.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-09-09 23:46:13 CEST; 1h 3min ago
     Docs: man:hd-idle(8)
  Process: 8664 ExecStart=/usr/sbin/hd-idle $HD_IDLE_OPTS (code=exited, status=1/FAILURE)
 Main PID: 8664 (code=exited, status=1/FAILURE)

Sep 09 23:35:03 hostname systemd[1]: Started hd-idle - spin down idle hard disks.
Sep 09 23:35:03 hostname hd-idle[8664]: symlinkPolicy=0, defaultIdle=0, defaultCommand=ata, debug=false, devices=[{sda /dev/disk/by-id/ata-ST4000DM004-ID 600 ata} {sdb /dev/disk/by-id/ata-ST6000DM003-ID 600 ata}], logFile=
Sep 09 23:46:13 hostname hd-idle[8664]: sdb spindown
Sep 09 23:46:13 hostname hd-idle[8664]: 2019/09/09 23:46:13 SCSI response not ok
Sep 09 23:46:13 hostname hd-idle[8664]: SCSI status: 2 host status: 0 driver status: 8
Sep 09 23:46:13 hostname hd-idle[8664]: SENSE:
Sep 09 23:46:13 hostname hd-idle[8664]: 72 00 00 1d 00 00 00 0e 09 0c 00 00 00 00 00 00 00 00 00 00 40 50 00 00 00 00 00 00 00 00 00 00
Sep 09 23:46:13 hostname hd-idle[8664]: NO ADDITIONAL SENSE INFORMATION
Sep 09 23:46:13 hostname systemd[1]: hd-idle.service: Main process exited, code=exited, status=1/FAILURE
Sep 09 23:46:13 hostname systemd[1]: hd-idle.service: Failed with result 'exit-code'

Should I skip using ata as default and instead specify for each -c ata? It seems that it spindown my sdb drive, but not my first drive (sda). I'll look more into this tomorrow.

Update: Using scsi as default and specify the two other HDDs with -c ata didn't do any difference.

Update 2:
I get the same error with only one HDD. The HDD gets spun down just before the error occur.

$ sudo systemctl status hd-idle
* hd-idle.service - hd-idle - spin down idle hard disks
   Loaded: loaded (/lib/systemd/system/hd-idle.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-09-10 00:28:20 CEST; 4s ago
     Docs: man:hd-idle(8)
  Process: 2218 ExecStart=/usr/sbin/hd-idle $HD_IDLE_OPTS (code=exited, status=1/FAILURE)
 Main PID: 2218 (code=exited, status=1/FAILURE)

Sep 10 00:17:09 hostname systemd[1]: Started hd-idle - spin down idle hard disks.
Sep 10 00:17:09 hostname hd-idle[2218]: symlinkPolicy=0, defaultIdle=0, defaultCommand=scsi, debug=false, devices=[{sda /dev/disk/by-id/ata-ST4000DM004-ID 600 ata}], logFile=
Sep 10 00:28:19 hostname hd-idle[2218]: sda spindown
Sep 10 00:28:20 hostname hd-idle[2218]: 2019/09/10 00:28:20 SCSI response not ok
Sep 10 00:28:20 hostname hd-idle[2218]: SCSI status: 2 host status: 0 driver status: 8
Sep 10 00:28:20 hostname hd-idle[2218]: SENSE:
Sep 10 00:28:20 hostname hd-idle[2218]: 72 01 00 1d 00 00 00 0e 09 0c 00 00 00 00 00 00 00 00 00 00 40 50 00 00 00 00 00 00 00 00 00 00
Sep 10 00:28:20 hostname hd-idle[2218]: NO ADDITIONAL SENSE INFORMATION
Sep 10 00:28:20 hostname systemd[1]: hd-idle.service: Main process exited, code=exited, status=1/FAILURE
Sep 10 00:28:20 hostname systemd[1]: hd-idle.service: Failed with result 'exit-code'.
$ sudo systemctl status hd-idle
* hd-idle.service - hd-idle - spin down idle hard disks
   Loaded: loaded (/lib/systemd/system/hd-idle.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-09-10 00:58:19 CEST; 7s ago
     Docs: man:hd-idle(8)
  Process: 2190 ExecStart=/usr/sbin/hd-idle $HD_IDLE_OPTS (code=exited, status=1/FAILURE)
 Main PID: 2190 (code=exited, status=1/FAILURE)

Sep 10 00:47:08 hostname systemd[1]: Started hd-idle - spin down idle hard disks.
Sep 10 00:47:08 hostname hd-idle[2190]: symlinkPolicy=0, defaultIdle=0, defaultCommand=scsi, debug=false, devices=[{sda /dev/disk/by-id/ata-ST6000DM003-ID 600 ata}], logFile=
Sep 10 00:58:18 hostname hd-idle[2190]: sda spindown
Sep 10 00:58:19 hostname hd-idle[2190]: 2019/09/10 00:58:19 SCSI response not ok
Sep 10 00:58:19 hostname hd-idle[2190]: SCSI status: 2 host status: 0 driver status: 8
Sep 10 00:58:19 hostname hd-idle[2190]: SENSE:
Sep 10 00:58:19 hostname hd-idle[2190]: 72 00 00 1d 00 00 00 0e 09 0c 00 00 00 00 00 00 00 00 00 00 40 50 00 00 00 00 00 00 00 00 00 00
Sep 10 00:58:19 hostname hd-idle[2190]: NO ADDITIONAL SENSE INFORMATION
Sep 10 00:58:19 hostname systemd[1]: hd-idle.service: Main process exited, code=exited, status=1/FAILURE
Sep 10 00:58:19 hostname systemd[1]: hd-idle.service: Failed with result 'exit-code'.

Symlinks pointing to partitions don't work

Currently only symlinks pointing to disks work on configuration.
This is a limitation that makes using symlinks less useful, because neither by-label, by-partlabel, by-partuuid nor by-uuid symlinks resolve to disks but to partitions.

Improve use on non-systemd init scheme

Hello,

OS : Devuan beowulf, init : SysV, headless, no X server
hd-idle: v1.15, installed using amd64.deb

hd-idle relies on systemd to put the process into the background and to provide system logging, which causes problems under other init schemes.

As distributed, the sysvinit script (introduced in response to #43) is not usable, because hd-idle does not detach itself from the init process, which stalls, halting the boot process (manual line wrap for readability):

[....] Starting the hd-idle daemon: hd-idlesymlinkPolicy=0, defaultIdle=0, defaultCommand=ata,\
debug=false, logFile=/var/log/hd-idle.log,\
devices={name=sdb, givenName=sdb, idle=300, commandType=ata}\
{name=sdc, givenName=sdc, idle=300, commandType=ata}\
{name=sdd, givenName=sdd, idle=300, commandType=ata}\
{name=sde, givenName=sde, idle=300, commandType=ata}

This is the same output as running hd-idle from the command line (#37).

It is possible to force hd-idle into the background by modifying the init script like this:

case "$1" in
    start)
        log_daemon_msg "Starting the hd-idle daemon" "hd-idle"

---     start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $HD_IDLE_OPTS
+++     start-stop-daemon --start --quiet --oknodo --background --exec $DAEMON -- $HD_IDLE_OPTS

        log_end_msg $?
        ;;

This allows the system to boot, but has two problems :

  • No feedback if hd-idle fails to start
  • No system log messages (only logs to logfile option, if set)

Would it be possible to look at these problems, please?

[Feature Request] Integrate logrotate configuration

Hi,
I think would be great if you could integrate the logrotate configuration for hd-idle, so when a user enables logs does not get flooded by them.

I don't know where to place the PR, so here's the config I'm using:
/etc/logrotate.d/hd-idle

/var/log/hd-idle.log {
      missingok
      notifempty
      compress
      delaycompress
}

Resolve symlinks also after start

Currently the symlinks for devices are only resolve on application's start.
It would be nice to have a way to make hd-idle to resolve symlinks in runtime.
Because resolving symlinks will add an overhead, this feature should be disable by default and only enable via configuration.

LUKS Disk is in standby and hd-idle reports as spunDown as false

Hello,

I am using the ata command to spindown the disk with an interval of 1800 (30 minutes).

hdparm reports,

# hdparm -C  /dev/sdt

/dev/sdt:
 drive state is:  standby

However, hd-idle log shows it up as spunDown as false.

# journalctl -u hd-idle  |grep sdt |tail -1
Mar 01 07:48:29 nas hd-idle[7238]: disk=sdt command=ata spunDown=false reads=22594484 writes=64 idleTime=1800 idleDuration=0 spindown=2022-03-01T05:50:28 spinup=2022-03-01T05:51:28 lastIO=2022-03-01T07:48:29

The disk is formatted with LUKS and has no partitions. The drive is reported as dm-3 in /dev/disk/by-id/

#cat /proc/diskstats |grep 'dm-3\|sdt'
  65      48 sdt 96418 23051 22594500 231457 13 0 64 1039 0 149140 232704 0 0 0 0 5 206
 254       3 dm-3 119258 0 22582664 821020 13 0 72 1040 0 140360 822060 0 0 0 0 0

lsblk shows,

sdt                 65:48   0   7.3T  0 disk  
└─encrypteddiski     254:3    0   7.3T  0 crypt /srv/nfs/media2
                                              /mnt/media2

Finally, hd-idle is running as

HD_IDLE_OPTS=" -c ata -i 0 -a /dev/disk/by-id/ata-WDC_redacted -i 1800 -d -l /var/log/hd-idle.log"

Looks like it is the same bug as #62

removable disk - how to skip

hello,
I have the following problem. I have a memory card reader - it is detected as follows:

[    3.184546] sd 6:0:0:0: [sdf] Attached SCSI removable disk
[    3.187044] sd 6:0:0:2: [sdh] Attached SCSI removable disk
[    3.189671] sd 6:0:0:4: [sdj] Attached SCSI removable disk
[    3.193002] sd 6:0:0:1: [sdg] Attached SCSI removable disk
[    3.197299] sd 6:0:0:3: [sdi] Attached SCSI removable disk

hd-idle wants to turn off disks in it even though the disks are not there.

hd-idle.service - hd-idle - spin down idle hard disks
   Loaded: loaded (/lib/systemd/system/hd-idle.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2019-10-18 10:10:13 CEST; 7min ago
     Docs: man:hd-idle(8)
  Process: 1150 ExecStart=/usr/sbin/hd-idle $HD_IDLE_OPTS (code=exited, status=1/FAILURE)
 Main PID: 1150 (code=exited, status=1/FAILURE)

paź 18 10:00:08 epc systemd[1]: Started hd-idle - spin down idle hard disks.
paź 18 10:00:08 epc hd-idle[1150]: symlinkPolicy=0, defaultIdle=600, defaultCommand=scsi, debug=false, devices=[{sda sda 0 scsi}], logFile=/var/log/hd-idle.log
paź 18 10:10:11 epc hd-idle[1150]: sdd spindown
paź 18 10:10:12 epc hd-idle[1150]: sde spindown
paź 18 10:10:13 epc hd-idle[1150]: sdf spindown
paź 18 10:10:13 epc hd-idle[1150]: 2019/10/18 10:10:13 open /dev/sdf: no medium found
paź 18 10:10:13 epc systemd[1]: hd-idle.service: Main process exited, code=exited, status=1/FAILURE
paź 18 10:10:13 epc systemd[1]: hd-idle.service: Failed with result 'exit-code'.

Is there any option to bypass removable drives? Maybe you can do the option bypassing all replaceable disks (e.g. --no-removable)

Error trying to create .deb file

I have Ubuntu 18.04.3 LTS.
Go Version: go version go1.12.7 linux/amd64
I run these commands:

$ mkdir -p $GOPATH/src/github.com/adelolmo
$ cd $GOPATH/src/github.com/adelolmo
$ git clone https://github.com/adelolmo/hd-idle.git
$ cd hd-idle
$ dpkg-buildpackage -us -uc -b -d

But I get this error:

$ dpkg-buildpackage -us -uc -b -d
dpkg-buildpackage: info: source package hd-idle
dpkg-buildpackage: info: source version 1.4
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by Andoni del Olmo [email protected]
dpkg-buildpackage: info: host architecture amd64
dpkg-source --before-build hd-idle
fakeroot debian/rules clean
dh clean --buildsystem=golang --with=golang
dh_auto_clean -O--buildsystem=golang
debian/rules override_dh_clean
make[1]: Entering directory '/home/user/go/src/github.com/adelolmo/hd-idle'
rm -f debian/debhelper.log
dh_clean
make[1]: Leaving directory '/home/user/go/src/github.com/adelolmo/hd-idle'
debian/rules build
dh build --buildsystem=golang --with=golang
dh_update_autotools_config -O--buildsystem=golang
dh_auto_configure -O--buildsystem=golang
debian/rules override_dh_auto_build
make[1]: Entering directory '/home/user/go/src/github.com/adelolmo/hd-idle'
dh_auto_build -- -ldflags "-s -w"
build cache is disabled by GOCACHE=off, but required as of Go 1.12
cd obj-x86_64-linux-gnu && go install -gcflags="-trimpath=/home/user/go/src/github.com/adelolmo/hd-idle/obj-x86_64-linux-gnu/src" -asmflags="-trimpath=/home/user/go/src/github.com/adelolmo/hd-idle/obj-x86_64-linux-gnu/src" -v -p 1 -ldflags "-s -w"
can't load package: package .: no Go files in /home/user/go/src/github.com/adelolmo/hd-idle/obj-x86_64-linux-gnu
dh_auto_build: cd obj-x86_64-linux-gnu && go install -gcflags="-trimpath=/home/user/go/src/github.com/adelolmo/hd-idle/obj-x86_64-linux-gnu/src" -asmflags="-trimpath=/home/user/go/src/github.com/adelolmo/hd-idle/obj-x86_64-linux-gnu/src" -v -p 1 -ldflags "-s -w" returned exit code 1
debian/rules:50: recipe for target 'override_dh_auto_build' failed
make[1]: *** [override_dh_auto_build] Error 1
make[1]: Leaving directory '/home/user/go/src/github.com/adelolmo/hd-idle'
debian/rules:43: recipe for target 'build' failed
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2

Could you help me please?

Thanks!!

How to understand logs

After a while of running, I checked the log file, it contains following entries, can you help explain what does it mean?

date: 2020-07-28, time: 08:00:25, disk: sdc, running: 600, stopped: 73892
date: 2020-07-28, time: 10:32:22, disk: sdc, running: 601, stopped: 8516
date: 2020-07-29, time: 07:59:57, disk: sdc, running: 601, stopped: 76654

I assume the time is for spin up/down, how to know it's up or down?

What does the running/stopped mean?

Thanks.

smartctl --all /dev/sda make reads and no spin down

Hi,
I use command periodically (60s) to get temperature of disk:
smartctl --all /dev/sda | awk '/Temperature_Celsius/ {print $10}'
but hd-idle reports reads and thus won't spin down:
disk=sda command=scsi spunDown=false reads=39880915 writes=33187968 idleTime=77 idleDuration=8 spindown=0001-01-01T00:00:00 spinup=2022-03-04T16:28:55 lastIO=2022-03-04T16:32:00 disk=sda command=scsi spunDown=false reads=39880923 writes=33187968 idleTime=77 idleDuration=0 spindown=0001-01-01T00:00:00 spinup=2022-03-04T16:28:55 lastIO=2022-03-04T16:32:16 disk=sda command=scsi spunDown=false reads=39880923 writes=33187968 idleTime=77 idleDuration=8 spindown=0001-01-01T00:00:00 spinup=2022-03-04T16:28:55 lastIO=2022-03-04T16:32:16 disk=sda command=scsi spunDown=false reads=39880923 writes=33187968 idleTime=77 idleDuration=15 spindown=0001-01-01T00:00:00 spinup=2022-03-04T16:28:55 lastIO=2022-03-04T16:3
If I spun disk down manually it stays down and reading temp works too.
Is there any solution of this?
Thanks Jiri

Option to pick between disk vs partition activity.

I recently updated from 1.13 to 1.16 and I ran into an issue:

I have disks which are passed through to a virtual machine, thus the partitions never get accessed by the host. The /proc/diskstats never reports any activity for the partitions, only for the disk. All disks (try to) spin down when the set amount of time elapses after boot, even when there is activity. And never after.
Would it be possible to add a flag/option to select between the disk based vs partition based monitoring methods? (And add a note/warning for now that it may falsely mark the drive as active if some monitoring tool accesses it.)

Before marking the drive as "spun up" it would be possible to check it's power state. hdparm/smartctl supports getting the power state (idle/active, standby) without waking up the drive. diskstats's metrics increases when I check the power state of a drive (the drive itself does not spin up) but hd-idle (1.13) logs its as a spinup event.

Thanks for this useful tool!

hd-idle does not detect drive spinning up due to `smartctl` activity

When drives are spun "up" by smartctl activity (such as a smartctl -x /dev/sdX run), hd-idle does not detect this activity.

It appears that its internal state remains at "spunDown=true", and consequently the drive is never spun back down again.

Is there any way that this situation can be accounted for?

Exec format error

I did a clean install to latest version of Debian Buster arm64 today and my setup work as earlier except from hd-idle which throw the error seen below. I've done two clean installations without luck. The issue might be related to the content in hd-idle.service given the information from systemctl. If I run sudo /usr/sbin/hd-idle -v -f /etc/default/hd-idle, I get the following:

/usr/sbin/hd-idle: 1: /usr/sbin/hd-idle: Syntax error: word unexpected (expecting ")")

systemctl status hd-idle:

● hd-idle.service - hd-idle - spin down idle hard disks
   Loaded: loaded (/lib/systemd/system/hd-idle.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-02-03 20:13:45 CET; 3min 44s ago
     Docs: man:hd-idle(8)
  Process: 6861 ExecStart=/usr/sbin/hd-idle $HD_IDLE_OPTS (code=exited, status=203/EXEC)
 Main PID: 6861 (code=exited, status=203/EXEC)

Feb 03 21:58:45 Hostname systemd[1]: Started hd-idle - spin down idle hard disks.
Feb 03 21:58:45 Hostname systemd[6861]: hd-idle.service: Failed to execute command: Exec format error
Feb 03 21:58:45 Hostname systemd[6861]: hd-idle.service: Failed at step EXEC spawning /usr/sbin/hd-idle: Exec format error
Feb 03 21:58:45 Hostname systemd[1]: hd-idle.service: Main process exited, code=exited, status=203/EXEC
Feb 03 21:58:45 Hostname systemd[1]: hd-idle.service: Failed with result 'exit-code'.

When restart from suspend or hibernate not work

If we suspend the computer or hibernate, when it resumes, hd-idle no longer works. It only works when we start the computer or restart, if we suspend or hibernate it, when it resumes, it no longer works.
After much reading, I saw that this happens because the hd-idle counter, I do not remember now exactly, does not count well when we wake up the computer to sleep or hibernate.
We need created a new systemd-unit that restarts the hd-idle service, / etc / systemd / system /
and must be activated with the command:
systemctl enable hd-idle-restart-resume.service
The content of the file:
[Unit]
Description=Restart hd-idle
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
Type=simple
ExecStart=/bin/systemctl --no-block restart hd-idle

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Thanks and regards.

Uploading to Debian?

I like this implementation of hd-idle, it seems to fix problems with the original version and is actively maintained. Do you have any plans to upload it to Debian as an official package? Perhaps the biggest hurdle would be the name conflict with the existing hd-idle package. Maybe rename this one to hd-idle-ng ?

hd-idle killed the disk? [Edit: Nope, it was a faulty disk]

I used hd-idle to spin down my USB HDD on my Raspberry Pi 4. But even after restarting, and on other PCs (running macOS and Windows 10 which do not have hd-idle installed) after connecting the drive it does nothing. It never starts, it never spins up again. It gets power, the white LED is on, but nothing else. Is it dead Jim?

Disk: Western Digital Elements 4TB (WDBHDW0040BBK) USB 3.0 Micro-B
I used: hd-idle_1.16_armhf.deb

Edit:
lsbusb doesn't show the disk at all. I believe it is seriously dead. While lsusb hangs for 30 seconds, but then does not show anything (tested on different computers, not just the Pi), macOS does show the drive in the System Information but not in the disk utility.

Screenshot 2022-01-14 at 18 41 50

Raspberry Pi 4B - how to build HD-Idle

Hello, newbie here.

I see you have mentioned in the readme that it can be build for debian.
However, I'm unsure how to build it on/for the Raspberry Pi 4B.
The readme seems to assume that Go is already installed, but I'm unfamiliar with Go and am unsure if the new Pi 32-bit OS is "armhf".

Any hints or assistance would be appreciated.

Guidance on spinups vs idle?

Hi Andoni, thanks for hd-idle.

If I spin down my disk, it's down 88% of the time, which seems like a win for device longevity.

But, it spins up 10 times per day, increasing wear-and-tear.

Do you have any idea what the balance is between those two? Does the 88% idle time beat out the spin-ups for increasing the life of the disk, or the other way around?

PPA or other repository for Ubuntu

Hello! Have you considered providing a PPA for this package? I find it very helpful on my machine, but keeping it up to date is a bit difficult... a PPA would make it super easy.

errors building from source in a Raspberry Pi 4B

Hello. Thanks for this utility.

I have a Raspberry Pi 4 ... so I tried to build hd-idle from source per instructions at https://github.com/adelolmo/hd-idle#build-from-source and received errors as shown below.

Suggestions would be appreciated.

Thanks.

Install go:

cd ~/Desktop
wget https://golang.org/dl/go1.15.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.15.linux-armv6l.tar.gz
chmod +777 /usr/local/go
chmod +777 -R /usr/local/go

Added these 2 lines to /etc/profile :

sudo nano /etc/profile
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/usr/local/go

Rebooted.

Ran the go test at https://golang.org/doc/install section "Test your installation" which was succfessful.

Per instructions at https://github.com/adelolmo/hd-idle#build-from-source :

mkdir -p $GOPATH/src/github.com/adelolmo
cd $GOPATH/src/github.com/adelolmo
git clone https://github.com/adelolmo/hd-idle.git
cd hd-idle
dpkg-buildpackage -a armhf -us -uc -b

Resulting log with errors copied from the console:

dpkg-buildpackage: info: source package hd-idle
dpkg-buildpackage: info: source version 1.10
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by Andoni del Olmo <[email protected]>
dpkg-buildpackage: info: host architecture armhf
 dpkg-source --before-build .
dpkg-checkbuilddeps: error: Unmet build dependencies: debhelper (>= 9) golang-go:native (>= 1.3.3) dh-golang
dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting
dpkg-buildpackage: warning: (Use -d flag to override.)

Readability of logfile

When scrolling through a bunch of entries I find it quite hard to pick up the date and time.

What do you think about changing the format to a shorter (and I might even argue more standard) form?
I'd also suggest to use the same terms that smartctl or hdparm use instead of "stopped" and "running".

Current format is this:
- date: 2021-10-07, time: 12:48:25, disk: sdc, running: 1200, stopped: 6326
My suggestions I could think of:
- [2021-10-07 12:48:25] disk: sdc, active: 1200 [s], standby: 6326 [s]
- [2021-10-07 12:48:25] disk: sdc, active: 1200, standby: 6326
- [2021-10-07 12:48:25] disk: sdc | active: 1200 [s] | standby: 6326 [s]

Someone in issue #49 mentioned he's parsing the syslog, so at least for his setup this change wouldn't affect him.

Pls let me know what you think.

Feature proposal: Add an option to query disk spinning state

Proposal is to add a new option to hd-idle for reporting whether a disk is spinning or not (without spinning up the disk).

Example (a

hd-idle -a sdb -q 

Output e.g.

/dev/sdb spinning

Example (b

hd-idle -a sdc -q 

Output e.g.

/dev/sdc idle

Example (c

hd-idle -q 

Output e.g.

/dev/sdb spinning
/dev/sdc idle

I have asked a solution for this also on superuser, but so far without any success.

I can spin down my WD MyBook USB3 HD boxes with hd-idle, so most likely, it should be possible to add a reporting option to the program.

Thank you for your help.

SCSI response not ok

Hey there,

I had some problems putting eight HGST HC530 14 GB SATA drives on a machine to sleep reliably. The software sometimes errors out and leaves drives up and running, when they really should be in standby with motor turned off. There is no disk access that would warrant keeping any disk awake.

Background: I run a ZFS RAIDZ2 storage on Arch (latest, LTS kernel). Mainboard uses a C236 chipset, 4 disks are on chipset, 4 disks via a JMB585 add-in card (AHCI). The errors happen on random ports. As far as I remember the problem exists also with original hd-idle. The drives appear to ignore any attempt to set a standby timer using hdparm -S. They might support "Extended Power Conditions" (EPC), but I haven't found any tool for Linux to set the relevant timers. Also I do not know if these settings persist after powerloss. So last option for me right now really is hd-idle.

This is one error I got:

Oct 01 13:27:04 host hd-idle[699045]: symlinkPolicy=0, defaultIdle=0, defaultCommand=ata, debug=false, logFile=, devices={name=sdf, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}{name=sdg, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}{name=sdh, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}{name=sdd, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}{name=sde, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}{name=sdc, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}{name=sdb, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}{name=sdi, givenName=/dev/disk/by-id/ata-WDC_WD140EDFZ-11A0VA0_XXXXXXXX, idle=600, commandType=ata}
Oct 01 13:37:04 host hd-idle[699045]: sde spindown
Oct 01 13:37:04 host hd-idle[699045]: cannot spindown ata disk /dev/sde:
Oct 01 13:37:04 host hd-idle[699045]: SCSI response not ok
Oct 01 13:37:04 host hd-idle[699045]: SCSI status: 2 host status: 0 driver status: 8
Oct 01 13:37:04 host hd-idle[699045]: SENSE:
Oct 01 13:37:04 host hd-idle[699045]: 72 01 00 1d 00 00 00 0e 09 0c 00 00 00 00 00 00 00 00 00 00 00 50 00 00 00 00 00 00 00 00 00 00
Oct 01 13:37:04 host hd-idle[699045]: NO ADDITIONAL SENSE INFORMATION

Since a manual hdparm -y works, I patched hd-idle with a new option to just call hdparm -y with the device name. Now all disks sleep reliably. I am leaving the patch below in case it helps somebody. I suspect hd-idle and hdparm go about things slightly differently when putting disks into standby. Right now I am out of time though sadly to figure out exactly what hdparm does differently so it succeeds while hd-idle does not.

diff --git a/hdidle.go b/hdidle.go
index c7afab6..fbd1d7d 100644
--- a/hdidle.go
+++ b/hdidle.go
@@ -24,12 +24,14 @@ import (
        "log"
        "math"
        "os"
+       "os/exec"
        "time"
 )
 
 const (
        SCSI       = "scsi"
        ATA        = "ata"
+       HDPARM     = "hdparm"
        dateFormat = "2006-01-02T15:04:05"
 )
 
@@ -200,6 +202,14 @@ func spindownDisk(deviceName, command string) {
                        fmt.Printf("cannot spindown ata disk %s:\n%s\n", device, err.Error())
                }
                return
+       case HDPARM:
+               cmd := exec.Command("hdparm", "-y", device)
+               stdoutStderr, err := cmd.CombinedOutput()
+               if err != nil {
+                       fmt.Printf("cannot spindown disk %s with hdparm:\n%s\n", device, err.Error())
+                       fmt.Printf("%s\n", stdoutStderr)
+               }
+               return
        }
 }
 
diff --git a/main.go b/main.go
index 147fc5c..65109d2 100644
--- a/main.go
+++ b/main.go
@@ -40,7 +40,7 @@ func main() {
 
        defaultConf := DefaultConf{
                Idle:          defaultIdleTime,
-               CommandType:   SCSI,
+               CommandType:   HDPARM,
                Debug:         false,
                SymlinkPolicy: 0,
        }
@@ -110,14 +110,14 @@ func main() {
                case "-c":
                        command := os.Args[index+2]
                        switch command {
-                       case SCSI, ATA:
+                       case SCSI, ATA, HDPARM:
                                if deviceConf == nil {
                                        config.Defaults.CommandType = command
                                        break
                                }
                                deviceConf.CommandType = command
                        default:
-                               fmt.Printf("Wrong command_type -c %s. Must be one of: scsi, ata", command)
+                               fmt.Printf("Wrong command_type -c %s. Must be one of: scsi, ata, hdparm", command)
                                os.Exit(1)
                        }

Patch released under public domain, all rights disclaimed.

Regards,
Stephan

No output in log file

I just installed current hd-idle (deb of 1.16) from github on my armbian buster system (odroid hc2). I use
the systemd unit with

START_HD_IDLE=true HD_IDLE_OPTS="-a sda -i 1800 -l /var/log/hd-idle.log"

in /etc/default/hd-idle (its actually two separate lines, I dont know what goes wrong with the quoting here).

Spinning down seems to work (at least from the messages in /var/log/syslog, I have no physical access
to the system at the moment), but I dont find any output in the log file /var/log/hd-idle.log.

What is the problem?

Jürgen

only calculate partition access

Hi Adelolmo,

I have installed monitorix to watch my system, incl. disk temp and smart reporting. The data collection script runs every minute but this increase the diskstats counters for the disk devices (sda, sdb, etc...)

Thats why hd-idle never spins down the devices even if there is no disk activity on it's partitions.

Could you please add a config switch that ignores the device entry in /proc/diskstats and counts only the partition entries sda1...sdaX? Or make this the (IMHO) default behavior and add a config switch to include the device entry.

Thanks and best regards
Heiko

Fix encrypted hard drive

This extends on PR 48 Use partitions read/write to calculate disk activity and Issue 38 only calculate partition access:

hd-idle (1.16) is still not working on newer kernel if timeout is set to >=600 seconds and the complete device is encrypted (no partitions).
For encrypted drives, idle checks should be done on partition level too (same as since #48 for unecrypted).

As far as I understand, the encrypted partitions are the dm-0, dm-1,... entries in /proc/diskstats.

  8       0 sda 12345 123....
  8      16 sdb 12345 123....
  8      17 sdb1 12345 123....
...
 253       2 dm-2 12345 123....
 253       3 dm-3 12345 123....

So hd-idle should check dm-x partition for activity instead of device itself.

Only thing to find out is what dm-? partition maps to the device:
Could be done via looping through /sys/block/dm-?. Directory slaves has device name. (Maybe there is even a better way)

In this example, to idle sda, dm-2 needs to be monitored
/sys/block/dm-2/slaves/sda/


hd-idle 1.16
5.11.0-37-generic, 20.04.2-Ubuntu

the disk won't spin up!

Hi
I have installed from you .deb release hd-idle and it can spin down the disk after 10 minuts.
the problem is thar the disk can't spin up when I need to read something on the disk.

The disk export a folder via nfs for other computers on my home network, but I use it via vnc too as local files.

My system is a RaspberryPi4 (32bit) an the disk is a normal usb3 3.5" of 2 TB with his own power supply

Do you need some others infos? How to obtain them?

Crash with some command line arguments

Hi,

Certain combinations of arguments (or too many?) seem to cause a crash (i'm using raspbian lite):

$ hd-idle -ad
symlinkPolicy=0, defaultIdle=600, defaultCommand=scsi, debug=false, logFile=, devices=
^C
$ hd-idle -a -d
symlinkPolicy=0, defaultIdle=600, defaultCommand=scsi, debug=true, logFile=, devices={name=-d, givenName=-d, idle=600, commandType=scsi}
^C
$ hd-idle -da
symlinkPolicy=0, defaultIdle=600, defaultCommand=scsi, debug=false, logFile=, devices=
^C
$ hd-idle -d -a
panic: runtime error: index out of range [3] with length 3

goroutine 1 [running]:
main.main()
	/media/andoni/two/projects/go/src/github.com/adelolmo/hd-idle/main.go:81 +0xd5c

Thanks for your time,
Matt

No log file despite -l /path/to/file.log

Hi,
Fist congratulation for the project I'm really enjoying the program and it works for me. I'm trying to use the log file to track how many times the disk spin up and down during a normal day. I need this to find the best sleep time to balance between disk durability/performance, by reducing the number of spinning up events per day and not allowing the disk to stay up 24/7. I'm using a raspberry 4 and a external HD as a backup centre for my other computers.
I've changed the last line of /etc/default/hd-idle to:
HD_IDLE_OPTS="-i 600 -l /home/USER/hd-idle.log"
I've also enabled and started it in systemctl and I can see that it is working and includes the log option using htop. However after I watched the disk spin up and down for a while, there is no log file in the directory.
Best

hd-idle not starting on Ubuntu 20.4.01

I tried installing the latest 1.11 amd64 package on Ubuntu 20.04.1 LTS. No matter which command line option I choose, even when I just use -h, it only prints the following and then hangs:

symlinkPolicy=0, defaultIdle=600, defaultCommand=scsi, debug=false, logFile=, devices=

I previously had the original hd-idle from C. Mueller installed on my system (built from source). Before installing this new version of hd-idle, I made sure to remove the old binary to ensure there are no conflicts, but unsure if there are any other residual files that may cause issues on my end.

I also tried building this version of hd-idle from source but having the same issue above still. I can confirm that on my system, /proc/diskstats is present.

Would love to use this version of hd-idle on my Ubuntu system, but am stuck. Any help is appreciated :)

Idle time problem

I compiled latest version on a new Debian 11 bullseye system and have an issue with the idle-time.
HD spins not down when i'm using time greater then 500.
tried several variants of time - working fine till value 500.
With Debian 10 buster its working - same setup.

/etc/default/hd-idle:
START_HD_IDLE=true
HD_IDLE_OPTS="-i 0 -a sdb -i 1200 -l /var/log/hd-idle.log"

surely /proc/diskstats is present; same issue when i use hd-idle from the debian repo with apt install...

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.