Page 1 of 2

How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 3:55 am
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?

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 4:32 am
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?

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 8:34 am
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).

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 9:00 am
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.

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 12:56 pm
by AndyMH
Learn't something - compactVD - thanks :)

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 2:24 pm
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.

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 2:25 pm
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

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 4:48 pm
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.

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 7:19 pm
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).

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sat Jul 14, 2018 7:23 pm
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

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sun Jul 15, 2018 2:08 am
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.

Re: How to Shrink Windows 10 Guest in VirtualBox?

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

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sun Jul 15, 2018 11:35 am
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.

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sun Jul 15, 2018 2:27 pm
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

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sun Jul 15, 2018 2:27 pm
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

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sun Jul 15, 2018 2:28 pm
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

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Sun Jul 15, 2018 3:04 pm
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...)

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Fri Jan 04, 2019 5:54 pm
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.

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Fri Jan 04, 2019 6:42 pm
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.

Re: How to Shrink Windows 10 Guest in VirtualBox?

Posted: Fri Jan 04, 2019 8:15 pm
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