How to install CentOS 5 on a software partitionable RAID1.
What exactly is a software partitionable RAID1?
Short answer: it is a mdadm RAID volume which can be partitioned as a regular hard drive.
For the long time the traditional way of using mdadm RAIDs was to create a separate partition on each drive going into the raid volume, mark these partitions as type 0xfd (linux raid autodetect), build a volume from these partitions, format it to a certain filesystem and use it. If you needed several filesystems on RAID, you had to setup several RAID volumes, which means that you had to create several exactly the same partitions on each of the drives in the RAID and create several RAID volumes. Compare this to a true RAID controller which allows you to build one RAID volume which can be partitioned as a regular hard drive.
So, since mdadm 2.6 it is possible to create partitionable RAID volumes. Such RAID volumes get device names like /dev/md_dX and /dev/md_dXpY for partitions on the volume. The dev entries for partitions on partitionable RAIDs are created automatically by mdadm when the volume is assembled.
Why would you want to have a system installed on a partitionable software RAID1?
If you are installing a system on a partitionable RAID you can use the whole hard drive as a RAID component device, and since RAID1 is a mirror, you will be able to boot your system from any of the drives in case of failure without any additional tricks required to preserve bootloader configuration, etc. And when you need to repair a failed RAID volume with the whole hard drive as a RAID component, all you have to do is to insert a new hard drive and run mdadm --add; no partitioning or anything else required.
Installation procedure
This guide describes how to install CentOS 5 on a partitionable raid system from scratch. However you may migrate your existing non-raid installation to a partitionable raid if you have some unpartitioned space at the end of your drive, or you can resize the last partition to free some space. To do the migration follow this guide starting from step 3.
In this howto we assume that your system has two hard drives, /dev/sda and /dev/sdb.
Install CentOS using standard installer on the first hard disk, /dev/sda. Select manual partitioning during the installation, and leave at least 1 unit at the very end of the disk unpartitioned. You will be able to redeem most of this space back later. You need to reserve this space for mdadm which stores it's metadata at the last chunk of a raid volume.
- Boot from the CentOS installation disk in the Rescue mode. The installer will ask you if you wish to mount an existing CentOS installation, you must refuse.
Build the software RAID1 using mdadm in degraded mode, with /dev/sda as the only drive:
mdadm --create --level=1 --raid-devices=2 /dev/md_d0 /dev/sda missing
Add the spare drive /dev/sdb into the raid and check /proc/mdstat to see that the raid started building:
mdadm --add /dev/md_d0 /dev/sdb
cat /proc/mdstat
Now you must manually mount the system and chroot to it to modify the boot settings:
mkdir /mnt/sysimage
mount /dev/md_d0p1 /mnt/sysimage
mount -o bind /dev /mnt/sysimage/dev
mount -o bind /selinux /mnt/sysimage/selinux
mount -t proc none /mnt/sysimage/proc
mount -t sysfs none /mnt/sysimage/sys
chroot /mnt/sysimage
All of the following actions must be done in the chrooted system.Create the /etc/mdadm.conf:
mdadm --examine --scan > /etc/mdadm.conf
Edit the resulting /etc/mdadm.conf, you must change /dev/md0 to /dev/md_d0.
Edit /etc/fstab, you must change all mounts from using LABEL= to explicit device names, like /dev/md_d0p1, /dev/md_d0p2, ...
Edit /etc/grub.conf, replace root=LABEL=... with root=/dev/md_d0p1 (or the corresponding partition for your setup).
Now you have to patch the mkinitrd script. Download the patch from this page and do the following:
cd /sbin
cp mkinitrd mkinitrd.dist
patch -p0 < /tmp/mkinitrd-md_d0.patch
See the corresponding bug report for more details.
Disable updating mkinitrd rpm with yum, append
exclude=mkinitrd*
to /etc/yum.conf.Build the new initrd image:
cd /boot
mv initrd-2.6.18-128.el5.img initrd-2.6.18-128.el5.img.bak
mkinitrd /boot/initrd-2.6.18-128.el5.img 2.6.18-128.el5
Now all you have to do is to check /proc/mdstat periodically to check if the raid is rebuilt. When the rebuild process is finished you may safely reboot the system.
- Optionally, you may resize the last partition of your raid to redeem the remaining unpartitioned space.
If you need to update the mkinitrd package some time later and the bug with partitionable raid detection will not be fixed yet, you will need to reapply the patch to mkinitrd and recreate the initrd after update.
http://wiki.centos.org/HowTos/Install_On_Partitionable_RAID1