RAID conversion
The following article is a concise description of a VMware dry run to convert a Redhat 7.3 server to a software RAID. The actual server migration is more complex and involves breaking a "hardware" RAID on an onboard Fastrack controller. An objective of the test run is to avoid use of a boot disk, as it hangs during kernel startup on the real hardware.To outline the procedure, we set up new mirror sets where the new disks are primary and the original disk are set up as failed secondary. We create new filesystems on the degraded mirrors, copy the data, make them bootable, and finally add the original disks to the mirror.
The VMware guest uses two IDE disks, hda and hdb. The original partition layout is reproduced below:
Disk /dev/hda: 128 heads, 63 sectors, 520 cylinders Units = cylinders of 8064 * 512 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 16 64480+ 83 Linux /dev/hda2 17 49 133056 82 Linux swap /dev/hda3 50 520 1899072 83 Linux Disk /dev/hdb: 128 heads, 63 sectors, 520 cylinders Units = cylinders of 8064 * 512 bytes Device Boot Start End Blocks Id System /dev/hdb1 * 1 16 64480+ 83 Linux /dev/hdb2 17 49 133056 82 Linux swap /dev/hdb3 50 520 1899072 83 Linux
The system runs off hda; hdb is not assumed to hold data.
Step 1: Verify that the partition layout of the disks are compatible.
Step 2: Create /etc/raidtab
# / on md0 (primary hdb3, secondary hda3) # NB: hda3 is initially configured as failed raiddev /dev/md0 raid-level 1 nr-raid-disks 2 persistent-superblock 1 chunk-size 32 device /dev/hdb3 raid-disk 0 device /dev/hda3 failed-disk 1 # /boot on md1 (primary hdb1, secondary hda1) # NB: hda1 is initially configured as failed raiddev /dev/md1
raid-level 1 nr-raid-disks 2 persistent-superblock 1 chunk-size 32 device /dev/hdb1 raid-disk 0 device /dev/hda1 failed-disk 1
Needless to say, the disk ordering is extremely important.
Step 3: Instantiate the degraded RAIDs
mkraid /dev/md0
mkraid /dev/md1
It
may be necessary to use mkraid -R if there’s filesystem information
left. /proc/mdstats should now display the degraded RAIDs.
Step 4: Create filesystems on degraded RAID
mkfs -t ext3 /dev/md0
mkfs -t ext3 /dev/md1
Please note:
The persistent superblock decreases the physical filesystem size, which
necessitates a dump/restore of the data rather than a copy with dd.
For good measure, create a swap partition:
mkswap /dev/hdb2
Step 5: Populate the degraded RAID
mkdir /mnt/md
mount /dev/md0 /mnt/md
cd /mnt/md
dump 0f - / | restore rf -
rm -f restoresymtable
mount /dev/md1 /mnt/md/boot
cd /mnt/md/boot
dump 0f - /boot | restore rf -
rm -f restoresymtable
# make sure the journal inodes exist
tune2fs -j /dev/md0
tune2fs -j /dev/md1
Step 6: Edit fstab of the RAID
The devices for / and /boot should reflect the RAID devices:
/dev/md0 / ext3 defaults 1 1
/dev/md1 /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/hda2 swap swap defaults 0 0
/dev/hdb2 swap swap defaults 0 0
/dev/cdrom /mnt/cdrom iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
Step 7: Set up an initrd
An initrd may not be necessary if the kernel uses compiled-in RAID code.
cd /mnt/md/boot
# replace kversion with your kernel version
mkinitrd --fstab=/mnt/md/etc/fstab initrd-kversion-raid.img kversion
cp initrd-kversion-raid.img /boot
Step 8: Edit grub.conf
See the added entry to boot off the degraded RAID:
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title RAID (2.4.18-3)
root (hd0,0)
kernel /vmlinuz-kversion ro root=/dev/md0
initrd /initrd-kversion-raid.img
title Red Hat Linux (kversion)
root (hd0,0)
kernel /vmlinuz-kversion ro root=/dev/hda3
initrd /initrd-kversion.img
Install this file as /etc/grub.conf and /mnt/mnt/etc/grub.conf
Step 9: Change partition types of primary constituent partitions
cd /
umount /mnt/md/boot
umount /mnt/md
fdisk /dev/hdb
# set partition types of partition 1 and 3 to FD
T 1 FD
T 3 FD
Pitfall: On the real hardware it was necessary to rename
/etc/raidtab to prevent startup errors on the original non-RAID disk.
This is probably due to updated init scripts.
Step 10: Boot degraded RAID
At this point, the system
should boot either the old system on hda or the degraded RAID. Proceed
to the next step once you’re satisfied that the system can boot one or
the other.
Pitfall: Before starting the RAID recovery to the original boot and root partitions, it’s a good idea to create and test a boot floppy:
mkbootdisk -v --kernelargs='root=/dev/md0' kversion).
Step 11: Boot the RAID system and complete the mirror
Edit /etc/raidtab and replace the "failed-disk" with "raid-disk"
Add the old disks to the mirror:
raidhotadd /dev/md1 /dev/hda1
raidhotadd /dev/md0 /dev/hda3
Run a command like "watch cat /proc/mdstats" to wait for the resync to complete.
Run
fdisk on /dev/hda and change the partition types of hda1 and hda3 to
FD. Otherwise, the RAID will probably come up in degraded mode again.
Pitfall: In case that the RAID recovery breaks the grub loader, re-install it before rebooting:
grub
root (hd0,0)
setup (hd0)
quit
Step 12: Reboot
If the system fails to boot, grab a copy of Knoppix and your backup tapes.
