複製RedHat Linux系統(轉貼,,中英文)(轉)

BSDLite發表於2007-08-11
複製RedHat Linux系統(轉貼,,中英文)(轉)[@more@]本文講述一種實踐方法:將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 --&gt B:/x/boot
A:/ --&gt B:/x
A:/usr --&gt B:/x/usr
A:/var --&gt B:/x/var
A:/var/www --&gt B:/x/var/www
A:/home --&gt 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 --&gt B: /mnt/boot
A: /usr --&gt B: /mnt/usr
A: / (including /sbin, /etc, /bin, /etc, and the other stuff whatever on / file system, except for /proc, /tmp, /dev) --&gt B: /mnt
A: /var --&gt 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.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10617542/viewspace-945723/,如需轉載,請註明出處,否則將追究法律責任。

相關文章