Disabling Hard Disk caches on individual drives?

Nicholas Leippe nick at leippe.com
Mon Apr 1 04:39:17 MDT 2013


On Mon, Apr 1, 2013 at 2:20 AM, Dan Egli <ddavidegli at gmail.com> wrote:
>
> *Something that was mentioned a week or two back and I meant to follow up
> but never did was changing cache mode for Linux's disk writes. How does one
> accomplish that and can it be done on an individual drive basis? I.e.
> Suppose I am using a set of hard disks in USB3 or eSATA enclosures to
> backup my home system. If I backup the entire raid (i.e. dd if=/dev/md0
> of=/dev/md1) then how do I make sure that all the data was properly written
> to the drives in md1 before I disconnect the drives and turn them off
> (since they're in enclosures I can simply turn the enclosures off)? I don't
> want to write that way, only to assume that everything is OK and find out
> later that something didn't get written right. And yes, I know I could
> simply do an individual file backup, and that's on the agenda too. But even
> then, unless unmounting the md1 would force all cached data to be written
> immediately anyway. But I am considering both options.  So I would
> appreciate it if someone could explain to me (since I've never tried
> before) how you can go about disabling write caching to an individual drive.

umount # forces all data to be written
sync # also forces all data to be written

The above two may not cause underlying block device to commit caches.
These below should, if supported by the device:

hdparm -F
sdparm -C sync
sdparm --clear=WCE

other options may also exist

Also, some external enclosures interfere with reading/setting some or
all options that the underlying drive may actually provide. YMMV.


More information about the PLUG mailing list