Search

How to create and manage Redundant Array of Inexpensive (or Independent) Disks (RAID)

This lesson explains different steps to create Redundant Array of Inexpensive Disks (RAID) devices.

• Create partitions using fdisk: This example we are using four physical drives, /dev/sdd, /dev/sde, /dev/sdf, /dev/sdg.

Example (fdisk /dev/sdd):

[root@RHEL06 ~]# fdisk /dev/sdd

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Example (fdisk /dev/sde):

[root@RHEL06 ~]# fdisk /dev/sde

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Example (fdisk /dev/sdf):

[root@RHEL06 ~]# fdisk /dev/sdf

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Example (fdisk /dev/sdf):

[root@RHEL06 ~]# fdisk /dev/sdg

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

When creating partitions to use for the RAID device, make sure they are of type Linux raid auto. In fdisk, this is partition id fd.

After creating the partitions for the RAID device, use the following syntax as the root user to create the RAID device:

mdadm --create /dev/mdX --level=<num> --raid-devices=<num> <device list>

Example:

[root@RHEL06 ~]# mdadm --create /dev/md0 --level=0 --raid-devices=4 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1
mdadm: /dev/sdd1 appears to contain an ext2fs file system
size=20964608K mtime=Sat Jun 27 18:05:00 2009
mdadm: /dev/sdd1 appears to be part of a raid array:
level=raid5 devices=3 ctime=Sat Jun 27 18:03:13 2009
mdadm: /dev/sde1 appears to be part of a raid array:
level=raid5 devices=3 ctime=Sat Jun 27 18:03:13 2009
mdadm: /dev/sdf1 appears to contain an ext2fs file system
size=20964608K mtime=Sat Jun 27 18:05:00 2009
mdadm: /dev/sdf1 appears to be part of a raid array:
level=raid5 devices=3 ctime=Sat Jun 27 18:03:13 2009
mdadm: /dev/sdg1 appears to contain an ext2fs file system
size=20964608K mtime=Sat Jun 27 18:05:00 2009
mdadm: /dev/sdg1 appears to be part of a raid array:
level=raid5 devices=3 ctime=Sat Jun 27 18:03:13 2009
Continue creating array? y
mdadm: array /dev/md0 started.

The above command creates a RAID 0 array from four partitions, /dev/sdd1, /dev/sde1, /dev/sdf1 and /dev/sdg1. Here each partition is of 10GB and you will get a 40GB of space after creating the RAID 0 device.

Once you have created the RAID device, you can know the status of it from “/proc/mdstat” file. “/proc/mdstat” file lists the active RAID status information.

Example:

[root@RHEL06 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid0]
md0 : active raid0 sdg1[3] sdf1[2] sde1[1] sdd1[0]
41929216 blocks 64k chunks

unused devices: <none>

Note: You can use the “watch” command along with the above command to view the progress, since “watch” command refresh the display in a regular interval.

Example:

[root@RHEL06 ~]# watch cat /proc/mdstat

• Overlay a filesystem on the RAID device by using mkfs command.

[root@RHEL06 ~]# mkfs.ext3 /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
5242880 inodes, 10482304 blocks
524115 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
320 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

To gather more information about a RAID device, you can use the command “mdadm –-query –detail <device_name>”.

[root@RHEL04 ~]# mdadm --query --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Mon Sep 7 16:52:36 2009
Raid Level : raid0
Array Size : 25157376 (23.99 GiB 25.76 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Mon Sep 7 16:52:36 2009
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0

Chunk Size : 64K

UUID : d4856f05:4f9e1626:05ee9bd2:7ba66b78
Events : 0.1

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1

• Mount the RAID device on the required mount point by using the mount command.

[root@RHEL06 ~]# mount /dev/md0 /home1

How to stop a RAID device

To stop a RAID device, first unmount the device using umount command, and then issue the mdadm –stop <device_name> command.

[root@RHEL04 ~]# umount /home1
[root@RHEL04 ~]# mdadm --stop /dev/md0

How to create a RAID 5 device

[root@RHEL06 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: /dev/sdd1 appears to contain an ext2fs file system
size=41929216K mtime=Sun Jun 28 23:39:03 2009
mdadm: /dev/sdd1 appears to be part of a raid array:
level=raid0 devices=4 ctime=Sun Jun 28 23:33:19 2009
mdadm: /dev/sde1 appears to be part of a raid array:
level=raid0 devices=4 ctime=Sun Jun 28 23:33:19 2009
mdadm: /dev/sdf1 appears to be part of a raid array:
level=raid0 devices=4 ctime=Sun Jun 28 23:33:19 2009
Continue creating array? y
mdadm: array /dev/md0 started.

Adding and Failing RAID Partitions

To add a partition to a RAID device, execute the following as root after creating the partition of type Linux raid auto (fd in fdisk):

mdadm /dev/mdX -a <device list>

Example:

[root@RHEL06 ~]# mdadm /dev/md0 -a /dev/sdg1
mdadm: added /dev/sdg1

If a partition in the array fails, use the following to remove it from the array and rebuild the array using the spare partition already added:

mdadm /dev/mdX -f <failed device>

Related Tutorials
• Introduction to Logical Volume Manager (LVM)
• How to create and manage Logical Volume Manager (LVM)
• Introduction to Redundant Array of inexpensive (or Independent) Disks (RAID)
• Introduction to swap space
• How to create and manage swap space