Contents

This is for people who are in a hurry, not novices

The instructions are for people who don't build monolithic kernels, or use standard pre-compiled kernels. If you do build monolithic kernels, you can skip all the initrd stuff - just be sure md is compiled into your kernel.

Let's assume your existing installation is on hda, and you've just added hdd. We also assume that hdd is the same size as (or bigger than) hda. You have two partitions: / and /boot on hda currently.

  • Install the mdadm tools
apt-get install mdadm  <---- Enable autostart when asked
  • Make sure that you don't have mdadm version 1.8.1* - they are development releases and don't produce random UUIDs! If you have a raid array created with one of these mdadms, it will give error messages on boot, and may accidentaly merge it with another array!!!!
  • Make sure that you have a recent version of grub. (Not grub2). 0.97-47lenny2 is okay. See [1]
  • Remove or rename /etc/mdadm/mdadm.conf if it exists. We'll set it up later.
  • Set up the partition tables
sfdisk -d /dev/hda | sfdisk /dev/hdd -O hdd-partition-sectors.save
fdisk /dev/hdd -> set all partition types (except extended partition) to FD
  • Create the (degraded) RAID devices

We'll use md0 for /boot, md1 for the root filesystem and md2 for swap.

mdadm -C /dev/md2 --level=raid1 --raid-devices=2 missing /dev/hdd6
mdadm -C /dev/md1 --level=raid1 --raid-devices=2 missing /dev/hdd5
mdadm -C /dev/md0 --level=raid1 --raid-devices=2 missing /dev/hdd1

You may have to use the following instead if you get the following error during the next boot:

md: Autodetecting RAID arrays.
md: invalid raid superblock magic on hda1
mdadm -C /dev/md2 -e 0.90 --level=raid1 --raid-devices=2 missing /dev/hdd6
mdadm -C /dev/md1 -e 0.90 --level=raid1 --raid-devices=2 missing /dev/hdd5
mdadm -C /dev/md0 -e 0.90 --level=raid1 --raid-devices=2 missing /dev/hdd1

This is because mdadm version 2.5 uses a version 1.0 superblock which does not support in-kernel auto-detection. To verify this, just cat /proc/mdstat | grep super, and you will see 'super 1.0'

NOTE: depending on you installation your partitions might be called differently, check the partition table!

  • Have a look at the results
cat /proc/mdstat
  • Create a swap partition on one of the RAID devices
mkswap /dev/md2
swapon /dev/md2
swapon -s

NOTE: the latter two steps are merely to test if you were succesful in creating swap space

  • Create EXT3 partitions on the other two RAID devices
mkfs -t ext3 /dev/md0
mkfs -t ext3 /dev/md1
  • Copy all your files into the two new RAID devices

First the / partition

mount /dev/md1 /mnt
cd /
cp -ax /dev /mnt/
cp -ax . /mnt/
or
find . -xdev -print0 | cpio -0pdvum --sparse /mnt
then
umount /mnt

Then the /boot partition

mount /dev/md0 /mnt
cp -ax /boot /mnt/
or
cd /boot
find . -xdev -print0 | cpio -0pdvum --sparse /mnt
cd /
then
umount /mnt
  • Now mount both new partitions and set up fstab
mount /dev/md1 /mnt
mount /dev/md0 /mnt/boot
vim /mnt/etc/fstab          <--- hda1 => md0, hda5 => md1, hda6 => md2
  • Change the grub config:
vim /mnt/boot/grub/menu.lst

First copy and paste all lines of your current bootoption. Then change the first occurrence of the two identical bootoptions. You need to replace hda1 with md0 and hda5 with md1. Further change the name of the initrd-image so it ends in -raid. Don't forget the change the title so it reflects this is the raid option.

NOTE: the unaltered copy of your current boot options is merely for safety sake.

  • Install the grub loader:
grub>
 device (hd0) /dev/hdd
 root (hd0,0)
 setup (hd0)
 quit
  • Now create a new initrd for the degraded RAID so you can reboot using the RAID modules.
cd /mnt
mount -o bind /proc ./proc
# check if you see anything below /mnt/dev, if not:
mount -o bind /dev ./dev
chroot /mnt
mkinitrd -r /dev/md1 -o /boot/initrd.img-2.6.28-raid 2.6.28
or
mkinitramfs -r /dev/md1 -o /boot/initrd.img-2.6.28-raid 2.6.28

Do yourself a favour and check if the image contains the necessary modules. Smart way to do this:

gunzip -c <the initrd-image-name from the grub config>-raid | cpio -it

and check for modules md (or dm-) and raid1

  • Reboot (into hdd not hda) and test if you can boot directly into the RAID array. You have two ways to go about:

(1) Copy the lines from the raid bootoption in the grub config on the raided device and paste those into the grub config on the non-raided device. Be sure to change the root line so it says

root            (hd1,0)

(2) Boot as you would normally do, interrupt the boot process and go into grub (c)ommandline mode. Now type

root (hd1,0)
configfile /grub/menu.lst

You'll see the "new" bootmenu. Now choose the new raid boot option. Choose (e)dit, highlight the line root (hd0,0), again press (e)dit and change it into root (hd1,0). Now (b)oot!

  • Make the hda partition types "RAID auto-start" when the previous step works
fdisk /dev/hda -> set all partition types (except extended partition) to FD
  • Put hda into the RAID array (this is where hda gets clobbered)
mdadm /dev/md2 -a /dev/hda6
mdadm /dev/md0 -a /dev/hda1
mdadm /dev/md1 -a /dev/hda5
  • Make some coffee while hda gets overwritten
watch cat /proc/mdstat
  • Now you must create a non-degraded RAID initrd
mkinitrd -r /dev/md1 -o /boot/initrd.img-2.6.28-raid 2.6.28
or
mkinitramfs -r /dev/md0 -o /boot/initrd.img-2.6.28-raid 2.6.28
  • Change the grub config
vim /boot/grub/menu.lst

Remove all lines of the old bootoption (with hda)

  • Re-install the grub loader
grub>
 device (hd0) /dev/hda
 root (hd0,0)
 setup (hd0)
 quit
  • Set up /etc/mdadm/mdadm.conf. (If you had an old one, you can have a look to see if there's anything in there that you want.)
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
  • Reboot check that the RAID array does not come up degraded
  • Some commands that might come in handy (RTFM for details):
mdadm --zero-superblock /dev/hde5
mdadm -D /dev/md0
mdadm --stop /dev/md0
mdadm -S /dev/md0
less -S /proc/partitions
dpkg-reconfigure mdadm --> to de/re-activate autostart

Footnote 1

Earlier versions of grub are unable to read ext file-systems with 256-byte inodes. Newer versions of e2fsprogs use 256-byte inodes for ext4. If you have the combination described, grub will print this error at boot time: "error 2: bad file or directory". To fix the problem, either update grub, or create the ext file-system with smaller inodes so: mkfs.ext3 -I 128 /dev/sda1. To find out what size your inodes are: tune2fs -l /dev/sda1 | grep -i 'inode size'

Links

  • Here are some of the links I found useful:

The Software-RAID HOWTO

LinuxSA Mailing list archives

LinuxSA Mailing list archives

Linux Software RAID-1 for Crazy Sysadmins

Installing Debian with SATA based RAID

Software Raid

GRUB Resources


This page was last modified on 16 September 2009, at 06:59. This page has been accessed 39,572 times.

  
Powered by MediaWiki

Copyright © 1999-2009, Cape Linux Users Group | All contents are under GNU Free Documentation Licence | For all queries, join our mailing lists!