WARNING - THIS WILL DESTROY ANY DATA ON THE DISKS YOU INTEND TO USE IN YOUR RAID ARRAY
This is not the tutorial for you if you are trying to add RAID1 mirroring to an existing single disk system.
Assumptions:
1) You have a working Linux installation with / mounted on /dev/sda which is not part of any RAID array.
2) You have a pair of identical disks attached to /dev/sdb and /dev/sdc
Step 1 - use fdisk to create partitions on your RAID disks
fdisk /dev/sdb
n # create new partition
p # make this a primary partition
1 # partition number
First cylinder: 1
Last cylinder: press enter for end of disk (use whole disk for RAID)
t # change partition type
fd # change to Linux RAID
w # write changes and quit
n # create new partition
p # make this a primary partition
1 # partition number
First cylinder: 1
Last cylinder: press enter for end of disk (use whole disk for RAID)
t # change partition type
fd # change to Linux RAID
w # write changes and quit
Repeat for /dev/sdc
Use fdisk -l to check the partitions afterwards, you should have something like
Device Boot Start End Blocks Id System
/dev/sda1/ * 1 59573 478514176 83 Linux
/dev/sda2/ 59573 60802 9871360 82 Linux swap / Solaris
/dev/sdb1 1 60801 488384001 fd Linux raid autodetect
/dev/sdc1 1 60801 488384001 fd Linux raid autodetect
/dev/sda1/ * 1 59573 478514176 83 Linux
/dev/sda2/ 59573 60802 9871360 82 Linux swap / Solaris
/dev/sdb1 1 60801 488384001 fd Linux raid autodetect
/dev/sdc1 1 60801 488384001 fd Linux raid autodetect
Create the array
apt-get install mdadm
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
This will start building the mirror (even though it is empty). You can check progress with
mdadm --detail /dev/md0
or
cat /proc/mdstat
or
cat /proc/mdstat
Once the RAID array is built, you need to format the RAID partition /dev/md0 (with ext3 etc):
mke2fs -j /dev/md0
NOW PERSIST YOUR RAID CONFIG OR IT WILL BE GONE WHEN YOU REBOOT*
mdadm --detail --scan --verbose > /etc/mdadm/mdadm.conf
Make a mount point:
mkdir /mnt/raid
Then add the partition to /etc/fstab:
# file system mount point type options dump pass
/dev/md0 /mnt/raid ext3 defaults 0 2
/dev/md0 /mnt/raid ext3 defaults 0 2
* Here is how to recover your RAID1 array if mdadm can't find it after a reboot
1) fdisk /dev/sdb # remake sdb partition as above
2) fdisk /dev/sdc # remake sdc partition as above
3) mdadm --assemble --auto=yes --force /dev/md0 /dev/sdb1 /dev/sdc1 #reassemble the array
4) mdadm --detail --scan --verbose > > /etc/mdadm/mdadm.conf # SAVE IT THIS TIME DUMMY!
2) fdisk /dev/sdc # remake sdc partition as above
3) mdadm --assemble --auto=yes --force /dev/md0 /dev/sdb1 /dev/sdc1 #reassemble the array
4) mdadm --detail --scan --verbose > > /etc/mdadm/mdadm.conf # SAVE IT THIS TIME DUMMY!