To write this how to I’ll be redo the installation using two USB memory sticks as hard drives. The sticks, with 4GB capacity each one, are from different manufacturers but this should not affect the results.
So, let’s start:
- Boot in the Live CD (or USB) and choose to try without install
- Using GParted (System -> Administration -> GParted) create the partitions with the sizes you wish. Make sure the partitions you will use in RAID has exactly the same size. The file system type is not important because you will format the RAID array afterwards.
- Now, using apt-get, the application mdadm (don’t forget to run apt-get update first). That what will manage the array for us.
- During the installation process postfix (mail server) will also be installed. To configure it just choose Local only and answer the questions of the wizard.
- That’s an easy but important step, here we are going to create out array. To do that I used the following command:
- --create is creating the array /dev/md1
- --verbose gives you better idea what’s going on in case you have a problem
- --level=1 sets RAID 1
- --raid-devices=2 is the number of devices we want in the array
- /dev/sdb1 /dev/sdc1 are the devices members of the created array
- To format the new array with the file system you want use the command line. In the following example I’m using ext4 but it could be ext2, ext3, xfs, etc.
- Open the Ubuntu Installer using the shortcut in the desktop. Choose the language you prefer, the time zone you are located and your keyboard layout. After that you should be in the step 4: Prepare disk space. Choose the last option “Specify partitions manually (advanced)“. Select the RAID array to be used by the mount point you want. In my case I’m using as / (root). Click in forward, configure you user, recheck the information and client in install.
- Wait until the installation in finished.
- Mount the installation (and also proc, sys and dev on it) and chroot to the directory:
- Install mdadm with apt-get (like you did in the step 3):
- At this point you should be able to boot in your new system, but WAIT! The Ubuntu installer usually install the boot loader (GRUB2) in just one of your disks, if this disk fails you won’t be able to boot your system. To avoid that let’s install it in both disks:
- Reboot your system, remove the CD and enjoy your redundancy. ;)
# mdadm --create /dev/md1 --verbose --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
Explainig the command:
Executing that command you probably get a message similar to that:
mdadm: /dev/sda1 appears to contain an ext2fs file system
size=3927860K mtime=Thu Jan 1 01:00:00 1970
mdadm: size set to 3909248K
Continue creating array?
Type “yes“ and press enter. Your array should be created.
# mkfs.ext4 /dev/md1
The following steps are the most tricky and took me a while to find out the problem. Our new ubuntu installation doesn’t have mdadm installed on it so when you try boot the array can’t be assemble and, obviously, you can’t boot on it. So let’s install mdadm.
# mount /dev/md1 /target/
# mount --bind /dev/ /target/dev/
# mount --bind /sys/ /target/sys/
# mount --bind /proc/ /target/proc/
# chroot /target
# apt-get update
# apt-get install mdadm
# grub-install /dev/sdb
# grub-install /dev/sdc
root@ubuntu:/# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb1[1] sdc1[0]
3909248 blocks [2/2] [UU]
by seocam - (Sergio Oliveira)
Thanks, exactly what I needed :-)
ReplyDeleteBeen following this instruction. Thanks very much for creating it.
ReplyDeleteI found that after following these steps I was getting these errors:
ReplyDelete/usr/sbin/grub-setup: warn: This GPT partition label has no BIOS Boot Partition; embedding won't be possible!.
/usr/sbin/grub-setup: error: embedding is not possible, but this is required when the root device is on a RAID array or LVM volume.
To fix them I did the following for both volumes in the mirror:
parted /dev/sda
toggle 1 bios_grub
quit
Great stuff, thanks! A couple notes from my experience...
ReplyDeleteBefore the chroot command, all commands require 'sudo' to work.
My drives were mounted as /dev/sda and /dev/sdb so I had to make those adjustments as needed.
Other than that it worked perfectly.
I don't know why I can't get this to work.
ReplyDeleteFirst of all, I want to have dual boot with windows. Windows is already installed.
When I tried this the first time, I was not able to shrink my windows partition in order to create a linux partition. So I booted the computer with a Partition magic CD. I was then able to create a new empty partition using partition magic.
After that I booted up with the ubuntu CD.
I tried to create a filesystem on the empty partition using GParted. That did not work. I got a message telling me that the devices was already in use.
So I skipped to step 3 and 4 of this guide. When I got to step 4, I got an error message telling me that /dev/md1 couldn't be created or something.
Any ideas what could be messing with me?
//U
Excellent, worked perfectly, Thanks!!
ReplyDeleteI did the same type of install but I used different method:
ReplyDelete1. Using Ubuntu Server CD create RAID and install the basic system.
2. Run tasksel and install GNOME.
That's it, done!
Install with this guide went flawless, except for the second installation of mdadm. Something got messed up during postfix and now every install with dpkg returns an error.
ReplyDeleteFound a fix for my problem; follow the guide and when you first start it up after the installation, remove/reinstall postfix. So...
ReplyDeletesudo apt-get remove --purge postfix
sudo apt-get install postfix
Alternatively, you can do a complete removal/installation through Synaptic. That's what I did. No more dpkg errors or failed installs.
Thanks for the post. It came in very handy when I used it to set up RAID5 using 4 disks.
ReplyDeleteIf anyone else does this you should be aware that by default the mdadm command always leaves 1 drive spare on RAID5 systems which means the state is left as clean, degraded. You can get around this but it is probably better to use the --force parameter to prevent it in the first place.
You've got to be superuser to run those commands; if you're running the Live version you just need to slap "sudo" in front of every command featured here.
ReplyDeleteI also tried Ubuntu server, but it failed for some reason or other. Not so friendly (in general), either.
everything it's all right, but grub2 returns error 21, the same problem has mstrswrd06, the second installation of mdadm (system says that mdadm is alredy isntalled).
ReplyDeletesorry for my english
I had reasonable success following the instructions, but I ended up getting stuck on an mdadm.conf with no ARRAY entries causing boot to fail. I managed to fix it eventually; commentary up at http://async.com.br/~kiko/diary.html?date=05.08.2010
ReplyDeleteI found that after you get into your new install, if you have left two equal partitions on your RAID 1 array, you can assemble them into another raid disk and then using the disk tool format them into swap space. Seems to be working so far.
ReplyDeleteI have never partitioned drives before. I am lost at step 6 where it says to "Select the RAID array to be used by the mount point you want" There are a bunch of things listed in that screen, do I need to change any of the others?
ReplyDeleteworked great - thanks a lot!
ReplyDeletesorry for this question if its too obvious...
ReplyDeleteon the 8th step what do we have to type on "/target/" ???
it gives me an error when i tried it
Ace! worked a treat! Thanks alot.
ReplyDeleteThank you very much, exactly what I needed. Only question, and yes fairly new, during step 6 I was not able to install a swap space? Did I miss something or was this not needed? Thanks again.
ReplyDeleteHi,
ReplyDeleteThank you for this tuto. This works, except a problem that is booting in degraded mode on the second drive is impossible.
It works with 2 drives, it works in degraded mode with the first drive, but not with the second.
Is it OK for you?
This is the greatest tutorial ever. I just used it to get Kubuntu 10.10 to install on RAID 0. Thanks for taking the time to write it all down!
ReplyDeleteWorked like a charm with ubuntu 10.10 as well. Thank you for sharing this!
ReplyDeleteOnly caveeat: Could not do apt-get upgrade with the live cd. The updates plainly used up all avail RAM and stopped so I went back to simply install mdadm. Worked fine though.
BTW: Used cfdisk to create my partitions. Gparted displayed the size of my discs wrong and I didn't feel like taking the risc ;)
-- beko
Excellent article - worked for me, many thanks :)
ReplyDeleteThis is excellent! Just copy from start to finish using sudo where required.
ReplyDeleteMany Many thanks.
ITMANAGER
Hey, exellent guide.
ReplyDeleteSeems to me it would be easier to do this using the alternate install CD instead of trying to do this through the standard graphical install. The alternate install partitioning tool allows you to set up RAID and/or LVM as part of the installation process, and ensures that the required tools (e.g. mdadm) are part of the initial install.
ReplyDelete