Hack 63 Migrate to Software RAID 
Move your entire root partition to RAID 1 or
RAID 5 without a backup and restore.
Software RAID can ensure failover
protection even on a low budget. If you want to migrate a system to
software RAID, you might be faced with the prospect of doing a
complete backup and restore. If you have a low budget, you might not
have a spare drive to temporarily back up your data to in addition to
the drives you are using for the RAID. With a Knoppix disc and the
following instructions, you can migrate a system to RAID 1 or 5 with
just the disks you are planning to use for the RAID.
RAID 1 and 5 provide failover, so you can run a system and access
files even if a drive in the array has failed. You can leverage
failover in RAID 1 and 5 to migrate a partition that is not yet
software RAID to RAID 1 or 5 if you create the RAID with a failed
drive (the current root partition), copy all of the data over to the
newly created RAID, boot onto that RAID, and then add the root
partition to the RAID. For this to work, all RAID utilities, such as
mkraid and raidhotadd,
should already be present on the system. Distribution package names
vary, but two examples of package names are
raidtools and raidtools2
under Debian. The kernel should already have support for software
RAID compiled in, so check the "Multi-device
support" section of your kernel's
configuration and make sure all the RAID types you wish to use are
enabled. This hack covers migrating a complete root filesystem that
is on /dev/hda1 to a RAID 1 spanning
/dev/hda1 and /dev/hdb1, or
a RAID 5 spanning /dev/hda1,
/dev/hdb1, and /dev/hdc1.
First create the array; create /etc/raidtab in
Knoppix and add the following configuration for a RAID 1 array:
raiddev /dev/md0
raid-level 1
nr-raid-disks 2
nr-spare-disks 0
chunk-size 4
persistent-superblock 1
device /dev/hdb1
raid-disk 0
device /dev/hda1
failed-disk 1
Or add the following configuration for a RAID 5 array:
raiddev /dev/md0
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
Notice that the main root partition, /dev/hda1,
is listed as a failed-disk for the moment. The
RAID tools have problems starting the RAID when the first disk is a
failed disk, so list /dev/hda1 last. Once you
create this file, start the RAID with this command:
knoppix@tty0[knoppix]$ sudo mkraid /dev/md0
If you check /proc/mdstat, it lists the RAID (in
this example, a RAID 1):
knoppix@tty0[knoppix]$ cat /proc/mdstat
Personalities : [raid1]
read_ahead 1024 sectors
md0 : active raid1 hdb1[1]
2621312 blocks [2/1] [U_]
unused devices:
Now the RAID is created, and you can format it with the filesystem of
your choice with:
knoppix@tty0[knoppix]$ sudo mkfs -t xfs /dev/md0
 |
Since /dev/hda1 is marked
failed, the RAID does not overwrite all of the
files on that partition yet, and you are safe to format the new RAID
partition and copy files to it.
|
|
Next, you must create a temporary directory to mount the new RAID,
mount the RAID and the original partition read/write, and then copy
the system over to the RAID using the same method covered in [Hack #61] :
knoppix@tty0[knoppix]$ sudo mkdir /mnt/temp
knoppix@tty0[knoppix]$ sudo mount -o rw /dev/md0 /mnt/temp
knoppix@tty0[knoppix]$ sudo mount /dev/hda1 /mnt/hda1
knoppix@tty0[knoppix]$ cd /mnt/hda1
knoppix@tty0[hda1]$ sudo sh -c "find . -xdev -print0 | cpio -pa0V /mnt/temp"
Once the copy process finishes, copy the
/etc/raidtab in Knoppix to
/mnt/temp/etc/. Then edit
/mnt/temp/etc/fstab and make sure the entry for
/dev/hda1 is changed to
/dev/md0. You must also edit
lilo or grub configuration
files, and make sure that any root device configuration now
references /dev/md0 instead of
/dev/hda1. Be sure to leave any boot device
configuration alone so that it installs the boot code onto
/dev/hda instead of
/dev/md0. If you use lilo
as your boot loader, you must also run lilo to
update the MBR as covered in [Hack #52] .
Once you update all of the configuration files, add the primary
partition to the RAID by unmounting /dev/hda1:
knoppix@tty0[knoppix]$ sudo umount /dev/hda1
 |
Note that the data on the partition has remained untouched. Once you
add this drive to the array, it will be overwritten with whatever
files are already in /dev/md0, so be sure you
are ready before continuing.
|
|
To add the drive to the array, edit /etc/raidtab
on the ramdisk, not the RAID, and replace
failed-disk with raid-disk.
Then, add the drive to the array with the following command:
knoppix@tty0[knoppix]$ sudo raidhotadd /dev/md0 /dev/hda1
Run the following command to monitor the RAID as it updates
/dev/hda1 with all of the mirroring information:
knoppix@tty0[knoppix]$ watch cat /proc/mdstat
You can still use and write to the RAID while this is going on, so
copy the new /etc/raidtab to
/mnt/temp/etc/. You must wait for the mirror to
be completely synced before moving to the next step
(/proc/mdstat lets you know when you are in
sync).
Now enable RAID autodetection for both of the partitions; unmount and
stop the RAID:
knoppix@tty0[knoppix]$ sudo umount /dev/md0
knoppix@tty0[knoppix]$ sudo raidstop /dev/md0
Then run fdisk or cfdisk,
and change the partition type for both /dev/hda1
and /dev/hdb1 from 83 to
fd. Then write the changes to make sure that the
Linux kernel autodetects this RAID as it boots (which is important
because it is the root partition). After autodetection has been
enabled, reboot into your new software RAID root partition.
6.13.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).
|