[ Bloke.com || Linux || JavaScript || Java || Volleyball || Link Me ]
Free: [ Guestbook || MessageBot || Plugins || Counter || AusPrices || Advertise ]

Home - Linux - Raid

I needed to convert a running system from ext3 to raid 1. This is what I did.

BTW: This is a really easy way to loose data. One typo from you (or me here) could cause you to loose all your data. So do so at your own risk.

I have Fedora core 6 running on one disk, and the important data running on a second disk. I added a third disk to mirror the second. I had lots of problems, but the source of all evil, was I was expecting to add the disk with the data on it first, and then add in the blank disk. Well, that was wrong.

Once I got that around the right way, it was pretty smooth.

It's easiest if the disks are identical, but in my case, I have already had a raid failure, so I wanted to different disks. Might I also add, it's way easier to set up raid at install time (and much safer too!). And as recommended elsewhere, if you can afford the downtime, you are probably better off setting up the system from scratch.

My first step was to backup the data (/www) to the first disk (since there was space), and also to another computer. To back up locally, I used

mkdir /wwwbak
cd /wwwbak
rsync -azvH /www .
Someone else used:
cp -ax /www /wwwbak
I didn't try that, but it seems reasonable.

To backup to the remote computer I used:

cd /
rsync -e ssh -azvH www cameron@remoteComputer:/f/
Now I commented out the existing partition from /etc/fstab, and rebooted. This will allow me to mount and umount the paritition at will.

My valuable data is on /dev/sdb1 (which is a partition that takes up the whole drive), and the new disk is /dev/sdc1. This partition is created with fdisk

#The following steps will delete and data on /dev/sdc if there was any
fdisk /dev/sdc
'p'  print the curent information for the disk, so make sure you have the right one.
'c' create 'p' primary  '1'.
'w' write the partition table out and exit

You should make sure the system id for the partition is 'fd' for Linux raid autodetect.

Create the raid array:

mdadm --create /dev/md0 -l 1 -n 2 /dev/sdc1 missing
Which creates a raid 1 (mirror) array with 2 disks. Note that sdc1 is the *new* disk, that doesn't have the data on it yet. And our /dev/sdb1 is marked as missing, and we'll add that near the end.

Now create the filesystem on it. I like ext3, so

mkfs.ext3 /dev/md0
mkdir /foo
mount /dev/md0 /foo
Now copy the original content from sdb1 (/www) onto this drive, I used rsync again: (I also brought the system down to init level 1. YOu can do this with
init 1
Or by adjusting your boot params to boot into init level 1. You do this in grub, by entering 'e' to edit commends, then edit the kernel /vmlinuz... and add <space> 1 on the end. In my case I also made sure that my network cable was disconnected (since I didn't want remote changes made at this time).
cd /www
rsync -azH  * /foo
#note that the above would mean any '.' files if there were in in /www.
Okay, so now you have one half of the raid. Verify /foo is as you want it to be. I also unmounted and remounted it to be sure.

Now add the original disk into the array

mdadm /dev/md0 -a /dev/sdb1
And check the status with:
cat /dev/mdstat
For me it took 80 minutes for 60 gig (very roughly). When it was all done, I unmounted everything and remounted. And I also did a reboot and check before finally leaving everything in /etc/fstab and rebooting. I did that because I had some wierd problem earlier. and had to use linux rescue to fix my /etc/fstab. my /etc/fstab entry:
/dev/md0         /www                    ext3    defaults        1 1

See Also:


Last Change: Sunday, 18-Feb-2007 09:52:42 EST


The information provided within these pages is provided AS IS, and without any warranty. Following these directions may (but not limited to) crash your computer, delete all the information on your hard disk, open up security holes or cause your house to burn down. I made these pages to provide some information about the setup that I have done, but I did not proofread it for correctness, and in most cases did not test it. There are commands in these pages that would definately delete or corrupt all the data on your computer (especially the dualboot section). In fact it happened to me.... So you are on your own!

Cameron Gregory