LoginSignup
4
3

More than 5 years have passed since last update.

hdparmでHDDの電源を落とす

Last updated at Posted at 2017-06-29

Ubuntu 17.04で動作確認。

udevからhdparmを呼び、スピンダウンタイムアウトを設定します。removableではないこと(USBメモリーではない)、rotationalであること(HDDである)を条件にしています(参考:hdparm - ArchWiki)。/etc/hdparm.confから設定すると個別にディスクを設定する必要があるので、udevから設定する方が楽です。

/etc/udev/rules.d/50-hdparm.rules
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{removable}=="0", ATTR{queue/rotational}=="1", RUN+="/sbin/hdparm -S 240 /dev/%k"

その後不必要に復帰していないか、一括で確認します。

lsblk -d -n -o NAME,RM,TYPE,MODEL,SERIAL -p |
  while read LINE; do NAME=$(echo $LINE | cut -d' ' -f1) &&
    [ $(echo $LINE | cut -d' ' -f2) -ne 0 -o "$(echo $LINE | cut -d' ' -f3)" != 'disk' ] &&
    continue;
    echo $(sudo hdparm -C $NAME | grep -e 'drive state is:') \
      $NAME \
      $(echo $LINE | cut -d' ' -f4) \
      $(echo $LINE | cut -d' ' -f5) \
      $(echo $LINE | cut -d' ' -f6);
  done
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3