您的位置:首页 > 其它

使用dd 批量安装gentoo 系统

2009-03-21 16:02 363 查看
使用dd 批量安装gentoo 系统

一.源机器分区情况:
hda1 为:boot(启动分区)
hda2 为:swap(交换分区)
hda3 为:boot (根 / 分区)
hda4 为:data (数据盘)

#fdisk -l /dev/hda
Disk /dev/hda: 11.8 GB, 11811160064 bytes
15 heads, 63 sectors/track, 24411 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
Disk identifier: 0x0eb4a58f

Device Boot Start End Blocks Id System
/dev/hda1 * 1 621 293391 83 Linux
/dev/hda2 622 1680 500377+ 82 Linux swap / Solaris
/dev/hda3 1681 10147 4000657+ 83 Linux
/dev/hda4 10148 24411 6739740 83 Linux

#cat /etc/fstab
/dev/hda1 /boot ext2 noauto,noatime 1 2
/dev/hda3 / ext3 noatime 0 1
/dev/hda2 none swap sw 0 0
/dev/hda4 /data ext3 noatime 0 1

备份源机器分区:
1.备份启动分区(boot)到数据盘
dd if=/dev/hda1 | gzip >/data/hda1.gz
2.备份根分区(/) 到数据盘
dd if=/dev/hda3 | gzip >/data/hda3.gz

二,目标机器:
1.使用启动盘启动系统
2.分区:把 boot swap / 这3个分区分成跟源机器一样的大小。
还有分出一个数据盘来存放 源机器备份下来的文件。
#mke2fs /dev/hda1
#mke2fs -j /dev/hda3
#mke2fs -j /dev/hda4
#mkswap /dev/hda2 && swapon /dev/hda2
#mkdir /data
#mount /dev/hda4 /data
#cat /etc/fstab
/dev/hda1 /boot ext2 noauto,noatime 1 2
/dev/hda3 / ext3 noatime 0 1
/dev/hda2 none swap sw 0 0
/dev/hda4 /data ext3 noatime 0 1

3.把源机器的备份文件拉到数据盘
#scp root@192.168.230.132:/data/hda1.gz /data/
#scp root@192.168.230.132:/data/hda3.gz /data/

4.恢复系统:
#gzip -dc /data/hda1.gz | dd of /dev/hda1
#gzip -dc /data/hda3.gz | dd of /dev/hda3

5.grub 使用 dd 恢复系统会造成错误,不能启动,所以必须重新配置一下grub
#mount /dev/hda3 /mnt/gentoo
#mount /dev/hda1 /mnt/gentoo/boot
#mount -t proc proc /mnt/gentoo/proc
#mount -o bind /dev /mnt/gentoo/dev
#chroot /mnt/gentoo /bin/bash
#env-update && source /etc/profile
>>> Regenerating /etc/ld.so.cache...

# grub
Probing devices to guess BIOS drives. This may take a long time.

grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd

grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 16 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 /boot/
grub/menu.lst"... succeeded
Done.

grub> quit

到此为止,系统已经完全恢复好,重新启动系统。

6.(注意)dd 恢复系统也会造成网卡不能启动:

启动网卡错误表现:
#/etc/init.d/net.eth0 start
*Starting eth0
* Bringing up eth0
* dhcp
* network interface eth0 does not exist
* Please verify hardware or kernel module (driver)

查看 /var/log/kennel/Current 日志发现
Mar 21 12:40:04 [kernel] pcnet32.c:v1.35 21.Apr.2008 tsbogend@alpha.franken.de
Mar 21 12:40:04 [kernel] pcnet32 0000:02:00.0: PCI INT A -> GSI 18 (level, low) -> IRQ 18
Mar 21 12:40:04 [kernel] pcnet32: PCnet/PCI II 79C970A at 0x2000, 00:0c:29:94:de:df assigned IRQ 18.
Mar 21 12:40:04 [kernel] eth0: registered as PCnet/PCI II 79C970A
Mar 21 12:40:04 [kernel] pcnet32: 1 cards_found.
Mar 21 12:40:04 [kernel] Floppy drive(s): fd0 is 1.44M
Mar 21 12:40:04 [kernel] FDC 0 is a post-1991 82077
Mar 21 12:40:04 [kernel] udev: renamed network interface eth0 to eth1

interface eth0 to eth1 这里有个改名的日志(因为:系统从源电脑备份来的,网卡的mac 记录的是源电脑网卡的mac,跟目标电脑的网卡的mac不匹配,系统会自动识别网卡的mac,并在/etc/udev/rules.d/70-persistent-net.rules 文件中产生一条正确的记录)

A:解决方法一
ls /etc/init.d/
lrwxrwxrwx 1 root root 6 Mar 18 21:54 net.eth0 -> net.lo
-rwxr-xr-x 1 root root 30696 Apr 26 2008 net.lo
并没有 net.eth1 启动文件
#cd /etc/init.d/
#ln -s net.lo net.eth1

重新启动网卡
#/etc/init.d/net.eth1 start (ok)

B:解决方法二
编辑:/etc/udev/rules.d/70-persistent-net.rules
查出ATTR{address} 跟源电脑网卡mac一样的 注掉,重新启动电脑,网卡就可以使用了。
# This file was automatically generated by the /lib/udev/write_net_rules
# program run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.

# PCI device 0x1022:0x2000 (pcnet32)
#查出ATTR{address} 跟源电脑网卡mac一样的 注掉
#SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:0c:29:95:53:ca", NAME="eth1"

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:0c:29:94:de:df", NAME="eth0"

注:查看网卡的mac 可以简单的使用启动盘,启动系统查看。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: