If your kernel compiled with RAID support and your system supports RAID, the /proc/mdstat exists
[shanren@newemachines ~]$ cat /proc/mdstat Personalities : unused devices:
|
I have reserved two equal-sized unformatted partitions
[shanren@newemachines ~]$ egrep '(sda4|sdb3|blocks)' /proc/partitions major minor #blocks name 8 4 9052627 sda4 8 19 9052627 sdb3
|
Let's grab mdadm--RAID administration tool
[root@newemachines shanren]# yum -y install mdadm Loading "installonlyn" plugin Setting up Install Process Parsing package install arguments fedora 100% |=========================| 2.1 kB 00:00 Resolving Dependencies --> Running transaction check ---> Package mdadm.i386 0:2.6.2-4.fc7 set to be updated
Dependencies Resolved
============================================================================= Package Arch Version Repository Size ============================================================================= Updating: mdadm i386 2.6.2-4.fc7 updates 817 k
Transaction Summary ============================================================================= Install 0 Package(s) Update 1 Package(s) Remove 0 Package(s)
Total download size: 817 k Downloading Packages: (1/1): mdadm-2.6.2-4.fc7. 100% |=========================| 817 kB 00:11 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Updating : mdadm ######################### [1/2] Cleanup : mdadm ######################### [2/2]
Updated: mdadm.i386 0:2.6.2-4.fc7 Complete!
|
I want to construct RAID 1 with two partitions on separate hard drives and format it with ext3 file system
[root@newemachines shanren]# /sbin/mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/sda4 /dev/sdb3 mdadm: size set to 9052544K mdadm: array /dev/md0 started.
[root@newemachines shanren]# /sbin/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) 1133440 inodes, 2263136 blocks 113156 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2319450112 70 block groups 32768 blocks per group, 32768 fragments per group 16192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
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.
|
Checking the status of building the RAID
[root@newemachines shanren]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdb3[1] sda4[0] 9052544 blocks [2/2] [UU] [==========>..........] resync = 50.0% (4530496/9052544) finish=5.0min speed=15035K/sec unused devices:
[root@newemachines shanren]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdb3[1] sda4[0] 9052544 blocks [2/2] [UU] unused devices:
|
Mount the RAID
[root@newemachines shanren]# mkdir /mnt/raid [root@newemachines shanren]# mount -t ext3 -v /dev/md0 /mnt/raid /dev/md0 on /mnt/raid type ext3 (rw)
|
Create the configuration file for mdadm so I can assemble the created array easily later on. I use mdadm with --detail option to obtain the detailed array information and add that information to /etc/mdadm.conf. My final mdadm.conf is shown.
[root@newemachines shanren]# /sbin/mdadm --detail --scan ARRAY /dev/md0 level=raid1 num-devices=2 UUID=00c674c9:04162ff3:124ba3d9:31646810 [root@newemachines ~]# cat /etc/mdadm.conf DEVICE /dev/sda4 /dev/sdb3 ARRAY /dev/md0 level=raid1 num-devices=2 UUID=00c674c9:04162ff3:124ba3d9:31646810 devices=/dev/sda4,/dev/sdb3
|
Should we check how well RAID 1 perform?
[root@newemachines shanren]# ls -lh debian-testing-i386-netinst.iso |cut -d" " -f5 159M [root@newemachines shanren]# time cp debian-testing-i386-netinst.iso Desktop/
real 0m0.720s user 0m0.018s sys 0m0.629s [root@newemachines shanren]# time cp debian-testing-i386-netinst.iso /mnt/raid/
real 0m0.697s user 0m0.019s sys 0m0.613s
[root@newemachines shanren]# ls -lh F-7-i386-DVD.iso |cut -d" " -f5 2.8G [root@newemachines shanren]# time cp F-7-i386-DVD.iso Desktop/
real 3m18.350s user 0m0.422s sys 0m14.498s [root@newemachines shanren]# time cp F-7-i386-DVD.iso /mnt/raid/
real 7m14.209s user 0m0.453s sys 0m13.556s
|
As the file size increases, the overhead of RAID 1 becomes quite noticeable.
I would like to see if RAID 1 does what it is supposed to do--Mirroring
[root@newemachines shanren]# umount /dev/md0 [root@newemachines shanren]# /sbin/mdadm --stop /dev/md0 mdadm: stopped /dev/md0
[root@newemachines shanren]# mkdir /mnt/raiddevice0 /mnt/raiddevice1 [root@newemachines ~]# mount /dev/sda4 /mnt/raiddevice0 [root@newemachines ~]# mount /dev/sdb3 /mnt/raiddevice1
[root@newemachines ~]# md5 /mnt/raiddevice0/F-7-i386-DVD.iso 355bdb01b0268a4bb7c757f2737dcf7c /mnt/raiddevice0/F-7-i386-DVD.iso [root@newemachines ~]# md5 /mnt/raiddevice1/F-7-i386-DVD.iso 355bdb01b0268a4bb7c757f2737dcf7c /mnt/raiddevice1/F-7-i386-DVD.iso
|
Obviously, it does because the md5 of the files written to two RAID devices is the same
Let's clean it up...
[root@newemachines ~]# umount /mnt/raiddevice0 /mnt/raiddevice1 [root@newemachines ~]# rmdir /mnt/raiddevice0 /mnt/raiddevice1 [root@newemachines shanren]# /sbin/mdadm --assemble --verbose /dev/md0 mdadm: looking for devices for /dev/md0 mdadm: /dev/sda4 is identified as a member of /dev/md0, slot 0. mdadm: /dev/sdb3 is identified as a member of /dev/md0, slot 1. mdadm: added /dev/sdb3 to /dev/md0 as 1 mdadm: added /dev/sda4 to /dev/md0 as 0 mdadm: /dev/md0 has been started with 2 drives.
|
Reference:
Link 1, Link 2, Link 3