Tuesday, May 11, 2010

Installing Ubuntu 10.04 Desktop with RAID 1 (mirror) Using the Graphic Installer

Last weekend I spend some considerable time trying to install the Lucid Lynx in my computer using RAID 1 and in the end it works :)

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:

  1. Boot in the Live CD (or USB) and choose to try without install

  2. 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.

  3. 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.

  4. That’s an easy but important step, here we are going to create out array. To do that I used the following command:

  5. # mdadm --create /dev/md1 --verbose --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

    Explainig the 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

    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.

  6. 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.

  7. # mkfs.ext4 /dev/md1

  8. 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.

  9. Wait until the installation in finished.

  10. 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.

  11. Mount the installation (and also proc, sys and dev on it) and chroot to the directory:

  12. # mount /dev/md1 /target/
    # mount --bind /dev/ /target/dev/
    # mount --bind /sys/ /target/sys/
    # mount --bind /proc/ /target/proc/
    # chroot /target

  13. Install mdadm with apt-get (like you did in the step 3):

  14. # apt-get update
    # apt-get install mdadm

  15. 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:

  16. # grub-install /dev/sdb
    # grub-install /dev/sdc

  17. Reboot your system, remove the CD and enjoy your redundancy. ;)
PS: If you want to check the status of the syncronization of your disc check the file /proc/mdstat

root@ubuntu:/# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb1[1] sdc1[0]
3909248 blocks [2/2] [UU]

by seocam - (Sergio Oliveira)

26 comments:

  1. Thanks, exactly what I needed :-)

    ReplyDelete
  2. Been following this instruction. Thanks very much for creating it.

    ReplyDelete
  3. I found that after following these steps I was getting these errors:


    /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

    ReplyDelete
  4. Great stuff, thanks! A couple notes from my experience...

    Before 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.

    ReplyDelete
  5. I don't know why I can't get this to work.

    First 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

    ReplyDelete
  6. Excellent, worked perfectly, Thanks!!

    ReplyDelete
  7. I did the same type of install but I used different method:

    1. Using Ubuntu Server CD create RAID and install the basic system.

    2. Run tasksel and install GNOME.

    That's it, done!

    ReplyDelete
  8. 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.

    ReplyDelete
  9. Found a fix for my problem; follow the guide and when you first start it up after the installation, remove/reinstall postfix. So...

    sudo 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.

    ReplyDelete
  10. Thanks for the post. It came in very handy when I used it to set up RAID5 using 4 disks.

    If 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.

    ReplyDelete
  11. 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.
    I also tried Ubuntu server, but it failed for some reason or other. Not so friendly (in general), either.

    ReplyDelete
  12. 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).

    sorry for my english

    ReplyDelete
  13. 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

    ReplyDelete
  14. I 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.

    ReplyDelete
  15. I 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?

    ReplyDelete
  16. worked great - thanks a lot!

    ReplyDelete
  17. sorry for this question if its too obvious...

    on the 8th step what do we have to type on "/target/" ???

    it gives me an error when i tried it

    ReplyDelete
  18. Ace! worked a treat! Thanks alot.

    ReplyDelete
  19. Thank 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.

    ReplyDelete
  20. Hi,

    Thank 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?

    ReplyDelete
  21. 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!

    ReplyDelete
  22. Worked like a charm with ubuntu 10.10 as well. Thank you for sharing this!

    Only 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

    ReplyDelete
  23. Excellent article - worked for me, many thanks :)

    ReplyDelete
  24. This is excellent! Just copy from start to finish using sudo where required.

    Many Many thanks.

    ITMANAGER

    ReplyDelete
  25. Hey, exellent guide.

    ReplyDelete
  26. Seems 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