压缩虚拟机硬盘大小方法
2014-04-23 15:04
375 查看
在实际运维中,特别是p2v后的虚拟机,占用存储空间较大,能否收缩磁盘占用存储空间大小呢?
实际测试发现可行。
1.首先虚拟机存储占用空间查看方法:1)client在虚拟机概要面板右边存储使用情况中,浏览存储中进入虚拟机文件夹也可以看到vmdk大小。2)web client也是在概要面板查看,但没有刷新按钮,存储大小有更新,不方便了解情况。
2.测试虚拟机增加大文件后删除大文件,在存储空间查看界面就可以看到存储使用变大,但删除文件后,存储空间不会变小。
3.此时就要采用方法进行压缩磁盘。
方法如下:
首先要在系统上,把所有没用的数据写零,特别特别注意,执行下列命令之前,请确保存储空间剩余空间超过硬盘置备大小减去实际占用大小。及日常使用增长情况估算,对数据写零操作跟硬盘大小有关,硬盘较大,时间也较长。
linux下执行
dd if=/dev/zero of=/bigemptyfile
rm /bigemptyfile
windows下执行
sdelete -c -z C:\
再关闭系统,开始压缩硬盘文件
vmkfstools -K /path/to/disk-name.vmdk
注意:一些网站上介绍可以采用存储vmotion可以压缩,实测发现是有条件的,必须二个存储块大小不一致,而实际中,公司存储块大小基本是一致的,所以网上介绍的不对,详情请参考如下:
英文文档请参考链接http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004155
Null blocks are copied from source to destination resulting in a VMDK that is the same size, despite thin being chosen as the destination disk type.
When attempting to thin a disk after either using VMware Tools Prepare to shrink option or using a third-party product to zero disk blocks within a guest operating system, null blocks are copied.
When the source filesystem uses a different blocksize from the destination filesystem, the legacy datamover (FSDM) is used. When the blocksizes of source and destination are equal, the new datamover (FS3DM) is used. FS3DM decides if it will use VAAI or just the software component. In either case, null blocks are not reclaimed.
To work around this issue, Storage vMotion the virtual machine or VMDK to a datastore that has a different block size. This reclaims the zeroed out disk space.
To shrink a thin provisioned disk (VMDK):Use a third-party tool within the guest operating system to zero-out disk blocks that may have previously been written with data, but have subsequently been deleted.
Storage vMotion the virtual machine or VMDK to a datastore formatted with a different block size.
For example, if the VMDK is on a datastore formatted with 2 MB blocks, format the target VMFS datastore with a 1 MB, 4 MB, or 8 MB block size.
To reclaim the unused space of a virtual disk in ESXi/ESX 4.1 or later:Note: Where vmkfstools supports the -K option (--punchzero), you can reclaim the zeroed blocks of thin-provisioned virtual disks without the need to clone to another VMFS datastore with a different block size.
Ensure the disk has no Snapshots.
In a Windows virtual machine, use the
Note: Zeroing all unused blocks inflates the disk to its full size and converts it into an eagerzeroed disk. If the original disk is a thin provisioned disk, ensure there is sufficient space on the datastore to allow the disk to grow to its full size. For more information, seeDetermining if a VMDK is zeroedthick or eagerzeroedthick (1011170).
Shut down the virtual machine or temporarily remove the virtual disk from the virtual machine to ensure it is not in use.
Erase all unused blocks by running the command:
This option de-allocates all zeroed out blocks and leaves only those blocks that were allocated previously and contain valid data. The resulting virtual disk is in thin format. For more information on the
本文出自 “IT技术” 博客,请务必保留此出处http://lysweb.blog.51cto.com/3468677/1401165
实际测试发现可行。
1.首先虚拟机存储占用空间查看方法:1)client在虚拟机概要面板右边存储使用情况中,浏览存储中进入虚拟机文件夹也可以看到vmdk大小。2)web client也是在概要面板查看,但没有刷新按钮,存储大小有更新,不方便了解情况。
2.测试虚拟机增加大文件后删除大文件,在存储空间查看界面就可以看到存储使用变大,但删除文件后,存储空间不会变小。
3.此时就要采用方法进行压缩磁盘。
方法如下:
首先要在系统上,把所有没用的数据写零,特别特别注意,执行下列命令之前,请确保存储空间剩余空间超过硬盘置备大小减去实际占用大小。及日常使用增长情况估算,对数据写零操作跟硬盘大小有关,硬盘较大,时间也较长。
linux下执行
dd if=/dev/zero of=/bigemptyfile
rm /bigemptyfile
windows下执行
sdelete -c -z C:\
再关闭系统,开始压缩硬盘文件
vmkfstools -K /path/to/disk-name.vmdk
注意:一些网站上介绍可以采用存储vmotion可以压缩,实测发现是有条件的,必须二个存储块大小不一致,而实际中,公司存储块大小基本是一致的,所以网上介绍的不对,详情请参考如下:
英文文档请参考链接http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004155
Storage vMotion to thin disk does not reclaim null blocks (2004155)
Symptoms
When using Storage vMotion to move a thin disk between two VMFS volumes with the same block size, null blocks are not reclaimed.Null blocks are copied from source to destination resulting in a VMDK that is the same size, despite thin being chosen as the destination disk type.
When attempting to thin a disk after either using VMware Tools Prepare to shrink option or using a third-party product to zero disk blocks within a guest operating system, null blocks are copied.
Cause
This issue occurs when the destination datastore is of the same block size as the source datastore, regardless of whether the datastores are VMFS3 or VMFS5.When the source filesystem uses a different blocksize from the destination filesystem, the legacy datamover (FSDM) is used. When the blocksizes of source and destination are equal, the new datamover (FS3DM) is used. FS3DM decides if it will use VAAI or just the software component. In either case, null blocks are not reclaimed.
Resolution
This is expected behavior.To work around this issue, Storage vMotion the virtual machine or VMDK to a datastore that has a different block size. This reclaims the zeroed out disk space.
To shrink a thin provisioned disk (VMDK):Use a third-party tool within the guest operating system to zero-out disk blocks that may have previously been written with data, but have subsequently been deleted.
Storage vMotion the virtual machine or VMDK to a datastore formatted with a different block size.
For example, if the VMDK is on a datastore formatted with 2 MB blocks, format the target VMFS datastore with a 1 MB, 4 MB, or 8 MB block size.
To reclaim the unused space of a virtual disk in ESXi/ESX 4.1 or later:Note: Where vmkfstools supports the -K option (--punchzero), you can reclaim the zeroed blocks of thin-provisioned virtual disks without the need to clone to another VMFS datastore with a different block size.
Ensure the disk has no Snapshots.
In a Windows virtual machine, use the
SDeletecommand (or a tool with similar functionality) to zero out all unused space. The syntax for the SDelete command is SDelete -z <driveletter>. If you use
SDelete, ensure that you use version 1.6 or later.
Note: Zeroing all unused blocks inflates the disk to its full size and converts it into an eagerzeroed disk. If the original disk is a thin provisioned disk, ensure there is sufficient space on the datastore to allow the disk to grow to its full size. For more information, seeDetermining if a VMDK is zeroedthick or eagerzeroedthick (1011170).
Shut down the virtual machine or temporarily remove the virtual disk from the virtual machine to ensure it is not in use.
Erase all unused blocks by running the command:
vmkfstools -K /path/to/disk-name.vmdk
This option de-allocates all zeroed out blocks and leaves only those blocks that were allocated previously and contain valid data. The resulting virtual disk is in thin format. For more information on the
vmkfstoolscommand, see Removing Zeroed Blocks in the ESX Configuration Guide.
See Also
Determining if a VMDK is zeroedthick or eagerzeroedthick (1011170)Request a Product Feature
To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.本文出自 “IT技术” 博客,请务必保留此出处http://lysweb.blog.51cto.com/3468677/1401165
相关文章推荐
- 压缩虚拟机硬盘(VMDK VDI)大小
- 扩大虚拟机的硬盘大小方法
- 虚拟机添加硬盘修改/etc/fstab错误,导致无法正常访问(freebsd),解决方法
- VMware vm linux 虚拟机 硬盘空间不足 磁盘最大大小调整 方案
- wdcp的/www目录大小调整或增加分区/硬盘的方法
- Linux系统下批量压缩图片尺寸大小的方法
- asp.net 图片超过指定大小后等比例压缩图片的方法
- VMware 虚拟机中添加新硬盘的方法
- VMware vm linux 虚拟机 硬盘空间不足 磁盘最大大小调整 方案
- VMware虚拟机修改硬盘大小的方法
- (转贴) VM虚拟机改硬盘大小的方法
- VMware 虚拟机中添加新硬盘的方法
- 如何扩大虚拟机硬盘容量大小
- Centos7.2在虚拟机Vmware中增加硬盘的方法
- 扩展虚拟机的虚拟硬盘的大小的方法
- X Chen笔记---KVM调整虚拟机硬盘大小
- VMware 虚拟机中添加新硬盘的方法
- vps分区 挂载wdcp 的/www目录大小调整或增加分区/硬盘的方法
- 最新图片质量和按大小压缩方法
- Win8.1系统怎么查看硬盘大小?Win8.1查看硬盘容量的方法