Build a Linux Software RAID from Scratch - Page 2

Part Two: Last week we considered Linux software RAID's advantages, this week we show you how to do it.

By  Carla Schroder | May 17, 2005
Page 2 of 3   |  Back to Page 1
Print ArticleEmail Article
  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn

Continued From Page 1

Creating The Array and Filesystem
The next steps are starting up the array and creating filesystems. First create an /etc/raidtab file. This is your master RAID configuration file. Let's say our new data partitions are /dev/hdb1 and /dev/hdc1:

# /etc/raidtab
raiddev /dev/md0
raid-level              0
nr-raid-disks           2
persistent-superblock   1
chunk-size              32
device                  /dev/hdb1
raid-disk                0
device                  /dev/hdc1
raid-disk               1

Now initialize the array:

# mkraid /dev/md0

Monitor progress:

# watch /proc/mdstat

Stop the watch command with CTRL+C. When the array is built you may create whatever filesystem you like on the data partitions: Ext2/3, JFS, ReiserFS, XFS, VFAT- anything that Linux supports. Use the utilities specific to the filesystems to create them. For example, this creates Ext3:

# mke2fs -j /dev/md0

This creates a Reiser filesystem:

# mkreiserfs /dev/md0

Be sure to follow the documentation for your chosen filesystem. Then create and initialize the swap partitions:

# mkswap /dev/hdb2
# mkswap /dev/hdc2
# swapon /dev/hdb2
# swapon /dev/hdc2

Start It Up
Now it's time to fire up your shiny new RAID 0 array:

# raidstart /dev/md0

Create mountpoints and mount the array:

# mkdir /mnt/raid0
# mount /dev/md0 /mnt/raid0

Now you can read and write to /mnt/raid0 just like any other directory.

Starting RAID at Boot
You probably want your nice new RAID 0 array to be automatically mounted at boot, so you must add a line to your /etc/fstab file:

/dev/md0   /mnt/raid0  reiserfs  defaults  0 1

Of course you may specify whatever mount options you like. Finally, there is one more kewl performance-enhancing trick you can do with the swap partitions. This is not a RAID function, but a kernel function- set up swapping in parallel in /etc/fstab:

/dev/hdb2   none   swap   sw,pri=0     0 0
/dev/hdc2   none   swap   sw,pri=0     0 0

This is a good time to reboot and verify that everything works. cat /proc/mdstat tells the status of the array.

RAID 1 and RAID 5
Now that you know the basics of setting up RAID, it's simple to create other RAID levels in /etc/raidtab. RAID 1 is just the same as our RAID 0 example, except for this line:

raid-level        1

Adding a three-disk RAID 5 array requires but three changes to /etc/raidtab:

raid-level       5
nr-raid-disks    3
parity-algorithm     left-symmetric

Continued on page 3: Standby Spare Disk

 


Updated: The examples in this article included a mistake in the commands used to create and prepare swap partitions for use. We've updated the examples. Thanks to the readers who notified us of the error.

Comment and Contribute
(Maximum characters: 1200). You have
characters left.
Get the Latest Scoop with Enterprise Networking Planet Newsletter
Helpful Links
  • Yankee Group Mobile WAN Optimization Report

    Mobile work continues to evolve. Your organization must keep up with the demands of its mobile workforce. This report introduces the concept of mobile WAN optimization and provides three case studies including RCM, PRTM and Einstein that highlight how this emerging technology can help IT departments achieve what previously appeared to be conflicting goals. Read >

  • Network Security Resources

    More threats than ever before pose a danger to today's enterprise network. Get the latest tips and intel on the newest risks in our guide to network security resources. Read >

  • Extreme Savings: Cutting Costs with WAN Optimization

    Did you know it's possible to cut IT costs without impacting day-to-day IT operations? In fact, when you download this whitepaper from Riverbed on cost-savings through WAN optimization, you'll discover how businesses of all different sizes have realized a return on investment in just a few months through significant hard cost savings in areas such as bandwidth reduction and IT consolidation. It's called Extreme Savings and its only from Riverbed. Read >