The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @samgerrits: Caroline en asielzoekers, een tweeluik. Links: dwepen met een speldje gekregen van een Iraanse asielzoeker, rechts: nou ja… 2 hours ago
    • RT @delphijunkie: Yeah, nah. I'm good thanks Twitter. https://t.co/eTMPUoeSEa 2 hours ago
    • RT @d_feldman: Microsoft: We have world class AI research Google: We have world class AI research Meta: We’re one or two steps behind in AI… 2 hours ago
    • RT @SchipholWatch: Op dit moment is kerosine zo’n tien keer goedkoper dan alternatieve synthetische brandstof. De overheid moet dit prijsve… 2 hours ago
    • RT @jasongorman: One aspect of LLMs many folks overlook is the energy cost of training one. GPT-3 used an ~936 MWh and training it took 102… 2 hours ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,178 other subscribers

ESXi: shrinking a Windows disk

Posted by jpluimers on 2020/09/04

I had to shrink down a Windows disk of an ESXi based Virtual Machine from 240 Gibibyte to about 140 gigabyte.

In this case, it was Windows 7 on ESXi 6.5, but the actual versions do not really matter.

The only way to decrease ESXi .vmdk files is by fiddling with disk sector counts in the text based .vmdk files (not the binaries .vmdk files!) of a diskname.vmdk / diskname-flat.vmdk text/binary pair. This is described for instance in these two articles:

Notes:

  1. This article presumes you already shrunk your NTFS partition (for instance as described in Consolidating NTFS free space).
  2. If you only have a binary .vmdk file, then you can use vmkfstools to create a text/binary pair for you, for instance by using these commands:
    vmkfstools --clonevirtualdisk Windows7.vmdk Windows7.thick.vmdk
    vmkfstools --clonevirtualdisk Windows7.vmdk Windows7.thin.vmdk --diskformat thin
  3. You cannot workaround 2. as the --geometry functionality of vmkfstools only displays existing geometry, see

ESXi has .vmdk files that count disk sizes in sectors, but the tooling that ship with Windows to not show partition sizes in sectors, especially not the partition ending sector.

All permutations of tooling like DISKPART, PowerShell, WMIC and terms partition, ending sector, cylinder, head, etc failed me to return built-in tools.

Luckily, “powershell” “partition” “ending sector” found the documentation for [WayBack] Test Disk | File System | Data Management titled “TestDisk Documentation, Release 7.1, Christophe GRENIER” which lead to:

[WayBack] TestDisk Download – CGSecurity

Download TestDisk & PhotoRec. TestDisk is a free and open source data recovery software tool designed to recover lost partition and unerase deleted files. PhotoRec is a file carver data recovery software tool.

It is available for many platforms, including Windows x86 (fully featured) and x64 (limited features):

There was also the much more convoluted PowerForensics which is also more difficult to install:

As a check (because the calculations by hand are too cumbersome to trust on a first trey), I also downloaded the ISO image of gparted:

Let’s get started for real!

Running TestDisk is easy

  1. Start it with UAC confirmation:
  2. Create the log file (which at first is in memory):
  3. Select the unix based disk (so do NOT start with drive C: as we are after physical disks, not logical drives):
  4. Windows drivers have an Intel/PC partition table, so select the first:
  5. Now you see which partitions are on the disk, and where (at which ending cylinder/head/sector) it ends:
  6. Now you can do the multiplication math from ending cylinder/head/sector to sector count: (17463 * 255 * 63) + (34 * 63) + 43 = 280545280
    • the first part is the ending cylinder number (17463) multiplied by heads per disk count (255) and sectors per cylinder count (63).
    • the second part is the ending head number (34) times sectors per cylinder count (63)
    • the third part is the ending cylinder number (43)

This is all very cumbersome, so let’s verify this

Running gparted

Booting from CD-ROM requires a boot delay (longer than the default of 0 milliseconds):

That way you can press Esc during boot to get into the boot-order menu, and change it to CD-ROM boot:

Too bad the gParted people choose a psychedelic background bleed:

Anyway: here are the steps in gParted to get the sector counts:

  1. Use the default keyboard layout:
  2. Keep default language:
  3. Keep default video settings:
  4. Select the lowest partition (the “unallocated” one):
  5. Now in the menu, choose “Partion”, then “Information:
  6. The first sector of the unallocated partition is 1 sector beyond the last used partition 280545280 versus 280545279 which matches the one we found:

Another example

(5112 * 255 * 63) + (40 * 63) + 48 = 82126848

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: