5

It is often written that disks in a mirrored RAID (like RAID 1) are an exact mirror copy one of another.

So can I turn the machine off and simply swap the two harddisks cables?

And if one of the two disks crashes and is dead forever, can I simply turn the machine off, put a third (new) harddisk instead of the dead one, boot from a live CD and "dd" the entire content of the disk which is still good to the new disk and then boot again with RAID 1 operational?

If it's not that simple, why isn't it so?

8

An identical copy of your data is stored on each disk (provided the array is not "dirty"—e.g., if power is lost after writing to disk 0, but before writing to disk 1). However, the metadata is different; it allows mdadm & md to tell the two disks apart.

Can you swap the cables around?

You can swap the cables on the two disks. When you (or your distro's boot scripts) do mdadm --assemble on the array, mdadm looks at the metadata on each disk, and from that figures out which is disk 1 and which is disk 2.

This is in fact extremely flexible—you could, for example, remove one of the disks, put it in a USB-SATA enclosure, and attach it to a USB port, and mdraid would still be perfectly happy.

Can I recover a degraded array by using dd?

No. If you did that, you'd have two disk 1's, or two disk 2's, and mdadm would be confused (and, I haven't tested this, but I assume it'd refuse to assemble the array).

In general, all array management is done with mdadm and further it is seldom a good idea to go around mdraid. To recover your array, you add the new disk/partition to it. Something like this, assuming sdb1 is the partition on the replacement disk:

mdadm --add /dev/md0 /dev/sdb1

mdraid will then copy the data, and you can watch the status by cat /proc/mdstat. You are free to continue using the array during the re-sync. There is no need to boot from a live CD or similar (you should be able to boot from the degraded array). In fact, if you have hot-swap trays in your machine, you can replace a failed sdb like this:

  1. mdadm -r /dev/md0 /dev/sdb1
  2. Remove the drive
  3. Put in new drive
  4. Partition the new drive (often, but not always, will be sdb again).
  5. mdadm -a /dev/md0 /dev/sdb1

This does not require any downtime.

Note also that if you're booting from a mirror, you need to make sure the bootloader (e.g., grub) is installed to both disks. How to do this depends on your distro.

Anything else?

Yes. mdadm --create is not a recovery step. It is used to create a new, blank array, and the next step would typically be pvcreate or mkfs. Already existing arrays are started using mdadm --assemble. (This seems to be a common enough error, and has the potential to destroy data.)

Final remarks

You should probably take a bit to familiarize yourself with the mdraid documentation (you are trusting it with your data, after all). In particular, read through the mdadm manual page, any RAID documentation your distro puts out, and Documentation/md.txt (from the kernel sources, corresponding to your kernel version). These are probably not the most understandable documents, but they are all generally up-to-date.

There is also a Linux Raid wiki, but beware that not everything there is fully up-to-date.

There are other pages out there, but be especially cautious of anything mentioning mkraid or /etc/raidtab other than as a historical note, as those tools have be obsolete for a decade.

  • +1, thanks a lot for the detailed explanation and the caveat about the old mkraid and /etc/raidtab doscs! It's a bit clearer now. I'm still not sure if it's worth to configure on my desktop / workstation but I'll look into it. – Cedric Martin Oct 23 '13 at 14:55
  • @CedricMartin if you have two disks, it's worth it on a desktop. It's not that much to configure (especially if you're using a distro like Debian where the installer will do it for you) and you'll be quite happy when it saves you from a disk failure, bad sector, etc. – derobert Oct 23 '13 at 14:57
3

The disks are not 100% identical. Each linux softraid device contains a metadata block with a uniq guid. So dd might not work.

The ports don't matter though. You can even put your drive into an extrernal usb box and it will still work. Doesn't work with hardware raid of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.