Software RAID on Linux- Part 1

by Amit

This is the first post in a series of posts listing my experiments with Software RAID on Linux. I am using Ubuntu 7.10 with the generic kernel for my experiments. The test machine has the following hardware specs- 80 GB SATA HDD, 512 MB RAM, Pentium Dual core processor.

Installing RAID support

check whether the RAID support is enabled

cat /proc/mdtstat

if you get a message saying “File is missing” or something alike, go ahead and install RAID support first. This can be done by installing the tool ‘mdadm’ which is a tool to work with RAID devices and it also installs the RAID support

amit@amit-desktop:~$ sudo apt-get install mdadm
Reading package lists... Done
Building dependency tree
Reading state information... Done
Recommended packages:
The following NEW packages will be installed:
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 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

Now verify whether RAID support has been installed:

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.

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

We shall now combine sda9, sda10 to form one large logical device to form a RAID.

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, create a filesystem on the RAID device we just created:

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:~$ mkdir /media/RAID0
mkdir: cannot create directory `/media/RAID0': Permission denied
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
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


In this post, I have shown you how to create a RAID 0 device, creating a filesystem on it and mounting it as any other block device.

Stay tuned for more!