How do you turn off write cache permanently for external USB drives in Linux (I'm using Ubuntu)?
I've tried:
Command line method :
hdparm -W0 /dev/sdb <—- that works but only for the current drive and resets after reboot.
The hdparm "-k1" flag should force it to keep the setting, but it says:
HDIO_SET_KEEPSETTINGS failed: Invalid argument
HDIO_GET_KEEPSETTINGS failed: Invalid argument
Configuration file method (seems to be another way to do it permanently) :
The next thing I found was modifying the "hdparm.conf" file located in /etc.
However, that seems to require that you know ahead of time the drive letter, "sdb, sdc…" etc.
How do you just blanket cover ALL drives no matter what, or specifically all USB externals?
The key problem is.. I'm not sure of the order I will connect these USB external drives, therefore the drive letter will change, so I can't just name "sdb" specifically since it might not be "sdb"…
Is this a situation where hdparm.conf can have an entry multiple times over even for drives letters that aren't even connected? That way, no matter what drive is connected it will just turn the write_cache off preemptively. Or will that mess something up?
Possible /etc/hdparm.conf example (will this work?):
/dev/sda {
write_cache = off
}
/dev/sdb {
write_cache = off
}
/dev/sdc {
write_cache = off
}
/dev/sdd {
write_cache = off
}
Again, those drives may not even exist yet… Just covering as many letters of the alphabet preemptively so no matter what, the write_cache is off. I would think there's got to be a better way than this though..
Any other ideas? Or better approaches? Thank you!
Best Answer
You need to use the -K option. From man hdparm