You are not logged in.

#1 2010-08-08 22:45:29

tntcoda
Member
Registered: 2007-07-24
Posts: 115

Persistent hdparm idle drive spindown (Solved)

Hi,

I want to spin down 3 hard drives after a few minutes of idling.

It works fine with: hdparm -S 120 /dev/sdX

My question is, where is the best place to put this to make it persistent across reboots?

Thanks.

EDIT:

Also, is there anyway to check if a given drive has an idle spin down time set on it?

Last edited by tntcoda (2010-08-09 01:26:48)

Offline

#2 2010-08-08 23:57:37

lagagnon
Member
From: an Island in the Pacific...
Registered: 2009-12-10
Posts: 1,087
Website

Re: Persistent hdparm idle drive spindown (Solved)

Put those commands at the bottom of your /etc/rc.local file.
"sudo hdparm -I /dev/sdX" should give you the info you want.


Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.

Offline

#3 2010-08-09 00:17:55

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Persistent hdparm idle drive spindown (Solved)

The current power mode status can be checked using the -C flag.
-S 120 means 10 minutes.

Offline

#4 2010-08-09 00:33:38

tntcoda
Member
Registered: 2007-07-24
Posts: 115

Re: Persistent hdparm idle drive spindown (Solved)

lagagnon wrote:

Put those commands at the bottom of your /etc/rc.local file.
"sudo hdparm -I /dev/sdX" should give you the info you want.

Thanks very much.

Can I make use of that script on a non-sudo system? I always use su to get root.

Offline

#5 2010-08-09 00:40:06

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Persistent hdparm idle drive spindown (Solved)

tntcoda wrote:
lagagnon wrote:

Put those commands at the bottom of your /etc/rc.local file.
"sudo hdparm -I /dev/sdX" should give you the info you want.

Thanks very much.

Can I make use of that script on a non-sudo system? I always use su to get root.

You mean

su -c "hdparm -I /dev/sda1"

? Sure, you can use su, why not.

Offline

#6 2010-08-09 00:48:20

tntcoda
Member
Registered: 2007-07-24
Posts: 115

Re: Persistent hdparm idle drive spindown (Solved)

karol wrote:
tntcoda wrote:
lagagnon wrote:

Put those commands at the bottom of your /etc/rc.local file.
"sudo hdparm -I /dev/sdX" should give you the info you want.

Thanks very much.

Can I make use of that script on a non-sudo system? I always use su to get root.

You mean

su -c "hdparm -I /dev/sda1"

? Sure, you can use su, why not.

I just wanted to avoid entering the root password on every boot with su when the script runs, but given that I should probably just get sudo up and running smile Thanks.

EDIT: oops, it looks like rc.local runs as root anyway so shouldnt be an issue smile

Last edited by tntcoda (2010-08-09 00:51:39)

Offline

#7 2010-08-09 00:53:06

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Persistent hdparm idle drive spindown (Solved)

tntcoda wrote:
karol wrote:
tntcoda wrote:

Thanks very much.

Can I make use of that script on a non-sudo system? I always use su to get root.

You mean

su -c "hdparm -I /dev/sda1"

? Sure, you can use su, why not.

I just wanted to avoid entering the root password on every boot with su when the script runs, but given that I should probably just get sudo up and running smile Thanks.

After you get sudo, you can set all the things you want via the 'visudo' command - passwordless executing commands too.

Offline

#8 2010-08-09 16:45:08

R00KIE
Forum Moderator
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: Persistent hdparm idle drive spindown (Solved)

As far as I know rc.local is ran as root so there is no need to add su or sudo, at least it works for me™ without those.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#9 2010-11-12 22:57:43

dwheeler
Member
Registered: 2010-11-12
Posts: 16

Re: Persistent hdparm idle drive spindown (Solved)

I needed to do something similar: with a funky mobo/BIOS/drive combo, one of my drives doesn't always save SMART settings, which results in bad things happening if the drive comes up with this turned off and various services (DBUS-related mostly) start sending SMART commands. Also, write-caching s/b turned off for drives with mysql database files. rc.conf would execute both of these things much too late in the boot process. I found this buried in /etc/rc.d/functions:

###############################
# Custom hooks in initscripts #
###############################
# Hooks can be used to include custom code in various places in the rc.* scripts
#
# Define a hook function in a functions.d file using:
#  function_name() {
#    ...
#  }
#  add_hook hook_name function_name
# It is allowed to register several hook functions for the same hook
# Is is also allowed to register the same hook function for several hooks
#
# Currently, the following hooks exist:
# sysinit_start: at the beginning of rc.sysinit
# multi_start: at the beginning of rc.multi
# single_start: at the beginning of rc.single
# shutdown_start: at the beginning of rc.shutdown
# sysinit_end: at the end of rc.sysinit
# multi_end: at the end of rc.multi
# single_end: at the end of rc.single
# sysinit_udevlaunched: after udev has been launched in rc.sysinit
# single_udevlaunched: after udev has been launched in rc.single
# sysinit_udevsettled: after uevents have settled in rc.sysinit
# single_udevsettled: after uevents have settled in rc.single
# sysinit_premount: before local filesystems are mounted, but after root is mounted read-write in rc.sysinit
# shutdown_prekillall: before all processes are being killed in rc.shutdown
# single_prekillall: before all processes are being killed in rc.single
# shutdown_postkillall: after all processes have been killed in rc.shutdown
# single_postkillall: after all processes have been killed in rc.single
# shutdown_poweroff: directly before powering off in rc.shutdown
#
# Make sure to never override the add_hook and run_hook functions via functions.d

Armed with this knowledge, I added a new file - /etc/rc.d/functions.d/hd_settings - with the commands and the hook setup like so:

hd_settings() {
    /usr/sbin/smartctl -s on /dev/sda
    /usr/sbin/smartctl -s on /dev/sdb
    /sbin/hdparm -W0 /dev/sda
}
add_hook sysinit_udevsettled hd_settings

This executes the needed commands as soon as udev has settled - i.e., as soon as dev nodes are available.

Offline

Board footer

Powered by FluxBB