Linux Software RAID Upgrade

Well last night my right hand nerd, Scotty and I upgraded the server to use software RAID1 from a SCSI drive. This is what we did.

Manually Install new hard drives: This was simple. It’s a dell with some green rails that make it easy.We set them both as masters and threw them on different IDE channels so we have /dev/hda & /dev/hdc and then we got busy.

fdisk the /dev/hda drive

Device Boot Start End Blocks Id System
/dev/hda1 1 13 104391 fd Linux raid autodetect
/dev/hda2 14 12463 100004625 fd Linux raid autodetect
/dev/hda3 12464 12713 2008125 82 Linux swap / Solaris

We don’t worry about the hdc drive because we are going to set up one drive and then just let the RAID restore the second drive, so we tell mdadm to create the array with a drive missing.

mdadm --create /dev/md0 --level=1 --raid-disk=2 missing /dev/hda1
mdadm --create /dev/md1 --level=1 --raid-disk=2 missing /dev/hda2

Then we format them

mkfs.ext3 /dev/md0
mkfs.ext3 /dev/md1

Mount them up

mkdir /mnt/md0
mkdir /mnt/md1
mount /dev/md0 /mnt/md0
mount /dev/md1 /mnt/md1

Next we go to single user mode and copy all the files over

init 1
cp -dpRxv /boot/* /mnt/md0
cp -dpRxv / /mnt/md1

Remount /dev/md0 to /mnt/md1/boot

umount /mnt/md0
mount /dev/md0 /mnt/md1/boot

Then chroot

chroot /mnt/md1 /bin/bash

Edit fstab changing sda to md’s

#/dev/sda2 / ext3 errors=remount-ro 0 1
#/dev/sda3 none swap sw 0 0
/dev/md1 / ext3 errors=remount-ro 0 1
/dev/md0 /boot ext3 defaults 0 2

Change the swap in fstab

#/dev/sda3 none swap sw 0 0
/dev/hda3 none swap sw 0 0
/dev/hdc3 none swap sw 0 0

Then we had to deal with grub

#(hd0) /dev/sda
(hd0) /dev/hda
(hd1) /dev/hdc

title Debian GNU/Linux, kernel 2.6.17
root (hd0,0)
kernel /vmlinuz-2.6.17 root=/dev/md1 ro
#kernel /vmlinuz-2.6.17 root=/dev/sda2 ro
initrd /initrd.img-2.6.17

Install grub on the raid drives

grub-install /dev/hda
grub-install /dev/hdc

Then re-installed the linux-image so a new initrd would be built & installed
dpkg -i /usr/src/linux-image-2.6.17.dk5.1.deb

Now we reboot and when we get to the grub on sda which is still plugged in we hit “e” for edit and change root=/dev/sda to root=/dev/md1 and then hit “b” to boot it to the raid. and drink a shot of tequila.

So now we have it booted up on the md devices, however we still have to bring the second drive into the array. We start by copying the partition tables over.

sfdisk -d /dev/hda | sfdisk /dev/hdc

Then add them to the array

mdadm /dev/md0 -a /dev/hdc1
mdadm /dev/md1 -a /dev/hdc2

Let it rebuild, when finished you end up with this

Personalities : [linear] [multipath] [raid0] [raid1] [raid5] [raid4] [raid6] [raid10] md1 : active raid1 hdc2[0] hda2[1] 100004544 blocks [2/2] [UU] md0 : active raid1 hdc1[0] hda1[1] 104320 blocks [2/2] [UU]

unused devices:

Reboot and disconnect scsi drive
Linux Software RAID Upgrade … done

Leave a Reply

Your email address will not be published. Required fields are marked *