dcsimg

Linux Software RAID – A Belt and a Pair of Suspenders

Linux comes with software-based RAID that can be used to provide either a performance boost or add a degree of data protection. This article gives a quick introduction to Linux software RAID and walks through how to create a simple RAID-1 array.

There is an old phrase about wearing a belt and a pair of suspenders if you want to make sure your pants stay up (why haven’t plumbers figured that out?). The point of the phrase is that if you want to be sure that your plans will happen you should have a backup plan as well. In the case of file systems this is literally the truth. If you want to make sure you don’t lose any data, do backups as well as provide some other form of data protection. That something else for data protection is RAID (Redundant Array of Inexpensive Disks).

This article is a brief introduction to software RAID, which is really md (Multiple Device Driver) for Linux. As with the article on LVM, this article is just a quick introduction and not a deep tutorial. The intent is to quickly demonstrate Linux software RAID using md and mdadm. Perhaps this article will show you how easy it is to add software RAID to your repertoire to either help improve performance or provide extra protection. In essence, this article will introduce you to Linux software RAID becoming the “suspenders” to the “belt” of backups.

Quick Introduction

The original intent of RAID was to improve IO performance as well as using smaller disks to create larger virtual disks (although the phrase “virtual” disk was not originally used, in this age of “virtual-everything” it seems appropriate). The basic concept was then embraced and developed from the 1987 inception to today.

RAID has evolved into a technology that is ubiquitous as storage drives themselves. It allows system designers to add in performance while also providing some additional data protection (don’t forget to wear your “belt”). There are many choices with RAID such as various RAID levels and software and/or hardware RAID. Software RAID means the RAID functionality is provided in software by the OS. Hardware RAID means the RAID functionality is provided by a card, usually in a PCI or PCIe slot. There a couple of articles that can present the pros and cons of the various RAID options, here and here. But this article will focus on software RAID with Linux using the md capability of Linux.

It’s beyond the scope of this article to discuss the various RAID level options. There are better articles for this (it may be wikipedia, but it’s a good introduction to the various RAID levels). Instead this article will go through the creation of a simple RAID-1 setup. RAID-1 mirrors disks (actually disk partitions) so if you write to one, the data is copied to the other disk(s). This is a simple way to provide some data protection because you can lose a single disk without losing any data (but it is not a substitute for real backups). So what is a good way to create and manage RAID arrays on Linux?

Madam – I’m mdadm

Handling md groups can be very complex and difficult. It can require hand editing files where a mistake can cause the lose of RAID groups. If you are careful, it works very well. But to help you maintain your RAID groups, Neil Brown started a project for an administrative tool for md called mdadm.

The mdadm tool is very comprehensive and has a variety of functions:


  • Assemble: Assemble the components of a previously created array into an active array

  • Build: Build an array that doesn’t have a superblock on each device

  • Create: Create a new RAID array with a superblock on each device

  • Monitor: Monitor one or more md devices and act on any changes

  • Grow: Change the size (grow or shrink) or reshape an md device. This also allows you to add devices as needed

  • Incremental Assembly: Add a single device to an array

  • Manage: This function allows you to manage specific components of the RAID array such as adding new spare devices or removing faulty devices

  • Misc: This is the function that contains all other functions that might be needed

  • Auto-detect: This function, while not explicit, has the kernel activate any auto-detected arrays

The man pages are quite good and you can find it on-line here.

This article will present a simple example with two drives. For this article, a CentOS 5.3 distribution was used on the following system:


  • GigaByte MAA78GM-US2H motherboard
  • An AMD Phenom II X4 920 CPU
  • 8GB of memory
  • Linux 2.6.30 kernel
  • The OS and boot drive are on an IBM DTLA-307020 (20GB drive at Ulta ATA/100)
  • /home is on a Seagate ST1360827AS
  • There are two drives for testing. They are Seagate ST3500641AS-RK with 16 MB cache each. These are /dev/sdb and /dev/sdb.

Using this configuration a simple RAID-1 configuration is created between /dev/sdb and /dev/sdc.

Step 1 – Set the ID of the drives
The first step in the creation of a RAID-1 group is to set the ID of the drives that are to be part of the RAID group. The type is “fd” (Linux raid autodetect) and needs to be set for all partitions and/or drives used in the RAID group. You can check the partition types fairly easy:

# fdisk -l /dev/sdb

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       60801   488384001   fd  Linux raid autodetect
# fdisk -l /dev/sdc

Disk /dev/sdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       60801   488384001   fd  Linux raid autodetect

Step 2 – Create the RAID set using mdadm The tool mdadm allows the easy creation of a RAID group. In this article, a simple RAID-1 group, a two disk group is created.

[root@test64 ~]# mdadm --create --verbose /dev/md0 --level raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: /dev/sdb1 appears to contain an ext2fs file system
    size=244187136K  mtime=Sun Aug 16 13:06:51 2009
mdadm: /dev/sdc1 appears to contain an ext2fs file system
    size=244187136K  mtime=Sun Aug 16 13:06:51 2009
mdadm: size set to 488383936K
Continue creating array? y
mdadm: array /dev/md0 started.

The options are fairly easy to understand. The first option “–create” creates a RAID group (naturally). After the “–verbose” option is the md device, in this case it’s /dev/md0. After that is the RAID level (“–level”) – in this case it’s raid1. Finally the RAID devices are specified using the “–raid-devices” option. Also notice that it prompts the user if there is a file system on the drives (partitions).

RAID works on a block level. That is, the RAID controller, be it software RAID or hardware RAID, works on the blocks of the devices in the RAID group. This means it’s independent of the file system. Consequently, immediately after the RAID1 group is created, the drives are “synchronized”. That is, the contents of the blocks from the first partition (drive) are copied to the second partition (drive). Below is the output of that synchronization process at very stages of completion (just to give you an idea of speed and time).

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      488383936 blocks [2/2] [UU]
      [>....................]  resync =  0.2% (1444224/488383936) finish=112.3min speed=72211K/sec

unused devices:

Notice that the status of the synchronization process is found by “cat-ing” the contents of the file /proc/mdstat.

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      488383936 blocks [2/2] [UU]
      [==========>..........]  resync = 50.1% (245077952/488383936) finish=57.4min speed=70554K/sec

unused devices:
[root@test64 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      488383936 blocks [2/2] [UU]
      [================>....]  resync = 80.1% (391254144/488383936) finish=25.9min speed=62269K/sec

unused devices:
[root@test64 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      488383936 blocks [2/2] [UU]
      [===================>.]  resync = 99.6% (486830720/488383936) finish=0.5min speed=47731K/sec

unused devices:

After the synchronization process is finished, the output should look like the following.

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      488383936 blocks [2/2] [UU]

unused devices:

Comments on "Linux Software RAID – A Belt and a Pair of Suspenders"

Very nice post. I simply stumbled upon your weblog and wished to say that I have really enjoyed browsing your weblog posts. After all I’ll be subscribing to your rss feed and I hope you write again very soon!|

Here is a superb Weblog You might Uncover Interesting that we encourage you to visit.

We came across a cool website which you may take pleasure in. Take a search for those who want.

What’s up everyone, it’s my first go to see at this web page, and piece of writing is truly fruitful for me, keep up posting these types of content.|

Thanks for finally writing about > %blog_title% < Liked it!|

I’m not that much of a online reader to be honest but your blogs really nice, keep it up! I’ll go ahead and bookmark your site to come back down the road. All the best|

Usually posts some extremely intriguing stuff like this. If you?re new to this site.

Thanks for making me to get new odpdoss concepts about computers. I also have the belief that one of the best ways to help keep your notebook in perfect condition has been a hard plastic case, and also shell, that fits over the top of one’s computer. These types of protective gear usually are model targeted since they are made to fit perfectly over the natural outer shell. You can buy these directly from the seller, or through third party sources if they are available for your notebook computer, however don’t assume all laptop will have a cover on the market. Yet again, thanks for your suggestions.

Please check out the sites we adhere to, including this one, as it represents our picks in the web.

Below you?ll find the link to some web sites that we believe you’ll want to visit.

Every as soon as in a even though we pick out blogs that we read. Listed below would be the most current web pages that we pick.

The time to read or go to the content material or web sites we have linked to below.

Wonderful story, reckoned we could combine some unrelated data, nevertheless actually worth taking a search, whoa did 1 study about Mid East has got much more problerms also.

The time to study or visit the content or web pages we’ve linked to beneath.

Leave a Reply