How does one enable --write-mostly with Linux RAID?

7

2

Unfortunately the mdadm and mdadm.conf man pages are not quite up to par. I would like to enable the --write-mostly flag for my RAID, but neither the man pages nor the internet will tell me how. I am not aware of any place to put default arguments for mdadm, nor aware of when it would be launched and by what.

It seems the logical place to add this information is mdadm.conf, but the flag is unmentioned in man mdadm.conf. Where and how can I enable --write-mostly? Thank you.

user76871

Posted 2012-01-17T16:50:16.890

Reputation: 791

Answers

15

You can set a device to be write mostly with, for example,

echo writemostly > /sys/block/md0/md/dev-sda1/state

and clear the write-mostly status with

echo -writemostly > /sys/block/md0/md/dev-sda1/state

Note that you probably need to be root for this to succeed, and that

sudo echo state > /sys/block/md0/md/dev-sda1/state

won't work.

If you have other questions about mdadm or Linux Software RAID, please post them to

linux-raid@vger.kernel.org

(you do not need to be subscribed).

The kernel panic bug that you mentioned in your answer is fixed in Linux kernel versions released in Jan 2012 and later – 3.1.10, 3.2.2, and 3.3-rc1. It only affected arrays in which all devices are 'write-mostly'.

NeilBrown

Posted 2012-01-17T16:50:16.890

Reputation: 166

1I find it strange how the sysfs input parameter is "writemostly", sysfs state file output is "write_mostly", and mdadm command line parameter is "write-mostly". Why so little consistency here I wonder. – lkraav – 2014-11-30T19:23:39.380

On my system, it looks like the path would instead be/sys/block/md0/md/dev-sda1/state (note the additional /md between md0 and dev-sda1), but I'm also using an older version. – rob – 2012-06-21T20:48:51.647

I just tried this with both mdadm v2.6.3 and v3.2.3, and typing the command as @NeilBrown originally wrote it produces a "No such file or directory" error. Typing the command as I wrote it in my previous comment works as long as you are logged in as root. I've edited the answer to reflect the correct path. – rob – 2012-06-22T21:27:46.807

Hmm, it seems the writemostly property is not persistent when set using this method. After a reboot, the property disappeared. – rob – 2012-06-22T21:34:30.887

3

It's been over a week, so to answer my own question:

Apparently you pass it as a command-line argument to mdadm when you create a new RAID array; just take the example in the man page and add --write-mostly. The man page says all devices after it will have write-mostly enabled; this is vague language so I can only assume it means the reasonable thing: that it applies to the next argument.

On kernel 3.1 (released Oct 2011), however, trying --write-mostly / --write-behind triggered a panic in [something...]scsi.c during some critical step, and destroyed my RAID array.

Also if you are splitting your array, make sure you know what you're doing. I found that my array had new UUIDs (possibly due to a new major metadata version) and was unsure how to proceed.

user76871

Posted 2012-01-17T16:50:16.890

Reputation: 791