{"id":1623,"date":"2024-09-23T18:20:48","date_gmt":"2024-09-23T23:20:48","guid":{"rendered":"http:\/\/zewwy.ca\/?p=1623"},"modified":"2024-09-23T18:20:48","modified_gmt":"2024-09-23T23:20:48","slug":"hole-punching-a-linux-vm-on-esxi","status":"publish","type":"post","link":"https:\/\/zewwy.ca\/index.php\/2024\/09\/23\/hole-punching-a-linux-vm-on-esxi\/","title":{"rendered":"Hole Punching a Linux VM on ESXi"},"content":{"rendered":"<p>I covered this in the past here:<\/p>\n<p><a href=\"http:\/\/zewwy.ca\/index.php\/2016\/05\/28\/reclaim-unused-space-from-vmdk\/\">Reclaim unused space from VMDK \u2013 Zewwy&#8217;s Info Tech Talks<\/a><\/p>\n<p>But this time I wanna covered it a bit differently. Things I noticed:<\/p>\n<ol>\n<li>A proper VM with VMtools installed, and thin provisioned will automatically shrink the overall size being shown and used on disk on the ESXi browser.<\/li>\n<\/ol>\n<p>Yet for some reason after I used the SCP method to move a VM from one host to another (frowned upon as it secretly converts it from thin to thick). Yet even after migrating to a new datastore specifying thin, it still show as full disk usage on the host.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/FXYNsHN.png\" \/><\/p>\n<p>I know is less checking the VM itself via it&#8217;s console\/terminal whatever:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/3YTjYvu.png\" \/><\/p>\n<p>In my old blog post I mentioned &#8220;using DD&#8221; but not showing for stating how at all, <a href=\"https:\/\/serverfault.com\/questions\/772571\/dd-zero-out-all-the-remaining-unused-space-of-a-drive\">Googling this I found this thread<\/a> with an interesting answer:<\/p>\n<p>&#8220;The \/zero-Tag is actually a file name. The command just copies zeros from the virtual File \/dev\/zero (infinite number of zeros) into \/mnt\/hdb\/zero until the disk is full, or some other error occurs.<\/p>\n<p>This is why you have to remove the file \/mnt\/hdb\/zero after that in order to regain the unused space.<\/p>\n<p>However, a better way to fill free space with zeros (on ext2,3,4 file systems) is to use a tool called zerofree.&#8221;<\/p>\n<p>Oooo zerofree?<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/873xCtb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/873xCtb.png\" alt=\"\" width=\"1018\" height=\"644\" \/><\/a><\/p>\n<p>Huh, something created (a tool) for exactly the task (job) at hand. Great!<\/p>\n<p>Error, how classic, complained path is mounted RW, like yeah and?<\/p>\n<p>Ughhh, google? <a href=\"https:\/\/askubuntu.com\/questions\/1092812\/zerofree-on-ubuntu-18-04\">virtualbox &#8211; zerofree on ubuntu 18.04 &#8211; Ask Ubuntu<\/a><\/p>\n<p>Step 1) Reboot into ubuntu recovery console, hold down [Perfect ESC keystroke]<\/p>\n<p>K how do I get into Advanced Grub boot? Holding Shift did nothing, if I mash ESC I get grub&gt; (notices tiny flicker of Grub menu).. great I have to Mash ESC only once perfectly in a less then 1 second boot window&#8230; man give me a break&#8230; Once in I see advanced option as stated by the answer.<\/p>\n<p>Step 2) advanced options -&gt; recovery mode -&gt; root console<\/p>\n<p>Step 3) find the root directory<\/p>\n<pre>mount | grep \"sda\"<\/pre>\n<p>Step 4) run zerofree<\/p>\n<pre>echo \"u\" &gt; \/proc\/sysrq-trigger\r\nmount \/dev\/mapper \/ -o remount,ro\r\nzerofree -v \/dev\/sda1<\/pre>\n<p>Step 5) reboot<\/p>\n<p>Checking the ESXi host&#8230; what it went up 2 gigs, da fuq man&#8230;<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/Q6P5t5f.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/Q6P5t5f.png\" alt=\"\" width=\"403\" height=\"26\" \/><\/a><\/p>\n<p>Step 6) Compress Disk.<\/p>\n<p>In my previous post this was to vMotion to datastore or use holepunch option which from what I can tell this the -K option, which I dont&#8217; think can be used on a live VM, and a storage vMotion can&#8217;t be done. without vCenter. Since I&#8217;m temp working without a vCenter server, let&#8217;s try the holepunch option, this will require shutting down the VM, but since the zerofree required it anyway down time was already in play.<\/p>\n<p>On the ESXi host:<\/p>\n<pre>[root@Art-ESXi:~] vmkfstools -K \/vmfs\/volumes\/Art-Team\/VM1\/VM1.vmdk\r\nvmfsDisk: 1, rdmDisk: 0, blockSize: 1048576\r\nHole Punching: 100% done.<\/pre>\n<p>Oh noooo I&#8217;ve tainted my results&#8230; checking the web UI the space has gone back done to stating 20 Gigs like the first snippet&#8230; but doing a du -h on the flat file shows it is only the 10 Gigs as expected it to be:<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/ykrk23k.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/ykrk23k.png\" alt=\"\" width=\"561\" height=\"26\" \/><\/a><\/p>\n<p>Well I don&#8217;t know what to make of this discrepancy&#8230;<\/p>\n<p>Huh, <a href=\"https:\/\/www.virten.net\/2014\/11\/howto-shrink-a-thin-provisioned-virtual-disk-vmdk\/\">I found this post of someone doing the exact same thing around the time<\/a> I wrote my original post but simply used the command:<\/p>\n<pre>dd bs=1M count=8192 if=\/dev\/zero of=zero<\/pre>\n<p>I have no clue how output file of zero means the disk&#8230; guess you can try that too, then holepunch the VMDK just like I did.<\/p>\n<p>There.. I shutdown the VM again and this time did my ol trick to <a href=\"https:\/\/zewwy.ca\/index.php\/2022\/04\/04\/how-to-vmotion-a-vm-without-vcenter\/\">vMotion a VM without vCenter,<\/a> and after re-registering the vMotion (between two datastores) it finally showed up with the correct space in the UI. \ud83d\ude42<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/eLEW1W6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/eLEW1W6.png\" alt=\"\" width=\"464\" height=\"29\" \/><\/a><\/p>\n<p>Hope this post helps someone, it&#8217;s been covered many times in the past.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I covered this in the past here: Reclaim unused space from VMDK \u2013 Zewwy&#8217;s Info Tech Talks But this time I wanna covered it a bit differently. Things I noticed: A proper VM with VMtools installed, and thin provisioned will automatically shrink the overall size being shown and used on disk on the ESXi browser. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/zewwy.ca\/index.php\/2024\/09\/23\/hole-punching-a-linux-vm-on-esxi\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Hole Punching a Linux VM on ESXi&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","footnotes":""},"categories":[5,8],"tags":[],"class_list":["post-1623","post","type-post","status-publish","format-standard","hentry","category-hypervisors","category-server-administration"],"_links":{"self":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/1623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/comments?post=1623"}],"version-history":[{"count":2,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/1623\/revisions"}],"predecessor-version":[{"id":1625,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/1623\/revisions\/1625"}],"wp:attachment":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/media?parent=1623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/categories?post=1623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/tags?post=1623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}