Hands-on Linux Software RAID
What is Software RAID?
Software RAID is RAID implemented with software - no additional hardware such as a RAID controller is needed. Thus, software RAID is a good starting point to start getting some hands-on RAID experience. Also, software RAID is independent of proprietary management software - maintaining a software RAID works the same way on all machines that run Linux. However, there is something to think about too: when considering software RAID, think about performance. All RAID algorithms are done by the system CPU and every block has to be copied over the system's data bus (i.e. sda1 <-> IO controller <-> RAM, possibly CPU <-> IO controller <-> sdb1). (Thanks to René Pfeiffer of the Answer Gang for pointing that out.)
Enabling your Kernel to support RAID
I am using Ubuntu 7.10 with the "stock" kernel for my experiments. The test machine has an 80GB SATA HDD.
First, check whether the RAID support is enabled in your kernel:
cat /proc/mdtstat
If you get a message saying:
cat: /proc/mdstat: No such file or directory
then you need to enable RAID support. There are two possiblities:
- RAID support was disabled while compiling the kernel and you will have to recompile it
- You will have to insert the multiple disk (md) support module manually.
Check whether the "md*" modules exist under /lib/modules/$(uname
-r)/kernel/drivers/md/ and insert the module as follows:
$ sudo modprobe md-mod Password:
(Thanks to Kapil of the Answer Gang for this one)
Now, you can verify whether RAID support is active:
amit@amit-desktop:~$ cat /proc/mdstat Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] unused devices:
This means that now we have RAID support in the kernel.
Tools for manipulating RAID arrays
Now that you have got a RAID enabled Kernel, you will need to use some user-space tools to help you out to play with RAID.
Slightly outdated 'raidtools' and the newer, better 'mdadm' are the tools available to you. My focus in this article will be on 'mdadm'. For more information on using 'raidtools' and a comparison of the two, please refer to the How-To mentioned in the References.
Installing 'mdadm'
amit@amit-desktop:~$ sudo apt-get install mdadm Reading package lists... Done Building dependency tree Reading state information... Done Recommended packages: mail-transport-agent The following NEW packages will be installed: mdadm 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 220kB of archives. After unpacking 627kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com gutsy/main mdadm 2.6.2-1ubuntu2 [220kB] Fetched 220kB in 48s (4515B/s) Preconfiguring packages ... Selecting previously deselected package mdadm. (Reading database ... 88932 files and directories currently installed.) Unpacking mdadm (from .../mdadm_2.6.2-1ubuntu2_i386.deb) ... Setting up mdadm (2.6.2-1ubuntu2) ... Generating array device nodes... done. Generating mdadm.conf... done. Removing any system startup links for /etc/init.d/mdadm-raid ... update-initramfs: deferring update (trigger activated) * Starting MD monitoring service mdadm --monitor [ OK ] Processing triggers for initramfs-tools ... update-initramfs: Generating /boot/initrd.img-2.6.22-14-generic
Creating a RAID device
My disk setup now is as follows:
Name Flags Part Type FS Type [Label] Size (MB) --------------------------------------------------------------------------------- sda1 Boot Primary NTFS [] 20612.56 sda5 Logical W95 FAT32 20579.66 sda6 Logical W95 FAT32 20587.88 sda7 Logical Linux ext3 12000.69 sda8 Logical Linux swap / Solaris 1019.94 sda9 Logical Linux 2048.10 sda10 Logical Linux 2048.10 sda11 Logical Linux 3446.40
I will now combine sda9 and sda10 to form one large logical device to form a RAID array. For the purpose of demonstration, and also since 0 is always a good point to start, creating a level-0 RAID is next.
[ Note the type of the partition. The Linux RAID kernel driver can automatically start a RAID device if the type of the partition is marked as 0xFD meaning "Linux RAID partition with autodetect using persistent superblock". -- René ]
Combining 2 consecutive partitions to form a RAID is not a smart thing to do, I was told by the Answer Gang. But till I find it why, I shall persist.
[ The purpose of having a RAID is to distribute the I/O load of any read/write
operations over multiple disks. Hard disks are slow, and take a while to
complete commands given to them. Depending on the I/O operation, a RAID will
allow the system to let the disks in a RAID work in parallel. This is especially
true when reading from a RAID0 or RAID1.
If you create a RAID device on the same physical device the RAID driver doesn't
notice. The problem you have then is that you put the poor drive under a lot of
load, since the driver now thinks it can issue a command in parallel while in reality
the is no parallelism. This means that the heads of the drive will probably move
a lot - and this is a bad idea as a friend of mine who does professional data
recovery once explained to me.
So, it's OK to do this for educational purposes, but please, don't ever ever put
live data on a production server into a RAID consisting of partitions on the same
physical drive. -- René]
Creating a Level-0 RAID
amit@amit-desktop:~$ sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sda9 /dev/sda10 [sudo] password for amit: mdadm: chunk size defaults to 64K mdadm: array /dev/md0 started.
Let us now check the RAID array we just created:
amit@amit-desktop:~$ cat /proc/mdstat Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] md0 : active raid0 sda10[1] sda9[0] 3999872 blocks 64k chunks unused devices:
Now, we'll create a filesystem on the new RAID device:
amit@amit-desktop:~$ sudo mkfs -t ext3 /dev/md0 [sudo] password for amit: mke2fs 1.40.2 (12-Jul-2007) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 500960 inodes, 999968 blocks 49998 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1027604480 31 block groups 32768 blocks per group, 32768 fragments per group 16160 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 33 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.Mount the RAID device:
amit@amit-desktop:~$ sudo mkdir /media/RAID0 amit@amit-desktop:~$ mount /dev/md0 /media/RAID0/ mount: only root can do that amit@amit-desktop:~$ sudo mount /dev/md0 /media/RAID0/ amit@amit-desktop:~$ df Filesystem 1K-blocks Used Available Use% Mounted on . . /dev/md0 3936940 73440 3663508 2% /media/RAID0
let us now use 'mdadm' to get some details on the RAID array:
amit@amit-desktop:~$ sudo mdadm --query /dev/md0 --detail /dev/md0: 3.81GiB raid0 2 devices, 0 spares. Use mdadm --detail for more detail. amit@amit-desktop:~$ sudo mdadm --detail /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Tue Mar 11 13:05:22 2008 Raid Level : raid0 Array Size : 3999872 (3.81 GiB 4.10 GB) Raid Devices : 2 Total Devices : 2 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Tue Mar 11 13:05:22 2008 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Chunk Size : 64K UUID : f77bd177:706b589c:2a7af8c6:cbd32339 (local to host amit-desktop) Events : 0.1 Number Major Minor RaidDevice State 0 8 9 0 active sync /dev/sda9 1 8 10 1 active sync /dev/sda10
Looking ahead
A RAID experimental bed is now ready for us. In some future articles, I shall try to share my experiments on the RAID setup. You may also consider visiting my blog posts on RAID here.
References
Acknowledgements
Thanks to the Answer Gang (TAG) for discussions on RAID a while back. Though none of the cool suggestions has been tried by me, the next article shall have them tried, tested and appreciated. I also had the privilege to get my article "live-edited" by the Answer Gang which I believe was a limited period offer . Thanks, guys!
Talkback: Discuss this article with The Answer Gang
The author is a freelance technical writer. He mainly writes on the Linux kernel, Network Security and XML.