Professional Documents
Culture Documents
Setup Software Raid1 Array On Running Centos 6.3 Using Mdadm
Setup Software Raid1 Array On Running Centos 6.3 Using Mdadm
Default CentOS 6.3 installation with two hard drives, /dev/sda and /dev/sdb which are identical in size. Machine
name is “serverbox.local”. /dev/sdb is currently unused, and /dev/sda has the following partitions:
df -h
fdisk -l
pvdisplay
vgdisplay
lvdisplay
modprobe linear
modprobe raid0
modprobe raid1
Verify personalities:
cat /proc/mdstat
2. Preparing /dev/sdb
To create a RAID1 array on a running system, prepare the /dev/sdb hard drive for RAID1, then copy the contents
of /dev/sda hard drive to it, and finally add /dev/sda to the RAID1 array.
Copy the partition table from /dev/sda to /dev/sdb so that both disks have exactly the same layout:
fdisk -l
fdisk /dev/sdb
fdisk -l
Remove any previous RAID installations on /dev/sdb : (error displayed if none exist)
Create RAID arrays /dev/md0 and /dev/md1. /dev/sdb1 will be added to /dev/md0 and/dev/sdb2 to /dev/md1.
Verify array created: ([_U] or [U_] means that an array is degraded while [UU] means that the array is ok)
cat /proc/mdstat
mkfs.ext4 /dev/md0
Logical volumes:
Initialize physical volume /dev/md1 for LVM: (Logical Volume Manager)
pvcreate /dev/md1
pvdisplay
vgdisplay
cp /etc/mdadm.conf /etc/mdadm.conf_orig
mdadm --examine --scan >> /etc/mdadm.conf
cat /etc/mdadm.conf
Modify file /etc/fstab. Replace /dev/sda1 with /dev/md0 so that the line looks as follows:
gedit /etc/fstab
[...]
/dev/md0 /boot ext4 defaults 0 2
[...]
gedit /etc/mtab
[...]
/dev/md0 /boot ext3 rw 0 0
[...]
gedit /boot/grub/menu.lst
[...]
default 0
fallback 1
[...]
Duplicate first kernel stanza [title ... savedefault]. In first stanza; replace root (hd0,0) with root (hd1,0):
[...]
title Vg_serverbox GNU/Linux, kernel 2.6.18-6-686
root (hd1,0)
kernel /vmlinuz-2.6.18-6-686 root=/dev/mapper/vg_serverbox-root ro
initrd /initrd.img-2.6.18-6-686
savedefault
[...]
* REMOVE any kernel options that prevent loading md devices (not ‘dm’).
Rebuild initramfs using mdadm.conf: https://wiki.ubuntu.com/Initramfs
Copy data from boot partition /dev/sda1 to array /dev/md0: (assuming /dev/sda1 is mounted at /boot)
mkdir /mnt/raid
touch /mnt/raid/.autorelabel
sync
umount /mnt/raid
Move the contents of LVM partition /dev/sda2 to LVM RAID array /dev/md1: (takes approx. 45 min. for 200 GB)
pvremove /dev/sda2
Verify /dev/md1 is the only physical volume for volume group vg_serverbox:
pvdisplay
Change the partition type of /dev/sda2 to Linux raid autodetect:
fdisk /dev/sda
Add /dev/sda2 to /dev/md1 array: (Takes approx. 35 min. for 200 GB array to be rebuilt)
5. Preparing GRUB
Install the GRUB bootloader on the hard drive /dev/sda and /dev/sdb:
grub
grub>
root (hd0,0)
setup (hd0)
root (hd1,0)
setup (hd1)
quit
reboot
df -h
Verify arrays are active: (status should be /dev/md1 [UU] and /dev/md0 [_U] )
cat /proc/mdstat
pvdisplay
vgdisplay
lvdisplay
fdisk /dev/sda
cat /proc/mdstat
Update /etc/mdadm.conf :
cp /etc/mdadm.conf_orig /etc/mdadm.conf
mdadm --examine --scan >> /etc/mdadm.conf
reboot
Testing and rebuilding
shutdown -h now
Reboot: System should boot in degraded state. Verify array is active but degraded: ( [_U] or [U_] )
cat /proc/mdstat
shutdown -h now
Put in a new /dev/sdb drive, or if failure of /dev/sda, move /dev/sdb to failed /dev/sda slot and connect the new
HDD as /dev/sdb. Boot the system.
fdisk -l
grub
grub>
root (hd0,0)
setup (hd0)
root (hd1,0)
setup (hd1)
quit