博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

2008GOGOGO

quekchdream.cublog.cn
RAID(Redundant Array of Inexpensive Disks)技术(2)
Start

 

Redhat 7.3 Root Partition Raid-1 Mirrorring

       Abstract: This article describes setting up a Linux system with root partition raid-1 mirrored, both disk are bootable either of two disks fail, then another disk is already read to boot system without any configuration, then we can replace failed hard disk with a new one an sync with the current one.

Hardware: 2*36G SCSI Hard Disk.

We already install Redhat Linux 7.3 on the first hard disk, what I am going to do is to use the second hard disk to convert the whole system to raid-1 mirrored system.

a.       Recompiling kernel 2.4.18 and enable e1000 module or do ‘mkinitrd’ to generate new initrd.img to be aware of raid devices.

You can download the latest kernel 2.4.18 to compile it on the current system, the most important thing is you must enable built-in raid-1 support, and ext3 file system support, scsi chip set support

b.       Alternatively, run command ‘mkinitrd /boot/initrd.img –preload raid1 2.4.18-3smp’, then do the following to support raid1 root file system;

# cp /boot/initrd.img /tmp/

# cd /tmp

# zcat initrd.img > initrd

# mkdir img

# mount –o loop initrd img

# cd img

# vi linuxrc

Adding ‘raidautorun /dev/md0’ after ‘mkrootdev /dev/root’

# cd dev

# mknod md0 b 9 0

# cd /tmp

# umount img

# dd if = initrd | gzip > /boot/initrd.img

You should see the following in /tmp/img/linuxrc

#! /bin/bash

echo “Loading raid1 module”

insmod /lib/raid1.o

echo “Loading scsi_mod module”

insmod /lib/scsi_mod.o

echo “Loading sd_mod module”

insmod /lib/sd_mod.o

echo “Loading jbd module”

insmod /lib/jbd.o

echo “Loading ext3 module”

insmod /lib/ext3.o

echo Mounting /proc filesystem

mount –t proc /proc/proc

echo Creating root device

mkrootdev /dev/root

# note: raidautorun is a internal command of shell nash which interactive with initrd

# image.

raidautorun /dev/md0

echo 0x0100 > /proc/sys/kernel/real-root-dev

echo Mounting root filesystem

mount –ro –t ext3 /dev/root /sysroot

umount /proc

pivot_root /sysroot /sysroot/initrd

 

And file /tmp/img/dev/md0

[root@localhost dev]# ls –la

 

And file /tmp/img/lib/raid1.o

[root@localhost lib]# ls –la

 

# vi /etc/grub.conf

Adding another kernel image to use /boot/initrd.img to boot up, you can still use the existing kernel

c.       Making partition for the second hard disk the same as the first hard disk

Use fdisk to make partition for the second hard disk, making it the exact same as the first hard disk, you can use the following command to do it faster.

# dd if = /dev/sda of = /dev/sdb

After running the above command, stop it right away, then use ‘fdisk –l /dev/sdb’ to check if you got the same partition system as the first hard disk

d.       Transfer/Clone OS to the second hard disk.

This is our current first hard disk partition information;

[root@localhost root]# fdisk –l /dev/sda

 

Disk /dev/sda: 255 heads, 63 sectors, 2213 cylinders

Units = cylinders of 16065 * 512 bytes

 

Device Boot Start End Blocks Id System

/dev/sda1 * 1 7 56196 de Dell Utility

/dev/sda2 8 14 56227+ fd linux

/dev/sda3 15 142 1028160 82 Linux swap

/dev/sda4 143 2213 16635307+ 5 Extended

/dev/sda5 143 334 1542208+ fd Linux

 

Put the following lines to /etc/raid

 

raiddev /dev/md0

raid-leve 1

nr-raid-disks 2

chunk-size 64k

persistent-superblock 1

device /dev/sdb2

raid-disk 0

device /dev/sda2

failed-disk 1

 

raiddev /dev/md1

raid-level 1

nr-raid-disks 2

chunk-size 64k

persistent-superblock 1

device /dev/sdb3

radi-disk 0

device /dev/sda3

failed-disk 1

 

raiddev /dev/md2

raid-level 1

chunk-size 64k

persistent-superblock 1

device /dev/sdb5

raid-disk 0

device /dev/sda5

failed-disk 1

 

then try to mkraid and mke2fs for the above md devices.

 

# mkraid –really-force /dev/md0

# mkraid – really-force /dev/md1

# mkraid – really-force /dev/md2

 

# mke2fs –j /dev/md0

# mkswap /dev/md1

# mke2fs –j /dev/md2

 

then mount them;

 

# cd /mnt

# mkdir newroot

# mount /dev/md2 newroot

# cd newroot

# mkdir boot

# mount /dev/md0 boot

 

then transfer the whole OS to the second hard disk

 

# (cd /;tar cvlpf - . ) | (cd /mnt/newroot; tar xvpf - )

# (cd /boot; tar cvlpf - . ) | (cd /mnt/newroot/boot;tar xvpf - )

 

change /mnt/newroot/etc/fstab to reflect the raid disk information:

 

# cd /mnt/newroot/etc

# vi fstab ( change / to /dev/md2 and /boot to /dev/md0 and swap to /dev/md1 )

 

umount all disk and raid:

 

# cd /mnt

# umount newroot/boot

# umount newroot

 

# raidstop -c /etc/raid /dev/md0

# raidstop -c /etc/raid /dev/md1

# raidstop -c /etc/raid /dev/md2

 

# sync

 

Finally, making a GRUB boot floppy disk before shutdown machine:

 

# cd /usr/share/grub/i386-redhat

# dd if=stage1 of=/dev/fd0 bs=512 count=1

# dd if=stage2 of=/dev/fd0 bs=512 seek=1

# sync

 

Shutdown machine, take out the first hard disk, leave floppy disk inside.

 

3. Installing GRUB for the second hard disk.

 

Even though you leave the second hard disk inside drive, SCSI system will change tag from /dev/sdb to /dev/sda dynamically. so you don't have to put the second hard disk to the first slot, just leave it there.

 

System will boot from floppy disk, bringing you to grub> prompt. Run the following commands.

 

grub> root (hd0,1)

note: specify the partion the kernel live is the first hard disk(hd0) and the second partition (hd0,1)

 

grub> setup (hd0)

note: install GRUB according to above setting, here we don't need to specify 'initrd /initrdxxx' because we compiled everything into kernel.

 

grub> reboot

note: reboot machine and take out the floppy disk

You should be able to boot system, then you can see the following information:

 

[root@localhost i386-redhat]# df -k

Filesystem 1k-blocks Used Available Use% Mounted on

/dev/md2 1517904 1079588 361212 75% /

/dev/md0 54348 15359 36183 30% /boot

none 450296 0 450296 0% /dev/shm

 

 

4. Adding the first hard disk into raid-1 matrix

 

Shutdown machine, put the second hard disk to the first slot, and the first hard disk to second slot, then reboot machine again.

 

After rebooting machine, you can add the original hard disk into raid-1 matrix:

 

use fdisk /dev/sdb (original hard disk) to change /dev/sdb2 /dev/sdb3 and /dev/sdb5 to partition type 'fd'

 

# mv /etc/raid /etc/raidtab

# vi /etc/raidtab

change as follows:

 

[root@localhost i386-redhat]# more /etc/raidtab

raiddev /dev/md0

raid-level 1

nr-raid-disks 2

chunk-size 64k

persistent-superblock 1

device /dev/sda2

raid-disk 0

device /dev/sdb2

raid-disk 1

 

raiddev /dev/md1

raid-level 1

nr-raid-disks 2

chunk-size 64k

persistent-superblock 1

device /dev/sda3

Google
 

发表于: 2008-01-03,修改于: 2008-01-03 14:35,已浏览355次,有评论0条 推荐 投诉

给我留言
版权所有 ChinaUnix.net 页面生成时间:0.018