How can I convert my running system to a RAID 1 System ?
To convert a standard installation with single drives to a system running on software raid devices, the following guide gives a how to.
(The instructions in this guide are tried procedures. We do not give
any guarantees and take no responsibility whatsoever, that the outlines
procedures work on any other system or that data stays intact. Make
backups of everything and proceed at your on risk!)
The
base system for the examples is a RHEL4 system with 256MB Ram and 4
SCSI drives on an ADAPTEC 29160, but the procedure should work on any
system and any distribution.
The initial layout for the hard disks was:
Device Mountpoint Size
/dev/sda 9,2GB
/dev/sda1 /boot 78MB
/dev/sda2 swap 512MB
/dev/sda3 / 4096MB
/dev/sda4 /scratch2 5048MB
The other hard disks are /dev/sdb (9,2GB), /dev/sdc (4,2GB), /dev/sdd (4,2GB).
(Everything has do be done as root)
- Back everything up! You might want to get your data back after you crashed the conversion.
Trust me on this! - Verify Backup! See above.
- Create partitions on /dev/sdb identical to the partitions on /dev/sda in one of the following ways:
fdisk (or cfdisk or parted) /dev/sdb, create the partitions manually
sfdisk -d /dev/sda | sfdisk /dev/sdb
- Change the partition type on all partitions of /dev/sdb to 0xfd (Linux raid autodetect)
- Run the following commands:
mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1
mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb2
mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/sdb3
mdadm --create /dev/md3 --level=1 --raid-disks=2 missing /dev/sdb4
This generates the raid devices 0 to 3 in a degenerated state because the first drive is missing. - Create the filesystem on these new software raid devices:
mke2fs -j /dev/md0
mke2fs -j /dev/md2
mke2fs -j /dev/md3
If you want to make sure, create the swap filesystem on /dev/md1:
mkswap /dev/md1 - Check the output of
#cat /prco/mdstat
Personalities : [raid1]
md1 : active raid1 sdb2[1]
473792 blocks [2/2] [_U]
md2 : active raid1 sdb3[1]
4980032 blocks [2/2] [_U]
md3 : active raid1 sdb4[1]
3349440 blocks [2/2] [_U]
md0 : active raid1 sdb1[1]
80192 blocks [2/2] [_U]
unused devices: <none> - Next we have to rebuild the initrd to include the the software RAID kernel modules:
mkinitrd -f /boot/initrd-`uname -r`.img `uname -r`
- Copy the data from the existing (and still running) partitions to the newly created raid partitions:
mkdir /mnt/md0
mount /dev/md0 /mnt/md0
cp -axu /boot/* /mnt/md0
sync
umount /mnt/md0
mkdir /mnt/md2
mount /dev/md2 /mnt/md2
cp -axu / /mnt/md2
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. - In /mnt/md2/etc/fstab change the line containing the mount point / to
/dev/md2 / ext3 defaults 1 1
and the line containing the mount point /boot to
/dev/md0 /boot ext3 defaults 1 1
The line for mounting /scratch2 will be changed to
/dev/md3 /var/log ext3 defaults 1 2
but keep it commented for the moment.
Mount /dev/md0 again.
In /mnt/md0/grub/menu.lst change the entry for the kernel to
kernel PATH-TO-KERNEL ro root=/dev/md2 SOME OPTIONS
Just to be sure the system will boot from the raid array copy the file /mnt/md0/grub/menu.lst to /boot/grub/menu.lst and /mnt/md2/etc/fstab to /etc/fstab (Beforehand you could make copies of these files for safety, but that's the cowards way). - Reboot the machine
- After the reboot went smoothly, add the existing partitions to the raid devices:
- change the partition type to 0xfd on all partitions using fdisk, cfdisk or parted
- run partprobe
- mdadm /dev/md0 -a /dev/sda1
- mdadm /dev/md1 -a /dev/sda2
- mdadm /dev/md2 -a /dev/sda3
- mdadm /dev/md3 -a /dev/sda4
watch -n 5 cat/proc/mdstat
The output should look similar to the one below and be updated every 5 seconds:Personalities : [raid1]
md1 : active raid1 sdb2[1] sda2[0]
473792 blocks [2/2] [UU]
[===>.................] recovery 25.0% (118448/473792) finish=2.4min speed=2412
md2 : active raid1 sdb3[1] sda3[0]
4980032 blocks [2/2] [UU]
resync=DELAYED
md3 : active raid1 sdb4[1] sda4[0]
3349440 blocks [2/2] [UU]
resync=DELAYED
md0 : active raid1 sdb1[1] sda1[0]
80192 blocks [2/2] [UU]
unused devices: <none> - change the partition type to 0xfd on all partitions using fdisk, cfdisk or parted
As soon as all the md devices are done recovering your system is in essence up and running.
We added some additional steps to gain on performance and redundancy.
First, the system should be able to boot even if the first hard disk fails.
For this to happen, the following step has to be done:
- create a boot record on the second hard disk
# grubSet the root device temporarily to the second disk:
grub>
grub> root (hd1,0)
Filesystem type is ext2fs, partition type is 0xfd
grub> setup (hd1)
Checking if "/boot/grub/stage1" exists ... no
Checking if "/grub/stage1" exists ... yes
Checking if "/grub/stage2" exists ... yes
Checking if "/grub/e2fs_stage1_5" exists ... yes
Running "embed /grub/e2fs_stage1_5 (hd1)" ... 16 sectors embedded.
succeeded
Running "install /grub/stage1 (hd1) (hd1)1+16 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit
As a secondary measure to increase performance and to keep disk space from getting low, we move /var/log to the raid device /dev/md3:
mount /dev/md3 /scratch2Edit /etc/fstab so that /dev/md3 will be mounted to /var/log.
cp -axu /var/log/* /scratch2
umount /scratch2
rm -r /var/log/*
mount /var/logRestart syslog and other services that write their logs to /var/log.
Now you are done.