Effectively reduce the size of virtual machine image files

After using this method, the size of the image produced by our project is 2.7G
, and if we do not clean up the image produced by our project, the size of the image produced by our project will be 18G

. In order to make the img file smaller, we need to clean up the garbage in the virtual machine first.
1. The swap area is an area on the hard disk that is designated as memory, and the contents inside can be cleaned up.
2. Format the disk 0 in the free area.

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 , eg,
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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327013173&siteId=291194637