From one disk Installation to software RAID5 with Suse 12.2
After the second crash of my disk, recovered by backup copies, decide to have a more secure system with less job for recover data.
Decide to start to configure a software RAID5 with 3 disks.
Starting from an existent and working installation.
My configuration was:
/dev/sda | – Installed non-RAID system disk |
---|---|
/dev/sda1 | – swap partition |
/dev/sda2 | – root partition |
|
|Adding 2 disks become:||
|
|
|
|/dev/sdb| – First empty disk for the RAID mirror|
| /dev/sdc| – Second empty disk for the RAID mirror|
| /dev/md0| – Mirrored swap partition|
| /dev/md1| – Mirrored root partition|
First of all: Backup the system, I use PartImage (Partimage) inside SystemResqueCD (SystemRescueCd) on USB stick.
Following http://www.novell.com/communities/node/4520/migrating-sles-software-raid1#degradedarray i modify:
(Modified document available: https://www.dropbox.com/s/c5wszpxo8c8udys/Novell%20Migration.rtf)
Create the degraded Array using:
mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 missing
mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sdb2 /dev/sdc2 missing
Remember to use the already existent disk format of the existent partition (/dev/sda1), ext3, reiserfs,…for the Array partition.
mkreiserfs /dev/md1
mkfs.ext3 /dev/md1
[FONT=Helvetica]Follow: **Creating a SLES9 initrd **[/FONT]
adding raid5 module
INITRD_MODULES="raid1 raid5 mptscsih reiserfs"
Relating the Grub installation I had many errors and the system wasn’t able to reboot itself.
Reading I discover that the Array partition of RAID5 cannot be read on startup and Grub cannot find the /boot directory, also I read that Grub is not able to manage mdX partitions of RAID5.
I try many suggestions on internet forums without success, take a decision to upgrade my system to openSuse 12.3 with Grub2 stable (not in beta like in my openSuse 12.2).
First of all i have to modify the partitions table for have a boot partition outside the RAID5 Array.
My system with single disk had a 16 GB of swap, now with RAID5 swap partition you can configure 3 partitions of 8GB each that will be 16 GB in RAID5 configuration.
Delete the swap partition with fdisk.
Create, with fdisk, two new partitions (sdx1 and sdx3) of 8 GB each on each disk (you can decide different size, the boot partition need no more than 200 MB of space).
Create a new array RAID5 for swap:
create /dev/md0 --level=5 --raid-devices=3 /dev/sdb3 /dev/sdc3 /dev/sda3
Format the Array:
mkswap /dev/md0
Make active for swap:
swapon /dev/md0
Format the boot partition:
mkfs.ext3 /dev/sda1
mkfs.ext3 /dev/sdb1
mkfs.ext3 /dev/sdc1
Upgrade the system to openSuse 12.3:
Boot from LiveCD openSuse 12.3
When the update ask for configure the Grub2 select inside the boot loader location:
Custom Boot Partition > /dev/sda1
the installation goes in error with:
<< Because the partitioning the boot loader cannot be installed properly >>
doesn’t matter about it.
Reboot the system with the System Rescue CD (or with openSuse live CD)
mount the array with the new (openSuse 12.3) /boot directory:
mkdir /mnt/array
mount /dev/md1 /mnt/array
mount the boot partition:
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
Copy all the data inside:
cp -ax /mnt/array/boot /mnt/sda1
check if /mnt/sda1 contain the boot directory
reboot the system
Now Grub2 is doing its job and boot the system itself.
How now preserve the security of the boot partition without copy the /boot dir to each partition each change ?
Create a RAID1 array (that is in mirroring and the partitions are directly readable) with /dev/sda1, /dev/sdb1 and /dev/sdc1.
copy on /dev/sdb1 and /dev/sdc1 the /dev/sda1 contents:
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
mkdir /mnt/sdb1
mount /dev/sdb1 /mnt/sdb1
mkdir /mnt/sdc1
mount /dev/sdc1 /mnt/sdc1
cp -ax /mnt/sda1 /mnt/sdb1
cp -ax /mnt/sda1 /mnt/sdc1
Create a copy of the MBR of sda:
dd if=/dev/sda of=/tmp/sda_mbr.bin bs=512 count=1
copy the .bin file in a safe place (NFS Backup, USB,…)
Copy MBR on the other disks for make them bootable:
dd if=/tmp/sda_mbr of=/dev/sdb bs=512 count=1
dd if=/tmp/sda_mbr of=/dev/sdc bs=512 count=1
This command work only for same sized disks (as we need to have)
Alternative can be:
dd if=/dev/sda of=/dev/sdb_mbr.bin bs=512 count=1
dd if=/dev/sda of=/dev/sdc_mbr.bin bs=512 count=1
But i prefer to have a copy of the MBR saved in a safe place.
Create the RAID1 array without format it:
create /dev/md2 --level=1 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sda1
Reboot the system
Now you have one data RAID5 partition and one RAID1 partition for boot the system.
If one disk fail, you can change in the BIOS the alternative disk for boot and take your time for substitute the failed one.
Now I need to be advised when one disk fail and looking around i modify this script (http://www.novell.com/support/kb/doc.php?id=7001034)
#!/bin/bash
mdadm RAID health check
Events are being passed to xmessage via $1 (events) and $2 (device)
Setting variables to readable values
event=$1
device=$2
Check event and then popup a window with appropriate message based on event
if $event == ‘Fail’ ];then
xmessage “A failure has been detected on device” $device
echo “A failure has been detected on device” $device | mailx -s “Report Array” -r sender_mail@yahoo.com destination@gmail.com
else
if $event == ‘FailSpare’ ]; then
xmessage “A failure has been detected on spare device” $device
echo “A failure has been detected on spare device” $device | mailx -s “Report Array” -r sender_mail@yahoo.com destination@gmail.com
else
if $event == ‘DegradedArray’ ]; then
xmessage “A Degraded Array has been detected on device” $device
echo “A Degraded Array has been detected on device” $device | mailx -s “Report Array” -r sender_mail@yahoo.com destination@gmail.com
else
if $event == ‘TestMessage’ ]; then
xmessage “A Test Message has been generated on device” $device
echo “A Test Message has been generated on device” $device | mailx -s “Report Array” -r sender_mail@yahoo.com destination@gmail.com
fi
fi
fi
fi
#~~~~~~~~~~~~~~~~~~~~~~~~~ End of Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This script as to be saved as /etc/raid-events.
Add in /etc/mdadm.conf the red row:
ARRAY /dev/md/2 metadata=1.0 UUID=ec581aef:88267373:d93089ad:89ff5267 name=linux.workgroup:2
ARRAY /dev/md/1 metadata=1.2 UUID=7d0a0a37:2f6158e9:cdbbb404:a0166df8 name=linux:1
ARRAY /dev/md/0 metadata=1.0 UUID=bcbff4ac:701c47ad:aa66ad83:36465b3d name=linux.workgroup:0
PROGRAM /etc/raid-events
The script will open a popup window on your screen and send a mail when disk failure happen.
Test it:
mdadm --monitor --scan --test
If you need to load the monitor on boot:
edit /etc/init.d/boot.local adding the row:
mdadm --monitor --scan --daemonize
For permit mailx to send mail through an external SMP edit /etc/mail.rc and add the red row:
set asksub append dot save crt=20
set smtp=smtp.domain.com (with the SMTP of your domain)
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via
Now my system is up and running and SAFE.