Mirroring Partitions after Installing RHEL
Release:
RedHat Enterprise Linux Server 3.x, 4.x & 5.x
Problem:
Configuring software mirroring in RHEL after OS installation.
Solution:
1) On the second disk create partitions exactly the same size as those on the first disk, and set the type as fd (Linux raid autodetect).
# sfdisk -d -f /dev/sda > mirror
# sfdisk /dev/sdb < mirror
# fdisk /dev/sdb
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 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.
# partprobe /dev/sdb
2) Create the raid devices in a degenerated state (i.e. one disk missing).
#mknod /dev/md1 b 9 1
#mknod /dev/md2 b 9 2
#mdadm –C /dev/md0 –l 1 –n 2 missing /dev/sdb1
#mdadm –C /dev/md1 –l 1 –n 2 missing /dev/sdb2
#mdadm –C /dev/md2 –l 1 –n 2 missing /dev/sdb3
3) Create a filesystem on the new software raid devices
# mke2fs –j /dev/md0
#mke2fs –j /dev/md1
#mkswap /dev/md2
4) Rebuild the initrd image to include the software RAID kernel modules
# mkinitrd -f /boot/initrd-`uname -r`.img `uname -r`
5) Move the data from our existing partitions to the software partitions
# mkdir /mnt/md0
# mount /dev/md0 /mnt/md0
#cp –axu /boot/* /mnt/md0
#sync
#umount /mnt/md0
# mkdir /mnt/md1
# mount /dev/md1 /mnt/md1
#cp –axu / /mnt/md1
6) Now the raid devices are created and the existing data have been manually copied to the new disk. Now fstab within the RAID Devices have to be edited for the new changes in RAID meta devices. Edit the /mnt/md2/etc/fstab file so the system can boot from the new raid devices. In the fstab file change the line for the boot and root file system
Content as follows before editing:
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
LABEL=SWAP-sda3 swap swap defaults 0 0
Content as follows after editing:
/dev/md1 / ext3 defaults 1 1
/dev/md0 /boot ext3 defaults 1 2
/dev/md2 swap swap defaults 0 0
7) Finally, edit the /boot/grub/grub.conf file
In “HDD” line change root (hd0,0) to root (hd1,0)
In the “kernel" line change root=LABEL=/ to root=/dev/md2.
8) Reboot the system
# init 6
9) Add the existing partitions (/dev/sda) to the RAID devices
# fdisk /dev/sda
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 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.
# partprobe /dev/sda
10) Now, add the existing partitions to the RAID array
# mdadm -a /dev/md0 /dev/sda1
# mdadm -a /dev/md1 /dev/sda2
# mdadm -a /dev/md2 /dev/sda3
11) To see if the array is rebuilding, run the following command
# watch -n 2 cat /proc/mdstat
Every 2.0s: cat /proc/mdstat Tue Aug 3 07:45:37 2010
Personalities : [raid1]
md0 : active raid1 sda1[0] sdb1[1]
104320 blocks [2/2] [UU]
md1 : active raid1 sda2[0] sdb2[1]
4610560 blocks [2/1] [_U]
[============>........] recovery = 61.8% (2853760/4610560) finish=1.1min speed=26390K/sec
md2 : active raid1 sda3[2] sdb3[1]
522048 blocks [2/2] [UU]
unused devices:
12) After reboot, RAID status can be confirmed or monitored by following commands,
a. cat /proc/mdstat
b. mdadm –D /dev/md0 /dev/md1 /dev/md2