Author Topic: How To Create A RAID-1 Setup On A CentOS/RedHat 6.0 Server  (Read 1393 times)

mahbub-web

  • Guest
How To Create A RAID-1 Setup On A CentOS/RedHat 6.0 Server
« on: April 21, 2013, 12:08:13 AM »
How To Create A RAID-1 Setup On A CentOS/RedHat 6.0 Server

This tutorial is for turning a single disk CentOS 6 system into a two disk RAID1 system. The GRUB bootloader will be configured in such a way that the system will still be able to boot if one of the hard drives fails (no matter which one).

NOTE: Everything has to be done as root:

Code: [Select]
su -
enter root password

In this example the initial layout for the hard disks was:

Disk with installed OS. “Original”

Device Mountpoint Size

——————————————————————————–
/dev/sdb ~1002GB
/dev/sdb1 /boot 256MB
/dev/sdb2 / 24GB
/dev/sdb3 swap 4GB
/dev/sdb5 /var 4GB
/dev/sdb6 /home ~900GB

And we will be adding the other hard disk: /dev/sda (~1002GB). “Target disk”.

1. Back everything up! You might want to get your data back after you crashed the conversion. Trust me on this!
2. Verify Backup! See above.
3. Create partitions on /dev/sda identical to the partitions on /dev/sdb:

Code: [Select]
sfdisk -d /dev/sdb | sfdisk /dev/sda
4. We load a few kernel modules (to avoid a reboot):

Code: [Select]
modprobe linear
modprobe raid0
modprobe raid1

5. Now run:

Code: [Select]
cat /proc/mdstat
The output should look as follows:

root@server:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] unused devices: <none>

Here we see now that the RAID kernel modules are working, but there are no RAID sets yet.

6. Run the following commands:

Code: [Select]
mdadm --create /dev/md0 --level=1 --raid-disks=2 /dev/sda1 missing
mdadm --create /dev/md1 --level=1 --raid-disks=2 /dev/sda2 missing
mdadm --create /dev/md2 --level=1 --raid-disks=2 /dev/sda5 missing
mdadm --create /dev/md3 --level=1 --raid-disks=2 /dev/sda6 missing

This generates the raid devices 0 to 3 in a degenerated state because the second drive is missing.

7. If you want to use Grub 0.97 (default in CentOS 5 or 6)) on RAID 1, you need to specify an older version of metadata than the default. Add the option “–metadata=0.90″ to the above command. Otherwise Grub will respond with “Filesystem type unknown, partition type 0xfd” and refuse to install. This is supposedly not necessary with Grub 2.

Like this:

Code: [Select]
mdadm --create /dev/md0 --metadata=0.90 --level=1 --raid-devices=2 /dev/sda1 missing
8. Check the output of

Code: [Select]
cat /proc/mdstat
#cat /proc/mdstat
Personalities : [raid1] md1 : active raid1 sdb2[1] 473792 blocks [2/2] [U_]

md2 : active raid1 sdb5[1] 4980032 blocks [2/2] [U_]

md3 : active raid1 sdb6[1] 3349440 blocks [2/2] [U_]

md0 : active raid1 sdb1[1] 80192 blocks [2/2] [U_]

unused devices: <none>

9. Create a mdadm.conf from your current configuration:

Code: [Select]
mdadm --detail --scan > /etc/mdadm.conf
10. Display the contents of the file:

Code: [Select]
cat /etc/mdadm.conf
At the bottom of the file you should now see details about our (degraded) RAID arrays.
11. We use dracut to rebuild the initramfs with the new mdadm.conf:

Code: [Select]
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.old
Code: [Select]
dracut --mdadmconf --force /boot/initramfs-$(uname -r).img $(uname -r)
12. Create the filesystems on these new software raid devices:

Code: [Select]
mkfs.ext2 /dev/md0 # For /boot ext2 is good
mkfs.ext4 /dev/md1 # For / ext4 is good
mkfs.ext4 /dev/md2 # For /home ext4 is good
mkfs.ext4 /dev/md3 # For /var ext4 is good
mkswap -c /dev/sda2 #We want swap partitions on both drives for performance

13. Copy the data from the existing (and still running) partitions to the newly created raid partitions:

Code: [Select]
mkdir /mnt/raid
mount /dev/md0 /mnt/raid
cd /boot; find . -depth | cpio -pmd /mnt/raid

(If SELinux is in use also do this:

Code: [Select]
touch /mnt/raid/.autorelabel
)

Code: [Select]
sync
umount /mnt/raid

Code: [Select]
mount /dev/md1 /mnt/raid
cd / ; find . -depth -xdev | grep -v '^\./tmp/' | cpio -pmd /mnt/raid
sync
umount /mnt/raid

NOTES: You really do not want to copy files in /tmp and /var/tmp.
This command will create empty mount points like ‘proc’ or ‘dev’ and will not forget things like /.autofsck.

Code: [Select]
mount /dev/md2 /mnt/raid
cd /var; find . -depth | cpio -pmd /mnt/raid sync umount /mnt/raid

Code: [Select]
mount /dev/md3 /mnt/raid
cd /home; find . -depth | cpio -pmd /mnt/raid
sync
umount /mnt/raid

At this point we have our raid system created and the existing data was mirrored manually onto the new devices.
To make sure that the system will boot from the raid devices we have to change some entries in /etc/fstab and /boot/grub/menu.lst.

ref: http://www.servernoobs.com/how-to-create-a-raid-1-setup-on-a-centosredhat-6-0-server/