RAID 1 is useful. If you didn’t understand that sentence, stop reading here; this posting is not for you. My new desktop PC makes use of a 40Gb SSD for the operating system, and a pair of 1Tb drives in a RAID 1 array for the home directories and other dynamic content. Frustratingly, Ubuntu 10.04 desktop edition doesn’t have an option to install with RAID (unlike the server edition), so I had to do it by hand. Here’s the solution, because it’s not terribly difficult, and because it might be useful for someone.
On my system, I created partitions on the SSD for the root, /boot, /usr and swap, and intended to partition my 1Tb RAID volume up for the /home and /var folders. Hopefully what follows should be clear enough that you can easily adapt it for your own partitioning preferences.
Boot from the Ubuntu live CD and choose to “Try without installing”. Let it boot into the desktop environment.
Create your partitions. You can either use fdisk if you’re old-fashioned, or GPartEd from the System/Administration menu on the desktop. The partitions that you’re going to use as components of the RAID array must be exactly the same size on all volumes. Assign file system types to your non-RAID partitions (if you have any) but not to the RAID partitions. We’ll do that later.
$ sudo su -
Install the RAID tools:
# apt-get update
# apt-get install mdadm
(For some reason, the mdadm installation includes postfix. Just tell the postfix wizard that you’re local, and it’ll not matter.)
Now for the important bit: creating the RAID array. I have to do this twice: once for the /home partition and once for the /var partition:
# mdadm --create /dev/md1 --verbose --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
# mdadm --create /dev/md2 --verbose --level=1 --raid-devices=2 /dev/sdb2 /dev/sdc2
(This should be pretty self-explanatory; –level=1 says I want to use a RAID 1 array, –raid-devices=2 says there’s two drives in the array, and /dev/md1 is the name of the RAID pseudo-device that’s created out of /dev/sdb1 and /dev/sdc1.)
Now we can create the filing system and format the array:
# mkfs.ext4 /dev/md1
# mkfs.ext4 /dev/md2
If you’re planning on using a different filing system (caution, ReiserFS may cause you to murder unsatisfactory mail-order brides) then just use a different mkfs instruction at this point.
Now to install Ubuntu. Run the installer (it’s right there on the desktop) and run through the usual question-and-answer process until you get to “Prepare disk space”. Choose to specify the partitions manually, and set the RAID array md devices where appropriate. (By way of example, I had /dev/sda1 for /, /dev/sda2 for /usr, /dev/sda3 for /boot, /dev/md1 for /home and /dev/md2 for /var.) Continue with the installation Q&A and then let the OS install itself.
Once it’s all installed don’t just go rebooting, because if you do, you’ll regret it. Problem is, Ubuntu desktop doesn’t include the RAID array manager mdadm in the default installation. Reboot now and your new OS won’t know how to access the RAID volumes. So before you reboot, you need to install mdadm into your new OS.
You need to mount your new installation and then tell the OS to treat that mount-point as the root. If you’ve got everything in one partition, that’s pretty straightforward. I had to do several mount operations to get all my partitions in place. If your partitions are simpler, adjust the mount operations accordingly. You must do the /dev, /proc and /sys mounts though:
# mount /dev/sda1 /mnt/
# mount /dev/sda2 /mnt/usr
# mount /dev/sda3 /mnt/boot
# mount /dev/md1 /mnt/home
# mount /dev/md2 /mnt/var
# mount --bind /proc /mnt/proc
# mount --bind /sys /mnt/sys
# mount --bind /dev /mnt/dev
# chroot /mnt
Install mdadm just like before (even the postfix), only this time it’s permanent:
# apt-get update
# apt-get install mdadm
For me, this was the end of the process. If your root volume is not part of a RAID array (mine wasn’t) then pop the CD out, reboot now and enjoy the fruits of your labours! However, if your root volume is part of a RAID array, then you’ll also have to fix the grub boot-loader, which will only be installed on one of the disks in the RAID array. For example, if your root volume is on /dev/md1 and that device comprises /dev/sda1 and /dev/sdb1 then you’ll need to do this, just to be on the safe side:
# grub-install /dev/sda
# grub-install /dev/sdb
Reboot, and cat /proc/mdstat or run the Ubuntu Disk Utility (on the System/Administration menu) to check that your RAID devices are syncing.