hpserver# mount /dev/ad1s1e /mnt
4、将数据迁移,这里也有两种方法,一种是使用tar,另一种是使用dump,我分别介绍,大家可以根据需要而选择备份方式。
(1) 使用tar备份并还原数据。
hpserver# cd /var
hpserver# tar cf - * | (cd /mnt; tar xf -)
(2) 使用dump备份并用restore还原数据。就我个人而言,我推荐使用这种方法,因为我曾经试过用tar备份var目录的时候,出现了错误并自动停止,我分析了一下原因,一些正在使用的文件或者临时文件可能不能备份,但dump不是以文件为单位,而是而block为单位的,应该不存在这样的情况,所以这是我推荐使用dump和restore的原因。
hpserver# cd /mnt
hpserver# dump -f- /var | restore -f- -r
在过程中和结束会出现类似以下信息:
DUMP: Date of this level 0 dump: Wed Jan 14 23:44:35 2004
DUMP: Date of last level 0 dump: the epoch
DUMP: Dumping /dev/ad0s1e (/var) to standard output
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 305 tape blocks.
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: DUMP: 361 tape blocks
DUMP: finished in less than a second
DUMP: DUMP IS DONE
5、有一点提醒的是,你要确保备份后没有数据写入原来的/var,否则,这些数据没有备份到新分区中。结束后别忘了检查一下结果,并卸载/mnt。
hpserver# ls /mnt
hpserver# umount /mnt
6、编辑/etc/fstab文件,将原来指向/var的文件系统改为/dev/ad1s1e,重新启动就可生效。
9.2. How do I move my system over to my huge new disk?
The best way is to reinstall the OS on the new disk, then move the user data over. This is highly recommended if you have been tracking -STABLE for more than one release, or have updated a release instead of installing a new one. You can install booteasy on both disks with boot0cfg(, and dual boot them until you are happy with the new configuration. Skip the next paragraph to find out how to move the data after doing this.
Should you decide not to do a fresh install, you need to partition and label the new disk with either /stand/sysinstall, or fdisk( and disklabel(. You should also install booteasy on both disks with boot0cfg(, so that you can dual boot to the old or new system after the copying is done. See the formatting-media article for details on this process.
Now you have the new disk set up, and are ready to move the data. Unfortunately, you cannot just blindly copy the data. Things like device files (in /dev), flags, and links tend to screw that up. You need to use tools that understand these things, which means dump(. Although it is suggested that you move the data in single user mode, it is not required.
You should never use anything but dump( and restore( to move the root filesystem. The tar(1) command may work - then again, it may not. You should also use dump( and restore( if you are moving a single partition to another empty partition. The sequence of steps to use dump to move a partitions data to a new partition is:
1.
newfs the new partition.
2.
mount it on a temporary mount point.
3.
cd to that directory.
4.
dump the old partition, piping output to the new one.
For example, if you are going to move root to /dev/ad1s1a, with /mnt as the temporary mount point, it is:
# newfs /dev/ad1s1a
# mount /dev/ad1s1a /mnt
# cd /mnt
# dump 0af - / | restore xf -
Rearranging your partitions with dump takes a bit more work. To merge a partition like /var into its parent, create the new partition large enough for both, move the parent partition as described above, then move the child partition into the empty directory that the first move created:
# newfs /dev/ad1s1a
# mount /dev/ad1s1a /mnt
# cd /mnt
# dump 0af - / | restore xf -
# cd var
# dump 0af - /var | restore xf -
To split a directory from its parent, say putting /var on its own partition when it was not before, create both partitions, then mount the child partition on the appropriate directory in the temporary mount point, then move the old single partition:
# newfs /dev/ad1s1a
# newfs /dev/ad1s1d
# mount /dev/ad1s1a /mnt
# mkdir /mnt/var
# mount /dev/ad1s1d /mnt/var
# cd /mnt
# dump 0af - / | restore xf -
You might prefer cpio(1), pax(1), tar(1) to dump( for user data. At the time of this writing, these are known to lose file flag information, so use them with caution.作者: wangbin 时间: 2007-05-18 16:05
支持!!!!!!!!作者: lbt5210 时间: 2007-10-29 01:35
好文!!!!作者: bestwc 时间: 2007-10-29 02:46
已经看过了,似乎是永远的Unix上的文章。作者: fish_happy 时间: 2008-05-22 13:13
ddddddddddddd作者: @kang 时间: 2008-06-03 14:06
確實是用dump | restore 比較方便,我也是用此法更換過一個硬盤。作者: 我自逍遥 时间: 2008-10-22 14:56
用此方法克隆了一套系统。成功。作者: wangbin 时间: 2008-10-24 21:14
过了这些年了,还有没有更好的方法!