If there are images in this attachment, they will not be displayed.  Download the original attachment
Page 1
HOWTO: Configure software RAID1 using mdadm
Most modern-day distribution installers allow you to configure your software
RAID easily using menus. You must however, understand how RAID works
before you can do it using an installer or a utility.
Additionally, I've found it difficult to find a very basic guide to setting up a
RAID using mdadm, since most HOWTOs are written using raidtools, and I get
nervous when I have too many questions and just want a simple step-by-step
guid.
Nowadays, I usually configure the software RAID to mirror my swap drive. So
that in case one goes down, the RAID will keep the swap going. However, I've
heard this is a slower solution and that it is possible to configure two
partitions to be your swap, and the minute one goes down, the kernel switches
to the other. I'm not sure whether this would crash your system. If anyone
knows what the better solution is, please email me at deriziotis@gmail.com.
What is RAID1?
Two hard-drives are mirrored completely, in case one goes down, the other
takes over.
Configuring your RAID using the installer
I'm using the native Debian installer in the following example, however, it's
pretty much the same thing for Red Hat and any other distribution out there.
During your installation, the installer will propose a viable partition scheme
for your operating system, instead of accepting the default, choose Manually
Edit Partition Table, and get ready to set up your software RAID.
What you need to do is make sure that the partitions on each hard-drive are
roughly the same size and set the filesystem type as Physical Volume for
RAID on each partition. I usually make one partition on each drive for the
SWAP and one partition for the root partition (/) and mirror each of those.
Then you go to the Configure Software RAID menu option and select
Create New Device (these will be md0 and md1). Choose the two Physical
RAID partitions that you configured for your swap, and then create another
RAID device and choose the two Physical RAID partitions that you configured
for your root mount point (/).
When you go back to the partition list after this, you'll see the RAID devices
that you've created. We now stop working with the actual physical devices and
work solely with md0 and md1, which are basically virtual devices which treat
the mirror as a single device, and can be treated as regular devices. Every
change you make to md0 will be made to both hard-disks mirrored in that
device.
Don't forget to assign your RAID devices mount points. Do this from the main

Page 2
menu by pressing enter on your RAID device partition. Select a swap area
and a root mount point (/) from your mirrored device partitions (md0, md1).
Choose Finish Paritioning and Write Changes to Disk, and you're done.
Managing your RAID can be done as root using mdadm. So refer to that
documentation for any changes you want to make after you've installed.
Building a RAID using mdadm
I'll be using two identically sized hard-drives for the RAID mirror, hde1 and
hdg1.
Start off by fdisk'ing the partitions you want to mirror. Give them the
filesystem type Linux Raid Autodetect.
fdisk /dev/hdg
fdisk /dev/hde
n – for new partition
d – delete partition
t – assign filesystem type
w – write changes and quit
q – quit without writing changes
After that you need to create your RAID device:
mdadm --create /dev/md2 --raid-devices=2 --level=1 /dev/hdg1
/dev/hde1
/dev/md2 refers to the RAID device. Since the kernel sees a literal device when
it sees the RAID device and treats it as a single point of access to that device, it
resides in /dev. By giving it a name of /dev/mdx we can see that it is a RAID
device (which means essentially that there are many hard-drives in a RAID
which is treated as a single filesystem).
If you don't have any RAIDs already configured, then you'll probably want to
use /dev/md0. I'm using /dev/md2 since I've got a 2 drives mirrored under
/dev/md0 for my swap, 2 drives mirrored for my OS installation under /dev/md1
and I want to mount my users' home folders under /dev/md2, another mirror.
--raid-devices=2 is just letting mdadm know how many hard-drives your
attaching to the RAID. 2 in this case because it's a mirror.
--level is the RAID level. Ergo, --level=1 is a RAID1 (mirror), --level=2 is a
RAID2, and so on.
Finally, the actual partitions that will be used in the RAID is listed at the end of
the command. It might say, it looks like your raid contains a filesystem (ext3),
do you wish to continue? Just say yes, and it'll automagically sort itself out.

Page 3
Now you can just watch your RAID build itself. Type the following to take a look
at the status of your RAID device:
mdadm -D /dev/md2
and you should see something similar to this:
Update Time : Fri Dec 9 19:18:08 2005
State : clean, resyncing
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Rebuild Status : 5% complete
UUID : 429bf851:8c1ff898:438ddd43:c177824b
Events : 0.1
Number
Major
Minor
RaidDevice State
0
34
1
0
active sync
/dev/hdg1
1
33
1
1
active sync
/dev/hde1
When the Rebuild Status reaches 100%, then we can test it.
mount /dev/md2 /mnt/drive
The thing is, it seems to have taken the ext3 filesystem.. I don't know if it auto-
did it because that was the filesystem on the drive or for some other reason.
What do you do if there is no fs on the drive? Also, what if you don't want to
lose the data on the one drive?