I was having some difficulty with a disk spinning up periodically and in the process of debugging it I created a small shell script which others might find useful if they have the same problem.
What it does:
- It writes out buffered data to the disk
- Enables Block Dump Reporting
- Puts the Drive into Standby (spin-down)
- Then sits in a while loop waiting for the drive to spin back up.
- When it does spin up it turns off the reporting and displays the messages relating to the drive you are watching.
Run: find_culprit <drive>
Example: find_culprit sdc
(/dev/sdc is my spin disk)
#!/bin/sh
#
# Discover what is writing to disk
#
set -e
DISK=${1-sdc}
HDPARM_CMD="/sbin/hdparm -C /dev/$DISK"
SLEEP_TIME=45
# Sync to flush the cache to disk
sync
# Enable Block Dump Reporting
echo 1 > /proc/sys/vm/block_dump
# Clear old messages
dmesg -c > /dev/null
echo "Putting the disk $DISK into standby..."
hdparm -y /dev/$DISK > /dev/null
sleep 3;
# Check the drive/sleep until it is awake
echo "Checking the status of $DISK."
HDPARM_RES=$($HDPARM_CMD|grep drive|cut -c 19-25)
while [ "$HDPARM_RES" = "standby" ]; do
echo "Drive is still in standby. Sleeping $SLEEP_TIME seconds..."
sleep $SLEEP_TIME;
HDPARM_RES=$($HDPARM_CMD|grep drive|cut -c 19-25)
done
echo "Drive is awake!"
# Turn off block dump
echo 0 > /proc/sys/vm/block_dump
# Display the accesses that awoke the disk
dmesg | grep $DISK
Alles anzeigen
Output looks like this:
root@openmediavault:~# ./find_culprit
Putting the disk sdc into standby...
Checking the status of sdc.
Drive is still in standby. Sleeping 45 seconds...
Drive is still in standby. Sleeping 45 seconds...
Drive is still in standby. Sleeping 45 seconds...
...
Drive is still in standby. Sleeping 45 seconds...
Drive is still in standby. Sleeping 45 seconds...
Drive is still in standby. Sleeping 45 seconds...
Drive is awake!
[24818.951861] cp(27268): dirtied inode 19005626 (Plex Media Server.log) on sdc1
[24818.951925] cp(27268): dirtied inode 19005626 (Plex Media Server.log) on sdc1
[24818.953546] cp(27268): WRITE block 278272 on sdc1 (256 sectors)
[24818.954386] cp(27268): dirtied inode 19005465 (com.plexapp.system.log) on sdc1
[24818.954441] cp(27268): dirtied inode 19005465 (com.plexapp.system.log) on sdc1
[24818.954962] cp(27268): WRITE block 608649568 on sdc1 (64 sectors)
[24818.956155] cp(27268): dirtied inode 19005451 (PMS Plugin Logs) on sdc1
[24818.956458] cp(27268): dirtied inode 19005448 (Logs) on sdc1
[24824.467173] jbd2/sdc1-8(1464): WRITE block 625215344 on sdc1 (8 sectors)
[24829.539190] flush-8:32(27274): WRITE block 0 on sdc1 (8 sectors)
[24829.539248] flush-8:32(27274): WRITE block 8 on sdc1 (8 sectors)
[24829.539279] flush-8:32(27274): WRITE block 296 on sdc1 (8 sectors)
[24829.539311] flush-8:32(27274): WRITE block 8808 on sdc1 (8 sectors)
[24829.539428] flush-8:32(27274): WRITE block 608174424 on sdc1 (8 sectors)
Alles anzeigen
So now I can see that the files:
- Plex Media Server.log (in Logs)
- com.plexapp.system.log (in PMS Plugin Logs)
Were modified.
In this case it was actually sync'ing the RAM directories back to the physical disk that woke it up (daily cron job). But this helps automate the work of finding what is accessing your disk and waking it up.