Chinaunix首页 | 论坛 | 博客
  • 博客访问: 481978
  • 博文数量: 82
  • 博客积分: 3003
  • 博客等级: 中校
  • 技术积分: 1285
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-11 15:27
文章分类

全部博文(82)

文章存档

2011年(1)

2010年(5)

2009年(63)

2008年(13)

我的朋友

分类: LINUX

2009-10-10 16:28:11

实验要求:

RHEL中加一块盘,将两块盘做成RAID-1,再从RAID-1上启动

实验环境:

VMware6.5

RHEL5U3

实验步骤:

1,新添一块和原来的盘一样大小的硬盘,开启系统。

2,将所有的分区类型都改为fd类型

#fdisk /dev/sda

首先改sda1

输入t,然后选择要改的分区号1,输入fd类型,输入w保存

sda2,sda3同)

#fdisk -l   查看改了以后的磁盘情况。

Disk /dev/sda: 6442 MB, 6442450944 bytes

255 heads, 63 sectors/track, 783 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         523     4096575   fd  Linux raid autodetect

/dev/sda3             524         654     1052257+  fd  Linux raid autodetect

3,将第一块盘的分区导入到第二块盘中,使两块盘分区情况一致。

[root@localhost ~]# sfdisk -d /dev/sda>part 把分区信息写入part文件,再导入到目标磁盘中,这样操作比较方便

[root@localhost ~]# sfdisk /dev/sdb

Checking that no-one is using this disk right now ...

OK

Disk /dev/sdb: 783 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature

 /dev/sdb: unrecognized partition table type

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   8401994    8193150  83  Linux

/dev/sdb3       8401995  10506509    2104515  82  Linux swap / Solaris

/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).)

[root@localhost ~]# fdisk -l      ####可看到两块盘的分区情况一模一样####

Disk /dev/sda: 6442 MB, 6442450944 bytes

255 heads, 63 sectors/track, 783 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         523     4096575   83  Linux

/dev/sda3             524         654     1052257+  82  Linux swap / Solaris

Disk /dev/sdb: 6442 MB, 6442450944 bytes

255 heads, 63 sectors/track, 783 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         523     4096575   83  Linux

/dev/sdb3             524         654     1052257+  82  Linux swap / Solaris

4,以sda做单盘raid1,不能直接用两块盘建raid1,因为那样同步的话可能会第二块盘把第一块盘同步,两个都成为空盘。

注:这里必须在rescue模式下建Raid阵列,在mount的情况下会报错如下

# mdadm -C /dev/md0 -l1 -n1 /dev/sda1 --force

mdadm: Cannot open /dev/sda1: Device or resource busy

mdadm: create aborted

进入rescue模式后

#mdadm -C  /dev/md1 -l1 -n1 --force /dev/sda1  ----Force to create a Raid 1 md0 with only one disk,注:在4U7的环境下 --force必须在/dev/md1之前

#mdadm  /dev/md1 -a /dev/sdb1       --Add  /dev/sda1 as a spare disk into md0

#mdadm  /dev/md1 -G -n2   --Using -G option to update the Raid 1 and make it to a two-disks Raid device

(md1,md2 are the same)

#mdadm -C  /dev/md2 -l1 -n1 --force /dev/sda2

#mdadm  /dev/md2 -a /dev/sdb2

#mdadm  /dev/md2 -G -n2

#swapoff  /dev/sda3

#mdadm -C  /dev/md3 -l1 -n1 --force /dev/sda3

#mdadm  /dev/md3 -a /dev/sdb3

#mdadm  /dev/md3 -G -n2

#cat /proc/mdstat    

Raid上新建swap分区

#mkswap /dev/md2

#swapon /dev/md2

5,修改/boot/grub/grub.conf文件,把root指向的label给改了,要找到该配置文件,必须把根给挂上

#mkdir /mnt/sysimage

#mount /dev/md2 /mnt/sysimage

#mount /dev/md1 /mnt/sysimage/boot

#chroot /mnt/sysimage

#vi /boot/grub/grub.conf

Root=/dev/md2

6,修改/etc/fstab文件,把系统启动自动挂载的设备改成mdX的设备

#vi /etc/fstab

/dev/md2          /         ext3       defaults        1 1

/dev/md1         /boot         ext3       defaults      1 1

...

/dev/md3         swap         swap       defaults        0 0

(这里直接把原来swap那一行注释掉也可以)

 

7,重启系统,再进一次rescue模式,这时选择continue而不是skip,进入/boot目录下重做镜像文件。因为重新加载了Raid设备,所以要重做镜像文件把设备加载到系统中。

#chroot /mnt/sysimage

#cd boot/

#mv initrd-2.6.18-128.el5.img /tmp/

# mkinitrd initrd-2.6.18-128.el5.img $(uname -r)     重建镜像

# gunzip -cd initrd-2.6.18-128.el5.img | cpio -vid  

# ls -R 查看镜像文件看raid有没有加载成功

8,发现有raid模块后重启系统,系统正常启动到第四阶段会报错说/的文件系统大小大于物理设备,要求进repair模式调整,但是因为在mount的状态下不能进行e2fsck -f /dev/xxx 的操作,所以得重新进rescue模式调根的大小。

这里有两种方法

1,选择skip方法进救援模式,因为是skip的,所以系统找不到md1,不能对其直接进行操作,只能分别对sda2sdb2同时进行操作

#e2fsck -f /dev/sda2

#e2fsck -f /dev/sdb2

#resize2fs /dev/sda2

#resize2fs /dev/sdb2

2,也可以选择continue的方式进入救援模式,再umount /mnt/sysimage/...下的所有文件,再对md1进行操作就可以了

# mount 查看都mount上了哪些文件,再一个个卸掉

#umount /mnt/sysimage/boot

#umount /mnt/sysimage/dev

#umount /mnt/sysimage/sys

#umount /mnt/sysimage/proc

#umount /mnt/sysimage/

#e2fsck -f /dev/md1

# resize2fs /dev/md1

9#exit  重启系统发现又出现类似的报错,不过这次是在/boot 上,与第八步同样的方法进行文件系统的调整,选continue方法进去到救援模式

#umount /mnt/sysimage/boot

#e2fsck -f /dev/md0

# resize2fs /dev/md0

再重启就可以正常启动了

注:如果有其他的文件系统出现第89步的类似报错,还要依次修改这些文件系统的大小才行。

 

ok,实验完成。

阅读(2036) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~