Due to insufficient pre-planning in the work, disk space allocation is large, and is thick-provisioned. When the latter is no longer needed, the space can not be freed up, resulting in wasted space. After groping and experimental verification, summed up a set of methods.
Risk Warning: This method is validated in my environment, but does not mean that it is suitable for all situations, and the production environment must be cautious!
Environment: Esxi 6.5,vcenter 6.5 u1e,ubuntu 16.04
Since the initial allocation to the Ubuntu 16.04 virtual machine hard disk space is 2T, the amount of late data increases the need to increase space, the Discovery partition table is not GPT, cannot exceed 2T.
resulting in the virtual machine in the vcenter to increase the space wasted, that is, the number can only be raised, can not be lowered.
VMware Official provides a workaround for this situation: by migrating, changing the vdisk format, from "thick provisioning" to "thin provisioning", reducing the amount of space actually occupied.
Official website: https://kb.vmware.com/s/article/2014832
Processed through official solutions, as shown, with mixed results
Hi is the actual occupancy of the space really reduced, the worry is that the reduced space is only unallocated unallocated this part, previously allocated space, although the file has been deleted, but does not decrease.
By finding a variety of data, we think of a method that is validated by the following experiments. 1. Assign 40G Thick-provisioned hard disk space to the virtual machine and install the system, without any operation after installation, and shut down directly.
2. After shutting down the virtual machine, the virtual disk format is changed from "thick provisioning" to "thin provisioning", and the space has been reduced to 6GB, which means that the official method can reduce the actual space consumption without writing data.
3. Migrate the virtual machine again, change the virtual disk format from "Thin provisioning" to "thick provisioning", and then copy the large file to fill the hard disk space.
4. Delete the large files, migrate the virtual machines after shutting down, and change the virtual disk format from "thick provisioning" to "thin provisioning". As you can see, although large files are deleted, it is only possible to reclaim a small piece of space that has not been written to data by way of migration.
5. Start the virtual machine with SYSTEMRESCUECD, reduce/partition the size
Fdisk–lu #查看磁盘分区情况
E2FSCK–F/DEV/SDA1 #检查文件系统
RESIZE2FS/DEV/SDA1 10G #把文件系统大小调整为10G
PARTED/DEV/SDA #使用parted调整硬盘分区, attention is/DEV/SDA .
(parted) Resizepart 1 12G #调整分区大小, 1 for/DEV/SDA1
Note: Parted partition size is calculated differently, so leave more space to prevent data loss
RESIZE2FS/DEV/SDA1 #调整文件系统大小 so that it matches the size of the partition
6. Reboot, boot from local hard drive, view disk partition size, you can see that the/DEV/SDA1 has been compressed.
7. Create a new partition in unallocated space, and then place all zeros
DD bs=64k If=/dev/zero of=/dev/sda2 #bs表示每次写的块的大小
In GParted, you can see that the file system becomes unknown
Remove/dev/sda2 to make it unallocated
8. Migrate the virtual machine after shutdown and change the virtual disk format from "Thin provisioning" to "thick provisioning fast 0".
The reason to do this is because the above operation only in the operating system to the unused space to zero, the virtual machine does not know, so it is necessary to pass this step, so that the virtual machine will not use the space also zeroed.
9. Migrate the virtual machine again, change the virtual disk format from "thick provisioning" to "thin provisioning", you can see that the space used to reduce to 10GB, that is, the actual occupied space is actually reduced.
The above experiment basically verifies the standard of virtual machine reclaim space:
- Data has not been written after allocation;
- The data was written after the allocation, but both the operating system and the virtual machine had 0 operations in place.
The above method is to reclaim the space of the Linux system, in theory, the Windows system can also be recycled through this method, just use different software.
Since the virtual machine that occupies 6T space is going to be migrated to the physical machine immediately, the problem of limited space is not very urgent, so wait until the migration is complete, then test again, and then add the results of the operation later.
Early planning is very important, not well planned, the latter will waste a lot of time to pits.
VMware virtual machines, from thick provisioning to thin provisioning, and reduce actual disk footprint