Wednesday, September 26, 2012

Soft RAID: Setting UP RAID1 under Debian Etch on DELL SC440


Why we choose RAID1:

The difference between RAID1 and RAID0,is that we do not allow mirroring of two drives on the server, any time it allows perfect operation of the Bandwidth I / O that which means the use of all the space of the two disks on the machine by adding their speed to the storage device, but the concern is that it does not manage fault tolerance. RAID1 meanwhile it gives us a total of two mirroring / multiple discs with fault tolerance.

PS :
We must ensure that there is no anterior RAID configuration by going into the 'Prop RAID' and removes all 'ARRAYS' existing by answering 'Y', when starting removing RAID arrays.
This shoul be done, by entring in RAID controller BIOS.



System config :

In my case, I have partitions mounted like this :

- partition : /boot ➔ mounted on sda1 en ext3
- partition : swap ➔ mounted on sda2
- partition : / : ➔ mounted on sda3 en ext3

At the end we will have this table :

/dev/md0 (/dev/sda1 et /dev/sdb1): partition /boot, ext3

/dev/md1 (/dev/sda2 et /dev/sdb2): swap

/dev/md2 (/dev/sda3 et /dev/sdb3): / partition, ext3

PS: Marking partitions as follows is done using the "Labels" during the partitioning step.


- Description of software services
Program that will manage the software RAID is 'mdadm' (multi disks admin)
Configuring data and application techniques:


Installing and loading tools and modules required:

The command '

~#apt-get install initramfs-tools mdadm

will install the necessary tools to manage the RAID. To load them, we run :

~#modprobe md

~#modprobe linear

~#modprobe multipath

~#modprobe raid0

~#modprobe raid1

~#modprobe raid5

~#modprobe raid6

~#modprobe raid10

After that, we make a simple verification by typing: cat /proc/mdstat’ that would return :

Personalities: [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]

unused devices: <none>


Preparation of /dev/sdb: To create the layout in RAID1 disk 'sdb', you must copy the contents of / dev / sda and finally add / dev / sda to this provision.

First time you copy the contents of / dev / sda / dev / sdb they respectively for the same content using the command:


~#sfdisk –d /dev/sda | sfdisk /dev/sdb

‘fdisk –l’ output, must have :



Disk /dev/sda: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



Device Boot Start End Blocks Id System

/dev/sda1 * 1 18 144553+ 83 Linux

/dev/sda2 19 80 498015 82 Linux swap / Solaris

/dev/sda3 81 652 4594590 83 Linux



Disk /dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



Device Boot Start End Blocks Id System

/dev/sdb1 * 1 18 144553+ 83 Linux

/dev/sdb2 19 80 498015 82 Linux swap / Solaris

/dev/sdb3 81 652 4594590 83 Linux

NEXT:

~#fdisk /dev/sdb

Command (m for help): <-- t

Partition number (1-4): <-- 1

Hex code (type L to list codes): <-- L

Hex code (type L to list codes): <-- fd

Changed system type of parti tion 1 to fd (Linux raid autodetect)

We continue in the same way with the other three partitions.



When you're done:

Command (m for help): <-- w

The partition table has been altered!



Calling ioctl() to re-read partition table.

Syncing disks.

To prevent any anterior RAID setup on /dev/sdb :



~#mdadm --zero-superblock /dev/sdb1

~#mdadm --zero-superblock /dev/sdb2

~#mdadm --zero-superblock /dev/sdb3

We should have this output :



‘mdadm --zero-superblock /dev/sdb1

mdadm: Unrecognised md component device - /dev/sdb1’



RAID arrays creation step :



RAID arrays /dev/md0, /dev/md1, and /dev/md2. /dev/sdb1 seront ajouté sur /dev/md0, /dev/sdb2 to /dev/md1, et /dev/sdb3 sur /dev/md2 /dev/sda1, /dev/sda2, et /dev/sda3 ne pourra pas etre ajouté (parce que le systeme les utilise):



~#mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1

~#mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb2

~#mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/sdb3



Shoud have this output after cat /proc/mdstat command:



Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]

md2 : active raid1 sdb3[1]

4594496 blocks [2/1] [_U]



md1 : active raid1 sdb2[1]

497920 blocks [2/1] [_U]



md0 : active raid1 sdb1[1]

144448 blocks [2/1] [_U]



unused devices: <none>

 

File system creation:



Reached this stage, we create the file system:



RAID arrays (ext3 sur /dev/md0, /dev/md2 et swap sur /dev/md1)



~#mkfs.ext3 /dev/md0
~#mkswap /dev/md1
~#mkfs.ext3 /dev/md2

Setting mdadm.conf :

~#cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
~#mdadm --examine --scan >> /etc/mdadm/mdadm.conf
~#cat /etc/mdadm/mdadm.conf



# mdadm.conf

#

# Please refer to mdadm.conf(5) for information about this file.

#



# by default, scan all partitions (/proc/partitions) for MD superblocks.

# alternatively, specify devices to scan, using wildcards if desired.

DEVICE partitions



# auto-create devices with Debian standard permissions

CREATE owner=root group=disk mode=0660 auto=yes



# automatically tag new arrays as belonging to the local system

HOMEHOST <system>



# instruct the monitoring daemon where to send mail alerts

MAILADDR root



# This file was auto-generated on Mon, 26 Nov 2007 21:22:04 +0100

# by mkconf $Id: mkconf 261 2006-11-09 13:32:35Z madduck $

ARRAY /dev/md0 level=raid1 num-devices=2 UUID=72d23d35:35d103e3:01b5209e:be9ff10a

ARRAY /dev/md1 level=raid1 num-devices=2 UUID=a50c4299:9e19f9e4:01b5209e:be9ff10a

ARRAY /dev/md2 level=raid1 num-devices=2 UUID=99fee3a5:ae381162:01b5209e:be9ff10a




Setting up the OS to use in RAID1 : or mounting /dev/md0 and /dev/md1

~#mkdir /mnt/md0

~#mkdir /mnt/md2

~#mount /dev/md0 /mnt/md0

~#mount /dev/md2 /mnt/md2


Verifying with mount command, we should have :

dev/sda3 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
/dev/md0 on /mnt/md0 type ext3 (rw)
/dev/md2 on /mnt/md2 type ext3 (rw)



Modifying fstab file /etc/fstab:



~#vi /etc/fstab :

We replace: /dev/sda1 avec /dev/md0, /dev/sda2 avec /dev/md1, /dev/sda3 avec /dev/md2 pour avoir cette sortie :

# /etc/fstab: static file system information.

#



# <file system> <mount point> <type> <options> <dump> pass>



proc /proc proc defaults 0 0

/dev/md2 / ext3 defaults,errors=remount-ro 0 1

/dev/md0 /boot ext3 defaults 0 2

/dev/md1 none swap sw 0 0

/dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0

/dev/fd0 /media/floppy0 auto rw,user,noauto 0 0



Adapting /etc/mtab by replacing /dev/sda1 avec /dev/md0, dev/sda3 avec /dev/md2:



/dev/md2 / ext3 rw,errors=remount-ro 0 0

tmpfs /lib/init/rw tmpfs rw,nosuid,mode=0755 0 0

proc /proc proc rw,noexec,nosuid,nodev 0 0

sysfs /sys sysfs rw,noexec,nosuid,nodev 0 0

udev /dev tmpfs rw,mode=0755 0 0

tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0

devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=620 0 0

/dev/md0 /boot ext3 rw 0 0



The famous GRUB boot loader /boot/grub.menulist:



[...]

default 0

fallback 1

[...]



After that, juste copy/past this, to avoid mistakes, be careful your system won't boot.



copy and paste just before the first block by replacing 'root = / dev / sda3 with root = / dev/md2 and root (hd0, 0) with root (hd1, 0), in other words, we should have this output



[...]

## ## End Default Options ##



title Debian GNU/Linux, kernel 2.6.18-4-486 RAID (hd1)

root (hd1,0)

kernel /vmlinuz-2.6.18-4-486 root=/dev/md2 ro

initrd /initrd.img-2.6.18-4-486

savedefault



title Debian GNU/Linux, kernel 2.6.18-4-486

root (hd0,0)

kernel /vmlinuz-2.6.18-4-486 root=/dev/sda3 ro

initrd /initrd.img-2.6.18-4-486

savedefault



title Debian GNU/Linux, kernel 2.6.18-4-486 (single-user mode)



root (hd0,0)

kernel /vmlinuz-2.6.18-4-486 root=/dev/sda3 ro single

initrd /initrd.img-2.6.18-4-486

savedefault



### END DEBIAN AUTOMAGIC KERNELS LIST







Configuring RAMDSIK:



~#update-initramfs –u

~#cp –dpRx / /mnt/md2

~#cd /boot

~#cp –dpRx . /mnt/md0



Preparing GRUB(1st part):



~#grub

grub>root (hd0,0)

Filesystem type is ext2fs, partition type 0x83

grub>setup (hd0)



setup (hd0)



Checking if "/boot/grub/stage1" exists... no



Checking if "/grub/stage1" exists... yes



Checking if "/grub/stage2" exists... yes



Checking if "/grub/e2fs_stage1_5" exists... yes



Running "embed /grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.



succeeded



Running "install /grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/grub/stage2 /grub/menu.lst"... succeeded.

Done.




grub>root (hd1,0)



Filesystem type is ext2fs, partition type 0xfd



grub>setup (hd1)



Checking if "/boot/grub/stage1" exists... no



Checking if "/grub/stage1" exists... yes



Checking if "/grub/stage2" exists... yes



Checking if "/grub/e2fs_stage1_5" exists... yes



Running "embed /grub/e2fs_stage1_5 (hd1)"... 15 sectors are embedded.



succeeded



Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/menu.lst"... succeeded



Done.



grub>quit



REBOOT REQUIRED.





If all goes well; we should have this with df -h command :



Filesystem Size Used Avail Use% Mounted on

/dev/md2 4.4G 730M 3.4G 18% /

tmpfs 126M 0 126M 0% /lib/init/rw

udev 10M 68K 10M 1% /dev

tmpfs 126M 0 126M 0% /dev/shm

/dev/md0 137M 17M 114M 13% /boot



Setting up /dev/sda Raid Autodetect:



~#fdisk /dev/sda’



Command (m for help): <-- t



Partition number (1-4): <-- 1



Hex code (type L to list codes): <-- L



Hex code (type L to list codes): <-- fd



Changed system type of partition 1 to fd (Linux raid autodetect)



SAME THING FOR THE OTHER 3 PARTITIONS:



NEXT:



Command (m for help): <-- w



The partition table has been altered!



Calling ioctl() to re-read partition table.



Syncing disks.



We can add respectively /dev/sda1, /dev/sda2, /dev/sda3



~#mdadm --add /dev/md0 /dev/sda1



~#mdadm --add /dev/md1 /dev/sda2



~#mdadm --add /dev/md2 /dev/sda3





~# cat /proc/mdstat



Personalities : [raid1]



md2 : active raid1 sda3[2] sdb3[1]



4594496 blocks [2/1] [_U]



[=====>...............] recovery = 29.7% (1367040/4594496) finish=0.6min speed=85440K/sec



md1 : active raid1 sda2[0] sdb2[1]



497920 blocks [2/2] [UU]



md0 : active raid1 sda1[0] sdb1[1]



144448 blocks [2/2] [UU]





unused devices: <none>