Link to home
Start Free TrialLog in
Avatar of josh2780
josh2780

asked on

Add RAID1 to Existing CentOS Installation

I have a CentOS 5 server with 2 drives (/dev/sda and /dev/sdb).  It was originally setup without RAID (/dev/sdb was blank).  I've gone through the process of configuring the second drive, setting up the raid, etc.  When I try to boot the RAID, it hangs with the following message:

-----
mount: could not find filestystem '/dev/root'.
Setting up other filesystems
Setting up new root fs
setuproot: moving /dev failed: No such file or directory
no fstab.sys mounting internal defaults
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
Switching to new root and running init
unmounting old /dev/
unmounting old /proc
unmounting old /sys
switchroot: mount failed: No such file or directory
Kernel panic - not syncing: Attempted to kill init
-----

Here's a summary of what I did to setup the RAID:

1) copy the partition table from /dev/sda to the secondary drive /dev/sdb
2) change the partition types to 'Linux raid auto'
3) create RAID 1 arrays (/dev/md1 as boot, md2 as swap, md3 as root)
4) Format filesystems (md1 and md3) and create the swap space (md2)
5) Rebuild initrd image to include raid1 (mkinitrd -v --preload=raid1 /root/initrd-2.6.18-53.1.19.el5.raid1.img 2.6.18-53.1.19.el5)
6) Modify /boot/grub/grub.conf and add the new boot option using the image just created:
title CentOS (2.6.18-53.1.19.el5) RAID1
        root (hd1,0)
        kernel /vmlinuz-2.6.18-53.1.19.el5 ro root=/dev/md3
        initrd /initrd-2.6.18-53.1.19.el5.raid1.img
7) Mount the raid devices (/dev/sda1 (boot) and /dev/sda3 (root))
8) Copy the contents of /dev/sda[1,3] to /dev/md[1,3] which are mounted on /mnt/md[1,3]  (using 'cp -a' to preserve everything)
9) Install grub on /dev/sdb (grub-install /dev/sdb) so that later the second drive can boot in the event the first drive fails.
10) Update /etc/fstab on /dev/md3 to use the raid devices (/dev/md[1,2,3]) instead of /dev/sda[1,2,3]
11) Reboot.  At the grub menu, select the RAID option created earlier.

Any ideas of where to go next?
Avatar of ravenpl
ravenpl
Flag of Poland image

1) how have You done this? like: sdparm -d /dev/sda | sdparm /dev/sdb
3) Have You created degradated arrays using ONLY sdbX? With missing parameter?
5) instead of --preload, You should create the /etc/mdadm.conf file, refer man mdadm
after 8) You probably should add sdaX partitions to degradated raids, wait until resync is performed
9) if resync is done, You should install grub on both, sda & sdb
Avatar of josh2780
josh2780

ASKER

Hi ravenpl, here is some more detail on the steps that I completed:

1) copy the partition table from /dev/sda to the secondary drive /dev/sdb
sfdisk -d /dev/sda | sfdisk /dev/sdb

2) change the partition types to 'Linux raid auto'
I just used fdisk to change the type to 'fd'

3) create RAID 1 arrays (/dev/md1 as boot, md2 as swap, md3 as root)
do mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/sdb1 --auto=md
do mdadm --create /dev/md2 --level=1 --raid-devices=2 missing /dev/sdb2 --auto=md
do mdadm --create /dev/md3 --level=1 --raid-devices=2 missing /dev/sdb3 --auto=md

4) Format filesystems (md1 and md3) and create the swap space (md2)
Just used mke2fs -j /dev/mdX

5) Rebuild initrd image to include raid1
mkinitrd -v --preload=raid1 /root/initrd-2.6.18-53.1.19.el5.raid1.img 2.6.18-53.1.19.el5

6) Modify /boot/grub/grub.conf and add the new boot option using the image just created:
title CentOS (2.6.18-53.1.19.el5) RAID1
        root (hd1,0)
        kernel /vmlinuz-2.6.18-53.1.19.el5 ro root=/dev/md3
        initrd /initrd-2.6.18-53.1.19.el5.raid1.img

7) Mount the raid devices (/dev/md1 (boot) and /dev/md3 (root))
mnt /dev/md1 /mnt/md1
mnt /dev/md3 /mnt/md3

8) Copy the contents of /dev/sda[1,3] to /dev/md[1,3] which are mounted on /mnt/md[1,3]  (using 'cp -a' to preserve everything)
I just used 'cp -a' to copy the data while preserving permissions, timestamps, etc.  I manually created some items such as /mnt, /proc, etc.  Basically, 'ls /' is looks just like 'ls /mnt/md3'

9) Install grub on /dev/sdb (grub-install /dev/sdb) so that later the second drive can boot in the event the first drive fails.
I installed grub on sdb after the copy was finished in step 8.  sda already had grub installed.

10) Update /etc/fstab on /dev/md3 to use the raid devices (/dev/md[1,2,3]) instead of /dev/sda[1,2,3]

11) Reboot.  At the grub menu, select the RAID option created earlier.


I've tried creating the /etc/mdadm.conf with 'mdadm --examine --scan > /etc/mdadm.conf' and still run into the same kernel panic.  You also mentioned to add sdaX partitions to the degraded raids.  The processes that I followed online mentioned not to do this until the raid was confirmed to boot correctly, otherwise, if I added sdaX partitions to the raid, they would be rebuilt and I would then be in a state of no return.  If it didn't boot, I'd have nothing to fall back on...  but maybe I'm not understanding what you said.

Thanks.
Please, after You created the /etc/mdadm.conf(copy to md3 as well), recreate the initrd image. Copy the initrd to both sda3 and md3, so no matter which is going to be used it knows to bring the md devices up.
OK - the following /etc/mdadm.conf has been created on both sda3 and md3:
---
DEVICE /dev/sdb1 /dev/sdb2 /dev/sdb3
ARRAY /dev/md1 devices=missing,/dev/sda1
ARRAY /dev/md2 devices=missing,/dev/sda2
ARRAY /dev/md3 devices=missing,/dev/sda3
---

Recreated the initrd image:
mkinitrd -v --preload=raid1 /root/initrd-2.6.18-53.1.19.el5.raid1.img 2.6.18-53.1.19.el5
and copied it to both sda3 and md3.

Reboot.  Same kernel panic.
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't see anything regarding raid during boot...  things are flying by quickly and I can't scroll up after the kernel panic, but I watched a few times and never saw anything.  I did break apart the initrd image and make changes to init mentioned here: http://www.linuxquestions.org/questions/fedora-installation-39/fc5-panic-after-install-433048/ but it didn't help.

The mdadm.conf that I created was based on recommendations from some documentation that documents the process of setting up RAID1 after an install.  However, I recreated mdadm.conf using 'mdadm --examine --scan > /etc/mdadm.conf'.  Next I did your suggestion of creating a new initrd pointing it to fstab on md3.  Reboot and bingo!  That got init to start but now I get a lot of errors on services starting... things like:

/sbin/mdadm: error while loading shared libraries: libc.so.6: cannot open shared object file: Permission denied
/sbin/pam_console_apply.... <same error as above>
*** it enters run-level 3 and then continues with errors...
Applying ip6tables firewall rules: ip6tables-resetore... <same error as above>
Applying iptables firewall rules: iptables-resetore... <same error as above>
Bringing up interfaces... <same error as above but with libresolve.so.2>
*** and so on...
*** and then quite a few lines with
/sbin/mingetty: error while loading shared libraries: libc.so.6: cannot open shared object file: Permission denied
INIT: id "1" respawning too fast: disabled for 5 minutes
INIT: id "2" respawning too fast: disabled for 5 minutes
INIT: id "3" respawning too fast: disabled for 5 minutes
INIT: id "4" respawning too fast: disabled for 5 minutes
INIT: id "5" respawning too fast: disabled for 5 minutes
INIT: id "6" respawning too fast: disabled for 5 minutes
INIT: no more processes left in this runlevel

And that's where it stops.  /lib exists on /dev/md3 and the files are there.  ??
Looks like Your copy was not really 1-1. Probably SElinux context was not preserved
cp -ac # instead of cp -a
or disable SELinux.
You're right about SELinux being the problem.

Instead of doing a copy again, I just did a 'touch /mnt/md3/.autorelabel' and restarted.  SELinux relabeled the files and everything came up fine.

Thanks very much for your help!
thanks for your help.  great job.