Setting Write Cache on Drives on UnRAID

You might have run into this issue where the “Fix Common Problems” plugin gave you this warning:

Write Cache is disabled on parity/disk1/diskX

You may experience slow read/writes to parity/disk1/diskX. Write Cache should be enabled for better results. Read this post ( for more information. (…)

If you follow the link, you will see a recommendation to run hdparm -W 1 /dev/sdX and see whether it is successful, then add these commands to a script under the “User Scripts” plugin and set the scheduler so that it runs when the array is first mounted.

So you may write a script like this:


hdparm -W 1 /dev/sdb
hdparm -W 1 /dev/sdc
hdparm -W 1 /dev/sdd
# ... and so on ...

This script can be improved in two ways.

  1. Since we are running the same command with different parameters, group them into an array and iterate over it, like so:

declare -a drives=("sdb" "sdc" "sdd") # add more here

for drive in "${drives[@]}"
    hdparm -W 1 /dev/"$drive"
  1. Do not use /dev/sdX to access disks!

Why? Because these are not permanent, and may change across reboots as Linux sees fit!

A better solution would be to utilize the IDs that the drives come with. Run the following on your UnRAID server:

ls -al /dev/disk/by-id | grep "ata" | grep -v "\-part"

This will list the drives on your system, with their IDs and what /dev/sdX they map into:

# Example IDs, obviously
lrwxrwxrwx 1 root root   9 Jun 25 21:33 ata-WDC_WD1234ABCD-567890_WJAN01234567 -> ../../sdb
lrwxrwxrwx 1 root root   9 Jun 25 21:33 ata-WDC_WD1234ABCD-567890_WJAN01234568 -> ../../sdc
lrwxrwxrwx 1 root root   9 Jun 25 21:33 ata-WDC_WD1234ABCD-567890_WJAN01234569 -> ../../sdd
# ... and so on ...

Once you re-write the script, you should end up with something like this:


declare -a drives=("WDC_WD1234ABCD-567890_WJAN01234567" "WDC_WD1234ABCD-567890_WJAN01234568" "WDC_WD1234ABCD-567890_WJAN01234569") # add more here

for drive in "${drives[@]}"
    hdparm -W 1 /dev/disk/by-id/ata-"$drive"

Stick it in your “User Scripts” and set the schedule, and you should be good to go!