diff mbox series

gemini: Add hdparm setting

Message ID 20210704220106.3799-1-linus.walleij@linaro.org
State Changes Requested
Headers show
Series gemini: Add hdparm setting | expand

Commit Message

Linus Walleij July 4, 2021, 10:01 p.m. UTC
This uses "hdparm" (if present) to get the harddisk into low
power mode on NAS set-ups.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 .../linux/gemini/base-files/etc/board.d/03_hdparm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100755 target/linux/gemini/base-files/etc/board.d/03_hdparm

Comments

Adrian Schmutzler July 4, 2021, 10:54 p.m. UTC | #1
Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of Linus Walleij
> Sent: Montag, 5. Juli 2021 00:01
> To: Sebastian Luft <sebastian.luft@gmail.com>; Hans Ulli Kroll
> <ulli.kroll@googlemail.com>; Hauke Mehrtens <hauke@hauke-m.de>;
> Christian Lamparter <chunkeey@gmail.com>
> Cc: Florian Fainelli <f.fainelli@gmail.com>; openwrt-devel@lists.openwrt.org;
> Linus Walleij <linus.walleij@linaro.org>
> Subject: [PATCH] gemini: Add hdparm setting
> 
> This uses "hdparm" (if present) to get the harddisk into low power mode on
> NAS set-ups.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  .../linux/gemini/base-files/etc/board.d/03_hdparm | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>  create mode 100755 target/linux/gemini/base-files/etc/board.d/03_hdparm
> 
> diff --git a/target/linux/gemini/base-files/etc/board.d/03_hdparm
> b/target/linux/gemini/base-files/etc/board.d/03_hdparm
> new file mode 100755
> index 000000000000..68d76f0acdf8
> --- /dev/null
> +++ b/target/linux/gemini/base-files/etc/board.d/03_hdparm
> @@ -0,0 +1,15 @@
> +#!/bin/sh

board.d files are not executable anymore. Please remove shebang and execute bit.

Please add an SPDX license identifier instead.

> +# Spin down drives after one minute if inactive
> +
> +which hdparm > /dev/null

I think using which has been discouraged lately in favor of command -v ...

> +if [ ! $? -eq 0 ] ; then

"$?" != 0 ?

> +	exit 0
> +fi
> +
> +DISKS=`find /dev/sd[a-z] 2>/dev/null`

Please use $() instead of backticks.

Best

Adrian

> +for DISK in $DISKS
> +do
> +	if [ -b $DISK ] ; then
> +		hdparm -S 12 /dev/sda > /dev/null
> +	fi
> +done
> --
> 2.31.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Andrey Jr. Melnikov July 15, 2021, 11:42 p.m. UTC | #2
Linus Walleij <linus.walleij@linaro.org> wrote:
> This uses "hdparm" (if present) to get the harddisk into low
> power mode on NAS set-ups.

Use hotplug events for this. 

i.e. /etc/hotplug.d/block/10-spindown with contents:

if [ "$ACTION" = "add" -a "$DEVTYPE" = "disk" ]; then
	case "$DEVNAME" in
		sd*) hdparm -S 60 /dev/$DEVNAME
		;;
	esac
fi
diff mbox series

Patch

diff --git a/target/linux/gemini/base-files/etc/board.d/03_hdparm b/target/linux/gemini/base-files/etc/board.d/03_hdparm
new file mode 100755
index 000000000000..68d76f0acdf8
--- /dev/null
+++ b/target/linux/gemini/base-files/etc/board.d/03_hdparm
@@ -0,0 +1,15 @@ 
+#!/bin/sh
+# Spin down drives after one minute if inactive
+
+which hdparm > /dev/null
+if [ ! $? -eq 0 ] ; then
+	exit 0
+fi
+
+DISKS=`find /dev/sd[a-z] 2>/dev/null`
+for DISK in $DISKS
+do
+	if [ -b $DISK ] ; then
+		hdparm -S 12 /dev/sda > /dev/null
+	fi
+done