Jump to content











Photo
- - - - -

VHD Virtual Disks - Tips and Tricks

vhd fixed dynamic tools for vhd

  • Please log in to reply
9 replies to this topic

#1 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted A week ago

I decided to put together some info available about virtual disks.

 

Selecting the more compatible format:

 

If you are using a Virtual Machine (VM), when creating a Virtual Disk I suggest to always select MS format (VHD), more versatile format as it is compatable with all VMs available, or (if bootable) can be booted directly from the PC without the need of a VM, applies to Windows OSs, for Linux OSs see: http://reboot.pro/to...rom-vhd-how-to/

 

VHDs are also easy to create and attach on Windows OSs

 

VHD vs VHDX:

 

Contrary to MS info Win 10 can be installed on a VHD, as other members of the forum and I can confirm.

 

Unless your virtual disk requires more than 2 TB, do not use the VHDX format, VHD format is always preferable, as an example: MS Azure only accepts VHDs with a single partition.

 

Grub4dos is capable to boot VHDs as filedisk, also by means of grub4dos + SvBus driver can be Rambooted, for an SvBus x64 signed version see: http://reboot.pro/to...os/#entry208348

 

Fixed Size vs Expandable:

 

This is a matter of select the option that fits best user use/desires/likes, depending on benefits and disadvantages given of each one of this options.

 

Fixed Size VHD:

 

Benefits:

  • The space for the VHD is pre-alocated on your Mass Storage Device.
  • Helps prevent fragmentation on the disk containing it.
  • Helps reduce internal fragmentation on the VHD.

Disadvantages:

  • The space used on your Mass Storage Device is always equal to the VHD pre-alocated space, even if the VHD is empty.
  • For copying big size Virtual Disk to a USB device or other media requires a big size device.
  • Longer time required to copy the Virtual Disk to a USB device or other media.

Dynamically expandable size VHD:

 

Benefits:

  • The space for the VHD is not pre-alocated on your Mass Storage Device, saving space on it.
  • The space used on your Mass Storage Device is equal to the VHD used space.
  • Requires smaller size USB device or other media to copy it.
  • It is faster to copy the Virtual Disk to a USB device or other media.

Disadvantages:

  • Increase fragmentation on the disk containing it.
  • Increase internal fragmentation on the VHD.

 

Then depending on the desired use of the VHD, we select the right option.

 

Will continue on next post

 

alacran


  • ReTokener likes this

#2 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted A week ago

Minimizing the space requiered for a VHD:

 

In order to save space on the creation of a VHD we have NTFS Compression and Compact options.

 

NTFS Compression vs Compact

 

NTFS Compression

 

It is available since XP, it is possible to apply it on any disk or virtual disk, helps reduce the used size but creates a very fragmented environmenent, almost all files end fragmented and also the free space, it is necessary (at least highly recommended) to defragment the drive, compression level is not very hight, it is available on all OSs from XP to 10.

 

Compact

 

This is the new compression option available since Win 10, it is possible to apply it on any disk or virtual disk, helps reduce the used size but creates a fragmented environmenent, at the end all files will be defragmented (contiguous), but not the free space (files won't be contiguous to each other).

 

Compression level is better/higher using Compact than NTFS Compression.

 

For more info and link to a Command Line tool from JFX that (can be used from 7 to 10 OSs) see: http://reboot.pro/to...for-win7-win10/

 

Also wimb made a GUI Tool on Autoit (can be used from 7 to 10 OSs): http://reboot.pro/fi...7-wof-compress/

 

Both mentioned tools let you use several Compacting options: 4K, 8K, 16K and LZX.

 

Using Compact on a VHD:

 

Of course it is possible to apply it after creating a VHD, but if we are going to install an OS to a VHD it is better to do it during the install, to do this easily use WinNTSetup from JFX, or using any the tools from our forum member and very good friend  Retokener: DismMountService  or   wimlib-clc

 

In my experience I have found a reduction of about 2 GB or more when installing Win 10 using Compact 4K (default level of Dism), according to MS using 4K any new file added to the drive will be 4k Compacted, this applies also to moddified files.  Of couse it depends of OS version size installed, and after insllaing the OS compresivility of new files added (like drivers, programs, documents, etc).

 

It is possible to use a higer Compact level but then files will NOT be automatically compacted, you will have to do it manually if you want.

 

Of course the Compact mode install apply to fixed and expandable VHDs.

 

Example of a Compact 4k Win10 install on a expandable VHD, 7 GB max. size, from my post

Spoiler

 

Example of a Compact LZX Win10 install on a fixed size VHD, 5.5 GB, from my post

Spoiler

 

Will continue on next post

 

alacran



#3 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted A week ago

Wimboot install on VHD

 

On Win10 this install mode is deprecated and replaced by Compact, Win10 Dism has some issues when using a moded WimBootCompress.ini, but wimlib works very fine to make Wimboot installs of Win 10.

 

This install mode appeared with 8.1 update 1, basically it creates as much as possible Pointers (we can say it is a kind of links) to the source WIM file and only those files that need to be uncompressed to let the OS funtion properly are extracted to the target drive or virtual drive.

 

This install mode requires the install drive + the source WIM file to boot, but we can load to ram only the VHD where pointers are located in order to Ramboot.

 

This install mode is capable to allow the user to create a full Windows instal on a 512 MB VHD, after testing more depply this approach I found it is better to increase the size and by testing found a 1.5 GB VHD is a good size capable to run from a PC having at least 4 GB of Ram.

 

For additional info of this see:

 

Making the smallest Win10 install (Wimboot mode) on 512 MB VHD.

 

Latter it was the turn to reduce as much as possible the size of the source WIM file and of the coupled Wimboot VHD, see:

 

Reducing wimboot source wim file using LZX Compression, and VHD using gzip or LZ4 Compression, to save room, and also load faster on RAM.

 

LZ4 compression is a very good tool to let us reduce the size of the FIXED size Wimboot VHDs to let us load them faster on Ram during Ramboot, see on first post tools/programs required, not applicable to expandable VHDs. 

 

This is a link for the GUI lz4_compressor (also decompressor) applicable to VHDs or any other folder: http://reboot.pro/fi...lz4-compressor/

 

Our fellow wimb made a program with all integrated to let the users create Wimboot VHDs:

 

VHD_WIMBOOT - Apply and Capture of WIM Files for OS in VHD: http://reboot.pro/to...-for-os-in-vhd/

Only thing not available on VHD_WIMBOOT is LZ4 compression of VHD.

 

Also from wimb a very good program to create multi-boot USB devices capables to boot on CSM/MBR and on UEFI PCs without the need to enable CSM and/or dissable Secure Boot, with it is possible to boot from WimPE, Wimboot VHD and also several Linux distros, good for Linux users and also good to bypass all Windows restrictions on certain files/folders during copy/moddify them, also many repair tools for Windows are based on Linux.

 

UEFI MULTI - Make Multi-Boot USB Drive: http://reboot.pro/li...boot-usb-drive/

 

Will continue on next post.

 

alacran



#4 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted A week ago

Shrinking expandable VHDs

 

When working with expandable VHDs, during its use the internal size of the used space starts growing as any other Win OS does and when unmounted this increase in size is also noticiable on the VHD size.

 

Sometimes the unmounted VHD size is bigger than the internally used space, this is due to all writes made to the drive by Windows itself + the user, even if we run CCleaner into the VHD, we erase many garbage created by the OS and files deleted by the user, if we have selected on CCleaner on Options >>> Config:  Fast erasing (one pass), Clean free space of drive and Clean free space of MFT, the program will write Zeros to all free space.

 

Also defragmenting the VHD will liberate some space too, specially when followed by a new CCleaner run.

 

This tool recomended by cdob on this post can be used too:

Spoiler

 

But this is not enough to make the unmounted VHD size shrink to occupy on the disk only the used space, to make this happend we can do the following:

 

On elevated prompt, type:

 

DiskPart

Select vdisk file = D:\10x64-EC4.vhd
attach vdisk readonly
Compact vdisk

Detach disk
exit

 

On this example my D:\10x64-EC4.vhd is my expandable VHD.

 

I invite all member of the forum to share here any tips and/or tricks or free programs usefull when dealing with VHDs.

 

alacran



#5 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted A week ago

Cloning VHDs

 

If we want to make an image of a Wimboot VHD to apply it to another VHD and keep a compressed copy, best and fastest free GUI tool we can use is DismMountService from Retokener: http://reboot.pro/to...ount-service/  

Warning this program overwrites the full target disk.

 

If we are cloning a Wimboot or a non Wimboot VHD to another VHD or to a DISK use: HDD Raw Copy: https://hddguru.com/...-Raw-Copy-Tool/

Warning this program overwrites the full target disk.

 

If we are cloning a VHD or a partition into it to a formated partition on a disk or on a VHD use:

PartitionGuru Free: 4.9.5.508:  https://www.eassos.c...onguru-free.php

Warning this program overwrites the full target disk or partition.

 

If we are cloning a VHD or a partition into it to a unformated/unalocated/free space on a disk or on a VHD use:

MiniTool Partition Wizard Free v11.5:  https://www.partitio...on-manager.html

This program is safe as the target space needs to be unformated.

 

I invite all member of the forum to share here any tips and/or tricks or free programs usefull when dealing with VHDs.

 

alacran



#6 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted 3 days ago

Expand a VHD

 

 A VHD can be expanded this way:  (the VHD on following example was before 1024 MB fixed size, and was expanded to 1280 MB)

DiskPart
Select vdisk file = D:\W81ESP1x86-WB.vhd
expand vdisk maximum=1280      >>> Final Size, Always on MB.
exit

 

Later we need to expand the drive contained into the virtual disk:

DiskPart
Select vdisk file = D:\W81ESP1x86-WB.vhd
attach vdisk
list vol    >>> here we make note of volume letter assigned, to use on next step.

DiskPart
select vol X     >>> Where X is the volume letter contained into the virtual disk.
extend
exit

 

Or easier, having the VHD mounted after expanding it, open Disk Management on Win, select the volume/drive and just expand it in GUI.

 

After expanding and unmount, don't forget to defragment the VHD file, usually it is required.

 

alacran



#7 antonino61

antonino61

    Frequent Member

  • Advanced user
  • 484 posts
  •  
    Italy

Posted 3 days ago

As I already posted in other threads (VHD_WIMBOOT - Apply and Capture of WIM Files for OS in VHD and Ultimately Stop c:\ used space bulging from torquois...), I can confirm (nothing personal with anyone, let alone wimb the flying dutchman, whom I am an admirer of) that I have found the best (most faithful to the source) capturer in dism tool and the best wimboot capturer in wimboot tool. As for the read-only vhd that alacran suggested, I have not tried it yet.  

I envisaged the following options:

1) both capture and apply with dism tool: the best (smallest and most faithful to the source) - only possible if u want an integral version vhd (no wimboot);

2) capture with dism tool and apply with wimboot tool: possible for integral version vhd, problematic, erratic and sometimes even impossible for wimboot vhd (most of the time it cannot find addresses, the vhd sorta looses the wim, or viceversa, during the booting);

3) both capture and apply with wimboot tool: the only possible scenario without issues for wimboot vhd - this last time I have tried it (about 5 minutes ago) it went spick&span in terms of faithfulness to the source (what u see in the source is also what u get in the target wimboot vhd.

4) reverse 2): have not tried it out.

N.B.: all tests were made with the same wimbootcompress.ini, which, in my case, as was already posted, is almost bare.



#8 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted 3 days ago

I think you didn't understood clearly the idea in post No. 4, it was about shinking an expandable VHD that as an example has grown several GBs its used size after some time of use, with some files/folders added by the OS, the Browser and the AV, and also by the user, then if the user deletes those files/folders, the internal used espace on the VHD is reduced, but the size of the VHD used on the HD, do not shink automatically to its previous original size on the HD, and there I mentioned a way to do it, to liberate all those GBs on the user physical HD too.

 

First we need to write zeros to all the previously used espace where the deleted files/folders were, by means of CCleaner or using sdelete as suggested by cdob on his quoted post:

 

 

This tool recomended by cdob on this post can be used too:

Spoiler

Did you 'Zero free space (good for virtual disk optimization)' first?

https://docs.microso...wnloads/sdelete

 

 

But as said this is not enough to make the unmounted VHD size shrink to occupy on the HD only the used space, to make this happend we need to do the following: (I will use another example to make things more clear).

 

On elevated prompt, type:

 

DiskPart
Select vdisk file = L:\10x64.vhd
attach vdisk readonly
Compact vdisk
Detach disk
exit

 

In this case this is not a Wimboot VHD this is a full Win 10 install including all drivers, programs, AV, etc. on an Expandable VHD 50 GB max. size. And the user erased about 5 GB with CCleaner, (and ran also on CCleaner >>> Tools >>> Erase free espace of disk) and want to recover that free espace on his/her internal HD.

 

The command "attach vdisk readonly" on dispart  will mount the VHD as read only to protect all the files/folders from any change during running the next command.

The command "Compact vdisk" on dispart will shrink the space occupied on HD by the VHD, and make it same as the used espace into the VHD again. Whithout affecting the files/folders located on the drive into it. Let's say the VHD will stop using, and will liberate all espace that contain only zeros.

After this the user types exit to close diskpart and also same to close Command Prompt

 

So as you can see Dism, wimlib or VHD_WIMBOOT do not have anything in common with this, because we are not Capturing a VHD and/or Creating a new VHD an/or Applying anything to another VHD.

 

Using this commands to shrink the Expandable VHD size is faster than the procedure to Capture the VHD to a image file and latter Apply it to a new VHD.  And as you can imaginate as bigger and full the VHD the longer time to Capture it to a image file and latter Re-Apply it, always NOT as wimboot as this image is going to be loaded on Azure, and Azure do not admit wimboot VHDs.

 

alacran



#9 antonino61

antonino61

    Frequent Member

  • Advanced user
  • 484 posts
  •  
    Italy

Posted 2 days ago

ok even though I dont have azure, I will take ur tip and experiment on expandable vhds.



#10 alacran

alacran

    Gold Member

  • .script developer
  • 1173 posts
  •  
    Mexico

Posted 7 hours ago

Control the expansion of Expandable VHDs and VHDXs when booting from them.

 

Thanks to test made by Retokener on Post: http://reboot.pro/to...ve/#entry213549

 

Interesting is, by setting "VirtualDiskExpandOnMount"=dword:4 the vdisk size might increase only if data is written to it.

 

And on Post: http://reboot.pro/to...ve/#entry213550

 

 

Just tested setting: "VirtualDiskExpandOnMount"=dword:4

Yes, it works as expected, you can watch the vDisk size increase while data is written.

 

From: http://reboot.pro/to...ve/#entry213552

 

 

Then when creating an expandable VHD and applyng to it a WIM (index: X) image file by means of WinNTSetup, to control the expansion of the VHD, only thing we need to do is on WinNTSetup  >>> Tricks select a folder with the attached reg file located into it.  And WinNTSetup will take care to apply it to the registry of the OS into the VHD.

 

alacran

Attached Thumbnails
  • post-26560-0-91194600-1576099107_thumb.p
Attached Files unknown.gif  Controlled-Expansion-VHD.reg   322bytes

 

Or if the VHD is already created just run the reg file when booting it.

In case the VHD can't boot you will need to mount it and mount its registry and add that setting in the registry manually.

 

alacran


  • ReTokener likes this





Also tagged with one or more of these keywords: vhd, fixed, dynamic, tools for vhd

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users