Software Raid on Ubuntu and Debian
Although this procedure is not taken from the Managing RIAD on Linux, you should still get it because it is a great book!
After many, many attempts to get software RAID working on both Debian and Ubuntu the system would always lockup during boot and would not do any thing after that.
The system wont boot after a fresh install.
After banging my head a few hundred times I finally found a procedure that works!!!!!!
Install Ubuntu or Debian as you normally would, and configure RAID right from the installer. Once the installation is done the server will not boot, how stupid is that. what you need to do now is to insert the Ubuntu CD again and boot in Rescue mode.
Once the rescue mode reaches the disk partitioning screen press ESC and Select “Execurte a Shell” from the list.
Now mount your boot device, which you can do with
mount /dev/md0 /mntchroot /mnt
Now you should use grub to write the MBR to both disks. Type
grub
if you get an error like
'Error opening terminal: bterm' just set your terminal to something else like so:
export TERM=linux
You may not see a clear display, meaning the lines will overlap but it works. Now run grub again.
For disk 1:
grub device (hd0) /dev/hda root (hd0,0) setup (hd0) quit
For Disk 2:
grub device (hd1) /dev/hdb root (hd1,0) setup (hd1) quit
If you’re not sure which devices you have just do:
cat /boot/grub/device.map
Should look like this:
(hd0) /dev/hda (hd1) /dev/hdb
Use those! After doing this reboot your server, and you should now be able to boot your machine using RAID!
You should repeat this procedure every time you rebuild your RAID set or upgrade your Kernel.

Thanks very much for the tip! When I installed Ubuntu the system booted just fine, but this is exactly what I was trying to figure out to get the system to boot from disk 2.
I’ve incorporated your tips into an article I just posted on my blog… http://advosys.ca/viewpoints/2007/04/setting-up-software-raid-in-ubuntu-server
(By the way, the line breaks in the code examples in this post seem to be a little messed up)
I have to congratulate you D Webber on such a well written article!
Fixed the line breaks, thanks!
if you disconnect a drive from the array and reboot, it eventually goes to (initramfs).
shouldn’t there be MBRs on both disks individually so that if one disk fails that it will still work until someone can attend to the failed disk?
X William:
I’ve just tried. The MBR is there, but the behaviour is as you said, because it tries to boot on md0, which in turn cannot find sda1. But if you use mdadm to first mark sda1 as failed and then remove it from md0 (while the system is running of course), then when you reboot and phisically disconnect the drive it will boot without problems, because md0 is relying on sda2 only.
OK… this all looks wonderful except when chroot fails?
Yes there are the expected files in /mnt when I mount /dev/md0 on it, but it fails anyway.
I’ve seen the same problem on other how to articles, but no one seems to help.
Any ideas?
$ chroot /mnt
chroot: cannot execute /bin/sh: No such file or directory
Please help!
I ran throught this tutorial :
http://advosys.ca/viewpoints/2007/04/setting-up-software-raid-in-ubuntu-server/
and I’m unable to do this command :
device (hd0) /dev/hda
I get an error “Error 15 file not found”. However before starting grub, it was present. Any hint ?
Manny,
you need to find out what file represents your disk in your install. If you have SATA disks they usually don’t mount to /dev/hdx, but /dev/sdx. So try with /dev/sda, /dev/sdb, etc
Thanks for th tutorial. It worked for me on two Lenny systems. First one was a test server at home with two PATA disks. So I could use your tut nearly on the fly. I only had to change “root (hd0,0)” to point to my /boot partition whitch is /dev/hda2, so I used “root (hd0,1)” instead. Same on our root server, but there are SATA disks, so I had to choose the device /dev/sda and /dev/sdb.
I also experimented with unpluging the harddisks (after poweroff) and booting with only one disk. It worked like a charme. But after pluging in booth disks and powering on again, cat /proc/mdstat showed only one disk! So I had to add the disk / partitions to the md again: “mdadm /dev/md1 -a /dev/hda2″