How to Shrink Windows 10 Guest in VirtualBox?

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
thenewlinuxmint

How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

I tried running the VBoxManage command with the compact argument, but it did not do anything to my virtual disk. I even tried first going into the Windows 10 guest and shrinking the C drive so that there was a lot of gigabytes of unallocated space. Tried the VBoxManage command with the compact argument and no luck. Any ideas on how I can correctly shrink my VirtualBox virtual disk?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by catweazel »

thenewlinuxmint wrote: Sat Jul 14, 2018 3:55 am how I can correctly shrink my VirtualBox virtual disk?
Did you empty the trash, remove unwanted programs and data then fill the unused space with zeroes? Was the disk created as dynamic? Did you follow a tutorial, if so, what one?
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
AndyMH
Level 21
Level 21
Posts: 13569
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH »

My installation notes from when I had to resize the virtual disk, in my case making it bigger. Have no idea what would happen if you try and shrink to less than the existing win partition. From memory, I couldn't resize the existing VM so had to clone it, can't remember why, but it would be good practice to clone and modify the clone rather than screwing up the original.
51. Resizing the virtual disk. Searched on-line and tried messing around in terminal, managed to screw it up so that VB wouldn’t boot windows and had to do a complete restore of Mint to get back to a working windows system. To resize the disk:

(a) In VB manager right click on the guest OS (Windows), from the menu select clone.

(b) Accept the defaults, give the clone a name like Windows7xx without spaces (easier for what you do in terminal below and you can change it later). VB will generate a clone which will then appear in the VB window. This takes some time.

(c) Shut down VB.

(d) Open a terminal and navigate to the new folder containing the VDI, e.g.

/home/andy/VirtualBox VMs/Windows71

(e) In the terminal enter, as an example:

VBoxManage modifyhd Windows71.vdi --resize 30000

This will resize the image from whatever to 30GB.

(f) Re-start VB and run the guest OS, e.g. Windows 7.1. Goto control panel/admin computer management/storage/disk management and increase the size of C: to use the extra space. Unless this is done, windows will not see and use the additional space created. Note – while it may seem that you cannot change the size basically accept defaults and win will extend drive C:.

(g) Assume that the original guest OS image can now be deleted. Do this from VB manager (again right clicking on the guest OS that you want removed).
VB manual at:

https://www.virtualbox.org/manual/

Note - when I did this windows was happy, but office complained it was a new install and refused to run (and I'd already used up the max number of installs).
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
thx-1138
Level 8
Level 8
Posts: 2092
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thx-1138 »

...1) First run SDelete inside the VM with the -z option...
...2) Then use this for an easy gui-driven experience.

As already advised, always back-up your VMs first.
User avatar
AndyMH
Level 21
Level 21
Posts: 13569
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH »

Learn't something - compactVD - thanks :)
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
thenewlinuxmint

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

catweazel wrote: Sat Jul 14, 2018 4:32 am
thenewlinuxmint wrote: Sat Jul 14, 2018 3:55 am how I can correctly shrink my VirtualBox virtual disk?
Did you empty the trash, remove unwanted programs and data then fill the unused space with zeroes? Was the disk created as dynamic? Did you follow a tutorial, if so, what one?
I did all that you mentioned except for filling the unused space with zeroes. I read that you could use the Windows 10 Disk Defragmenter tool to do this, but Windows wouldn't let me do this because the disk is an SSD.
thenewlinuxmint

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

AndyMH wrote: Sat Jul 14, 2018 8:34 am My installation notes from when I had to resize the virtual disk, in my case making it bigger. Have no idea what would happen if you try and shrink to less than the existing win partition. From memory, I couldn't resize the existing VM so had to clone it, can't remember why, but it would be good practice to clone and modify the clone rather than screwing up the original.
51. Resizing the virtual disk. Searched on-line and tried messing around in terminal, managed to screw it up so that VB wouldn’t boot windows and had to do a complete restore of Mint to get back to a working windows system. To resize the disk:

(a) In VB manager right click on the guest OS (Windows), from the menu select clone.

(b) Accept the defaults, give the clone a name like Windows7xx without spaces (easier for what you do in terminal below and you can change it later). VB will generate a clone which will then appear in the VB window. This takes some time.

(c) Shut down VB.

(d) Open a terminal and navigate to the new folder containing the VDI, e.g.

/home/andy/VirtualBox VMs/Windows71

(e) In the terminal enter, as an example:

VBoxManage modifyhd Windows71.vdi --resize 30000

This will resize the image from whatever to 30GB.

(f) Re-start VB and run the guest OS, e.g. Windows 7.1. Goto control panel/admin computer management/storage/disk management and increase the size of C: to use the extra space. Unless this is done, windows will not see and use the additional space created. Note – while it may seem that you cannot change the size basically accept defaults and win will extend drive C:.

(g) Assume that the original guest OS image can now be deleted. Do this from VB manager (again right clicking on the guest OS that you want removed).
VB manual at:

https://www.virtualbox.org/manual/

Note - when I did this windows was happy, but office complained it was a new install and refused to run (and I'd already used up the max number of installs).
I tried to resize using that resize argument to shrink, but received an error that after investigation stems from the issue that VBoxManage doesn't let you shrink with the resize argument
User avatar
AndyMH
Level 21
Level 21
Posts: 13569
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH »

Try joining the virtuabox forum and asking there:

https://forums.virtualbox.org/

Also found this, which I think covers what you've already done:

https://www.howtogeek.com/312883/how-to ... isk-space/

It's clear from this that you do need to zero out all the free space with sdelete.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
thenewlinuxmint

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

thx-1138 wrote: Sat Jul 14, 2018 9:00 am ...1) First run SDelete inside the VM with the -z option...
...2) Then use this for an easy gui-driven experience.

As already advised, always back-up your VMs first.
I ran SDelete inside the VM with the -z argument

Then in my Linux Mint host, I ran CompactVD, opened the Windows 10 guest image, and pressed compact. What now? There was some yellow on the bar before compacting (yellow=not in use) but now it's just blue (system) and white (free).
thenewlinuxmint

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

thenewlinuxmint wrote: Sat Jul 14, 2018 7:19 pm
thx-1138 wrote: Sat Jul 14, 2018 9:00 am ...1) First run SDelete inside the VM with the -z option...
...2) Then use this for an easy gui-driven experience.

As already advised, always back-up your VMs first.
I ran SDelete inside the VM with the -z argument

Then in my Linux Mint host, I ran CompactVD, opened the Windows 10 guest image, and pressed compact. What now? There was some yellow on the bar before compacting (yellow=not in use) but now it's just blue (system) and white (free).
Update: I tried running the VBoxManage command with compact argument again, it completed to 100% but the disk image is still the same size
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by catweazel »

thenewlinuxmint wrote: Sat Jul 14, 2018 2:24 pm
catweazel wrote: Sat Jul 14, 2018 4:32 am
thenewlinuxmint wrote: Sat Jul 14, 2018 3:55 am how I can correctly shrink my VirtualBox virtual disk?
Did you empty the trash, remove unwanted programs and data then fill the unused space with zeroes? Was the disk created as dynamic? Did you follow a tutorial, if so, what one?
I did all that you mentioned except for filling the unused space with zeroes. I read that you could use the Windows 10 Disk Defragmenter tool to do this, but Windows wouldn't let me do this because the disk is an SSD.
In that case, you might reconsider using sdelete as it will shorten the life of your SSD.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
AndyMH
Level 21
Level 21
Posts: 13569
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH »

Simple question - is your vdi static or dynamically allocated? You can shrink one but not the other.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
thx-1138
Level 8
Level 8
Posts: 2092
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thx-1138 »

thenewlinuxmint wrote: Sat Jul 14, 2018 7:19 pm...........What now?
...not now, but...BEFORE: read the manual first maybe?
You know, it never hurt anyone. Other than that, you already got answers above (and furthermore, you still get one now).
Irrespective of the disk capacity and format....there are two options of how to create a disk image: fixed-size or dynamically allocated.
.............................
If you create a fixed-size image, an image file will be created on your host system which has roughly the same size as the virtual disk's capacity.
.............................
For more flexible storage management, use a dynamically allocated image.
This will initially be very small and not occupy any space for unused virtual disk sectors, but will grow every time a disk sector is written to for the first time, until the drive reaches the maximum capacity chosen when the drive was created.
The --compact option can be used to compact disk images, i.e. remove blocks that only contains zeroes.
This will shrink a dynamically allocated image again; it will reduce the physical size of the image without affecting the logical size of the virtual disk.
......................................................
For Windows guests, you can use the sdelete tool provided by Microsoft.
Execute sdelete -z in the guest to zero the free disk space before compressing the virtual disk image.
thenewlinuxmint

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

catweazel wrote: Sun Jul 15, 2018 2:08 am
thenewlinuxmint wrote: Sat Jul 14, 2018 2:24 pm
catweazel wrote: Sat Jul 14, 2018 4:32 am

Did you empty the trash, remove unwanted programs and data then fill the unused space with zeroes? Was the disk created as dynamic? Did you follow a tutorial, if so, what one?
I did all that you mentioned except for filling the unused space with zeroes. I read that you could use the Windows 10 Disk Defragmenter tool to do this, but Windows wouldn't let me do this because the disk is an SSD.
In that case, you might reconsider using sdelete as it will shorten the life of your SSD.
yikes, thanks for the info
thenewlinuxmint

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

AndyMH wrote: Sun Jul 15, 2018 5:26 am Simple question - is your vdi static or dynamically allocated? You can shrink one but not the other.
it is dynamically allocated
thenewlinuxmint

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint »

thx-1138 wrote: Sun Jul 15, 2018 11:35 am
thenewlinuxmint wrote: Sat Jul 14, 2018 7:19 pm...........What now?
...not now, but...BEFORE: read the manual first maybe?
You know, it never hurt anyone. Other than that, you already got answers above (and furthermore, you still get one now).
Irrespective of the disk capacity and format....there are two options of how to create a disk image: fixed-size or dynamically allocated.
.............................
If you create a fixed-size image, an image file will be created on your host system which has roughly the same size as the virtual disk's capacity.
.............................
For more flexible storage management, use a dynamically allocated image.
This will initially be very small and not occupy any space for unused virtual disk sectors, but will grow every time a disk sector is written to for the first time, until the drive reaches the maximum capacity chosen when the drive was created.
The --compact option can be used to compact disk images, i.e. remove blocks that only contains zeroes.
This will shrink a dynamically allocated image again; it will reduce the physical size of the image without affecting the logical size of the virtual disk.
......................................................
For Windows guests, you can use the sdelete tool provided by Microsoft.
Execute sdelete -z in the guest to zero the free disk space before compressing the virtual disk image.
thank you for the links. it's evident that cloning the (now) compacted vdi is the best way to go
User avatar
thx-1138
Level 8
Level 8
Posts: 2092
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thx-1138 »

thenewlinuxmint wrote: Sun Jul 15, 2018 2:28 pm............................
...out of curiosity, i tried to further dig around if using sdelete -z is problematic in any way, especially under SSDs:
1) The manual itself above recommends such.
2) The moderators on VirtualBox forums still do recommend it's usage even with SSDs (on other threads there as well...)

Basically, it 'just' overwrites unused blocks with 00s.
Ie. if you have a 10GB image and you overwrite 3GB unused blocks with 00s,
you've 'limited' your SSD's life by...exactly 3GB of write operations.
As that's exactly what a typical movie download / 'write-to-disk' would do these days, it's probably not really a big deal...

...For advanced cloning operations specifically they seem to recommend this app.
It's for Win systems, but you might still be interested in it (ie. running it under Wine etc etc...)
rustyp
Level 4
Level 4
Posts: 242
Joined: Sun Nov 02, 2014 1:45 pm

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by rustyp »

AndyMH wrote: Sat Jul 14, 2018 8:34 am My installation notes from when I had to resize the virtual disk, in my case making it bigger. Have no idea what would happen if you try and shrink to less than the existing win partition. From memory, I couldn't resize the existing VM so had to clone it, can't remember why, but it would be good practice to clone and modify the clone rather than screwing up the original.
51. Resizing the virtual disk. Searched on-line and tried messing around in terminal, managed to screw it up so that VB wouldn’t boot windows and had to do a complete restore of Mint to get back to a working windows system. To resize the disk:

(a) In VB manager right click on the guest OS (Windows), from the menu select clone.

(b) Accept the defaults, give the clone a name like Windows7xx without spaces (easier for what you do in terminal below and you can change it later). VB will generate a clone which will then appear in the VB window. This takes some time.

(c) Shut down VB.

(d) Open a terminal and navigate to the new folder containing the VDI, e.g.

/home/andy/VirtualBox VMs/Windows71

(e) In the terminal enter, as an example:

VBoxManage modifyhd Windows71.vdi --resize 30000

This will resize the image from whatever to 30GB.

(f) Re-start VB and run the guest OS, e.g. Windows 7.1. Goto control panel/admin computer management/storage/disk management and increase the size of C: to use the extra space. Unless this is done, windows will not see and use the additional space created. Note – while it may seem that you cannot change the size basically accept defaults and win will extend drive C:.

(g) Assume that the original guest OS image can now be deleted. Do this from VB manager (again right clicking on the guest OS that you want removed).
VB manual at:

https://www.virtualbox.org/manual/

Note - when I did this windows was happy, but office complained it was a new install and refused to run (and I'd already used up the max number of installs).
I am at step (d) my VDI is located on a external 1gig hard drive, how do I navigate to the external drive and directory , I searched and read for about an hour but have struck out I am pretty sure I will need a tutorial of some sort I did figure out its pointless researching something unless you know the language or lingo :-)

Thanks.
Before posting on this site I always verify I have the latest version of Linux Mint Cinnamon installed and run Update Manager.
Thanks.
User avatar
AndyMH
Level 21
Level 21
Posts: 13569
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH »

Assume you are running mint cinnamon and assume you have an external USB drive (1G sounds a bit small? more likely 1TB?).

Plug in the drive, mint will auto mount it in /media/you. And normally nemo (file manager) will open to show contents. Somewhere on that drive will be your VirtualBox VMs folder and inside that the folder containing your vdi file. When you are in the folder containing your vdi file right click in the file manager and open a terminal.
Win71_004.png
Then you can type in the commands in my previous post.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
rustyp
Level 4
Level 4
Posts: 242
Joined: Sun Nov 02, 2014 1:45 pm

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by rustyp »

Yes 1TB sorry

Nice trick on getting to the directory thanks.

I input VBoxManage modifyhd Windows 10 - Google Earth Clone-disk1.vdi --resize 50000

The output is

100@Tower /media/ooo/19381EB650CBB428/Virtual Box Appliances/Windows 10 - Google Earth Clone $ VBoxManage modifyhd Windows 10 - Google Earth Clone-disk1.vdi --resize 50000
Oracle VM VirtualBox Command Line Management Interface Version 5.2.22
(C) 2005-2018 Oracle Corporation
All rights reserved.

Usage:

VBoxManage modifymedium [disk|dvd|floppy] <uuid|filename>
[--type normal|writethrough|immutable|shareable|
readonly|multiattach]
[--autoreset on|off]
[--property <name=[value]>]
[--compact]
[--resize <megabytes>|--resizebyte <bytes>]
[--move <path]
[--description <description string>]

Syntax error: Invalid parameter '10'
100@Tower /media/ooo/19381EB650CBB428/Virtual Box Appliances/Windows 10 - Google Earth Clone $

Suggestions?

Thanks in advance
Before posting on this site I always verify I have the latest version of Linux Mint Cinnamon installed and run Update Manager.
Thanks.
Locked

Return to “Virtual Machines”