• Reclaim Space from a Windows VM on Virtual Box

    • This topic has 22 replies, 5 voices, and was last updated 5 years ago.
    Author
    Topic
    #2258539

    I have a Windows (2000) VM in VirtualBox with a dynamic expanding drive. I need to shrink the drive size since I’ve removed a couple GB of files from the VM. How would I go about doing that? Does it require zeroing out the data on the Windows side then finding a way to adjust the VM hard drive size?

    Thanks!

    Nathan Parker

    Viewing 12 reply threads
    Author
    Replies
    • #2258548

      It’s done in the VM manager with the client shut down – assuming it is possible in your software.

      Alternatively you could create a new disk, connect it to the VM, boot the whole lot with a backup/clone utility and clone. Then disconnect the old disk and connect the new one in the same location. If all is well, delete the old disk.

      cheers, Paul

      1 user thanked author for this post.
    • #2258555

      In the VirtualBox program directory is a command-line utility called vboxmanage.exe that is supposed to do this with the command “vboxmanage  modifyhd –compact”.

      That said, I’ve never had much luck getting it to compact very much, so I usually resort to Paul’s second suggestion: create a new (dynamically expanding) virtual disk, attach it to the VM, boot the VM from a cloning program’s boot disk (example: an ISO of a Macrium Reflect “Rescue CD”), and clone the original disk to the new disk. That does a really good job of shrinking a virtual disk file.

       

      1 user thanked author for this post.
    • #2258625

      To shrink the virtual disk file, free space has to be zeroed first. Within a Windows guest, it is generally suggested to do that with SDelete.

      I usually run SDelete after clearing app caches and getting rid of other temporary files with the built-in Disk Cleanup utility. Then I shut down the VM and run the “compact” command.

      From the online manual: 8.22. VBoxManage modifymedium (modifyhd is still supported).

      3 users thanked author for this post.
      • #2258720

        Within a Windows guest, it is generally suggested to do that with SDelete. I usually run SDelete after clearing app caches and getting rid of other temporary files with the built-in Disk Cleanup utility. Then I shut down the VM and run the “compact” command.

        I did not know about the sdelete utility. I tested it on a copy of a vdi file and it worked great!

         

        1 user thanked author for this post.
      • #2258757

        sdelete is the standard and most well-known way to resolve this issue.
        An alternative way built in the OS utility defrag is to run:
        defrag -C -L -H
        or the equivalent explicit
        defrag /AllVolumes /Retrim /NormalPriority
        For more information and suitable switches, try from a command line run as administrator:
        defrag /?

        1 user thanked author for this post.
    • #2258828

      Sounds good. I’ll try SDelete and the Compact Utility this week or next weekend and report back on how it goes.

      Thanks again!

      Nathan Parker

    • #2260679

      Having issues running sdelete on Windows 2000. I keep receiving an error message saying not a valid Win 32 application.

      Nathan Parker

      1 user thanked author for this post.
      • #2260732

        Sorry! It seems I didn’t pay attention to the SDelete documentation I linked to, and failed to notice it is for Vista and above.

        A bit of research suggests that in Windows 2000, perhaps the same job can be done with the built-in command line tool called cipher. For example, use cipher /w:C to wipe the free space on drive C.

        2 users thanked author for this post.
        • #2260853

          Sorry! It seems I didn’t pay attention to the SDelete documentation I linked to, and failed to notice it is for Vista and above.

          I guess I also missed that.

          In my experiment, I had disconnected the vdi file from the Win2K VM and connected it as a secondary to a Win7 VM, and ran the sdelete utility from Win7.

          I did that merely because I already had the sdelete utility downloaded to the Win7 VM, so it was quicker for me to move the vdi disk rather than booting the W2K VM and re-downloading the sdelete utility.

          So I guess I accidentally avoided the W2K incompatibility without knowing it.

           

          1 user thanked author for this post.
    • #2260698

      SDelete is only a data overwrite utility. It doesn’t free up space.
      I can’t see how that will affect a VM as the VM doesn’t track free/unused space, that’s done by the client OS and the VM expands the disk as the OS requests more file space.

      cheers, Paul

      1 user thanked author for this post.
      • #2260737

        Right. Once SDelete (or similar utility) has been used within the guest (client) to zero the free space created by deleting files, the VM manager’s compact utility will be able to do a nice job of shrinking the virtual disk file.

        As an example, this morning I ran through the process of updating my Windows 8.1 Pro guest with the April patches, then performing a Disk Cleanup and SDelete, and then compacting the VDI.

        Before starting up the guest:
        1_StartSize

        After running Windows Update, Disk Cleanup, SDelete, and shutting down the guest:
        2_PostUpdateCleanupSDelete

        After running VBoxManage modifymedium –compact ‘Windows 8.1 Pro.vdi’:
        3_AfterCompact

        • This reply was modified 5 years ago by SB9K.
        • This reply was modified 5 years ago by SB9K.
        1 user thanked author for this post.
    • #2260926

      Tried Cipher and the Compact, and it seems the reverse happened. It expanded the disk to its full size.

      Should I try cloning the drive to another dynamic expanding drive now? 🙂

      Thanks!

      Nathan Parker

      • #2260931

        Or! Find an older version of SDelete compatible with Windows 2000. 😉

        A walk through the Wayback Machine showed me that sometimes Microsoft upped the minimum supported version of Windows without actually updating SDelete!

        So, here’s a couple of links for ya:

        I suspect, but have not been able to verify (due to no handy copies of these older Windows versions) that SDelete 2.0 is the one that actually dropped support for pre-Vista versions.

        1 user thanked author for this post.
      • #2260935

        Should I try cloning the drive to another dynamic expanding drive now?

        That’s what I would do. But don’t use the vboxmanage.exe utility to clone/copy from outside the VM — I think vboxmanage.exe just duplicates the vdi file (with a new GUID), so you’d end up with another full-size duplicate.

        Go back to the second option Paul and I mentioned in the 2nd and 3rd posts: create/attach a new, dynamically expanding disk, then boot the VM and clone from inside the VM — for instance, by booting the VM from an ISO of a bootable Macrium “Rescue” CD, or similar.

        Depending on your choice of program, it might also work by installing the program in your W2K VM, but just to avoid any potential further conflicts, I’d instead create a bootable ISO (from another VM or a real machine) and clone from that environment instead of from W2K.

         

        1 user thanked author for this post.
      • #2260937

        It expanded the disk to its full size

        This is probably because it zeroed free space instead of reading the FAT for unused file locations and only zeroing them.

        cheers, Paul

        1 user thanked author for this post.
    • #2260936

      this morning I ran through the process of updating my Windows 8.1 Pro guest with the April patches, then performing a Disk Cleanup and SDelete, and then compacting the VDI.

      Please do the testing for us.

      1. Use the VM and create / delete lots of large files.
      2. Clone the VM by copying the files.
      3. Fire up both VMs and use SDELETE on one.
      4. Compact both.

      cheers, Paul

      1 user thanked author for this post.
      • #2260973

        I’m sorry, but I won’t be going that far. I’ve done my best to help the OP with the specific situation of needing to compact a Windows 2000 virtual disk in VirtualBox. If I hadn’t already had a VirtualBox-based VM, I wouldn’t have created one just for testing.

        If you’re curious to find out which of the two methods will save more space, you may compare them yourself. For my own use, I’m very happy with the results.

        I honestly didn’t expect a reduction of over 4GB, as the Disk Cleanup step had only removed 962MB. But then again, that was also the very first time that VDI had been compacted.

        Regardless of method used, I hope Nathan achieves success with shrinking the Windows 2000 VM.

        2 users thanked author for this post.
    • #2261115

      Sounds good. I’ll do the test with the SDelete versions posted. If I still have issues, I’ll do the clone.

      So I’ll do tests until something works, then report back. 🙂

      Nathan Parker

      1 user thanked author for this post.
    • #2261277

      I tried SDelete and the Compact, and it didn’t shrink the file size any. The version of SDelete did launch on Windows 2000. The command I ran was “sdelete -z C:\”. If that’s not the correct command, I can try another one.

      I’ll likely proceed with trying the clone. Where would I download the cloning ISO I can mount in the VM to take this for a spin? I’ll probably just use an ISO I can boot from to do the clone instead of hunting down a version that works with Windows 2000.

      Thanks!

      Nathan Parker

    • #2261287

      You need any of the usual backup utilities (EaseUs ToDo, Aomei etc) then create a recovery ISO from that. The ISO is around 500MB.

      Clonezilla is an open source alternative with a live CD download – probably easiest.

      cheers, Paul

      1 user thanked author for this post.
    • #2261570

      CloneZilla looks like the tool I’d need. I’ll give it a spin and report back.

      Nathan Parker

    • #2263218

      I tried to clone it through CloneZilla, and I also learned that multitasking isn’t a good idea. 🙂 I ended up messing something up and wiping out my Windows 2000 virtual hard drive. My backup didn’t work either due to the backup issues I’ve had with my NAS.

      The good news is I didn’t have much configured on it, and I had the installers for what I put on it (I didn’t have much time to configure it after setting it up), so it was pretty painless to nuke the virtual drives completely and put a fresh copy of Windows 2000 on a fresh virtual hard drive, then reinstall my programs. I’ve successfully backed that copy up now in case something else occurs, so I should be set.

      I’ve been knee-deep with my network transition, and trying to work this in while multitasking wasn’t the best move. I should have waited until I could focus on it, but at least the final restore wasn’t too painful.

      Nathan Parker

      2 users thanked author for this post.
    Viewing 12 reply threads
    Reply To: Reclaim Space from a Windows VM on Virtual Box

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: