歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 復制REDHAT系統

復制REDHAT系統

日期:2017/2/27 14:22:26   编辑:更多Linux
  本文講述一種實踐方法:將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.



Copyright © Linux教程網 All Rights Reserved