Howto Shrink a Thin Provisioned Virtual Disk (VMDK)

Posted by fgrehl on November 24, 2014Leave a comment (18)Go to comments
 

Thin provisioned disks are a great feature to save capacity as you virtual machines filesystem will never use the full capacity. I do not know a single system where you do not have at least 10GB of free space for OS disks. I am not considering databases, applications or fileservers which will grow constantly. Having thin provisioned disk is usually no longer a performance problem so it is a valid design choice even in production.

A common issue with thin disks is that the size will grow when required, but never shrink. When you require the capacity only once you might want to get it back from the virtual machine. This post describes how to reclaim unused space from the virtual machine.

Virtual Machine Preparation (Windows)

Windows does not automatically zero deleted blocks. Microsoft provides a tool that can zero blocks after while deleting a file or zero out the entire free space. This is required to reclaim space back from the virtual disk.

  1. Download SDelete
  2. run sdelete.exe -z [Drive]

Wait a couple of minutes until the process is finished. Please note that you virtual disk file (VMDK) will grow to the full size during the process.

Virtual Machine Preparation (Linux)

Linux does not zero deleted blocks too. There are various tools available to create zeroed blocks. The best known tool is dd which should be available on all systems.

  1. Identify free space with df
  2. Fill the free space with dd
vma:/mnt/data # df -h
vma:/mnt/data # dd bs=1M count=8192 if=/dev/zero of=zero

This will zero 8GB of the available 8.2GB (1MB Blocksize * 8192 = 8GB). Please note that you virtual disk file (VMDK) will grow to the full size during the process.

Shrink VMDK File

  1. Power off the Virtual Machine, or disconnect the virtual Disk you want to shrink
  2. Connect to the ESXi Host with SSH
  3. Navigate to the Virtual Machine Folder
  4. Verify disk usage with du
  5. Run vmkfstools -K [disk]
  6. Verify disk usage with du
root@esx3:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk
7.9G vma_1-flat.vmdk

root@esx3:/vmfs/volumes/ds1/vma $ vmkfstools -K vma_1.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 25% done.

root@esx3:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk
1.9G vma_1-flat.vmdk

[转帖学习]Howto Shrink a Thin Provisioned Virtual Disk (VMDK)的更多相关文章

  1. Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创)

    Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创) 由于java interface中声明的字段在编译时会自动加上static final的修饰符,即声明为常量.因而inter ...

  2. [转帖]学习关于TTL

    自己简单试了一下在家里与在公司里面服务器的连接: C:\Users\Administrator>tracert oms.inspur.com 通过最多 个跃点跟踪 到 oms.inspur.co ...

  3. [转帖]学习一下centos7 新地方

    总结的挺好  copy一下 慢慢学习: http://blog.itpub.net/312079/viewspace-2214440/ Centos7 单用户模式 centos7里不再有0-6启动级别 ...

  4. [转帖学习]Oracle的 SYS_CONTEXT 函数简介

    Oracle的 SYS_CONTEXT 函数简介 https://blog.csdn.net/IndexMan/article/details/48606369 1.什么是SYS_CONTEXT? S ...

  5. [转帖] 学习 Linux 大页的内存知识

    一.在解释什么情况下需要开启大页和为啥需要开启大页前先了解下Linux下页的相关的知识:以下的内容是基于32位的系统,4K的内存页大小做出的计算1)目录表,用来存放页表的位置,共包含1024个目录en ...

  6. [转帖] 学习一下 apache bench 的总结简介 ( LAMP的没用过..)

    PS:网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个自带的,名为ab的程序,可以对Apache或其它类型的服务器进行网 ...

  7. 算法学习 howto

    入门: The Most Important Algorithms http://www.risc.jku.at/people/ckoutsch/stuff/e_algorithms.html Alg ...

  8. 【2016-10-13】【坚持学习】【Day4】【virtual 虚函数】

    定义一个基类,有一个虚函数 定义三个子类,分别继承,重写,New,这个虚函数   abstract class Test { public virtual void Prinf() { Console ...

  9. VMware虚拟机磁盘文件vmdk单文件转多文件相互转换

    设置环境变量 set PATH=%PATH%;D:\Program Files (x86)\VMware\VMware Workstation    echo %PATH% C:\Users\Admi ...

随机推荐

  1. Python day2 ---python基础2

    本节内容 列表. 元组操作 购物车程序 字符串操作 字典操作 3级菜单 作业(购物车优化) 1. 列表操作 1.定义列表names = ['Alex',"Tenglan",'Eri ...

  2. POJ-2299 Ultra-QuickSort (树状数组)

    题目链接:Ultra-QuickSort 题意: 给出了一个序列,序列中有n个数,现在每次操作能交换相邻的两个数,要求操作几次可以将这个序列转换为一个从小到大排序的序列. 题解: 我的解法是先把所有的 ...

  3. 洛谷 P4478 [BJWC2018]上学路线

    洛谷 P4478 [BJWC2018]上学路线 原题 神仙题orz,竟然没有1A....容斥+卢卡斯+crt?? 首先用容斥做,记\(f[i][0/1]\)表示到i号点经过了奇数/偶数个点的方案数,因 ...

  4. 对ThreadLocal的源码解读

    早在JDK 1.2的版本中就提供Java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地编写出优美的多线程程序. 功能 ...

  5. c#指针和寻址运算

    一.指针和寻址运算 指针格式:<类型>*<变量> 寻址格式:&<变量> 以下程序的运行结果为   注意:每次运行程序时第一行显示的地址都不会一样. usin ...

  6. 接口自动化学习--mock

    好久没有写学习的总结,都正月十二了,但还是要来个新年快乐鸭. 一直都在看imooc的一套java接口自动化实战课程,现在看到了尾部了,然后想到之前那些testng,mock,httpclient等都没 ...

  7. 402. Remove K Digits/738.Monotone Increasing Digits/321. Create Maximum Number

    Given a non-negative integer num represented as a string, remove k digits from the number so that th ...

  8. 【坚持】Selenium+Python学习记录 DAY10

    2018/05/31-2018/06/1 [官方文档](https://www.jetbrains.com/help/pycharm/set-up-a-git-repository.html) 通过p ...

  9. 关于MySql数据库主键及索引的区别

    一.什么是索引?索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录.表里 ...

  10. nodejs加载模块心得,mongoose的继承,schematype的mixd介绍

    1. require("xxx")可以是原生模块, 也可以是根目录“/node_modules”下的某个模块 2. 多个模块的package.json使用同一个相同模块的时候,将改 ...