Hack 64 Migrate Software RAID 1 to RAID 5 
Move an existing software RAID 1 system to RAID
5 without a backup and restore.
After you use a RAID 1 array
for some time, you might find that you need to increase the space on
the array. Because of the way the RAID 1 array works, a two-disk
array is expanded by buying two new larger hard drives. At this
point, you might consider migrating over to RAID 5, because you can
double your storage space by adding a single drive. A RAID 1 array
with two 100-GB drives has only 100 GB of storage while a RAID 5
array with three 100-GB drives has 200 GB of space.
Switching RAID levels normally means a complete backup and restore
for the server, which requires the temporary use of a fourth drive to
store the system while you create the RAID 5 array. This, of course,
defeats one of the reasons to consider RAID 5—doubling the
storage of a RAID 1 array by purchasing a single drive. With a
Knoppix disc, you can migrate from a software RAID 1 array to a
software RAID 5 array without backing up the system to a fourth disc.
This hack goes through this migration step by step.
Here is the hypothetical situation for this migration. The complete
root partition exists on /dev/md0, which is a 20
GB RAID 1 array that spans two 20-GB drives, which are
/dev/hda1 and /dev/hdb1.
The /etc/raidtab for this configuration is
listed below:
raiddev /dev/md0
raid-level 1
nr-raid-disks 2
nr-spare-disks 0
chunk-size 4
persistent-superblock 1
device /dev/hda1
raid-disk 0
device /dev/hdb1
raid-disk 1
To convert this array to a three-disk 40-GB RAID 5 array, add a third
20 GB partition at /dev/hdc1. I have already
used cfdisk (you could use
fdisk or other programs as well) to create this
partition and set it with the fd partition type
(just like /dev/hda1 and
/dev/hdb1), and Linux automatically detects it
as a RAID partition. The RAID 1 array can temporarily survive on a
single drive, and a RAID 5 array can temporarily survive on two
drives, so you can do something similar to what was done in [Hack #63]
and disable drives from one array to add them to the other, then
finally add the final drive once all the files have been copied.
Sound scary? Well, it can be, so make sure that you already have tape
backups of important data, just in case. Remember, RAID safeguards
against a drive failure; it is not a substitute for backups.
First, create directories for the old and new RAID, mount the old
RAID device, and copy its raidtab file to
Knoppix:
knoppix@tty0[knoppix]$ sudo mkdir /mnt/md0 /mnt/md1
knoppix@tty0[knoppix]$ sudo mount /dev/md0 /mnt/md0
knoppix@tty0[knoppix]$ sudo cp /mnt/md0/etc/raidtab /etc/
Now edit /etc/raidtab and change
/dev/hdb1 from a raid-disk
to a failed-disk:
device /dev/hdb1
raid-disk 1
device /dev/hdb1
failed-disk 1
Then remove it from the current array:
knoppix@tty0[knoppix]$ sudo raidsetfaulty /dev/md0 /dev/hdb1
knoppix@tty0[knoppix]$ sudo raidhotremove /dev/md0 /dev/hdb1
Now that /dev/hdb1 is removed from the RAID 1
array, you can create the RAID 5 array by using it and the new hard
drive /dev/hdc1. Make sure to set
/dev/hda1 as a failed disk in this
configuration, so it is not overwritten when you create the new RAID.
The /etc/raidtab file looks like this:
raiddev /dev/md0
raid-level 1
nr-raid-disks 2
nr-spare-disks 0
chunk-size 4
persistent-superblock 1
device /dev/hda1
raid-disk 0
device /dev/hdb1
failed-disk 1
raiddev /dev/md1
raid-level 5
nr-raid-disks 3
nr-spare-disks 0
persistent-superblock 1
parity-algorithm left-symmetric
chunk-size 32
device /dev/hdb1
raid-disk 0
device /dev/hdc1
raid-disk 1
device /dev/hda1
failed-disk 2
Now you can create the new RAID 5 array with:
knoppix@tty0[knoppix]$ sudo mkraid --really-force /dev/md1
You must run mkraid with the
--really-force option, because
/dev/hdb1 already has RAID signatures from
/dev/md0 (the RAID 1 array), and by default,
mkraid does not overwrite an existing RAID with
a new one. Since /dev/hda1 is listed as a failed
drive, you can now format /dev/md1 (the RAID 5
array) and mount it without the risk of overwriting anything from
/dev/md0 (the RAID 1 array). Then you can copy
the entire system from md0 to
md1 using the find command
introduced in [Hack #61] :
knoppix@tty0[knoppix]$ sudo mkfs -t xfs -f /dev/md1
knoppix@tty0[knoppix]$ sudo mount -o rw /dev/md1 /mnt/md1
knoppix@tty0[knoppix]$ cd /mnt/md0
knoppix@tty0[md0]$ sudo sh -c "find . -xdev -print0 | cpio -pa0V /mnt/md1"
Once the filesystem is copied, unmount the RAID 1 array
/dev/md0, because you need it stopped before you
can add its final drive /dev/hda1 to your new
RAID 5 array, /dev/md1:
knoppix@tty0[knoppix]$ sudo umount /dev/md0
knoppix@tty0[knoppix]$ sudo raidstop /dev/md0
With the RAID 1 array stopped, you no longer need the
md0 configuration in
/etc/raidtab; remove it and also change
md1 so that /dev/hda1 is no
longer failed. Your new /etc/raidtab should look
like this:
raiddev /dev/md1
raid-level 5
nr-raid-disks 3
nr-spare-disks 0
persistent-superblock 1
parity-algorithm left-symmetric
chunk-size 32
device /dev/hdb1
raid-disk 0
device /dev/hdc1
raid-disk 1
device /dev/hda1
raid-disk 2
With the final disk restored, add it to the RAID 5 with this command:
knoppix@tty0[knoppix]$ sudo raidhotadd /dev/md1 /dev/hda1
You can watch it sync with the rest of the array by monitoring
/proc/mdstat:
knoppix@tty0[knoppix]$ watch cat /proc/mdstat
While the new partition is being restored, take this time to copy
over the new /etc/raidtab to
/mnt/md1/etc/, and edit your
/etc/fstab and lilo or
grub configuration so that it references
/dev/md1 instead of
/dev/md0. Once the RAID finishes recovering the
new drive, you should be able to reboot into your new RAID 5
partition.
6.14.1 See Also
The Software RAID HOWTO:
/usr/share/doc/raidtools2/Software-RAID.HOWTO on
your Knoppix disc. The raidhotadd, mkraid,
raidstop, and other RAID tools manpages (type
man commandname in
a console).
|