有效减少虚拟机镜像文件的大小

使用该方法后我们项目制作出的镜像大小在2.7G
而如果不做清理我们项目制作出的镜像会有18G

为了制作的img文件较小,我们需要先清理虚拟机中的垃圾。
1.交换区做为硬盘上被划为内存使用的区域,里面的内容是可以清理的。
2.把空闲区域的磁盘0格式化。

Shrinking the Disks
When you export your VMs in your OVF package you want to make sure
that all unused space is zeroed out, since this compresses really well
in the VMDK disk format. However, space used by swap disks and deleted
files often take up space on disk, since they are not eagerly zeroed
out by default by most operating systems. This means that even though
your VM says it only uses about 500 MB it may actually take up a lot
more space. Even worse, you may have confidential information on, e.g.,
your swap drive or old deleted files that you do not want to distribute
with the OVF package. There are several ways to solve this problem. On
most Linux distributions it is possible to do the following things to
clean up a disk before you export the VM: 1) Un-mount the swap drive;
2) Write a single file to disk containing only zeroes as large as
possible; 3) Delete the file immediately after you created it. On the
command line you can do these three steps by invoking these commands:
1. /sbin/swapoff -a (this will un-mount all swap disks)
2. dd if=/dev/zero of=zeroFile.tmp
3. rm zeroFile.tmp


使用vsphere制作ovf/ova img
stop the vm
In the vSphere Web Client, navigate to a virtual machine or vApp and select Export OVF Template from the Inventory Actions menu.

猜你喜欢

转载自lawrencej.iteye.com/blog/2244253