Free PBX On Software Raid 1

I began using FreePBX for my homes VOIP. I wanted a Raid 1 setup as one form or redundancy. Its not fail proof, but better than nothing. I found this site which explained it very well and put it here also if the other site goes down for some reason.

Turn Pbx in a Flash 2.0.6.22 in RAID1 system

 

In this example the initial layout for the hard disks was:

# mount|grep ^'/dev'
/dev/sda2 on / type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)

# fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000873c2

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 60704 487496704 83 Linux
/dev/sda3 60704 60802 786432 82 Linux swap / Solaris#

We have only one hard disk, sda, and all works fine ! We want to transform our working server in RAID 1 setup adding the other hard disk /dev/sdb.

Att.: Before to start we have to backup everything !!

Let’s start……

Create partitions on /dev/sdb identical to the partitions on /dev/sda.

# sfdisk -d /dev/sda | sfdisk --force /dev/sdb

To check.

# fdisk -l /dev/sdb
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 13 60704 487496704 83 Linux
/dev/sdb3 60704 60802 786432 82 Linux swap / Solaris

Now run the the following commands.

# mdadm --create /dev/md0 --metadata=0.90 --level=1 --raid-disks=2 /dev/sdb1 missing
mdadm: /dev/sdb1 appears to contain an ext2fs file system
size=102400K mtime=Thu Sep 20 15:05:01 2012
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

#mdadm --create /dev/md1 --metadata=0.90 --level=1 --raid-disks=2 /dev/sdb2 missing
mdadm: /dev/sdb2 appears to contain an ext2fs file system
size=487496704K mtime=Thu Sep 20 15:31:25 2012
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.

All these commands generates the raid devices in a degenerated state because the second drive is missing: we have only sdb in this RAID 1 !

Create a mdadm.conf from your current configuration.

# mdadm --detail --scan > /etc/mdadm.conf

Now we have to rebuild the initramfs with the new RAID: we will be using dracut.

# mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.old
# dracut --mdadmconf --force /boot/initramfs-$(uname -r).img $(uname -r)

Now we can create the correct filesystems on these new software raid devices, and initialize the swap on sdb3.

# mkfs.ext3 /dev/md0
# mkfs.ext3 /dev/md1
# mkswap -c /dev/sdb3
# swapon /dev/sdb3

Now we can copy the data from the existing partitions to the newly created raid partitions. We will begin with boot and after the root.

# mkdir /mnt/raid
# mount /dev/md0 /mnt/raid
# cd /boot; find . -depth | cpio -pmd /mnt/raid
# sync
# umount /mnt/raid
# mount /dev/md1 /mnt/raid
# cd / ; find . -depth -xdev | grep -v '^\./tmp/' | cpio -pmd /mnt/raid
# sync
# umount /mnt/raid

At this step we have our raid system created and the existing data was mirrored manually onto the new devices . Now we have to modifiy grub and the boot process to use the brand new RAID and the new swap: but we have to obtain the related UUID.

# blkid | grep /dev/md
/dev/md0: UUID="16b821f6-21ed-403e-a027-10e0bf89d9e5" SEC_TYPE="ext2" TYPE="ext3"
/dev/md1: UUID="55de6ac7-d6f6-4db2-a573-78f3132d568c" SEC_TYPE="ext2" TYPE="ext3"
# blkid | grep /dev/sdb3
/dev/sdb3: UUID="6f6a9cf2-9f06-4274-af0a-b45d6defe818" TYPE="swap"

Att.: Obviously your uuid will be different from mine.Pls write down the yours UUID: we will use shortly.

# mount /dev/md1 /mnt/raid

In fstab change the line containing the mount point /boot to the UUID of the new /dev/md0 filesystem and the line related root mount point to the UUID of /dev/md1.

# nano /mnt/raid/etc/fstab

Before edit

……
UUID=594ceeec-816c-4e61-83b4-7f492d2a4479 / ext3 defaults 1 1
UUID=c504f053-05aa-471c-a626-acc76b435b61 /boot ext3 defaults 1 2
UUID=bada5049-3902-4e08-a858-945c1ee8cf0f swap swap defaults 0 0

……

I have changed c504f053-05aa-471c-a626-acc76b435b61 with 16b821f6-21ed-403e-a027-10e0bf89d9e5.
Repeat for the UUID of the filesystem for the new / md device: I have changed 594ceeec-816c-4e61-83b4-7f492d2a4479 with 55de6ac7-d6f6-4db2-a573-78f3132d568c. Finally I have changed bada5049-3902-4e08-a858-945c1ee8cf0f with 6f6a9cf2-9f06-4274-af0a-b45d6defe818, the UUID related the swap area.

After edit.

….
UUID=55de6ac7-d6f6-4db2-a573-78f3132d568c / ext3 defaults 1 1
UUID=16b821f6-21ed-403e-a027-10e0bf89d9e5 /boot ext3 defaults 1 2
UUID=6f6a9cf2-9f06-4274-af0a-b45d6defe818 swap swap defaults 0 0

….

Close & Save and unmount /mnt/raid.

# umount /mnt/raid

Mount /dev/md0 again to /mnt/raid.

# mount /dev/md0 /mnt/raid/

Now we have to modify the grub menu.lst.

nano /mnt/raid/grub/menu.lst

Before edit

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
verbose=0
hiddenmenu
title CentOS (2.6.32-220.17.1.el6.i686)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.17.1.el6.i686 ro root=UUID=594ceeec-816c-4e61-83b4-7f492d2a4479 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM vga=791
initrd /initramfs-2.6.32-220.17.1.el6.i686.img

I have changed 594ceeec-816c-4e61-83b4-7f492d2a4479 with a5900125-51b9-4684-a268-bc47be21f705 and deleted the option rd_NO_DM.

After edit

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
verbose=0
hiddenmenu
title CentOS (2.6.32-220.17.1.el6.i686)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.17.1.el6.i686 ro root=UUID=a5900125-51b9-4684-a268-bc47be21f705 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us vga=791
initrd /initramfs-2.6.32-220.17.1.el6.i686.img

Now we have to install grub on the new hard disk

# grub
> root (hd1,0)
> setup (hd1)
> quit

It is possible to restart the system using the RAID. Reboot the machine and enter in the system BIOS, and choose the new disk as the one that your system boots from. Save the BIOS setting and boot.

If alla works fine after the reboot.

# mount|grep ^'/dev'

/dev/md1 on / type ext3 (rw)
/dev/md0 on /boot type ext3 (rw)

Att. The md is related to the RAID: the system is using RAID 1 !

Now you have to change the partition type

# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 13 60704 487496704 83 Linux
/dev/sdb3 60704 60802 786432 82 Linux swap / Solaris

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): p
Command (m for help): w
The partition table has been altered!

Reboot another time !

Now we can submit the sda in the raid. To begin reset the MBR.

# dd if=/dev/zero of=/dev/sda bs=512 count=1
# sfdisk -d /dev/sdb | sfdisk --force /dev/sda

Recreate grub on sda (hd0)

# grub
> root (hd0,0)
> setup (hd0)
> quit

Now try to restart: all works fine ? Now we launch the final command that will rebuild the RAID 1.

mdadm /dev/md0 -a /dev/sda1
mdadm /dev/md1 -a /dev/sda2

Will start the rebuild of the raid: it take very long time.
To see what’s going on, use the commands.

# cat /proc/mdstat

The final step is to configure the system to use the swap in both the hard drive: we have to add the sda3 swap area. We will use the swap on both drives for perfomance and because if a hard disk fails the other can support the swap process.

# blkid | grep /dev/sda3
/dev/sda3: UUID="52ef671d-a892-4059-9476-e1697e824381" TYPE="swap"
# mkswap -c /dev/sda3
# swapon /dev/sda3

Now we have to modify the /etc/fstab file adding a new line to use the swap in the other hard drive: before we have to find the UUID.

# blkid | grep /dev/sda3
/dev/sda3: UUID="52ef671d-a892-4059-9476-e1697e824381" TYPE="swap"
/etc/fstab before edit

….
UUID=a5900125-51b9-4684-a268-bc47be21f705 / ext3 defaults 1 1
UUID=56008161-316f-4d38-86a7-5e3043d0cc83 /boot ext3 defaults 1 2
UUID=52ef671d-a892-4059-9476-e1697e824381 swap swap defaults 0 0

……
I have add a new line

UUID=52ef671d-a892-4059-9476-e1697e824381 swap swap defaults 0 0

/etc/fstab after edit

….
UUID=a5900125-51b9-4684-a268-bc47be21f705 / ext3 defaults 1 1
UUID=56008161-316f-4d38-86a7-5e3043d0cc83 /boot ext3 defaults 1 2
UUID=6f6a9cf2-9f06-4274-af0a-b45d6defe818 swap swap defaults 0 0
UUID=52ef671d-a892-4059-9476-e1697e824381 swap swap defaults 0 0

DONE! Reboot once again and it should boot from the raid, begin rebuilding the raid and be using the swap on both drives.
……