vmware 虚拟机使用存储和真实存储不一致

本文介绍如何通过使用特定工具和技术,如SDelete和dd命令,以及ESXi的vmkfstools,来回收ESXi服务器上精简配置的VMDK文件中未使用的磁盘空间。此过程涉及从虚拟机内部删除数据后重新分配空闲块,最终通过发送SCSI UNMAP命令到存储阵列来缩小VMDK文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Reclaim disk space from thin provisioned VMDK files in ESXi Server

ith thin provisioned disks, you may have noticed that these will continue to grow, and never shrink, even after cleaning out data from within the VM. Currently, VMware does not have automatic space reclamation. Luckily, there are some tools to allow you to reclaim unused space from your virtual thin disks. The only downside is that you have to power off the affected machines.

 

Step 1: Run below command to check information such as firmware revision, thin provisioning status, the VAAI filter and status for the datastore virtual machine is running:

 

# esxcli storage core device list –d naa.60a98000572d54724a346a6170627a52
naa.60a98000572d54724a346a6170627a52
   Display Name: Hitachi Fibre Channel Disk (naa.60a98000572d54724a346a6170627a52)
   Has Settable Display Name: true
   Size: 51200
   Device Type: Direct-Access
   Multipath Plugin: NMP
   Devfs Path: /vmfs/devices/disks/naa.60a98000572d54724a346a6170627a52
   Vendor: HITACHI
   Model: LUN
   Revision: 8020
   SCSI Level: 4
   Is Pseudo: false
   Status: on
   Is RDM Capable: true
   Is Local: false
   Is Removable: false
   Is SSD: false
   Is Offline: false
   Is Perennially Reserved: false
   Thin Provisioning Status: yes
   Attached Filters: VAAI_FILTER
   VAAI Status: supported
   Other UIDs: vml.020033000060a98000572d54724a346a6170627a524c554e202020

Here we see that the device is indeed Thin Provisioned and supports VAAI. Now we can run a command to display the VAAI primitives supported by the array for that device. In particular we are interested in knowing whether the array supports the UNMAP primitive for dead space reclamation (what we refer to as the Delete Status). Another esxcli command is used for this step – 'esxcli storage core  device vaai status get -d  <naa>':

  1. naa.60a98000572d54724a346a6170627a52
           VAAI Plugin Name: VMW_VAAIP_HDS
           ATS Status: supported
           Clone Status: supported
           Zero Status: supported
           Delete Status: supported

The device displays Delete Status as supported meaning that it is capable of sending SCSI UNMAP commands to the array when a space reclaim operation is requested.

 

Step 2: "really" deleting space

 

Reclaiming disk space only works when the blocks on your virtual disk are really empty. Deleting data usually only removes the entries from the file allocation table but does not zero the blocks. As a result, ESX will still think the blocks are in-use. There are a few tools available to do this on Windows- and Linux-hosts.

 

Windows

Download SDelete. This command-line tool has a powerful feature which can track and zero unused blocks. You won't notice a difference in used disk space from within your VM, but this will enable VMware to track unused blocks and release them back to your datastore, effectively shrinking your thin provisioned disk.

 

Open an elevated command prompt and run SDelete:

sdelete.exe -z [drive:]

 

Replace [drive:] with the affected disk or partition. Note that when you have multiple partitions on a single virtual disk, you need to do this on all partitions for it to be effective. Otherwise, reclamation will only be partial because not every data block will be zeroed.

 

Linux

Linux has a different approach. Depending on your filesystem, there are several tools out there, but one that works everytime is by filling free space with a file of zeroes.

First, be sure to shutdown all services which write to the volume you want to shrink as to avoid problems with them running out of free disk space. Next, use ddto completely fill free space with zeroes:

$ dd if=/dev/zero of=/[mounted-volume]/zeroes && rm -f /[mounted-volume]/zeroes

Replace [mounted-volume] with wherever you've mounted the volume. Note that when you have multiple partitions on a single virtual disk, you need to do this on all partitions for it to be effective. Otherwise, reclamation will only be partial because not every data block will be zeroed.

 

Step 3: Run reclaim space in ESX

 

When data has been deleted, you're ready to really reclaim disk space. This is done by "punching out" zeroed blocks in the virtual disk's VMDK file.

First, power off the affected VMs and log into any ESX server with access to the VMFS datastore which has the VMDKs to shrink. Cd to the datastore and volume. Next, launch vmkfstools:

vmkfstools -K [disk].vmdk

Replace [disk] with the disk name. For ESX, don't reference the flat VMDK (usually called disk-flat.vmdk). You have to reference the descriptor file (disk.vmdk).

Depending on the size of the disk, this can be a lengthy process. When finished, all blocks that were previously zeroed from within the VM will now be gone from the VMDK and space will have been reclaimed.

 

  • Note:
  • 1. VMware Horizon View users: Reclamation of disk space won't apply to VDs until your next recompose.
  • 2. This above procedure only works with thin provisioned virtual disks
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

duan737174646

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值