How to Shrink Windows 10 Guest in VirtualBox?

Questions about virtualization software
Forum rules
Before you post please read how to get help
Post Reply
thenewlinuxmint
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » Sat Jul 14, 2018 3:55 am

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?

User avatar
catweazel
Level 17
Level 17
Posts: 7756
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by catweazel » 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?
¡uʍop ǝpısdn sı buıɥʇʎɹǝʌǝ os ɐıןɐɹʇsnɐ ɯoɹɟ ɯ,ı

User avatar
AndyMH
Level 5
Level 5
Posts: 750
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH » 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).
Homebrew i5-8400+GTX1080 Cinnamon 19, Thinkpad T430 i7-3632 Cinnamon 19, Thinkpad T420 Cinnamon 18.3, Thinkpad T410 Cinnamon 17.3, Thinkpad T60 19.0 Mate

User avatar
thx-1138
Level 6
Level 6
Posts: 1251
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thx-1138 » 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.

User avatar
AndyMH
Level 5
Level 5
Posts: 750
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH » Sat Jul 14, 2018 12:56 pm

Learn't something - compactVD - thanks :)
Homebrew i5-8400+GTX1080 Cinnamon 19, Thinkpad T430 i7-3632 Cinnamon 19, Thinkpad T420 Cinnamon 18.3, Thinkpad T410 Cinnamon 17.3, Thinkpad T60 19.0 Mate

thenewlinuxmint
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » 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.

thenewlinuxmint
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » Sat Jul 14, 2018 2:25 pm

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 5
Level 5
Posts: 750
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH » Sat Jul 14, 2018 4:48 pm

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.
Homebrew i5-8400+GTX1080 Cinnamon 19, Thinkpad T430 i7-3632 Cinnamon 19, Thinkpad T420 Cinnamon 18.3, Thinkpad T410 Cinnamon 17.3, Thinkpad T60 19.0 Mate

thenewlinuxmint
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » 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).

thenewlinuxmint
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » Sat Jul 14, 2018 7:23 pm

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 17
Level 17
Posts: 7756
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by catweazel » 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
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.
¡uʍop ǝpısdn sı buıɥʇʎɹǝʌǝ os ɐıןɐɹʇsnɐ ɯoɹɟ ɯ,ı

User avatar
AndyMH
Level 5
Level 5
Posts: 750
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by AndyMH » Sun Jul 15, 2018 5:26 am

Simple question - is your vdi static or dynamically allocated? You can shrink one but not the other.
Homebrew i5-8400+GTX1080 Cinnamon 19, Thinkpad T430 i7-3632 Cinnamon 19, Thinkpad T420 Cinnamon 18.3, Thinkpad T410 Cinnamon 17.3, Thinkpad T60 19.0 Mate

User avatar
thx-1138
Level 6
Level 6
Posts: 1251
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thx-1138 » 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.

thenewlinuxmint
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » Sun Jul 15, 2018 2:27 pm

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
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » Sun Jul 15, 2018 2:27 pm

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
Level 1
Level 1
Posts: 28
Joined: Sat Jul 07, 2018 3:29 am

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thenewlinuxmint » Sun Jul 15, 2018 2:28 pm

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 6
Level 6
Posts: 1251
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: How to Shrink Windows 10 Guest in VirtualBox?

Post by thx-1138 » Sun Jul 15, 2018 3:04 pm

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...)

Post Reply

Return to “Virtualization”