威联通设置硬盘休眠(待机)的解决方法

warning: 这篇文章距离上次修改已过444天,其中的内容可能已经有所变动。

背景

好奇观察了下 453Bmini 硬盘的休眠(待机)情况,发现在已有 SSD 作为系统和软件安装区域后,HDD 仍不进入休眠状态,或进入休眠短时间被唤醒。
我的 1 号硬盘位是SSD,所以以 2 号硬盘位的 HDD 举例:查看硬盘是否休眠可通过命令 hdparm -C /dev/sdb,如果输出 drive state is: active/idle 则表示硬盘是唤醒状态,如果输出 drive state is: standby 则表示硬盘已休眠(低功耗模式)。

调查

首先排查 NAS 系统中是否开启了硬盘待机,在“控制台”>“系统”>“硬件”中,我已经开启;
排查了官方文档中描述的其他场景,我用了 Container Station,但是全部都是在 SSD 上,应当也不会阻止 HDD 休眠。
这就比较奇怪了,只能网上搜索一番,直到找到下面这两篇博客给我解了疑:


1.在威联通NAS上完美实现硬盘单独休眠
2.QNAP 威联通磁盘分区探索与数据导出

我将上面的博客内容总结一下,除系统盘之外的硬盘不能休眠,是因为 QNAP 选择将每一块硬盘都分出来两个区块,然后将这部分区块组成了 RAID1(下文称为“系统 RAID1”,路径为 /dev/md9 和 /dev/md13),也就是说只要系统有读写,那所有硬盘都将不能休眠。

那如何解决呢?很简单,将非系统盘的分区移出“系统 RAID1”即可,这里以我的第二块硬盘举例:

mdadm /dev/md9 --fail /dev/sdb1
mdadm /dev/md13 --fail /dev/sdb4

RAID1 的初衷是避免数据损坏,那我们也可以通过定时任务每天恢复“系统 RAID1”一段时间用于同步数据,之后再断开即可。

添加定时任务
这里我提供两个脚本,一个用于断开“系统 RAID1”,一个用于恢复“系统 RAID1”:

#!/bin/sh
# fail_raid1.sh(断开系统 RAID1)
mdadm /dev/md9 --fail /dev/sdb1
mdadm /dev/md13 --fail /dev/sdb4
#!/bin/sh
# readd_raid1.sh(恢复系统 RAID1)
mdadm /dev/md9 --re-add /dev/sdb1
mdadm /dev/md13 --re-add /dev/sdb4
#!/bin/sh
# raid1_monitor.sh(监控 HDD 是否休眠)
echo `date` `hdparm -C /dev/sdb | grep state` >> /share/CACHEDEV1_DATA/my_cron/raid1_monitor.log 2>&1

需要注意的是,QTS(QNAP 的系统)不能通过 crontab -e 这个方式添加定时任务,因为系统内部有一套逻辑会覆盖通过这种方法增加的定时任务,详情可参考官方文档:Add_items_to_crontab

# 每天 0 点恢复系统 RAID1
echo "0 0 * * * /bin/bash /share/CACHEDEV1_DATA/my_cron/readd_raid1.sh" >> /etc/config/crontab
# 每天 0 点 15 分恢复系统 RAID1
echo "15 0 * * * /bin/bash /share/CACHEDEV1_DATA/my_cron/fail_raid1.sh" >> /etc/config/crontab
# 每 10 分钟检测 HDD 是否休眠,结果保存在 raid1_monitor.log 中
echo "*/10 * * * * /bin/bash /share/CACHEDEV1_DATA/my_cron/raid1_monitor.sh" >> /etc/config/crontab
# 重启 crontab
crontab /etc/config/crontab && /etc/init.d/crond.sh restart

优化结果
优化效果显著,监控日志见文末附件。

附件
每 10 分钟监控硬盘状态日志

...
Tue Mar 17 23:20:00 HKT 2020 drive state is: standby
Tue Mar 17 23:30:00 HKT 2020 drive state is: standby
Tue Mar 17 23:40:00 HKT 2020 drive state is: standby
Tue Mar 17 23:50:00 HKT 2020 drive state is: standby
Wed Mar 18 00:00:00 HKT 2020 drive state is: active/idle
Wed Mar 18 00:10:00 HKT 2020 drive state is: active/idle
Wed Mar 18 00:20:00 HKT 2020 drive state is: active/idle
Wed Mar 18 00:30:00 HKT 2020 drive state is: standby
Wed Mar 18 00:40:00 HKT 2020 drive state is: standby
Wed Mar 18 00:50:00 HKT 2020 drive state is: standby
Wed Mar 18 01:00:00 HKT 2020 drive state is: standby
Wed Mar 18 01:10:00 HKT 2020 drive state is: standby
Wed Mar 18 01:20:00 HKT 2020 drive state is: standby
Wed Mar 18 01:30:01 HKT 2020 drive state is: standby
Wed Mar 18 01:40:01 HKT 2020 drive state is: standby
Wed Mar 18 01:50:00 HKT 2020 drive state is: standby
Wed Mar 18 02:00:00 HKT 2020 drive state is: standby
Wed Mar 18 02:10:00 HKT 2020 drive state is: standby
Wed Mar 18 02:20:00 HKT 2020 drive state is: standby
Wed Mar 18 02:30:00 HKT 2020 drive state is: standby
Wed Mar 18 02:40:00 HKT 2020 drive state is: standby
Wed Mar 18 02:50:00 HKT 2020 drive state is: standby
Wed Mar 18 03:00:00 HKT 2020 drive state is: standby
Wed Mar 18 03:10:00 HKT 2020 drive state is: active/idle
Wed Mar 18 03:20:00 HKT 2020 drive state is: active/idle
Wed Mar 18 03:30:00 HKT 2020 drive state is: active/idle
Wed Mar 18 03:40:00 HKT 2020 drive state is: standby
Wed Mar 18 03:50:00 HKT 2020 drive state is: standby
Wed Mar 18 04:00:00 HKT 2020 drive state is: active/idle
Wed Mar 18 04:10:00 HKT 2020 drive state is: active/idle
Wed Mar 18 04:20:00 HKT 2020 drive state is: active/idle
Wed Mar 18 04:30:00 HKT 2020 drive state is: standby
Wed Mar 18 04:40:00 HKT 2020 drive state is: active/idle
Wed Mar 18 04:50:00 HKT 2020 drive state is: active/idle
Wed Mar 18 05:00:00 HKT 2020 drive state is: active/idle
Wed Mar 18 05:10:00 HKT 2020 drive state is: standby
Wed Mar 18 05:20:00 HKT 2020 drive state is: standby
Wed Mar 18 05:30:00 HKT 2020 drive state is: standby
Wed Mar 18 05:40:00 HKT 2020 drive state is: standby
Wed Mar 18 05:50:00 HKT 2020 drive state is: standby
Wed Mar 18 06:00:00 HKT 2020 drive state is: active/idle
Wed Mar 18 06:10:00 HKT 2020 drive state is: active/idle
Wed Mar 18 06:20:00 HKT 2020 drive state is: active/idle
Wed Mar 18 06:30:00 HKT 2020 drive state is: standby
Wed Mar 18 06:40:00 HKT 2020 drive state is: standby
Wed Mar 18 06:50:00 HKT 2020 drive state is: standby
Wed Mar 18 07:00:00 HKT 2020 drive state is: standby
Wed Mar 18 07:10:00 HKT 2020 drive state is: standby
Wed Mar 18 07:20:00 HKT 2020 drive state is: standby
Wed Mar 18 07:30:00 HKT 2020 drive state is: standby
Wed Mar 18 07:40:00 HKT 2020 drive state is: standby
Wed Mar 18 07:50:00 HKT 2020 drive state is: standby
Wed Mar 18 08:00:00 HKT 2020 drive state is: standby
Wed Mar 18 08:10:00 HKT 2020 drive state is: standby
Wed Mar 18 08:20:00 HKT 2020 drive state is: standby
Wed Mar 18 08:30:00 HKT 2020 drive state is: standby
Wed Mar 18 08:40:00 HKT 2020 drive state is: standby
Wed Mar 18 08:50:00 HKT 2020 drive state is: standby
Wed Mar 18 09:00:00 HKT 2020 drive state is: standby
Wed Mar 18 09:10:00 HKT 2020 drive state is: standby
Wed Mar 18 09:20:00 HKT 2020 drive state is: standby
Wed Mar 18 09:30:00 HKT 2020 drive state is: standby
Wed Mar 18 09:40:00 HKT 2020 drive state is: standby
Wed Mar 18 09:50:00 HKT 2020 drive state is: standby
Wed Mar 18 10:00:00 HKT 2020 drive state is: standby
Wed Mar 18 10:10:00 HKT 2020 drive state is: standby
Wed Mar 18 10:20:00 HKT 2020 drive state is: standby
Wed Mar 18 10:30:00 HKT 2020 drive state is: active/idle
Wed Mar 18 10:40:00 HKT 2020 drive state is: active/idle
Wed Mar 18 10:50:00 HKT 2020 drive state is: active/idle
Wed Mar 18 11:00:00 HKT 2020 drive state is: standby
Wed Mar 18 11:10:00 HKT 2020 drive state is: standby
Wed Mar 18 11:20:00 HKT 2020 drive state is: standby
Wed Mar 18 11:30:00 HKT 2020 drive state is: standby
Wed Mar 18 11:40:00 HKT 2020 drive state is: standby
Wed Mar 18 11:50:00 HKT 2020 drive state is: standby
Wed Mar 18 12:00:00 HKT 2020 drive state is: active/idle
Wed Mar 18 12:10:00 HKT 2020 drive state is: active/idle
Wed Mar 18 12:20:00 HKT 2020 drive state is: active/idle
Wed Mar 18 12:30:00 HKT 2020 drive state is: standby
Wed Mar 18 12:40:00 HKT 2020 drive state is: standby
Wed Mar 18 12:50:00 HKT 2020 drive state is: standby
Wed Mar 18 13:00:00 HKT 2020 drive state is: standby
Wed Mar 18 13:10:00 HKT 2020 drive state is: standby
Wed Mar 18 13:20:00 HKT 2020 drive state is: standby
Wed Mar 18 13:30:00 HKT 2020 drive state is: standby
Wed Mar 18 13:40:00 HKT 2020 drive state is: standby
Wed Mar 18 13:50:00 HKT 2020 drive state is: standby
Wed Mar 18 14:00:00 HKT 2020 drive state is: standby
Wed Mar 18 14:10:00 HKT 2020 drive state is: standby
Wed Mar 18 14:20:00 HKT 2020 drive state is: standby
Wed Mar 18 14:30:00 HKT 2020 drive state is: standby
Wed Mar 18 14:40:00 HKT 2020 drive state is: standby
Wed Mar 18 14:50:00 HKT 2020 drive state is: standby
Wed Mar 18 15:00:00 HKT 2020 drive state is: standby
Wed Mar 18 15:10:00 HKT 2020 drive state is: standby
Wed Mar 18 15:20:00 HKT 2020 drive state is: active/idle
Wed Mar 18 15:30:00 HKT 2020 drive state is: active/idle
Wed Mar 18 15:40:00 HKT 2020 drive state is: active/idle
Wed Mar 18 15:50:00 HKT 2020 drive state is: active/idle
Wed Mar 18 16:00:00 HKT 2020 drive state is: active/idle
...
最后修改于:2021年04月15日 12:45

添加新评论