Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Valid SSH Commands for creating and rebuilding RAID5 with 4 drives:

To create a RAID5 with 4 hard drives:

mdadm --create /dev/md1 --level=5 --raid-devices=4 /dev/hd[abcd]5

To rebuild a RAID5 with 4 hard drives:

mdadm --assemble /dev/md1 /dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2

share|improve this question

closed as unclear what you're asking by Braiam, desgua, mikewhatever, belacqua, guntbert Apr 30 '14 at 19:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

The data will be gone, but you will have a Raid 5... – davidbaumann Apr 29 '14 at 22:39
Please explain what you're trying to do (e.g., create a new, blank array, or repair an existing one), and why mdadm --assemble doesn't work. – derobert Apr 29 '14 at 22:56
@davidbaumann the use of --assume-clean shouldn't result in any data being overwritten other than the RAID configuration. – Zoredache Apr 29 '14 at 23:07
BTW, yes this may be a valid command to rebuild a RAID5 volume. No idea if it is the write command to re-build your volume, which I am guessing you are trying to recover. – Zoredache Apr 29 '14 at 23:09
@derobert, I am being trained to rebuild RAID5 arrays via SSH as an advanced technical support agent. I was told the above command is what should be used to do this, but I question it because the last time I used it, the RAID did not rebuild. I am looking for a better command. I think my instructor is missing something. – damata Apr 30 '14 at 4:50

Presuming you're trying to rebuild as in restore redundancy to an array that has lost one disk

  1. If the array is not already assembled, assemble it: mdadm --assemble --scan /dev/md1 (if it's in the config file) or mdadm --assemble /dev/md1 /dev/sda2 /dev/sdb2 /dev/sdc2 /dev/sdd2. If one of the disks has failed, just leave it off the line.
  2. If the rebuild was needed because because of an unclean shutdown, etc. it should happen automatically now. You can watch the status by cat /proc/mdstat. NOTE: If it says its in 'auto read-only mode', you need to write the the array (mounting the filesystem surely will), or use mdadm -w /dev/md1 to get it to start.
  3. If the rebuild is because of a failed disk, add the replacement disk to the array: mdadm -a /dev/md1 /dev/sde2 (sde2 being the new disk). You might have to do mdadm --run /dev/md1 as well.

If by "rebuild" you mean recover from something that is supposed to be fatal to RAID5 (e.g., double-disk failure), then that's more complicated, and the steps depend on exactly what lead up to the failure.

share|improve this answer
"If the rebuild is because of a failed disk, add the replacement disk to the array: mdadm -a /dev/md1 /dev/sde2 (sde2 being the new disk). You might have to do mdadm --run /dev/md1 as well." Can that last command be added to the former? something like :mdadm --run -a /dev/md1 /dev/sde2 – damata May 1 '14 at 21:14
@damata I don't think you can add it to the -a... you'd add it to the --assemble instead. I'm not sure if its required (and didn't feel like setting up a VM to test). – derobert May 1 '14 at 21:16
@damata I will add, though, that you probably should set up VMs to play with—they're a great way to learn how the stuff works. – derobert May 1 '14 at 21:17
Though I am a tech support agent, my IT dept doesn't believe in allowing us to install VM's to our workstations to test. I would do that if I could. I need 2 lines of code, one for rebuilding a RAID5 with 1 failed drive, one for creating a new RAID5 with 4 drives. I may also need some help with rebuilding a 2 disk RAID1 and have no help from the "Advanced Support". – damata May 1 '14 at 21:22
@damata --create is how you create a new (blank) one (though please don't use --assume-clean). --assemble is how you put together an existing array. -a is how you add a new disk to an array—if the array has all the disks it should, it will add a hot spare; if not, it'll use the new disk to rebuild a degraded array. Hopefully you can at least review the mdadm man page? Also, sounds may want to ask The Workplace how get your manager(s) to authorize training and/or experimentation. – derobert May 1 '14 at 21:30

No; --create means exactly what it says: create a new array. Replacing the failed drive with mdadm --add should automatically start the rebuild.

share|improve this answer
See the docs for the --assume-clean option, which the OP included in the command. The command has a chance of being valid, if what he uses has the options exactly indentical to the command that orignally created the array with the same drive order, chunk size and so on. – Zoredache Apr 29 '14 at 23:19
@Zoredache, rebuild means replace a failed drive, not blow away and recreate the array. The latter is very dangerous and often leads to tears. It should only be used if you really know what you are doing, and only then as a last resort. More often, people misuse it when they really want something else and trash their data. – psusi Apr 30 '14 at 3:12

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