Skip to contentSkip to conversation

script to disable writeback when a drive is idle

DISCUSSION [email protected] 1 participant 1 message Jan 6, 2021 bcache (block layer cache)

lore
Share & tools
lore
#0 lore raw

Hi all,

I have two stacks of a HDD with a bcache SSD in front of it in writeback mode. I have made the following quick and dirty script to disable writeback when the HDD is in standby. I hope it helps somebody:

# cat writeback.sh
#!/bin/bash

function sdbGetState()

{
        hdparmstr=$(hdparm -C /dev/sdb | grep drive)
    echo $hdparmstr
}

function sddGetState()

{
        hdparmstr=$(hdparm -C /dev/sdd | grep drive)
        echo $hdparmstr
}

strSdb=$(sdbGetState)
echo $strSdb

strSdd=$(sddGetState)
echo $strSdd

if [ "$strSdd" = 'drive state is: active/idle' ]; then
echo 1 > /sys/block/bcache0/bcache/writeback_running echo active
else
echo 0 > /sys/block/bcache0/bcache/writeback_running echo idle
fi

if [ "$strSdb" = 'drive state is: active/idle' ]; then
echo 1 > /sys/block/bcache1/bcache/writeback_running echo active
else
echo 0 > /sys/block/bcache1/bcache/writeback_running echo idle
fi

---

Take your mailboxes with you. Free, fast and secure Mail & Cloud: https://www.eclipso.eu - Time to change!