Académique Documents
Professionnel Documents
Culture Documents
While Intrepid is no longer the most current Ubuntu release currently, please note that the
choice does not really matter, which is why I deliberately decided to use. I want you to be
able to use the power of your knowledge without sticking to brands. I want you to be able
to understand the principle. Once you get the hang of things, the choice of the operating
system will become transparent. The only difference will be a slight cosmetic chance
between distros and/or release.
That said, I will also demonstrate RAID installation and the subsequent configuration in
several other distributions, in a sort of addendum article to this tutorial. In this sequel, I
will cover the RAID configuration in openSUSE - and some other distros - just to show
you that once you learn the idea, it will not matter which software you use. Pretty much
like driving a car.
Additionally, we will also use several command line tools particular to RAID, which
come included with most Linux distributions.
Introduction
RAID stands for Redundant Array of Inexpensive Disks. This is a solution where several
physical hard disks (two or more) are governed by a unit called RAID controller, which
turns them into a single, cohesive data storage block.
An example of a RAID configuration would be to take two hard disks, each 80GB in size,
and RAID them into a single unit 160GB in size. Another example of RAID would be to
take these two disks and write data to each, creating two identical copies of everything.
RAID controllers can be implemented in hardware, which makes the RAID completely
transparent to the operating systems running on top of these disks, or it can be
implemented in software, which is the case we are interested in.
Purpose of RAID
RAID is used to increase the logical capacity of storage devices used, improve read/write
performance and ensure redundancy in case of a hard disk failure. All these needs can be
addressed by other means, usually more expensive than the RAID configuration of
several hard disks. The adjective Inexpensive used in the name is not without a reason.
Advantages
The major pluses of RAID are the cost and flexibility. It is possible to dynamically adapt
to the growing or changing needs of a storage center, server performance or machine
backup requirements merely by changing parameters in software, without physically
touching the hardware. This makes RAID more easily implemented than equivalent
hardware solutions.
For instance, improved performance can be achieved by buying better, faster hard disks
and using them instead of the old ones. This necessitates spending money, turning off the
machine, swapping out physical components, and performing a new installation. RAID
can achieve the same with only a new installation required.
Disadvantages
The problems with RAID are directly related to their advantages. For instance, while
RAID can improve performance, this setup necessarily reduces the safety of the
implementation. On the other hand, with increased redundancy, space efficiency is
reduced.
Limitations
RAID introduces a higher level of complexity into the system compared to conventional
disk layout. This means that certain operating systems and/or software solutions may not
work as intended. A good example of this problem is the LKCD kernel crash utility,
which cannot be used in local dump configuration with RAID devices.
The problem with software limitations is that they might not be apparent until after the
system has been configured, complicating things.
To sum things up for this section, using RAID requires careful consideration of system
needs. In home setups, RAID is usually not needed, except for people who require
exceptional performance or a very high level of redundancy. Still, if you do opt for
RAID, be aware of the pros and cons and plan accordingly.
This means testing the backup and imaging solutions, the stability of installed software
and the ability to switch away from RAID without significantly disrupting your existing
setup.
RAID levels
In the section above, we have mentioned several scenarios, where this or that RAID
configuration may benefit this or that aspect of system work. These configurations are
known as RAID levels and they govern all aspects of RAID benefits and drawbacks,
including read/write performance, redundancy and space efficiency.
There are many RAID levels. It will be impossible to list them all here. For details on all
available solutions, you might want to read the Wikipedia article on the subject. The
article not only presents the different levels, it also lists the support for each on different
operating systems.
In this tutorial, we will mention the most common, most important RAID types, all of
which are fully supported by Linux.
RAID 0 (Striping)
This level is achieved by grouping 2 or more hard disks into a single unit with the total
size equaling that of all disks used. Practical example: 3 disks, each 80GB in size can be
used in a 240GB RAID 0 configuration.
RAID 0 works by breaking data into fragments and writing to all disk simultaneously.
This significantly improves the read and write performance. On the other hand, no single
disk contains the entire information for any bit of data committed. This means that if one
of the disks fails, the entire RAID is rendered inoperable, with unrecoverable loss of data.
RAID 0 is suitable for non-critical operations that require good performance, like the
system partition or the /tmp partition where lots of temporary data is constantly written. It
is not suitable for data storage.
Note: Image taken from Wikipedia, distributed under GFDL.
RAID 1 (Mirroring)
This level is achieved by grouping 2 or more hard disks into a single unit with the total
size equaling that of the smallest of disks used. This is because RAID 1 keeps every bit of
data replicated on each of its devices in the exactly same fashion, create identical clones.
Hence the name, mirroring. Practical example: 2 disks, each 80GB in size can be used in
a 80GB RAID 1 configuration.
Because of its configuration, RAID 1 reduced write performance, as every chunk of data
has to be written n times, on each of the paired devices. The read performance is identical
to single disks. Redundancy is improved, as the normal operation of the system can be
maintained as long as any one disk is functional.
RAID 1 is suitable for data storage, especially with non-intensive I/O tasks.
Note: Image taken from Wikipedia, distributed under GFDL.
RAID 5
This is a more complex solution, with a minimum of three devices used. Two or more
devices are configured in a RAID 0 setup, while the third (or last) device is a parity
device. If one of the RAID 0 devices malfunctions, the array will continue operating,
using the parity device as a backup. The failure will be transparent to the user, save for
the reduced performance.
RAID 5 improves the write performance, as well as redundancy and is useful in mission-
critical scenarios, where both good throughput and data integrity are important. RAID 5
does induce a slight CPU penalty due to parity calculations.
Note: Image taken from Wikipedia, distributed under GFDL.
Linear RAID
This is a less common level, although fully usable. Linear is similar to RAID 0, except
that data is written sequentially rather than in parallel. Linear RAID is a simple grouping
of several devices into a larger volume, the total size of which is the sum of all members.
For instance, three disks the sizes of 40, 60 and 250GB can be grouped into a linear
RAID the total size of 350GB.
Linear RAID provides no read/write performance, not does it provide redundancy; a loss
of any member will render the entire array unusable. It merely increases size. It's very
similar to LVM.
Linear RAID is suitable when large data exceeding the individual size of any disk or
partition must be used.
Other levels
There are several other levels available. For example, RAID 6 is very similar to RAID 5,
except that it has dual parity. Then, there are also nested levels, which combine different
level solution in a single set. For instance, RAID 0+1 is a nested set of striped devices in
a mirror configuration. This setup requires a minimum of four disks.
These setups are less common, more complex and more suitable for business rather than
home environment, therefore we won't talk about those in this tutorial. Still, it is good to
know about them, in case you ever need them.
Summary
So, let's review what we've learned here. We have four major RAID levels that interest
us, each offering different results. The most important parameters are the I/O
performance, redundancy and space efficiency.
# devices: this column defines the minimum number of devices required to create such a
setup.
Efficiency: this term denotes how "well" the array uses the available space. For example,
if the array uses all available space, then its efficiency is equal to the total number of
devices used. For instance, a RAID 0 with four 80GB disks will have a total space of
320GB, in other words, 4 x 80GB - or simply: 4 (n).
Attrition: this tells us how many devices in the array can be lost without breaking the
functionality of the array and losing data.
Here's a small table showing the differences between the four levels discussed above:
Level
# devices
Efficiency
Attrition
RAID 0
2
n
0
RAID 1
2
n/2
n-1
RAID 5
3
n-1
1
Linear
2
n
0
RAID notation
We also have to talk about how RAID devices are seen and marked by Linux. In fact,
compared to hard disk notation, which takes into consideration a lot of parameters like
disk type and number, partition type, etc, RAID devices are fairly simple.
RAID devices are marked by two letters md and a number. Example: md0, md3, md8. By
themselves, the RAID device names tell us nothing about their type. In this regard, the
RAID notation is lacking compared to disk/partition notation.
To be able to get more information about our RAID devices, we need additional
tools. We will talk about these tools in greater detail later. For now, here's just a snippet
of information.
/proc/mdstat
Many parameters about the operating system can be extracted from different files under
the /proc tree. For instance, we can check all the running processes and their memory
maps, we can check CPU information, mounts, and more. We can also check the status of
our RAID devices.
This is done by printing out the contents of the mdstat file under /proc.
cat /proc/mdstat
If there are any RAID devices present, they will be printed out to the screen (STDOUT).
Here's an example:
What do we have here? Let's take a look at the first listed device, md1:
Personalities: [raid1]
This line tells us which types of RAID arrays are used on the system. In this case, we
have a single one.
md1 is a RAID 1 (mirror) device, spanning sda2 and sdb2 partitions. This device is active
and mounted. If it were not used, it would have been listed under unused devices further
below.
The second line gives us some more information about the device. [2/2] [UU] tells us
both partitions are used. This may seem a little strange, but it is not. Some RAID
configurations can continue functioning even if a number of devices are disabled (failed),
either deliberately or due to an error or disk problem. The RAID device would still exist,
but parts thereof would no longer be functioning properly.
In our case above, we have 2 out of 2 devices working, in which case the [UU] is a
redundant bit of information. However, what if we had [1/2] situation? This means one of
the partitions has malfunctioned. To know which one, we need to look at the second pair
of square brackets, which will tell us the device that still works.
As an exercise, we will deliberately fail one of our devices later, to demonstrate this.
Using cat /proc/mdstat is the fastest, simplest indication of the health and status of the
RAID arrays. If there are no RAID arrays on the system, the output of the command
would return output like this:
mdadm
This is a very important, powerful Linux software RAID management utility. It has no
less than seven modes of operation, which include assemble, build, create, monitor, grow,
manage, and misc. mdadm is a command-line utility and requires super-user (root)
privileges.
Simple, right?
OK, now that we know what RAID is and how it works, let's configure one - or two!
I will demonstrate the configuration of RAID using Ubuntu 8.10 Intrepid Ibex as the test
platform. As mentioned earlier, Ubuntu 8.10 is no longer the most current release - and
this does not matter one bit. The general idea remains the same - and this is what I want
you to learn: the principle. Once you grasp the fundamental concepts of RAID setup, you
will be able to this on any which operating system.
Furthermore, configuring RAID on Ubuntu is a good choice for several more reasons:
Ubuntu is the most popular Linux desktop distro, which probably means there's a
fair chance you will indeed be setting up RAID on Ubuntu or one of its flavors.
The default Ubuntu installation is very simple; so simple, in fact, that is strips
away some of the features for the sake of simplicity. One of the victims is indeed
RAID, which cannot be configured using the standard installation from the live
CD. You need the Alternate CD, which uses a text-driven installation menu and
allows you to setup RAID, as well as other advanced options. The text installers
looks "old" - meaning you will not really feel like you're installing Ubuntu. This
will help you understand the concept beyond colors and pretty menus, allowing
you to transition to other distributions with ease.
The use of an older release and the Alternate CD allows me to prove a point: that
no matter which distribution you choose, the power of Linux can be unleashed to
the fullest. You do not have to disqualify distros on the premises of being "too
simple" or "dumbed down" simply because such propositions are untrue.
All right, now that you know what we're up to, let's begin.
Installing Ubuntu via Alternate CD is similar to almost every Linux installation you have
seen or tried or read about. Place the CD into the CD tray, boot, follow instructions.
Partitioning
After a while, you will reach the Partition Disks stage. This is where the fun begins. We
will choose the manual method.
You will see the existing setup, if any. In our case, we have two hard disks, roughly
identical, each with three partitions on it. Each disk holds a primary ext3 partition and a
500MB swap and a ~2GB ext3 partition inside the Extended volume.
This means we have quite a bit of freedom when it comes to creating RAID arrays, where
the logic beckons to pair sda1 with sdb1, sda5 with sdb5 and so forth.
Edit partitions
To do that, we need to change the partitions. Highlight any and hit Enter. The installer
will graciously tell you that You are editing ... This partition is formatted with ..., so there
are no mistakes.
The installer now recognizes the partitions flagged as RAID volumes and can now
configure them.
The first thing, you will receive a warning. It tells you the changes you have just made
will be committed. Furthermore, no additional changes will be allowed. Make sure you
are satisfied with your layout before proceeding.
What is going to happen is that the RAID superblock is going to be written on the
devices, marking them with a higher order hierarchy than just physical partitions. This
will allow the operating system as well as RAID utilities to properly handle these
devices.
After that, the next step is to create a new MD device. By the way, earlier, we mentioned
the mdadm utility. One of its mode is the ability to create MD devices. In fact, this is
exactly what is happening underneath the hood. Later, we'll see the text command that do
the same job as the installer above.
Create MD device
The next step is to choose the RAID type. This is a step where some thorough thinking is
needed. You need to ask yourselves what are you trying to achieve?
Create a RAID 1 (mirror) device called md0 and later use it as root (/). This will
slow down the performance, but ensure reliability.
Create a RAID 0 (stripe) device called md1 and use it as swap. We'll both benefit
from a performance boost and increased total size. No need to worry about
reliability here.
Create a RAID 0 (stripe) device called md2 and use it as home (/home). This will
allow me to have a larger home directory than individual partitions allow.
Likewise, it should improve the performance.
This layout may not suit you at all. You may want performance for / and reliability for
/home, so you may want to use a different layout. Or you may want to create a linear
array for swap, because it does not really matter how you use it, as it's a raw device.
We need to decide how many (active) devices will participate in the mirror. We'll go for
two.
Choose spares
Now, we need to select which devices (those marked as RAID), we want to use. For the
first device, we'll use sda1 and sdb1.
Similarly, we'll repeat the procedure for the other two devices. Our swap will be a stripe,
as we want performance and no redundancy is needed.
And the last device, again a stripe:
Final layout
Now, for all practical purposes, the md devices are just like any other partition. We need
to format them and configure the mount points.
Configure root
Undo / Commit
If you're satisfied, you can commit the changes - OR - undo the operations and start over.
You will have to confirm your choices, in case you decide to commit them:
Installation
We can begin the installation.
You can now reboot and start enjoying your new system. What about the GRUB
bootloader, you're asking? Well, nothing special. We'll see what happens after the boot.
After installation
Our system booted up fine, as expected.
However, some of you may have read online that GRUB cannot install properly on RAID
devices and that a manual intervention may be needed in order to make sure the system is
bootable. This is partially true, and I will soon show you why.
Before that, let's see what RAID looks like inside a working system:
/proc/mdstat
Another interesting bit of information is that md1 and md2, both stripes, do not have any
information inside square brackets. This means that they have no redundancy. If any of
the components of their arrays goes bad, the arrays will fail. md0, on the other hand, is a
mirror, and has redundancy, which is manifested in the status of healthy, used devices.
This also tells us another bit of information: we can manipulate mirror devices
in vivo, but persistent changes for RAID 0 type devices will require a reboot to take
effect.
fdisk
fdisk is a handy partitioning utility for Linux. We've seen it in the GParted tutorial; it
allows us to manipulate partitions from the command line.
We can see that fdisk properly reports the RAID devices for all our partitions.
df
df reports file system disk usage. It also works with RAID devices and can tell us how
much free space we have left on our partitions. Used with flags -l (local) and -h (human),
it will report back for local partitions in human readable format (MB/GB):
df -lh | grep md
We can't see swap anywhere, though. So we need another utility to check it. We'll use
swapon.
swapon
swapon (and its sister swapoff) is used to start swap on files/devices, and display status of
currently used swap areas. swapon -s will display all used swap areas, their type, size,
usage, and priority.
As you can se below, we have a 1GB swap device /dev/md1, which consists of two
physical partitions (sda5 and sdb5) in a stripe configuration.
RAID & GRUB
Here comes the big question, how does GRUB fit into the RAID picture? Before we can
answer that question, you need to read my GRUB tutorial. Once you understand how
GRUB works, you'll be able to ponder the question raised here. I'm sorry, but it's a must.
Throughout this section, I will assume you have read the very long, thorough and detailed
GRUB tutorial.
Basically, GRUB is a bootloader that allows multiple operating systems to be run on the
same system. GRUB works by placing a piece of its code into the Master Boot Record
(MBR) and tells the system where to look for configuration files on which operating
system to boot.
When you're using the conventional partitioning layout, the configuration is simple.
GRUB is installed to the device sector 0 and that's it. For instance, GRUB is installed to
sda. End of story.
When you're using RAID for the root partition, there is more than one device involved.
The question is, where does GRUB go? sda? sdb? Both?
The answer depends on the type of RAID you want. I used mirror for the root partition,
which means we have two identical copies of everything on the system, including the
sector 0, which contains GRUB stage 1. Therefore, we elegantly avoid the question.
GRUB is installed on both devices. Reading any which MBR on either disk provides us
with the whole set of information required to boot the system.
We can confirm this by looking for stage1 (using the find command in GRUB menu):
We'll talk about what happens if RAID 0 is used a little later on.
GRUB menu
Let's take at the GRUB menu. GRUB menu, part of GRUB stage2, is usually located on
the /boot or / partition of the first boot device, inside grub directory.
As you can see, GRUB menu takes into consideration the higher hierarchy of RAID. The
root is called from an MD device and not the underlying hd/sd devices. For all practical
purposes, the setup is completely transparent when it comes to stage2. The only thing we
need to concern ourselves is stage1 that goes into MBR.
So, let's go back to the first question. Where does GRUB go? The best way for you to
understand and solve this problem is to treat RAID devices as your partitions. GRUB
needs to be in the MBR of the first boot disk. As simple as that.
This means that if you're using RAID1, there are no issues, as the sector exists "equally"
on all RAID array devices. If you're using a configuration where only partial information
exists on each device (like RAID0 or RAID5), the system will not be able to deduct the
whole of information by reading the MBR on just one device.
So, the answer is: you will have to install GRUB on all RAID devices. If you're using a
mirror configuration, this is done for you. If you're using stripe, you'll have to do it
manually.
The sequence of steps required to accomplish the task is very simple. First, you'll have to
find all available stage1. Then, you will have to setup GRUB into each one of them.
That's all!
So, let's look for stage1. This needs to be done from a live CD environment or during a
GRUB boot:
find /boot/grub/stage1
If all the devices included in the array get listed, you're ok. If not, you will have to install
GRUB on each one.
root (hdX,Y)
setup (hdX)
The values X and Y take the disk number and partition number where the root is
installed. For example, in our case, we have the root partition on sda1 and sdb1. This
means that we have to run the commands for (hd0,0) and (hd1,0).
Do not be tempted to look for menu.lst, because this one is deceiving. You might get a
"right" answer that it is located on both partitions, but stage1 might not be installed
properly.
You can also "brute-force" your way with grub-install command, if you know where the
root is expected to be. For more details how to do this, please refer to the GRUB tutorial.
Summary
Alternatively, you may also want to setup a small (~100-200MB) boot partitions in the
classic way, then use RAID for other partitions. This is similar to what Fedora does with
its LVM. A small sda1 boot is used and LVM is spread on sda2.
Which brings us to GParted ...
Advanced configurations
We've seen a lot of work done, but we did not see any commands executed. Which is
OK. For most people, for most practical purposes, RAID should be transparent. However,
if you want to be able to control your RAID at all times, you will have to muck your
hands a bit in the command line hocus pocus.
mdadm
So let's see how we can use mdadm to achieve what we did above.
Create MD device
Remember the wizard we ran through when we created our mirror array on md0? Well,
here it is, in text form:
We are creating a new device called /dev/md0. It is a RAID 1 device with 2 devices in it,
sda1 and sdb1. Simple eh?
After you hit Enter, you'll see the device created and then synced. The synchronization is
the process that takes after the RAID devices are created. Effectively, it creates the
required data structure on all RAID devices.
If we check mdstat, we see the old familiar picture:
Similarly, we can stop RAID devices, fail them, assemble them, and so forth. Mastering
the mdadm utility takes time, but it gives you a lot of power and freedom when it comes
to using Linux software RAID.
Fail/remove device
If you want to break apart a RAID, you will first have to fail its members and then
remove them. On active partitions used by the operating systems, this may not be
possible in-vivo and will require a reboot.
In reality, this might happen should the disk die or a partition get corrupted for some
reason.
After that we can remove it ... and then, for fun, re-add it. Here's a screenshot showing
the recovery progress after sdb1 was re-added. The RAID device is being rebuilt, with the
data from sda1 being cloned over to sdb1.
For more details, please read the man page for mdadm.
Other
In general, there are several things you should consider before deploying RAID. These
concern the cost, safety, performance, but also software compatibility.
You may need to check whether your imaging software, if you're using one, that is, is
compatible with RAID devices. Just like when we configured partitions with GParted, we
had to manually change the Inode size for our Ubuntu installation to make the partitions
compatible with Acronis True Image software, which requires Inode size of 128 bytes.
Plan ahead, make sure your setup will be flexible enough to suit your needs years ahead.
Make sure you can use your backup and rescue tools effectively and reliably on systems
deployed on RAID devices. Make sure you do not create impossible setups where you
have no ability to change things save for a complete reinstall.
That said, this concludes the tutorial.
Conclusion
Working with RAID is an advanced task, but it can be managed. Hopefully, this tutorial
cleared up things a bit.
Alongside the knowledge you have gained on working with the GRUB bootloader and
GParted partitioning software, the RAID tutorial should give you the skills needed
required to safely and with confidence wade into the waters of Linux system
administration.
In the future, we'll tackle more great stuff, including LVM, the iptables firewall and many
other exciting projects. And if you have suggestions, feel free to email me.
Have fun.
Software-RAID HOWTO*
Boot+Root+Raid+Lilo HOWTO*
Remember that this only makes sense after you've done it once... :)
Test PC:
PII-350, 384Mb RAM, and Adaptec 2940U2 SCSI controller, and 3 18Gb
Seagate drives.
Test Mac:
Blue & White G3, 256MB RAM, Adaptec 2940 SCSI controller, 3 8GB
SCSI drives.
These instructions have been tested on various flavors of OpenLinux,
Red Hat, Mandrake, and now Yellow Dog Linux for PowerPC.
RAID-5 requires 3 hard drives of the same size, so you should install
those and make sure they work before starting this process.
After installing Linux to the first large partition, the next step toward a
complete RAID-5 system is to recompile the kernel. Most distributions
ship their SCSI support as modules. This is normally a good thing, but
not if you want to load from a RAID device. That means we're
recompiling. If you're using SCSI devices, make sure you include SCSI
support, SCSI hard disk support, the driver for your SCSI controller in
the kernel and not as modules. For IDE devices, include IDE support,
IDE disk support, and support for your controller if needed (Promise
cards have their own driver for example). Also, whatever filesystem
your Linux drives are must be compiled in (ext2, ext3, ReiserFS, etc).
I'll be using Reiserfs for this example. Make sure you turn off the extra
checking option or Reiserfs can be really slow.
Once the recompile is complete, move the kernel into place and edit
grub/lilo/yaboot accordingly. Then reboot and check that all your
hardware is seen.
Now we'll create the /etc/raidtab file that will configure your RAID
devices. On the PC this should contain the following:
raiddev /dev/md0
raid-level 5
nr-raid-disks 3
nr-spare-disks 0
persistent-superblock 1
parity-algorithm left-symmetric
chunk-size 32
device /dev/sdb2
raid-disk 1
device /dev/sdc1
raid-disk 2
device /dev/sda2
failed-disk 0
raiddev /dev/md1
raid-level 1
nr-raid-disks 2
nr-spare-disks 0
persistent-superblock 1
chunk-size 32
device /dev/sda1
raid-disk 0
device /dev/sdb1
raid-disk 1
On the Mac:
raiddev /dev/md0
raid-level 5
nr-raid-disks 3
nr-spare-disks 0
persistent-superblock 1
parity-algorithm left-symmetric
chunk-size 32
device /dev/sdb4
raid-disk 1
device /dev/sdc2
raid-disk 2
device /dev/sda4
failed-disk 0
raiddev /dev/md1
raid-level 1
nr-raid-disks 2
nr-spare-disks 0
persistent-superblock 1
chunk-size 32
device /dev/sda3
raid-disk 0
device /dev/sdb3
raid-disk 1
This sets up /dev/md0 as our large RAID-5 array which will contain our
root ('/') filesystem. But what does all that mean?
raiddev /dev/md0 - specifies that we're creating raid device
/dev/md0
raid-level 5 - specifies that this is a RAID-5 array
nr-raid-disks - specifies the number of *active* disks in the array
nr-spare-disks - specifies the number of spare disks in the array
(spare disks are used automagically if an active disk fails)
persistent-superblock 1 - puts a block on each RAID device that
contains info about its position in the array (among other things).
Ever wonder what happens if you physically re-arrange drives in
the array by accident, or switch a cable to the wrong drive?
Without this, the array wouldn't know and would go to pieces. On
the PC this also allows booting from the array, which we'll get to
later.
parity-algorithm left-symmetric - specifies the algorithm used to
spread the parity info among multiple disks. Don't ask me how it
works, I haven't a clue.
chunk-size 32 - specifies the chunk size the array writes in. this
has an affect on performance, but since I don't understand all
that too well I just use what the docs recommended.
device /dev/sdxx - specifies the device name of each partition to
be included in the array.
raid-disk x - specifies a unique number assigned to each device
in the array.
failed-disk x - specifies a device that is in a failed state. In this
case, we specify our current non-raid boot device so that the raid
doesn't try to incorporate it into the array yet. That Would Be
Bad(tm).
What's the second RAID device for, you ask? Well, I'm glad you asked.
Booting to a RAID-5 array is a bit of a problem, and /dev/md1 is part of
the solution. Grub, LILO, and Yaboot do not understand the inner
workings of a RAID-5 array, so they can't boot to one directly. LILO and
Yaboot, however, can boot to a RAID-1 array. Therefore, once we've
created our arrays, we'll make /dev/md1 into our /boot partition. It will
contain the kernel, which is the only thing that needs to be accessible
to the bootloader. We'll configure the bootloader to boot that kernel,
and then we'll have a bootable RAID system.
1. mkraid /dev/md0
2. mkraid /dev/md1
If all goes well, your arrays should be created without comment. Use
the command 'cat /proc/mdstat' to check the status of your RAID
devices.(md, by the way, stands for 'multiple devices'. It's the kernel's
shorthand for RAID devices.)
NOTE: RAID autodetection steps are PC only, Mac users should skip this
section and resume reading at the 'make filesystems' step.
Now that we know our arrays are working, let's stop them and setup
auto-detection. Auto-detection makes use of the 'persistent superblock'
that we enable in /etc/raidtab. It installs that superblock on each RAID
device, and once we've set the partition type correctly, the kernel will
see all our RAID devices at boot.
1. raidstop /dev/md0
2. raidstop /dev/md1
That stops the arrays so that we can modify them. Now run fdisk on
*each disk* to alter the partition type:
1. fdisk /dev/sda
2. p
3. t
4. 1
5. fd
6. w
This lists the parition table, selects a partition to work on, and then
sets the partition type to RAID. It then writes the new partition table to
disk. Do this to *each partition* to be used in the array. Then reboot
and watch the kernel auto-detect your arrays.
Now, we'll make filesystems on our arrays. We'll make '/boot' ext2 and
'/' Reiserfs. You can also use other filesystems. For the Mac I tested
with Ext3.
1. mke2fs /dev/md1
2. mkreiserfs /dev/md0
Let's create a directory to mount our RAID to, so that we can copy our
existing data over to the array. I used:
mkdir /raid
Now, we'll copy our stuff over to the new '/boot' parition:
For PC, create a LILO configuration with a backup setting to test things:
1. umount /raid
2. vi /etc/lilo.conf
o boot=/dev/sda1
o install=/boot/boot.b
o lba32
o prompt
o delay=50
o
o timeout=50
o default=linux-raid
o image=/boot/vmlinuz-2.4.2-raid
o label=linux-raid
o root=/dev/md0
o read-only
o image=/boot/vmlinuz-2.4.2-raid
o label=fallback
o root=/dev/sda2
o read-only
Now, simply run /sbin/lilo to setup LILO on your first partition. Note
the 'fallback' entry. If something goes wrong you can still boot back to
your non-RAID configuration by typing 'fallback' at the LILO prompt.
Now, copy your lilo.conf to lilo.sda and lilo.sdb. We need one for each
mirror of the RAID-1 partition. The reason is that we're going to install
LILO on each so that if the primary disk fails, we can still boot.
Essentially, we're making LILO redundant. Change /etc/lilo.sda so that
the line reads 'boot=/dev/sda' and change /etc/lilo.sdb so that the line
reads 'boot=/dev/sdb' and then install LILO onto the MBR of each drive:
1. /sbin/lilo -C /etc/lilo.sda
2. /sbin/lilo -C /etc/lilo.sdb
Also, note the 'device=' line. That will be different depending on your
machine. Run ofpath /dev/sda to get the Open Firmware path for your
first SCSI drive. Put that in your 'device=' line.
Also important is the 'partition=' line. This should be the number of the
partition that contains your kernel. In this case, the array /dev/md1
contains our kernel and it's on partition 3.
Example yaboot.conf:
# ybin options
boot=/dev/sda2
magicboot=/usr/local/lib/yaboot/ofboot
delay=10
defaultos=linux
enablecdboot
# yaboot options
init-message="\nWelcome to Yellow Dog Linux\n\n"
timeout=50
default=linux
# yaboot images
image=/vmlinux-2.4.20-ben10
label=linux
root=/dev/md0
partition=3
append="md=0,/dev/sda4,/dev/sdb4,dev/sdc2 md=1,/dev/sda3,/dev/sdb3"
device=/pci@80000000/pci-bridge@d/ADPT,2940U2B@4/@0:
image=/boot/vmlinux-2.4.20-ben10
label=fallback
root=/dev/sda4
partition=4
Mac Note: The Blue & White G3 I used seems to have a pretty dumb
Open Firmware. If you unplug the primary drive to test the array, be
aware that the firmware takes a very long time to figure it out. In my
case, it made me type 'mac-boot' before it would even fail over. Not
very smart. I've been told that the G4's are better, but I haven't
verified that.
If all goes well, you've just booted from the array. Now it's time to add
that old partition into your RAID-5 array and enable redundancy. First,
edit /etc/raidtab and change the label 'failed-disk' to 'raid-disk'. This
tells the RAID the partition is OK for use now. Then add it to the array
by running:
Use 'watch cat /proc/mdstat' to see it build the redundancy. You should
see a line that says something about 'recovery' and an estimated time
for completion. Once it finishes you are running a fully redundant
system. You should be able to survive a hard drive failure without data
loss.
Now it's time to set up our swapfile. It will exist inside the array so that
a dead drive won't crash the machine. Generally you should set up a
swapfile that is 2 times the size of your RAM, though for machines with
lots of memory this may not be practical. First, figure out how many
blocks you'll be using. This is figured out by taking the RAM count in
MB and multiplying by 1024 (to convert to KB) and then doubling it. In
my case I have 256MB, so 256*1024*2 is 524288.
Now mkswap /swapfile and swapon /swapfile to create and activate the
swapspace.
Next we'll add our new swap space into /etc/fstab so that it will be used
automatically. Add a line to /etc/fstab that looks like this:
/swapfile swap swap defaults 0 0