红联Linux门户
Linux帮助

复制RedHat Linux系统(转贴,,中英文)

发布时间:2006-02-15 08:26:04来源:红联作者:007
本文讲述一种实践方法:将REDHAT LINUX系统(包括操作系统,应用程序,数据)从一个物理的系统复制到另一个兼容的物理的系统. 此方法可应用于系统迁移(Server Migration), 系统硬件升级(Server H/W Upgrade), 系统灾难恢复(O.S. Disaster Recovery)等.

假定被复制的系统(源系统)为A系统,将要建立的系统(目标系统)为B系统.两者都采用固定IP.

步骤如下:

1. 在目标系统上安装小的操作系统

在B系统上安装一个小的Linux,并配制其网络.在安装过程中选择"Server",且去除X Window, Web, Samba, FTP等.只需建2个分区, /(够用就行)和swap(亦将在最终系统上被使用).

安装光盘的版本须与源系统的版本一致.

2. 在目标系统上创建文件系统

按照A系统上的文件系统层次和大小,在B系统上创建相应的相同大小的文件系统.文件系统的大小可根据实际情况作相应调整.

譬如,A系统上有 /, /boot, /tmp, /usr, /var, /var/www, /home, 那么,在B系统上就创建/x, /x/boot, /x/tmp, /x/usr, /x/var, /x/var/www, /x/home.

此步骤亦可在安装操作系统时进行.

3. 将数据从源系统复制到目标系统

把操作系统,应用程序及其数据从A系统复制到B系统的新建的相应的文件系统上,并修改/x/etc/fstab.

A:/boot --> B:/x/boot
A:/ --> B:/x
A:/usr --> B:/x/usr
A:/var --> B:/x/var
A:/var/www --> B:/x/var/www
A:/home --> B:/x/home

根文件系统的复制须包括所有在A系统根文件系统上,除了/proc, /tmp, /dev的数据.

将数据从A:/复制到B:/x的命令行大致为(须根据实际情况):
[ B # ] ssh A "cd /; tar -czf - bin etc initrd misc lib sbin root" | (cd /x; tar -xzf -)

将数据从A:/boot复制到B:/x/boot的命令行为:
[ B # ] ssh A "cd /; tar -czf - boot" | (cd /x; tar -xzf -)

将数据从A:/var/www复制到B:/x/var/www的命令行为:
[ B # ] ssh A "cd /var; tar -czf - www" | (cd /x/var; tar -xzf -)

若A:/var上一些大的日志文件或临时文件无需复制,可用在tar命令行中加--exclude-from:
[ B # ] ssh A "cd /;tar --exclude-from=/home/chinaux/var.exclude -czf" | (cd /x; tar -xzf -)
然后在B:/x/var上根据实际需要"touch"这些文件.

4. 复制新装系统的设备文件

在目标系统上将新装系统的设备文件复制到新建文件系统/x上:
[ B # ] (cd /; tar -czf - dev) | (cd /x; tar xzf -)

5. 创建/proc, /tmp等

[ B # ] mkdir -m 755 /x/proc

[ B # ] mkdir -m 755 /x/mnt
[ B # ] mkdir -m 755 /x/mnt/floppy /x/mnt/cdrom

[ B # ] mkdir -m 1777 /x/tmp ## 若/tmp将在根文件系统上
或,
[ B # ] chmod 1777 /x/tmp ## 若/tmp将为一独立的文件系统

6. 置换设备驱动程序

比较/etc/modules.conf, /x/etc/modules.conf; 比较"lsmod"在系统A和系统B上的输出. 若两者使用不同的设备驱动,在系统B上安装所需设备驱动程序(若有此需要; 安装的根目录为/x),修改/etc/modules.conf, 重建RAMDISK(# chroot /x; mkinitrd ...).

通常需要置换设备驱动程序是SCSI,NIC设备驱动.

此步骤可省略若源系统和目标系统的硬件相同或相似.

7. 修改引导菜单,网络配置

添加复制的操作系统到/boot/grub/grub.conf上(保留其原有行,以防复制的系统不可引导); 修改/x/etc/hosts, /x/etc/sysconfig/network和/x/etc/sysconfig/network-scripts/ifcfg-eth0.

8. 重启目标系统

重启B系统,并引导复制的操作系统.若引导失败,引导至所安装的小系统,并解决问题.


How to duplicate RedHat to another system

The following describes a workaround to copy a Redhat Linux(inculding applications & data) from one system to another, even they have different models of HDs and different H/W.

Assuming the box to be modelled after is system A, and the system to be built is system B, the prodedure is as follows:

1. create a minimum O.S. on the target system

install mininum Linux on system B with networking enabled(a small / and desired swap, e.g. hda1 & hda2)

2. create file systems on the target system

follow the file system layout on system A to create partions on system B, and mount them, e.g. /mnt/boot, /mnt, /mnt/usr, /mnt/var. /mnt/tmp. re-use the swap, so no need to create a new swap.

note: mount /mnt at first, then create the directories /mnt/boot, /mnt/usr, etc., and mount the file systems.

3. copy the data from the source system to the target system

copy the O.S. and other data on system A to system B

A: /boot --> B: /mnt/boot
A: /usr --> B: /mnt/usr
A: / (including /sbin, /etc, /bin, /etc, and the other stuff whatever on / file system, except for /proc, /tmp, /dev) --> B: /mnt
A: /var --> B: /mnt/var

the command to copy A:/boot to B:/mnt/boot is
[ system B # ] ssh systemA "cd /; tar czf - boot" | (cd /mnt/; tar xzf -)

the command to copy A:/sbin to B:/mnt/sbin is
[ system B # ] ssh systemA "cd /; tar czf - boot" | (cd /mnt/; tar xzf -)

4. fix /tmp, /proc, /dev on the target system

[ system B # ] mkdir -m 755 /mnt/proc
[ system B # ] (cd /; tar czf - dev) | (cd /mnt/; tar xzf -)
[ system B # ] mkdir -m 1777 /mnt/tmp ## if /tmp will be on / file system
or,
[ system B # ] chmod 1777 /mnt/tmp ## if /tmp will be a seperate file system
5. fix driver issues (scsi driver, NIC drivers, etc)
compare /etc/module.conf & /mnt/etc/module.conf; compare the outputs of "lsmod" on the 2 systems

if a driver is required, install it (the root directory should be changed to /mnt), modify /mnt/etc/modules.conf, rebuild ramdisk image if neccessary(# chroot /mnt; mkinitrd ....)

6. fix bootup, networking & file system table

modify /boot/grub/grub.conf (don't remove the orignial entry in case the duplicated O.S. cannot be booted up), /mnt/etc/fstab, /mnt/etc/hosts, /mnt/etc/sysconfig/network and /mnt/etc/sysconfig/network-scripts/ifcfg-eth0.

7. reboot system B, boot from the duplicated O.S. - done

if the bootup fails, boot it from original minimum O.S., and fix the problems.
文章评论

共有 1 条评论

  1. pinkfirex 于 2006-07-20 11:12:54发表:

    good