免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2166 | 回复: 0
打印 上一主题 下一主题

Debian Lenny 迁移至soft raid1简易指南 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-14 15:17 |只看该作者 |倒序浏览
Debian Lenny 迁移至soft raid1简易指南
        By Xiantong,xiantong@gmail.com
        date:2009.12.10
1、查看源盘的分区清况
# fdisk -l
Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00099643
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          61      489951   83  Linux
/dev/hda2              62         183      979965   82  Linux swap / Solaris
/dev/hda3             184        1044     6915982+  83  Linux
2、安装好新硬盘
新硬盘最好和源盘同一型号,如实在不具备,可采用较源盘大的新盘,不过新盘只能当源盘相同大小来使用。
# fdisk /dev/hdb -l
Disk /dev/hdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/hdb doesn't contain a valid partition table
3、安装md tools
# apt-get install mdadm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  mdadm
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/275kB of archives.
After this operation, 799kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously deselected package mdadm.
(Reading database ... 21432 files and directories currently installed.)
Unpacking mdadm (from .../mdadm_2.6.7.2-3_i386.deb) ...
Processing triggers for man-db ...
Setting up mdadm (2.6.7.2-3) ...
Generating array device nodes... done.
Generating mdadm.conf... done.
update-initramfs: deferring update (trigger activated)
Starting MD monitoring service: mdadm --monitor.
Assembling MD arrays...done (no arrays found in config file or automatically).
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-2.6.26-2-686
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
W: mdadm: no arrays defined in configuration file.
4、把源盘hda的分区结构复制到新盘hdb
# sfdisk -d /dev/hda |sfdisk /dev/hdb
Checking that no-one is using this disk right now ...
OK
Disk /dev/hdb: 1044 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/hdb: 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/hdb1   *        63    979964     979902  83  Linux
/dev/hdb2        979965   2939894    1959930  82  Linux swap / So                                                                                                                                               laris
/dev/hdb3       2939895  16771859   13831965  83  Linux
/dev/hdb4             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).)
5、更改hdb的分区为raid分区
# fdisk /dev/hdb
The number of cylinders for this disk is set to 1044.
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): 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): 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
# fdisk /dev/hdb -l
Disk /dev/hdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1   *           1          61      489951   fd  Linux raid autodetect
/dev/hdb2              62         183      979965   fd  Linux raid autodetect
/dev/hdb3             184        1044     6915982+  fd  Linux raid autodetect
6、建立raid1
# mdadm --create /dev/md0 --level=1 --raid-disk=2 missing /dev/hdb1
mdadm: array /dev/md0 started.
debian:~# mdadm --create /dev/md1 --level=1 --raid-disk=2 missing /dev/hdb2
mdadm: array /dev/md1 started.
debian:~# mdadm --create /dev/md2 --level=1 --raid-disk=2 missing /dev/hdb3
mdadm: array /dev/md2 started.
7、格式化raid1相关分区
#mkfs.ext3 /dev/md0
#mkswap /dev/md1
#mkfs.ext3 /dev/md2
8、复制源盘数据至raid
# mount /dev/md2 /mnt
# cp -ax / /mnt
# mount /dev/md0 /mnt/boot/
# cp -ax /boot /mnt
9、修改menu.conf和fstab文件
#vi /mnt/boot/grub/menu.conf
title           Debian GNU/Linux, kernel 2.6.26-2-686
root            (hd0,0)
kernel          /vmlinuz-2.6.26-2-686 root=/dev/md2 md=2,/dev/hda3 ro quiet
initrd          /initrd.img-2.6.26-2-686
title           Debian GNU/Linux, kernel 2.6.26-2-686 (single-user mode)
root            (hd0,0)
kernel          /vmlinuz-2.6.26-2-686 root=/dev/md2 md=2,/dev/hda3 ro single
initrd          /initrd.img-2.6.26-2-686
#vi /mnt/etc/fstab
#               
proc            /proc           proc    defaults        0       0
/dev/md2       /               ext3    errors=remount-ro 0       1
/dev/md0       /boot           ext3    defaults        0       2
/dev/md1       none            swap    sw              0       0
/dev/hdd        /media/cdrom0   udf,iso9660 user,noauto     0       0
# cp /mnt/boot/grub/menu.lst /boot/grub/menu.lst
# cp /mnt/etc/fstab /etc/fstab
10、安装grub引导
#grub
   GNU GRUB  version 0.97  (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>deice (hd0) /dev/hdb
grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
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 (hd1)"...  17 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd1) (hd1)1+17 p (hd1,0)/grub/stage2 /grub/menu.lst"... succeeded
Done.
grub> quit
11、重启系统
#reboot
12、复制hdb分区结构至hda
# sfdisk -d /dev/hdb |sfdisk /dev/hda --force
13、把hda加入到阵列
# mdadm --manage /dev/md0 --add /dev/hda1
mdadm: added /dev/hda1
debian:~# mdadm --manage /dev/md1 --add /dev/hda2
mdadm: added /dev/hda2
debian:~# mdadm --manage /dev/md2 --add /dev/hda3
mdadm: added /dev/hda3
14、查看同步状态
#watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat                            Thu Dec 10 12:50:32 2009
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [ra
id10]
md0 : active raid1 hda1[0] hdb1[1]
      489856 blocks [2/2] [UU]
md1 : active raid1 hda2[0] hdb2[1]
      979840 blocks [2/2] [UU]
md2 : active raid1 hda3[2] hdb3[1]
      6915904 blocks [2/1] [_U]
      [========>............]  recovery = 43.4% (3005440/6915904) finish=3.1min
speed=20378K/sec
unused devices:
直至同步完成。
15、重新安装grub至hda
#grub
    GNU GRUB  version 0.97  (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>device (hd0) /dev/hda
grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
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)"...  17 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/grub/stage2 /grub/menu
.lst"... succeeded
Done.
grub> quit
迁移完成
16、几个常用操作
16.1、移除有问题的raid盘,比如这里移除md0中的hda1
#mdadm --manage /dev/md0 --fail /dev/hda1 --remove /dev/hda1
#mdadm --misc /dev/md0 --zero-superblock /dev/hda1
16.2、移除raid,比如这里移除用做swap的md1
注意md1不能在使用状态。可以通过更改/etc/fstab中的swap为/hda2或者/hdb2,然后重启来确保md1这个raid交换分区,不被使用,或者通过swapoff命令来暂停使用swap
#swapoff /dev/md1
#mdadm --misc /dev/md1 --stop /dev/md1
#mdadm --misc /dev/md1 --zero-superblock /dev/hda2
#mdadm --misc /dev/md1 --zero-superblock /dev/hdb2
# free
             total       used       free     shared    buffers     cached
Mem:        504132      30764     473368          0       3076      16080
-/+ buffers/cache:      11608     492524
Swap:            0          0          0
16.3、重新启用md1
# mdadm --create /dev/md1 --level=1 --raid-disk=2 /dev/hda2 /dev/hdb2
#swapon /dev/md1
# free
             total       used       free     shared    buffers     cached
Mem:        504132      31136     472996          0       3104      16080
-/+ buffers/cache:      11952     492180
Swap:       979832          0     979832
17、注意事项
17.1、使用raid1做为交换分区的时候,系统再没有写交换分区前,交换分区将为是只读状态,一量系统使用了交换分区,就会立刻切换到读写状态
# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 hda1[0] hdb1[1]
      489856 blocks [2/2] [UU]
md1 : active (auto-read-only) raid1 hda2[0] hdb2[1]
      979840 blocks [2/2] [UU]
md2 : active raid1 hdb3[1] hda3[0]
      6915904 blocks [2/2] [UU]
unused devices:
17.2、注意grub的安装
grub引导的时候其实还是使用hdb或者hda的MBR,并不是md0,所以确保hda和hdb的MBR都成功了安装了grub。
17.3、注意grub中的命名规则
root (hd0,0)表示第一块硬盘(hda或sda)的第一个分区(hda1或sda1),其中后一个0表示/boot文件夹所属分区,如果你的/boot分区使用的是/dev/sda2,则这里对应的应该是root (hd0,1)。
17.4、注意复制源盘数据(hda)至raid时的cp命令参数,以确保数据的完整性
        cp -ax或者cp -dpRx
        -d指不复制符号连接的源文件,但是复制该符号连接
        -p复制时保留mode模式,owership属主,以及timestamps时间戳
        -R复制目录及目录内的所有项目
        -x不跨越文件系统进行复制
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12199/showart_2120930.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP