Hack 62 Create Linux Software RAID

 < Day Day Up > 

figs/expert.gif figs/hack62.gif

Use Knoppix to create and reconfigure software RAID 0, 1, and 5 .

A rescue disk is very handy to configure and change a software RAID, particularly if the RAID is for a complete root partition. Knoppix comes with the major tools you need to create and modify Linux software RAID, and makes it very simple to create new software RAID drives . Linux software RAID supports many different styles of RAID, and this hack covers the three most popular configurations: RAID 0, RAID 1, and RAID 5. This hack assumes a basic familiarity with RAID principles, and a working knowledge of the differences between RAID 0, 1, and 5.

6.12.1 Configure /etc/raidtab

To create a RAID, first edit the /etc/raidtab configuration file and add a new RAID device. This differs depending on which type of RAID you want to create, so I go over the configuration for each of the three types. I have provided default RAID configurations for each type, because usually /etc/raidtab is empty or missing by default. Use these configurations as a starting point, and modify them to match your devices.

When you create a RAID, you don't need to format the partitions beforehand, as they are reformatted after the RAID is created. RAID 0

RAID 0, also known as striping, combines the storage and speed of two drives into a single larger drive. RAID 0 provides no redundancy, however, so if one drive fails, all of the data is lost. For this example, there are two regular Linux partitions, /dev/hda1 and /dev/hdb1 , of approximately the same size . To set up RAID 0, edit /etc/raidtab and add any partitions you want to use in the RAID. Open /etc/raidtab as root, and add the following lines to create a default RAID 0 config:

 raiddev /dev/md0         raid-level      0         nr-raid-disks   2         persistent-superblock 1         chunk-size        4         device   /dev/hda1   raid-disk       0         device   /dev/hdb1   raid-disk       1 RAID 1

RAID 1, also known as mirroring, uses two or more partitions essentially as mirrors of each other, so every byte written to one partition is simultaneously written to the other partitions. RAID 1 provides protection from drive failure: if a single partition fails, any other partition on the array still contains all the data, and when the failed partition is replaced , all of the mirrored data is automatically written to the new partition by the RAID program. To create a RAID 1 array across /dev/hda1 and /dev/hdb1 , the configuration in /etc/raidtab looks very similar to the one used for RAID 0:

 raiddev /dev/md0         raid-level      1         nr-raid-disks   2         nr-spare-disks  0         chunk-size     4         persistent-superblock 1         device   /dev/hda1   raid-disk       0         device   /dev/hdb1   raid-disk       1 

Other than changing the raid-level variable from 0 to 1, the primary difference here is the addition of the nr-spare-disks option to configure automatic failover disks, which you can use to automatically replace any failed partitions. In this example, I do not create any spare disks, but I still include the variable set to zero. RAID 5

RAID 5, also known as striping with parity, combines three or more similarly sized drives into a single larger drive. Any data written to the drive is striped across all drives in the array along with parity information. This parity information effectively uses up the space of a single drive, so if you combine three drives into a RAID 5 array, the array is only the size of two of the drives combined. With this parity information, if any drive fails, the remaining drives can continue running, and once a replacement drive is available, they can restore all of the data, including parity information, to the new drive. Unlike RAID 0 or RAID 1, RAID 5 requires at least three partitions, so this example creates a RAID 5 partition out of /dev/hda1 , /dev/hdb1 , and /dev/hdc1 . First create an /etc/raidtab to describe your desired RAID:

 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/hda1   raid-disk       0         device   /dev/hdb1   raid-disk       1         device   /dev/hdc1   raid-disk       2 

6.12.2 Creating the RAID

Regardless of which RAID you configure, once you have edited /etc/raidtab , creating the RAID is a simple matter of running:

 knoppix@tty0[knoppix]$  sudo mkraid  /dev/md0   

At this point, you can read /proc/mdstat to check the current status of the newly created RAID drive. For example, after you create a RAID 0 array, you see the following output:

 knoppix@tty0[knoppix]$  cat /proc/mdstat  Personalities : [raid0] read_ahead 1024 sectors md0 : active raid0 hdb1[1] hda1[0]       5242624 blocks 4k chunks unused devices: 

At this point, you can treat /dev/md0 like any other partition and format it, mount it, and copy files to it. If you have an existing Linux installation on a different partition and want it to use the RAID, make sure that its kernel supports software RAID and that it has the complete set of Linux software RAID tools like mkraid , raidhotadd , etc. Use the following command to mount the Linux installation read/write, then copy /etc/raidtab to the /etc/ directory on that drive:

 root@tty0[root]#  mount -o rw /dev/hda1 /mnt/hda1  

Most vendor kernels support RAID by default. If you are building your own kernel, make sure that "Multiple devices driver support" is enabled as are the different RAID modes you want to use in the "Multi-device support" section.

Once you boot the Linux system without Knoppix, check /proc/mdstat to see if an init script installed by your distribution has automatically started the RAID for you. If the RAID hasn't been started, run:

 root@tty0[root]#  raidstart  /dev/md0   

If your kernel supports software RAID autodetection (check the Multi-device support section in your kernel configuration), you can configure these partitions to be automatically detected by Linux as it boots. To do this, unmount the RAID and stop the array with:

 root@tty0[root]#  umount /dev/md0  root@tty0[root]#  raidstop  /dev/md0   

Replace md0 with the name of your array. Once the RAID is stopped , use fdisk or cfdisk as root to change the partition type for each partition in the RAID-to-RAID autodetection. By default, Linux partitions are of type 83 , but there is a special partition type, fd , set aside for Linux RAID autodetection. Once you change the partition type for the partitions, write the changes and reboot. A Linux kernel that supports software RAID autodetection automatically starts the device during boot and stops the device during shutdown.

Configuration of software RAIDs under Linux is pretty straightforward, and with Knoppix, you can easily experiment with RAID configurations on a system full of blank disks. You can also modify an existing RAID and unmount, stop, and start the RAID even if you are configuring a root partition. In addition, you can also leverage most of the filesystem-and-partition copying methods referenced in other hacks to easily copy entire systems over the network to a newly created software RAID, even if your particular distribution doesn't necessarily support installing to RAID by default.

6.12.3 See Also

  • [Hack #48]

  • [Hack #61]

 < Day Day Up > 

Knoppix Hacks. 100 Tips and Tricks
Knoppix Hacks. 100 Tips and Tricks
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net