RHEL4 UP4 下软raid1的创建
这个文档蛮好,其实raid1的创建难在/分区,因为它在系统运行的时候不能被umount下来,如果不对/分区做raid,网上资料到处可见, 我曾经试着用livecd启动系统创建raid1, 但没有成功, 这方法是我碰到的最好的一个方法! 不借助任何其他的工具,这是在国外的网站上找到的资料,加上自己的努力写成的,该方法简单易用!!!!!
1:分区状况介绍如下:
[root@quartz ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 140 1020127+ 82 Linux swap
/dev/sda3 141 1305 9357862+ 83 Linux
显然 /dev/sda1 对应 /boot
/dev/sda2 对应 swap
/dev/sda3 对应 /
打算添加一块硬盘/dev/sdb ,并将其分区为/dev/sdb1 、/dev/sdb2 ,/dev/sdb3
同时 /dev/md0对应/dev/sda1+/dev/sdb1
/dev/md1对应/dev/sda2+/dev/sdb2
/dev/md2对应/dev/sda3+/dev/sdb3
2: 现在创建raid一般都用mdadm(用于创建软raid的工具),一般系统安装时默认安装,可以用
[root@quartz ~]# which mdadm
/sbin/mdadm
[root@quartz ~]# rpm -qa | grep mdadm
mdadm-1.6.0-3
来验证mdadm是否已经安装, 如果出现上面类似的输出,则表示mdadm已经安装!
如果没有安装,到你的系统盘里找到mdadm的包,将其安装!
3:添加一块硬盘,和你现在的硬盘(/dev/sda)大小相同,如下:
[root@quartz ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 140 1020127+ 82 Linux swap
/dev/sda3 141 1305 9357862+ 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
4:raid1实际上就是mirror, 所以要求两个硬盘分区完全相同,下面是复制/dev/sda的分区表到/dev/sdb上去,如下:
[root@quartz ~]# sfdisk -d /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now ...
OK
Disk /dev/sdb: 1305 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdb: unrecognized partition
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sdb1 * 63 208844 208782 83 Linux
/dev/sdb2 208845 2249099 2040255 82 Linux swap
/dev/sdb3 2249100 20964824 18715725 83 Linux
/dev/sdb4 0 - 0 0 Empty
Successfully wrote the new partition table
Re-reading the partition table ...
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
下面查看/dev/sda 和/dev/sdb的分区状况!
[root@quartz ~]# fdisk -l /dev/sda
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 140 1020127+ 82 Linux swap
/dev/sda3 141 1305 9357862+ 83 Linux
[root@quartz ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 104391 83 Linux
/dev/sdb2 14 140 1020127+ 82 Linux swap
/dev/sdb3 141 1305 9357862+ 83 Linux
[root@quartz ~]#
显然这两个硬盘的分区表完全相同!
5:修改/dev/sdb上分区的文件类型(默认是ext3和swap),应该把文件类型修改为raid autodetect
详细过程如下:
[root@quartz ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 104391 83 Linux
/dev/sdb2 14 140 1020127+ 82 Linux swap
/dev/sdb3 141 1305 9357862+ 83 Linux
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): L
0 Empty 1e Hidden W95 FAT1 75 PC/IX be Solaris boot
1 FAT12 24 NEC DOS 80 Old Minix bf Solaris
2 XENIX root 39 Plan 9 81 Minix / old Lin c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 82 Linux swap c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 83 Linux c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 84 OS/2 hidden C: c7 Syrinx
6 FAT16 42 SFS 85 Linux extended da Non-FS data
7 HPFS/NTFS 4d QNX4.x 86 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 87 NTFS volume set de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3
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): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@quartz ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 140 1020127+ 82 Linux swap
/dev/sda3 141 1305 9357862+ 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 104391 fd Linux raid autodetect
/dev/sdb2 14 140 1020127+ fd Linux raid autodetect
/dev/sdb3 141 1305 9357862+ fd Linux raid autodetect
[root@quartz ~]#
#########:接下来确认这块硬盘上没有原来的raid分区
[root@quartz ~]# mdadm --zero-superblock /dev/sdb1
mdadm: /dev/sdb1 does not appear to have an MD superblock.
[root@quartz ~]# mdadm --zero-superblock /dev/sdb2
mdadm: /dev/sdb2 does not appear to have an MD superblock.
[root@quartz ~]# mdadm --zero-superblock /dev/sdb3
mdadm: /dev/sdb3 does not appear to have an MD superblock.
6:下面是创建raid1的过程, 我们把
/dev/md0对应/dev/sda1+/dev/sdb1
/dev/md1对应/dev/sda2+/dev/sdb2
/dev/md2对应/dev/sda3+/dev/sdb3
/dev/sdb1 /dev/sdb2 /dev/sdb3都不能被立刻加上,因为系统在运行!所以正确的添加方式应该为:
运行如下:
[root@quartz ~]# mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1
mdadm: array /dev/md0 started.
[root@quartz ~]# mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb2
mdadm: array /dev/md1 started.
[root@quartz ~]# mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/sdb3
mdadm: array /dev/md2 started.
[root@quartz ~]#
查看raid的状况如下:
[root@quartz ~]# cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sdb3[1]
9357760 blocks [2/1] [_U]
md1 : active raid1 sdb2[1]
1020032 blocks [2/1] [_U]
md0 : active raid1 sdb1[1]
104320 blocks [2/1] [_U]
unused devices:
##([_U] or [U_] means that an array is degraded while [UU] means that the array is ok)
7:下面是格式化的过程!
[root@quartz ~]# mkfs.ext3 /dev/md0
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
26104 inodes, 104320 blocks
5216 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@quartz ~]# mkswap /dev/md1
Setting up swapspace version 1, size = 1044508 kB
[root@quartz ~]# mkfs.ext3 /dev/md2
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1170432 inodes, 2339440 blocks
116972 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2399141888
72 block groups
32768 blocks per group, 32768 fragments per group
16256 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
8:接下来是创建/etc/mdadm.conf,开始这个文件时不存在的
[root@quartz ~]# ls /etc/mdadm.conf
ls: /etc/mdadm.conf: No such file or directory ##显然这个文件不存在
[root@quartz ~]# mdadm --detail --scan >/etc/mdadm.conf ##生成它
[root@quartz ~]# ls /etc/mdadm.conf ##查看文件是否存在
/etc/mdadm.conf
[root@quartz ~]# cat /etc/mdadm.conf ##查看文件的详细内容
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=6f14316d:0c3f2001:7e04c995:6c87ad75
devices=/dev/sdb3
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=50f5ab5a:64846ab9:37b591db:1643f2ab
devices=/dev/sdb2
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=8bc3e58a:7c8fed0b:79a37575:21b51e84
devices=/dev/sdb1
9:接下来是mount /dev/md0 和/dev/md2(/dev/md1暂时不需要mount,因为我们mount的目的是copy东西)
[root@quartz ~]# mkdir /mnt/md0
[root@quartz ~]# mkdir /mnt/md2
[root@quartz ~]# mount /dev/md0 /mnt/md0
[root@quartz ~]# mount /dev/md2 /mnt/md2
[root@quartz ~]# ls /mnt/md0
lost+found
[root@quartz ~]# ls /mnt/md2
lost+found
可以来查看是否已经成功mount上,如下:
[root@quartz ~]# mount | grep md
/dev/md0 on /mnt/md0 type ext3 (rw)
/dev/md2 on /mnt/md2 type ext3 (rw)
显然已经成功mount
10:接下来要修改/etc/fstab和/etc/mtab
/etc/fstab修改前如图:
[root@quartz ~]# cat /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
/dev/hdc /media/cdrom auto pamconsole,exec,noauto,managed 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0
修改后如图:
[root@quartz ~]# vi /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/md2 / ext3 defaults 1 1
/dev/md0 /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
/dev/md1 swap swap defaults 0 0
/dev/hdc /media/cdrom auto pamconsole,exec,noauto,managed 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0
###we modify /etc/fstab. Replace LABEL=/boot with /dev/md0, LABEL=SWAP-sda2 with /dev/md1, and LABEL=/ with /dev/md2
/etc/mtab修改前如图:
[root@quartz ~]# cat /etc/mtab
/dev/sda3 / ext3 rw 0 0
none /proc proc rw 0 0
none /sys sysfs rw 0 0
none /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/sda1 /boot ext3 rw 0 0
none /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/dev/md0 /mnt/md0 ext3 rw 0 0
/dev/md2 /mnt/md2 ext3 rw 0 0
修改后如下:
[root@quartz ~]# cat /etc/mtab
/dev/md2 / ext3 rw 0 0
none /proc proc rw 0 0
none /sys sysfs rw 0 0
none /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/md0 /boot ext3 rw 0 0
none /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/dev/md0 /mnt/md0 ext3 rw 0 0
/dev/md2 /mnt/md2 ext3 rw 0 0
###replace LABEL=/boot with /dev/md0 and LABEL=/ with /dev/md2 in /etc/mtab
11:vi /boot/grub/menu.lst将fallback=1添加到default=0之后,并
replace root=LABEL=/ with root=/dev/md2 and root (hd0,0) with root (hd1,0):
修改后如下:
[root@quartz ~]# cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda3
# initrd /initrd-version.img
#boot=/dev/sda
default=0
fallback=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux AS (2.6.9-42.ELsmp)
root (hd1,0)
kernel /vmlinuz-2.6.9-42.ELsmp ro root=/dev/md2 rhgb quiet
initrd /initrd-2.6.9-42.ELsmp.img
.........
红色字体部分为修改的部分!!
###root (hd1,0) refers to /dev/sdb which is already part of our RAID arrays. We will reboot the system in a few moments; the system will then try to boot from our (still degraded) RAID arrays; if it fails, it will boot from /dev/sda (-> fallback 1).
12:下面修改ramdisk(we adjust our ramdisk to the new situation)
[root@quartz ~]# mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_bak
[root@quartz ~]# mkinitrd /boot/initrd-`uname -r`.img `uname -r`
[root@quartz ~]# ls -l /boot
total 6098
-rw-r--r-- 1 root root 50333 Jul 13 2006 config-2.6.9-42.EL
-rw-r--r-- 1 root root 49926 Jul 13 2006 config-2.6.9-42.ELsmp
drwxr-xr-x 2 root root 1024 Dec 1 11:31 grub
-rw-r--r-- 1 root root 527565 Apr 15 2008 initrd-2.6.9-42.EL.img
-rw-r--r-- 1 root root 525421 Dec 1 11:40 initrd-2.6.9-42.ELsmp.img
-rw-r--r-- 1 root root 516479 Apr 15 2008 initrd-2.6.9-42.ELsmp.img_bak
drwx------ 2 root root 12288 Apr 15 2008 lost+found
-rw-r--r-- 1 root root 23108 Aug 4 2005 message
-rw-r--r-- 1 root root 21282 Aug 4 2005 message.ja
-rw-r--r-- 1 root root 749462 Jul 13 2006 System.map-2.6.9-42.EL
-rw-r--r-- 1 root root 766260 Jul 13 2006 System.map-2.6.9-42.ELsmp
-rw-r--r-- 1 root root 1504146 Jul 13 2006 vmlinuz-2.6.9-42.EL
-rw-r--r-- 1 root root 1444452 Jul 13 2006 vmlinuz-2.6.9-42.ELsmp
显然红色字体是我执行文件后的效果,先备份原来的文件,然后生成了一个新文件,看日期就可以区别(我执行的日期刚好是12月1号)
13:接下来复制/dev/sda1到/dev/md0 、复制/dev/sda3的内容到/dev/md2
[root@quartz ~]# cp -dpRx /boot/* /mnt/md0
[root@quartz md2]# cp -dpRxf / /mnt/md2
14:接下来在/dev/sda和/dev/sdb上安装grub,过程如下:
[root@quartz md2]# grub
Probing devices to guess BIOS drives. This may take a long time.
GNU GRUB version 0.95 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]
grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub> 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)"... 16 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub
.conf"... 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)"... 16 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd1) (hd1)1+16 p (hd1,0)/grub/stage2 /grub/grub
.conf"... succeeded
Done.
grub> quit
reboot 启动机器!
15:如果一切正常!则需要对/dev/sda进行处理(即:修改分区的文件类型!)
过程如下:
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 140 1020127+ 82 Linux swap
/dev/sda3 141 1305 9357862+ 83 Linux
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): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 fd Linux raid autodetect
/dev/sda2 14 140 1020127+ 82 Linux swap
/dev/sda3 141 1305 9357862+ 83 Linux
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
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 fd Linux raid autodetect
/dev/sda2 14 140 1020127+ fd Linux raid autodetect
/dev/sda3 141 1305 9357862+ 83 Linux
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 fd Linux raid autodetect
/dev/sda2 14 140 1020127+ fd Linux raid autodetect
/dev/sda3 141 1305 9357862+ fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mdadm --add /dev/md0 /dev/sda1
mdadm: hot added /dev/sda1
[root@localhost ~]# mdadm --add /dev/md1 /dev/sda2
mdadm: hot added /dev/sda2
[root@localhost ~]# mdadm --add /dev/md2 /dev/sda3
mdadm: hot added /dev/sda3
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sda2[0] sdb2[1]
1020032 blocks [2/2] [UU]
md2 : active raid1 sda3[2] sdb3[1]
9357760 blocks [2/1] [_U]
[>....................] recovery = 0.3% (31360/9357760) finish=9.9min speed=15680K/sec
md0 : active raid1 sda1[0] sdb1[1]
104320 blocks [2/2] [UU]
unused devices:
显然看到[>....................] recovery = 0.3% (31360/9357760) finish=9.9min 表面正在同步!
过个几分钟再次运行
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sda2[0] sdb2[1]
1020032 blocks [2/2] [UU]
md2 : active raid1 sda3[2] sdb3[1]
9357760 blocks [2/1] [_U]
[=================>...] recovery = 88.8% (8314752/9357760) finish=0.3min speed=57830K/sec
md0 : active raid1 sda1[0] sdb1[1]
104320 blocks [2/2] [UU]
unused devices:
看到88.8%, 显然正在同步!而UU表示已经同步完成!
16:再次修改grub, 目的:
We are almost done now. Now we must modify /boot/grub/menu.lst again. Right now it is configured to boot from /dev/sdb (hd1,0). Of course, we still want the system to be able to boot in case /dev/sdb fails. Therefore we copy the first kernel stanza (which contains hd1), paste it below and replace hd1 with hd0. Furthermore we comment out all other kernel stanzas so that it looks as follows:
修改后的内容如下:
cat [root@localhost ~]# cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda3
# initrd /initrd-version.img
#boot=/dev/sda
default=0
fallback=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux AS (2.6.9-42.ELsmp)
root (hd1,0)
kernel /vmlinuz-2.6.9-42.ELsmp ro root=/dev/md2 rhgb quiet
initrd /initrd-2.6.9-42.ELsmp.img
title Red Hat Enterprise Linux AS-up (2.6.9-42.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.ELsmp ro root=/dev/md2 rhgb quiet
initrd /initrd-2.6.9-42.ELsmp.img
注意这里千万不要修改错!如果出错系统就不能进入了。
见我的错误(因为修改错了grub.conf文件)
16:然后更新ramdisk,
[root@localhost etc]# mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig2
[root@localhost etc]# mkinitrd /boot/initrd-`uname -r`.img `uname -r`
17:重启机器即可!
当然raid1还有一种更简单的方法,那就是在安装linux时(两块硬盘做mirror)让系统帮你创建!
这种方式很简单! 就不介绍了!