After upgrading a VM [Virtual Machine] to the latest Insider build of Windows 10, I was compacting the VHD [Virtual Hard Disk] and it occurred to me that I'd never said anything about the 2 types of VHDs, Dynamic or Expanding vs. Fixed or Static. Oops... besides being good to know, it's probably something I should have mentioned as Suze was talking about setting up a VM in another thread -- the 1st step in setting up a VM is deciding what kind of VHD to use. So here's some info on VHDs...
I'll start with why you need VHDs -- they can come in handy in all sorts of ways, but where you really need them is with VMs. That's because you want & need to keep your OS files separate, to the point that you can't even set up a VM without using a VHD.
Second, there are several *brands* of VHDs available. Microsoft makes two, VirtualBox has one, VMware has one, Dell has one etc. They all require drivers -- when a VHD is *mounted* the Host or Guest OS [e.g. Windows, Linux etc.] sees the VHD file(s) as actual, physical hard drives. Mounting a physical drive is something you do & get used to in *nix, which can give you added flexibility -- Windows does it automatically so most are unaware of it. Maybe the easiest way of thinking about it is when you insert a USB stick into a USB port on your device, the device automatically mounts the drive so you can access it -- when you click the icon to Safely Remove Hardware in Windows [or when you just pull the USB stick out] it's unmounted.
With VMs the Host OS is the one that you boot to, that runs the PC/laptop/Server -- it can be Windows or *nix etc., or it can be a special light weight OS designed specifically to run VM software. The OSes running as VMs in the VM software [e.g. Virtualbox, VMware etc.] are the Guests. Technically it can get more complicated, as you can run VM software & a VM inside a running VM, in which case the higher level VM is both a Guest OS & a Host to the *nested* VM.
[You'll most often read about nested VMs regarding Truecrypt or Veracrypt as a way of hiding your stuff I think, or as something someone working with VMs thinks is cool, but there are actually technical applications, usually with servers. That said, it's a capability that's recently been introduced in Windows 10, so some useful aspects of doing such a thing *may* make it to 10 as well.]
As mentioned above, Microsoft has 2 related VHD formats, .vhd & .vhdx -- .vhdx is a later, improved generation. Of the two, you're more likely to see .vhdx with servers, though you can probably expect to see [read] Microsoft talking about it with Windows 10. Starting with Windows 7, the more common .vhd is native to Windows -- it's doesn't *know* about .vhdx. You can create and mount/un-mount .vhd files in the Disk Management section of Computer Management, which you'll find in Control Panel -> Administrative Tools, where mount/un-mount is called Attach & Detach. Right click Disk Management to Attach -- right click the Disk # [to the left of the mounted .vhd] to Detach. Once Attached it's the same as handling a regular disk/partition, e.g. adding or changing a drive letter so it's visible in Windows Explorer etc.
Now, while you can mount & access a .vhd file in Windows 7-10 [after adding drivers you can do it it earlier versions like XP], only one OS can access a VHD at a time -- if you want to use a VHD with or for a VM, it cannot be mounted in the Host OS. Sometimes it's handy to mount a .vhd file with a VM on it in Windows to access it's files, or back up its contents etc., but you can also mess up the VM by mounting its VHD in Windows -- it's pretty rare but I have had it happen.
You have to install special software to mount VirtualBox .vdi or VMware vmdk files in Windows. I use Microsoft's win7 version of Virtual PC & VirtualBox -- in either it's pretty easy to attach a 2nd [or 3rd etc.] VHD to a VM, so that after you start that VM it appears as a 2nd [or 3rd etc.] hard drive. If you have more than one VM then, you can fairly easily do the same sort of disk management &/or file transfer you might do by mounting a VHD in Windows. It can also be a necessity when you're working with Dynamically Expanding VHDs. Finally to the main reason for this post...
A VHD is a single file that mimics & stores data [almost] the same way a physical hard drive would. To store 100GB of data a VHD file has to be 100GB in size -- you can use file compression, like that built into Windows, but that adds another layer of overhead when you've already got the overhead of software running the VHD, so will slow things down. When you write or create a 100GB VHD, it takes as long as it would to write any 100GB file on your system [which can be quite a while]. But that's what you do when you create a static or fixed VHD -- you create & write a file to match whatever you decided should be the VHD's total capacity, but you only do that once & you're done... from then on you read & write data to the VHD like you would a regular hard drive.
Now you've undoubtedly got free or unused space on the system drive where Windows lives on your PC or laptop [or tablet] -- physical drives come in fixed sizes, & can't be matched to the actual amount of data you have to store. But VHDs can do that. A dynamically expanding VHD starts out tiny, and grows whenever you add data to it, up to a maximum, which is the VHD's capacity that you set when you create it. A 100GB VHD file will only be roughly 20GB in size if/when you've only written 20GB of data to it. Sounds -- and is -- very nice, but it has it's downsides.
Instead of writing the full size VHD file at the beginning, you're making the VHD file bigger when you add data to it, so you're not only writing the data, but increasing the size of that file -- writing new data that makes this sort of VHD expand or grow takes longer than writing the same amount of data to a VHD that's aleady big enough, that does not have to grow. And, if you use a dynamically expanding VHD for a [particularly Windows] VM, you'll find that over time the amount of free space on that mounted VHD will grow, and so will the VHD's file size along with it. Getting rid of that free space, making the VHD's file as small as possible, is called Compacting the drive. It's generally a multi-step, initially confusing, somewhat time consuming process.
I like to start by attaching the dynamically expanding VHD for a Windows VM to another VM, so I can delete large files like pagefile.sys, then run an error check on the disk, but both of those steps are optional. The 1st step in compacting the drive is running defrag, to get all the data to the front of the drive, & also in this case, starting end of the file. The 2nd step is zeroing out all the free space, which is usually done by writing some sort of filler character(s) to it, then deleting them. The 3rd step is actually compacting the drive, reducing the size of the VHD file, eliminating the space taken up by free space.
Sadly there's no nice, easy tool that you can use [if there is one it doesn't show up on the 1st several pages when you Google]. And if you try to do this stuff outside of a VM, you run the risk of expanding the VHD to it's maximum size. There are a number of methods & tools however, depending in part on the brand of VM Host software, brand of VHD, & whether the VHD is formatted MBR or GPT. Another wrinkle is that some of the tools or methods don't always work for everyone, while some of the tools may be harder for you to get your hands on, and many are cli [Command Line Interface] only.
So my advice is to spend some time using Google, browsing through the results, seeing what might fit your situation best, & giving it a try. Sdelete, a tool from Sysinternals at microsoft.com, can be used to mark the free space, and so can a Microsoft tool called Precompact.exe, that's part of their Virtual PC software. For a .vhd file you can use a tool that's built into Virtual PC, or Windows DiskPart, or some Hypervisor & Powershell tools associated with Microsoft's server software. For Virtualbox .vdi files there's a cli tool that's part of Virtualbox, or easier, you can use the Compact option with a small app called CloneVDI. I believe that there's a similar cli tool for VMware, but I don't know the best tools or methods for that software.
Real world, after upgrading the Windows 10 Insider build my bare Virtualbox VM grew to ~29GB -- after getting rid of ~ 19GB of leftovers, then going through the compacting process using win7's VPC, it's now a bit under 11.5 GB. MUCH easier to handle, copy etc., which is important because I want to always have more than one copy of a VHD -- they can & do become damaged... it's rare, but all it takes is once & you've lost everything. If you have a fixed or static VHD with free space, backing up a mounted VHD like a regular hard drive makes sense -- the disk image backup will only contain the data & not the free space. If the VHD has little or no free space however, just copying the VHD somewhere else is faster, easier, & works as well if not better.
When you transfer or copy or transform a working install of Windows to a VM, the original system partition includes however much free space that will be included on the VHD you create using tools like those from Paragon. You might be able to deal with it later through compacting etc., or you can reduce the system partition size beforehand, or you can restore a system partition image backup to a VHD, shrink the partition there, than backup/restore or copy that partition to a dynamically expanding VHD.
Using a VHD to work with a partition copy as above is just one of many things you can use a VHD for. When you install software you can usually target any drive or partition attached to Windows, but not always storage on a removable drive -- mount [attach] a VHD on that removable storage, & Windows will see it as a normal partition or drive. And while the process can seem a bit involved at 1st, it's really not that difficult to set up your system to boot to a copy of Windows installed to a VHD [possible since win7]. There are several pros & cons to doing it that way -- the major pro may be that it does not require another empty partition.