RAID-1 in a hurry with grub and mdadm
From CLUG Wiki
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!!!!
- I don't use /etc/mdadm/mdadm.conf so just delete it or it'll mess you around
- 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 / find . -xdev -print0 | cpio -0pdvum --sparse /mnt umount /mnt
Then the /boot partition
mount /dev/md0 /mnt cd /boot find . -xdev -print0 | cpio -0pdvum --sparse /mnt cd / 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 has more flavours, use one of the following two syntaxis (check manpage) # syntax 1 mkinitrd -r /dev/md1 -o <the initrd-image-name from the grub config>-raid # syntax 2 (a.o. Fedora FC3) mkinitrd <the initrd-image-name from the grub config>-raid <kernel-version>
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.4.24-1-586tsc-raid
- 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
- 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 mdadm --detail --scan >> /etc/mdadm/mdadm.conf
- Here are some of the links I found useful:
Linux Software RAID-1 for Crazy Sysadmins
Installing Debian with SATA based RAID
GRUB Resources
- GRUB Manual
- GRUB homepage
- Grub wiki
- Linux+Win+Grub HowTo
- Linux Recovery and Boot Disk Creation with Grub.
- Win32 Grub
- Booting with GRUB
- WinGRUB
- GRUB Installer for Windows
- GRUB for DOS - Bridging DOS/Windows to Unix/Linux
