|
Setup Raid1 on Already Installed System
|
|
This Howto covers Raid1 setup on preinstalled Centos 5.5 system. Raid array will have 2 disks.
Lets get some info about current partitions:
# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
Device Boot Start End Blocks Id System
Disk /dev/sdb: 10.7 GB, 10737418240 bytes Disk /dev/sdb doesn’t contain a valid partition table
# cat /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
There were 2 partitions, sda1 with /boot and sda2 with LVM. Now we need to start system in rescue mode. Reboot and set in BIOS boot priority. Insert CentOS install cd, save changes in BIOS and reboot again. When it boots up type:
Choose language You entered rescue mode. This mode is also very useful for fixing critical system problems. Load a few kernel modules (to avoid a reboot):
# modprobe linear
# cat /proc/mdstat
Copy partition structure from old system disk to new disk:
# sfdisk -d /dev/sda | sfdisk /dev/sdb
We need to change partition type to raid for both partitions:
# fdisk /dev/sdb
Command (m for help): <-- t
Command (m for help): <-- t
Command (m for help): <-- w
Calling ioctl() to re-read partition table.
Create RAID arrays:
# mdadm –create /dev/md0 –level=1 –raid-disks=2 missing /dev/sdb1
# mdadm –create /dev/md1 –level=1 –raid-disks=2 missing /dev/sdb2
Create filesystems on these arrays. First for /boot partition:
# mkfs.ext3 -L ‘/boot’ /dev/md0
Then for / and swap in LVM partition:
# lvm pvcreate /dev/md1 # lvm vgcreate RaidArray /dev/md1 # lvm lvcreate –size 1G –name swap RaidArray # lvm vgdisplay RaidArray
Look for “Free PE / Size” record (in this case it was): # lvm lvcreate –size 8.89G –name Root RaidArray # mkswap /dev/RaidArray/swap # mkfs.ext3 -L ‘/’ /dev/RaidArray/Root
Copy content of each old partition to equivalent raid partition:
# mkdir /mnt/boot.old
# mkdir /mnt/boot.new
We need to activate LVM:
# lvm vgchange –available y VolGroup00
# mkdir /mnt/root.old
# mkdir /mnt/root.new
Copy content:
# rsync -avXH /mnt/boot.old/* /mnt/boot.new/
Or if you prefer tar:
# tar -C /mnt/boot.old -cf – . | tar -C /mnt/boot.new -xf -
If you have SELinux create a flag file to request SELinux attributes get relabeled on boot time:
# touch /mnt/root.new/.autorelabel
Setup grub on raid disk:
# grub
In /mnt/boot.new/grub/menu.lst instead /dev/VolGroup00/LogVol00 put /dev/RaidArray/Root. In /mnt/root.new/etc/fstab instead /dev/VolGroup00/LogVol00 put /dev/RaidArray/Root, instead /dev/VolGroup00/LogVol01 put /dev/RaidArray/swap and instead LABEL=/boot put /dev/md0 . We need to create new initrd:
# umount /mnt/boot.new
Enter the new system:
# chroot /mnt/root.new
Find the current initrd image:
# ls /boot/*.img
returns something like:
Create new initrd image:
# mkinitrd -f /boot/initrd-2.6.18-128.1.6.el5.img 2.6.18-128.1.6.el5
Go back to rescue mode from chroot:
# exit
Time to cleanup:
# umount /mnt/root.new/selinux
Shutdown the system, remove/unplug sda drive or set in bios that primary disk is sdb and power on the machine. If it boots normally check if the system is on raid:
# mount
You should check if some lines have:
Shutdown the system and reinsert sda drive making it secondary drive in bios.
# fdisk -l
In my case disks were sdb (raid disk) and sda (old, no raid disk). Since there is no default mdadm.conf file in the installation media it should be created:
# mdadm –examine –scan > /etc/mdadm.conf
Activate all discovered RAID devices:
# mdadm –assemble –scan
See the current RAID status:
# cat /proc/mdstat md1 : active raid1 sdb2[1] unused devices:
Convert partitions on old no-raid device so it can be paired with raid device:
# sfdisk -d /dev/sdb | sfdisk /dev/sda
Check if new partitions are in Linux raid type:
# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
Device Boot Start End Blocks Id System
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
Device Boot Start End Blocks Id System
Add new partitions to raid device:
# mdadm /dev/md0 -a /dev/sda1
You can check the sync progress:
# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md0 : active raid1 sdb1[1] sda1[0]
unused devices:
Install grub on new raid disk:
# grub
To avoid error message when checking fdisk -l (Disk /dev/sdX doesn’t contain a valid partition table) you should do:
# fdisk /dev/sda
Calling ioctl() to re-read partition table.
# fdisk /dev/sdb
Calling ioctl() to re-read partition table.
You now have functional raid1 system made of 2 disks.
Resources: http://wiki.centos.org/HowTos/CentOS5ConvertToRAID http://howtoforge.net/software-raid1-grub-boot-fedora-8 http://tldp.org/HOWTO/LVM-HOWTO/createlv.html |