Software Raid with MD devices on linux
From Initq
This article will explain how to convert your one drive system to a raid 1 machine.
Contents |
Attach the second drive
It is always best to have the second drive same capacity as the first one. We attach a second drive and make sure we see it with fdisk.
Create partitions
Use sfdisk to merely copy the partitions to the new drive.
- sfdisk -d /dev/hda > hda.layout
- sfdisk /dev/hdb < hda.layout
Change partition type
- fdisk /dev/hdb
- l
- t 1 fd
- t 2 fd
- w
Clean up all partitions
- dd if=/dev/zero of=/dev/hdb1 bs=1024 count=100
- dd if=/dev/zero of=/dev/hdb2 bs=1024 count=100
Install Apps
Make sure you have mdadm, rsync, tar and cpio is installed.
Create the Raid volumes
- mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/hdb1
- mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/hdb2
Format the partitions
- mkfs.ext3 /dev/md0
- mkfs.ext3 /dev/md1
Go to run level 1
- init 1
Mount the drive to copy files
- mkdir /mnt/md1
- mount /dev/md1 /mnt/md1
- rsync -avH --delete --exclude 'mnt' --progress -x / /mnt/md1
Replace swap
- swapon -s
- swapoff /dev/hda1
- mkswap /dev/md0
- swapon /dev/md0
Write the raid config
- cat > /mnt/md1/etc/mdadm/mdadm.conf << EOF9
- MAILADDR root
- ARRAY /dev/md0 level=raid 1 num-devices=2 devices=missing,/dev/hdb1
- ARRAY /dev/md1 level=raid 1 num-devices=2 devices=missing,/dev/hdb2
EOF9
Fix fstab in the raid
- vi /mnt/md1/etc/fstab
- /dev/md0 swap swap defaults 0 0
- /dev/md1 / etx3 defaults 1 1