Hi,
Disk spin-down: What program to use and best practice today?
There are threads about udisk2, hdparm, hd-idle (malcolmlewis](https://forums.opensuse.org/member.php/740-malcolmlewis)). What is the best with Leap 15.3 and how to use it?
Thanks
Hi,
Disk spin-down: What program to use and best practice today?
There are threads about udisk2, hdparm, hd-idle (malcolmlewis](https://forums.opensuse.org/member.php/740-malcolmlewis)). What is the best with Leap 15.3 and how to use it?
Thanks
Nobody to advise me?
Use case:
I switch on my desktop every day. I have 4 HDD, each is used for different application. I don’t use all the applications every day, so I don’t need access to all the HDD every day. I would be glad to boot the PC without starting the 4 HDD.
I was thinking of an utility that could reach my need;
An applet that I could add in the panel with for each HDD a select option for starting it manually.
In a setting window for each HDD:
Is it possible to make this type of utility, does it exist?
But the first step is to find the good way to spin-down the HDD (my first request).
hd-idle starts on boot and manages the HDDs on my machines:
**erlangen:~ #** journalctl -b -1 -o short-monotonic -u hd-idle.service
3.464288] erlangen systemd[1]: Started hd-idle disk spindown service.
3.465527] erlangen hd-idle[762]: hd-idle starting in nodaemon mode
3.465527] erlangen hd-idle[762]: disk: sdb timeout: 300
3.465527] erlangen hd-idle[762]: default timeout: 0
393.469635] erlangen hd-idle[762]: spindown: sdb
7863.959542] erlangen hd-idle[762]: spinup: sdb
8463.966742] erlangen hd-idle[762]: spindown: sdb
[11244.411224] erlangen systemd[1]: Stopping hd-idle disk spindown service...
[11244.425346] erlangen systemd[1]: hd-idle.service: Deactivated successfully.
[11244.425450] erlangen systemd[1]: Stopped hd-idle disk spindown service.
**erlangen:~ #**
Configuration is easy:
**erlangen:~ #** cat /etc/default/hd-idle
# hd-idle command line options
# Options are:
# -a <name> Set device name of disks for subsequent idle-time
# parameters (-i). This parameter is optional in the
# sense that there's a default entry for all disks
# which are not named otherwise by using this
# parameter. This can also be a symlink
# (e.g. /dev/disk/by-uuid/...)
# -i <idle_time> Idle time in seconds.
#
# Options not exactly useful here:
# -t <disk> Spin-down the specfified disk immediately and exit.
# -d Debug mode. This will prevent hd-idle from
# becoming a daemon and print debugging info to
# stdout/stderr
# -h Print usage information.
# -l <logfile> Name of logfile (written only after a disk has spun
# up). Please note that this option might cause the
# disk which holds the logfile to spin up just because
# another disk had some activity. This option should
# not be used on systems with more than one disk
# except for tuning purposes. On single-disk systems,
# this option should not cause any additional spinups.
#
# spin down all disks after 180 seconds
#HD_IDLE_OPTS="-i 180"
#
# only spin down /dev/sdb after 180 seconds
#HD_IDLE_OPTS="-i 0 -a sdb -i 180"
**HD_IDLE_OPTS="-i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EZRX-22S_WD-WCC4E2FYXSNV -i 300" **
**erlangen:~ #**
Hi
You need to test them all to see what works best for your setup. You could try powering off the device, but does the system motherboard support SATA hotswap?
Almost done but…
~> cat /etc/default/hd-idle
...
# sda
#HD_IDLE_OPTS="-i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EFRX-68N_WD-WCC7K1URKCCA -i 180"
HD_IDLE_OPTS="-i 0 -a sda -i 180"
# sdb
#HD_IDLE_OPTS="-i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EFRX-68N_WD-WCC7K3FP1KRD -i 180"
HD_IDLE_OPTS="-i 0 -a sdb -i 180"
# sdc
#HD_IDLE_OPTS="-i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EFRX-68W_WD-WCC4E1XXZ0TY -i 180"
HD_IDLE_OPTS="-i 0 -a sdc -i 180"
# sdd
#HD_IDLE_OPTS="-i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EFRX-68N_WD-WCC7K1LDVZ6H -i 180"
#HD_IDLE_OPTS="-i 0 -a sdd -i 180"
~> sudo journalctl -b -o short-monotonic -u hd-idle.service
[sudo] password for root:
-- Logs begin at Mon 2022-03-14 17:46:44 GMT, end at Tue 2022-03-15 15:48:38 GMT. --
6.175759] localhost systemd[1]: Started hd-idle disk spindown service.
6.176789] localhost hd-idle[1118]: hd-idle starting in nodaemon mode
6.176789] localhost hd-idle[1118]: disk: sdc timeout: 180
6.176789] localhost hd-idle[1118]: default timeout: 0
As you can see only the last HDD in the list is taken into consideration, confirmed by few tries, by label or by id.
Global idle is working fine.
HD_IDLE_OPTS="-i 180"
Is it a bug?
What do you mean by “powering off the device”:
Hi
That’s expected, only one variable used, you specify all as one…
HD_IDLE_OPTS="-i 0 -a sda -i 180 -a sdb -i 180 -a sdc -i 180 -a sdd -i 180"
{Following should spin all down}
HD_IDLE_OPTS="-i 180"
My mistake, this is a variable. :shame:
Working fine.
Thanks
This is a first step, I’d be glad to reach what I explained in post #2
Maybe it’s not possible by software as at boot the power supply provides voltage to HDD to spin before any software command.
Hi
I use the following on another box (Intel M/B Leap 15.3) to just power off the devices and unplug from a SATA disk caddy…
if (( $# != 1 )); then
echo "Usage: $0 <Drive to remove /dev/sNX>" >&2
exit 1
fi
if test -h "$1"
then
disk=$(chase "$1")
else
disk="$1"
fi
echo $disk
if test -b "$disk"
then
echo "Syncing and unmounting $disk"
sync
umount /dev/$disk
sync
echo "Powering off $disk"
echo 1 >/sys/block/$(basename "$disk")/device/delete
echo "Disk $disk safe to remove"
else
echo "$0: not a block device: $1" >&2
exit 1
fi
Your script is good for a USB HDD but the issue with a SATA HDD is the power on/booting, the HDD start to spin.
Maybe it’s not possible to avoid this by software as at boot the power supply provides voltage to HDD to spin before any software command.
I tried to connect a HDD with only power connector, it spins. This is the setting by default to gain time. Is it possible to have “do not spin and wait the command” by default?
Hi
No, that script is used with SATA disks connected to the motherboard SATA connectors (The disks are in a 4xSATA Caddy) and once powered down disconnect (unplug), but they don’t need to be, just turn the power back on via another script, but in my case when plugging back in come back to life. The motherboard I have supports real hot swapping.
I learned something today. HDD power switches are for sell.
I didn’t know that.
So this is the only way.
For information, when HDD spin is off by hd-idle, it restarts after suspend to RAM and restart just before power off the PC.
Disk spins down and stays down:
**erlangen:~ #** journalctl -b -1 -o short-monotonic -u hd-idle.service -u systemd-suspend.service
3.038747] erlangen systemd[1]: hd-idle.service: Installed new job hd-idle.service/start as 224
3.302810] erlangen hd-idle[757]: hd-idle starting in nodaemon mode
3.302810] erlangen hd-idle[757]: disk: sdb timeout: 300
3.302810] erlangen hd-idle[757]: default timeout: 0
3.303622] erlangen systemd[1]: hd-idle.service: Passing 0 fds to service
3.303968] erlangen systemd[1]: hd-idle.service: About to execute /usr/sbin/hd-idle -n "\$HD_IDLE_OPTS"
3.304666] erlangen systemd[1]: hd-idle.service: Forked /usr/sbin/hd-idle as 757
3.305034] erlangen systemd[1]: hd-idle.service: Changed dead -> running
3.305139] erlangen systemd[1]: hd-idle.service: Job 224 hd-idle.service/start finished, result=done
3.305241] erlangen systemd[1]: Started hd-idle disk spindown service.
3.306532] erlangen systemd[757]: hd-idle.service: Executing: /usr/sbin/hd-idle -n -i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EZRX-22S_WD-WCC4E2FYXSNV -i 300
4.763593] erlangen systemd[1]: systemd-suspend.service: Collecting.
5.088142] erlangen systemd[1]: systemd-suspend.service: Collecting.
22.518632] erlangen systemd[1]: systemd-suspend.service: Collecting.
22.878986] erlangen systemd[1]: systemd-suspend.service: Collecting.
333.306337] erlangen hd-idle[757]: spindown: sdb
541.545341] erlangen systemd[1]: systemd-suspend.service: Collecting.
541.551879] erlangen systemd[1]: systemd-suspend.service: Installed new job systemd-suspend.service/start as 1726
541.558094] erlangen systemd[1]: systemd-suspend.service: Passing 0 fds to service
541.558380] erlangen systemd[1]: systemd-suspend.service: About to execute /usr/lib/systemd/systemd-sleep suspend
541.558731] erlangen systemd[1]: systemd-suspend.service: Forked /usr/lib/systemd/systemd-sleep as 2652
541.559310] erlangen systemd[1]: systemd-suspend.service: Changed dead -> start
541.559465] erlangen systemd[1]: Starting System Suspend...
541.559652] erlangen systemd[2652]: systemd-suspend.service: Executing: /usr/lib/systemd/systemd-sleep suspend
541.599605] erlangen systemd-sleep[2654]: INFO: Skip running /usr/lib/systemd/system-sleep/grub2.sleep for suspend
541.602814] erlangen systemd-sleep[2652]: Entering sleep state 'suspend'...
553.898986] erlangen systemd-sleep[2711]: INFO: Skip running /usr/lib/systemd/system-sleep/grub2.sleep for suspend
553.905301] erlangen systemd[1]: systemd-suspend.service: Failed to read oom_kill field of memory.events cgroup attribute: No such file or directory
553.905345] erlangen systemd[1]: systemd-suspend.service: Child 2652 belongs to systemd-suspend.service.
553.905380] erlangen systemd[1]: systemd-suspend.service: Main process exited, code=exited, status=0/SUCCESS (success)
553.905456] erlangen systemd[1]: systemd-suspend.service: Deactivated successfully.
553.905502] erlangen systemd[1]: systemd-suspend.service: Service will not restart (restart setting)
553.905536] erlangen systemd[1]: systemd-suspend.service: Changed start -> dead
553.905574] erlangen systemd[1]: systemd-suspend.service: Job 1726 systemd-suspend.service/start finished, result=done
553.905614] erlangen systemd[1]: Finished System Suspend.
553.905765] erlangen systemd[1]: systemd-suspend.service: Consumed 114ms CPU time.
553.906093] erlangen systemd[1]: systemd-suspend.service: Control group is empty.
553.907054] erlangen systemd[1]: systemd-suspend.service: Collecting.
1194.987125] erlangen systemd[1]: systemd-suspend.service: Collecting.
1199.966308] erlangen systemd[1]: systemd-suspend.service: Collecting.
1199.979277] erlangen systemd[1]: hd-idle.service: Installed new job hd-idle.service/stop as 2292
1200.025407] erlangen systemd[1]: hd-idle.service: Changed running -> stop-sigterm
1200.025539] erlangen systemd[1]: Stopping hd-idle disk spindown service...
1200.036316] erlangen systemd[1]: hd-idle.service: Failed to read oom_kill field of memory.events cgroup attribute: No such file or directory
1200.036389] erlangen systemd[1]: hd-idle.service: Child 757 belongs to hd-idle.service.
1200.036416] erlangen systemd[1]: hd-idle.service: Main process exited, code=killed, status=15/TERM (success)
1200.036459] erlangen systemd[1]: hd-idle.service: Deactivated successfully.
1200.036489] erlangen systemd[1]: hd-idle.service: Service restart not allowed.
1200.036518] erlangen systemd[1]: hd-idle.service: Changed stop-sigterm -> dead
1200.036542] erlangen systemd[1]: hd-idle.service: Job 2292 hd-idle.service/stop finished, result=done
1200.036566] erlangen systemd[1]: Stopped hd-idle disk spindown service.
1200.036706] erlangen systemd[1]: hd-idle.service: Consumed 10ms CPU time.
1200.047303] erlangen systemd[1]: hd-idle.service: Control group is empty.
**erlangen:~ #**
I try to understand the script as I am wandering if I can use the same.
After search on the web, I can’t find explanations for:
malcolmlewis, I’d be glad to get the second script to start the devices.
Thanks
This is what happen even when I don’t use any HDD. System is in nvme SSD.
~> sudo journalctl -b -o short-monotonic -u hd-idle.service -u systemd-suspend.service
[sudo] password for root:
-- Logs begin at Mon 2022-03-14 17:46:44 GMT, end at Wed 2022-03-16 12:05:19 GMT. --
6.237117] localhost systemd[1]: Started hd-idle disk spindown service.
6.238452] localhost hd-idle[1125]: hd-idle starting in nodaemon mode
6.238452] localhost hd-idle[1125]: disk: sdd timeout: 300
6.238452] localhost hd-idle[1125]: disk: sdc timeout: 300
6.238452] localhost hd-idle[1125]: disk: sdb timeout: 300
6.238452] localhost hd-idle[1125]: disk: sda timeout: 300
6.238452] localhost hd-idle[1125]: default timeout: 0
366.241048] ASR5600G hd-idle[1125]: spindown: sda
366.566703] ASR5600G hd-idle[1125]: spindown: sdb
367.307255] ASR5600G hd-idle[1125]: spindown: sdc
367.710989] ASR5600G hd-idle[1125]: spindown: sdd
1808.945861] ASR5600G hd-idle[1125]: spinup: sda
1808.945861] ASR5600G hd-idle[1125]: spinup: sdb
1808.945861] ASR5600G hd-idle[1125]: spinup: sdc
1808.945861] ASR5600G hd-idle[1125]: spinup: sdd
2138.948133] ASR5600G hd-idle[1125]: spindown: sda
2139.225745] ASR5600G hd-idle[1125]: spindown: sdb
2139.495551] ASR5600G hd-idle[1125]: spindown: sdc
2139.906531] ASR5600G hd-idle[1125]: spindown: sdd
3610.172364] ASR5600G hd-idle[1125]: spinup: sda
3610.172364] ASR5600G hd-idle[1125]: spinup: sdb
3610.172364] ASR5600G hd-idle[1125]: spinup: sdc
3610.172364] ASR5600G hd-idle[1125]: spinup: sdd
3910.174305] ASR5600G hd-idle[1125]: spindown: sda
3910.174863] ASR5600G hd-idle[1125]: spindown: sdb
3910.174863] ASR5600G hd-idle[1125]: spindown: sdc
3910.174988] ASR5600G hd-idle[1125]: spindown: sdd
5410.185095] ASR5600G hd-idle[1125]: spinup: sda
5410.185095] ASR5600G hd-idle[1125]: spinup: sdb
5410.185095] ASR5600G hd-idle[1125]: spinup: sdc
5410.185095] ASR5600G hd-idle[1125]: spinup: sdd
5710.187060] ASR5600G hd-idle[1125]: spindown: sda
5710.196890] ASR5600G hd-idle[1125]: spindown: sdb
5710.196890] ASR5600G hd-idle[1125]: spindown: sdc
5710.196890] ASR5600G hd-idle[1125]: spindown: sdd
7210.197720] ASR5600G hd-idle[1125]: spinup: sda
7210.197720] ASR5600G hd-idle[1125]: spinup: sdb
7210.197720] ASR5600G hd-idle[1125]: spinup: sdc
7210.197720] ASR5600G hd-idle[1125]: spinup: sdd
Is there a log where I could know why this happen, according to the timestamp? How to read it?
The above shows plain and utter blunder. hd-idle does what it advertises. It spins down the disk(s) after specified idle time and monitor both spin up and spin down:
**erlangen:~ #** systemctl status hd-idle.service
**●** hd-idle.service - hd-idle disk spindown service
Loaded: loaded (/usr/lib/systemd/system/hd-idle.service; enabled; vendor preset: disabled)
Active: **active (running)** since Wed 2022-03-16 05:48:08 CET; 7h ago
Main PID: 759 (hd-idle)
Tasks: 1 (limit: 4915)
CPU: 217ms
CGroup: /system.slice/hd-idle.service
└─759 /usr/sbin/hd-idle -n -i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EZRX-22S_WD-WCC4E2FYXSNV -i 300
Mar 16 05:48:08 erlangen systemd[1]: Started hd-idle disk spindown service.
Mar 16 05:48:08 erlangen hd-idle[759]: hd-idle starting in nodaemon mode
Mar 16 05:48:08 erlangen hd-idle[759]: disk: sdb timeout: 300
Mar 16 05:48:08 erlangen hd-idle[759]: default timeout: 0
Mar 16 05:53:38 erlangen hd-idle[759]: spindown: sdb
Mar 16 06:08:08 erlangen hd-idle[759]: spinup: sdb
Mar 16 06:13:08 erlangen hd-idle[759]: spindown: sdb
**erlangen:~ #**
**erlangen:~ #** journalctl -b -u hd-idle.service
Mar 16 05:48:08 erlangen systemd[1]: Started hd-idle disk spindown service.
Mar 16 05:48:08 erlangen hd-idle[759]: hd-idle starting in nodaemon mode
Mar 16 05:48:08 erlangen hd-idle[759]: disk: sdb timeout: 300
Mar 16 05:48:08 erlangen hd-idle[759]: default timeout: 0
Mar 16 05:53:38 erlangen hd-idle[759]: spindown: sdb
Mar 16 06:08:08 erlangen hd-idle[759]: spinup: sdb
Mar 16 06:13:08 erlangen hd-idle[759]: spindown: sdb
**erlangen:~ #**
Setting LogLevel=debug and rebooting results in additional messages as already shown in post #13.
**erlangen:~ #** grep LogLevel /etc/systemd/system.conf
**LogLevel**=debug
**erlangen:~ #**
Hi
I need to find and rebuild the chase command, it’s for following symlinks. The system I used has been semi retired since I got my HP Z440 workstation…
To show clock time, don’t use the -o short-monotonic
I would also check out this since you have WD drives…
https://build.opensuse.org/package/show/utilities/idle3-tools
~> sudo systemctl status hd-idle.service
[sudo] password for root:
● hd-idle.service - hd-idle disk spindown service
Loaded: loaded (/usr/lib/systemd/system/hd-idle.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-03-16 10:04:57 GMT; 3h 57min ago
Main PID: 1125 (hd-idle)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/hd-idle.service
└─1125 /usr/sbin/hd-idle -n -i 0 -a /dev/disk/by-id/scsi-SATA_WDC_WD40EFRX-68N_WD-WCC7K1URKCCA -i 300 -a /dev/disk/by->
Mar 16 13:10:03 ASR5600G hd-idle[1125]: spindown: sdc
Mar 16 13:10:03 ASR5600G hd-idle[1125]: spindown: sdd
Mar 16 13:35:03 ASR5600G hd-idle[1125]: spinup: sda
Mar 16 13:35:03 ASR5600G hd-idle[1125]: spinup: sdb
Mar 16 13:35:03 ASR5600G hd-idle[1125]: spinup: sdc
Mar 16 13:35:03 ASR5600G hd-idle[1125]: spinup: sdd
Mar 16 13:40:03 ASR5600G hd-idle[1125]: spindown: sda
Mar 16 13:40:03 ASR5600G hd-idle[1125]: spindown: sdb
Mar 16 13:40:03 ASR5600G hd-idle[1125]: spindown: sdc
Mar 16 13:40:03 ASR5600G hd-idle[1125]: spindown: sdd
More and more spinuo/spindown even when I don’t use the PC
I changed the loglevel to debug. I’ll reboot now.
Could you point me what it does, how to use it and how to install it as it is not in my repos?
Hi
So I built chase;
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 931.5G 0 disk
└─sda1 8:1 1 931.5G 0 part
sdb 8:16 1 7.6G 0 disk
├─sdb1 8:17 1 260M 0 part /boot/efi
├─sdb2 8:18 1 512M 0 part /boot
└─sdb3 8:19 1 6.9G 0 part [SWAP]
nvme0n1 259:0 0 232.9G 0 disk
├─nvme0n1p1 259:1 0 40G 0 part /
└─nvme0n1p2 259:2 0 192.9G 0 part /var
hotswap
Usage: /usr/sbin/hotswap <Drive to remove /dev/sNX>
hotswap /dev/sda
/dev/sda
Syncing and unmounting /dev/sda
umount: /dev//dev/sda: no mount point specified.
Powering off /dev/sda
Disk /dev/sda safe to remove
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 7.6G 0 disk
├─sdb1 8:17 1 260M 0 part /boot/efi
├─sdb2 8:18 1 512M 0 part /boot
└─sdb3 8:19 1 6.9G 0 part [SWAP]
nvme0n1 259:0 0 232.9G 0 disk
├─nvme0n1p1 259:1 0 40G 0 part /
└─nvme0n1p2 259:2 0 192.9G 0 part /var
I can unplug the drive, when plugged back in it reappears.
Look at http://idle3-tools.sf.net/
Just install direct from the utilities repo link? Or manually download and install the rpm with zypper.
Idle3-tools can only read and set the idle timer. Not useful as hd-idle run fine.
After running the script for one HDD, is it possible to mount, start it back without unplug and re-plug it, only by software?
I ask that because at this time, HDDs spinup/spindown at interval. If I unmount them it could avoid this behaviour.
BTW did you try autofs to self mount and unmount disks? I use it with a shared HDD with NFS connected to router USB, working fine.