Well, I have been waiting for this since long! While RAID has been with us since ages, it has always been amazing me ever since I got into Administration 😉 Since I own a very basic laptop with a single 250 GB Hard Disk, testing & managing RAID has never been easy 😦 But, thanks to Flipkart!! I could find dirt cheap USB storage devices (pen-drives, that’s what most people call it. But its NOT a drive as there are no rotating/moving parts & no Read-Write heads) & today I could test it out on my sweet old laptop 😉 So, below is how to set-up a RAID on your RHEL 6 (and many other similar Linux distributions). I have demonstrated a RAID 1 (mirroring) here.
Note – All the set-up has been done on a RHEL 6.2 virtual machine running on Oracle Virtual Box with 2 8GB pen-drives.
1. Insert your pen-drives. Go to Devices & enable them.
2. Change Partition Type to Linux RAID & reboot your server.
3. Create RAID1 by issuing below command.
mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb1 /dev/sdc1
You will run into below error.
[root@server ~]# mdadm --create --verbose /dev/md0 --level=mirror --raid-devices =2 /dev/sdb /dev/sdc mdadm: super1.x cannot open /dev/sdb: Device or resource busy mdadm: ddf: Cannot use /dev/sdb: Device or resource busy mdadm: Cannot use /dev/sdb: It is busy mdadm: cannot open /dev/sdb: Device or resource busy
To fix this error, remove dmraid package & reboot your server.
[root@server ~]# yum erase dmraid
Now retry creating your RAID. It will be successful.
4. Check RAID details.
[root@server ~]# mdadm --detail /dev/md0
5. Test RAID1 Functionality.
Create a file-system. Lets call it test_raid. Format RAID device /dev/md0 with ext4 file-system & mount /dev/sd0 to /test_raid.
[root@server ~]# mkfs.ext4 /dev/md0 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 488640 inodes, 1953913 blocks 97695 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2004877312 60 block groups 32768 blocks per group, 32768 fragments per group 8144 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 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@server ~]# mkdir /test_raid
[root@server ~]# mount /dev/md0 /test_raid/
[root@server ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.7G 6.5G 2.7G 71% / tmpfs 246M 100K 246M 1% /dev/shm /dev/sda1 97M 28M 65M 30% /boot /dev/md0 7.4G 145M 6.9G 3% /test_raid
cd to /test_raid & create a few files there.
[root@server ~]# cd /test_raid/
Since RAID1 means mirroring, our data will be stored on both the pen-drives. So, lets eject out one pen-drive & check RAID details once again. You may deselect one in Devices tab. See the text below in bold. It shows that no. of active device is now reduced to 1. Compare this with the RAID details above when there were 2 devices. Try changing to test_raid directory. Your data will still be there 🙂
[root@server test_raid]# mdadm --detail /dev/md0 /dev/md0: Version : 1.2 Creation Time : Sat Mar 28 02:19:57 2015 Raid Level : raid1 Array Size : 7815652 (7.45 GiB 8.00 GB) Used Dev Size : 7815652 (7.45 GiB 8.00 GB) Raid Devices : 2 Total Devices : 2 Persistence : Superblock is persistent Update Time : Sat Mar 28 02:25:01 2015 State : active, degraded Active Devices : 1 Working Devices : 1 Failed Devices : 1 Spare Devices : 0 Name : server.shashank.com:0 (local to host server.shashank.com) UUID : ed128599:3e80284f:33ce9d8a:0d5f2014 Events : 6 Number Major Minor RaidDevice State 0 0 0 0 removed 1 8 33 1 active sync /dev/sdc1 0 8 17 - faulty spare