CloneVDI tool - Discussion & Support

Discussions related to using VirtualBox on Windows hosts.

Re: CloneVDI tool - Discussion & Support

Postby mpack » 12. Feb 2020, 14:02

@EthanH:

I've just uploaded a new version of CloneVDI (v4.01) to the first page. Perhaps you could give it a try and report back.

It was actually a combination of two separate crashes, but since both were memory access exceptions you would get the same result code.

Crash #1 (invalid option used): was due to an error when trying to format the error string which says "unknown option". The fact that no error window or message appears ought to have been a clue for me here. Since people generally don't give it invalid command line options this has gone unreported until now.

Crash #2 (-c option used): has to do with the new GPT support features. I had to change the old "open a new disk" code because I need to know quite early on whether I'm dealing with an MBR or GPT drive. I neglected to make the same changes to the command line startup code.
mpack
Site Moderator
 
Posts: 30971
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: CloneVDI tool - Discussion & Support

Postby EthanH » 12. Feb 2020, 20:59

@mpack:

Your fixes worked perfectly. Many thanks!

Crash #1 (invalid option used): was due to an error when trying to format the error string which says "unknown option". The fact that no error window or message appears ought to have been a clue for me here. Since people generally don't give it invalid command line options this has gone unreported until now.

I'm good at creatively breaking things.
EthanH
 
Posts: 7
Joined: 15. Nov 2019, 20:12

Re: CloneVDI tool - Discussion & Support

Postby EthanH » 12. Feb 2020, 23:54

I attached a script we use to automate virtual disk compression with mpack's excellent CloneVDI tool. We use VirtualBox extensively to run test and measurement machines. Our typical servers host 8 - 12 VMs. Operating system updates (many of the VMs are Windows), general cruft, etc. bloat the size of the virtual disks over time. Manually compacting these drives is tedious, and while vboxmanage modifymedium --compact works, it requires first defragmenting the VM disk in the guest o/s, and zeroing out free space to work well. CloneVDI is far simpler.

The attached script iterates through all VMs registered with VirtualBox on your computer then calls CloneVDI to compact each vdi disk (the script is hard-coded for vdi; I have not tested CloneVDI on other virtual disk formats). Before compaction begins, any running virtual machines are shut down and VirtualBox is closed.

For full automation, either put the script in the same folder as CloneVDI.exe or pass the path to CloneVDI on the command line. Example:
Code: Select all   Expand viewCollapse view
(Powershell)
PS .\CompactAllVDI.ps1 "C:\Some Folder\CloneVDI.exe"

(command)
CompactAllVDI.ps1 "C:\Some Folder\CloneVDI.exe"


If CloneVDI is not in the same folder as CompactAllVDI.ps1, a dialog opens prompting you to locate it. The default action is to clone and compact each virtual disk, delete the original to the recycle bin, then rename the clone to the original disk name. VirtualBox is none the wiser, and you are left with vdi files that consume less disk space on your system. Compacting Windows 10 guests once a month or so typically frees 7 - 12GB per virtual disk.

If your VMs live on a SSD, particularly one without significant amounts of free space, the cloning and compaction process can consume enough space that throughput drops significantly. CompactAllVDI.ps1 has a command line option to empty the recycle bin for the drive a VM is on after the clone-compact process completes on each drive. This frees SSD blocks and fires the TRIM command to start garbage collection on the drive. The result is disk throughput stays more consistent. To enable this mode, set the -EmptyRecycleBin to $true:
Code: Select all   Expand viewCollapse view
PS .\CompactAllVDI.ps1 -EmptyRecycleBin $true


For a fully automated flow (e.g. a scheduled task), launch the script with the path to CloneVDI and, if desired, EmptyRecycleBin:
Code: Select all   Expand viewCollapse view
PS .\CompactAllVDI.ps1 -PathToCloneVDI "C:\Some Folder\CloneVDI.exe" -EmptyRecycleBin $true


Powershell WhatIf syntax is supported. CompactAllVDI will show what will happen but not actually do anything when called with -WhatIf. Also, the standard Get-Help commands work with CompactAllVDI.

Final notes: We've tested this script on Windows 10 and Windows server 2019 machines and dozens of VMs. No problems with file corruption yet, but as always, backups are highly recommended. The script requires either version 3.0.2 of CloneVDI or version 4.0.1+.

The script is signed with our Authenticode cert. Modifications require either signing it with your own cert or stripping the existing certificate out for Powershell to run it. Powershell's execution policy may need to be changed on your system. I recommend AllSigned (Set-ExecutionPolicy AllSigned) to require a signature on all Powershell scripts if you have your own trusted cert, or RemoteSigned to require all downloaded scripts be signed. Setting a policy of Bypass opens your system to more malicious activity than I am comfortable with.
-------------------------------------------

All code is now available on GitHub: https://github.com/ethan8989/CompactAllVDI

-------------------------------------------
[ Edit: 18-Mar-2020: Version 1.2.2 Reports disk space reduction for each vdi disk compaction and overall. ]
[ Edit: 11-Mar-2020: Version 1.2. Terminates orphaned VBoxSVC processes still running after all running VMs are shut down and VirtualBox closed. ]
Attachments
CompactAllVDI.zip
VDI compaction Powershell script
(12.57 KiB) Downloaded 5 times
Last edited by EthanH on 19. Mar 2020, 03:11, edited 2 times in total.
EthanH
 
Posts: 7
Joined: 15. Nov 2019, 20:12

Re: CloneVDI tool - Discussion & Support

Postby mpack » 13. Feb 2020, 12:22

Thanks for reporting back, and for contributing the script.
mpack
Site Moderator
 
Posts: 30971
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: CloneVDI tool - Discussion & Support

Postby Lisa Miller » 12. Mar 2020, 11:11

Hello,

I'm not sure if it is possible with CloneVDI to select a partition to create a RAW image or a VDI file from Windows 7 pro 64. At least I can't figure out how to select a partition. I only see how to select a single file.

Greeting
Lisa Miller
 
Posts: 5
Joined: 11. Mar 2020, 02:30

Re: CloneVDI tool - Discussion & Support

Postby mpack » 12. Mar 2020, 11:42

CloneVDI isn't a partition manager, it's a virtual disk cloning and tuning tool. What fundamentally are you trying to do?

[Edit] From your other posts I see you are trying to P2V a physical Win7 system. For that you should use Disk2VHD as Scott has already recommended. The latter is simple to use, however the VHD format itself is pretty awful (prone to corruption), so once you have the VHD you'd run it through CloneVDI to convert it to VDI. You'd then build a VM around the VDI, trying to make the VM "recipe" as close as possible to your old Win7.

If the VDI contains unwanted partitions then you would deal with that after you have a working VM, by just deleting the unwanted partitions in Win7 itself.
mpack
Site Moderator
 
Posts: 30971
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Previous

Return to VirtualBox on Windows Hosts

Who is online

Users browsing this forum: Baidu [Spider] and 52 guests