How to shrink a VirtualBox

Discussions related to using VirtualBox on Linux hosts.
Post Reply
Leloup78
Posts: 150
Joined: 21. Oct 2017, 15:13

How to shrink a VirtualBox

Post by Leloup78 »

Bonjour,

A lot of the work has been done. The size of /dev/sda2 has been reduced by 28G. :) Take a look at the picture below. It would be interesting to recover the space thus freed for another virtual machine or to store files under the host. But how? :?:
I did try to reduce the size of the virtual machine in the following way: C:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd E:\Leloup\LinuxMint19Mate.vdi --resize 12000 (the desired size in Mio) but it failed.
Do you have any idea? :?: :?:

Regards,
Leloup
Attachments
Shrinked_Space_02.png
Shrinked_Space_02.png (45.8 KiB) Viewed 3669 times
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to shrink a VirtualBox

Post by mpack »

Clone the drive using CloneVDI. Be sure to select the "Keep UUID" and "Compact" options. The clone VDI will be a drop in replacement for the current one, but smaller.
Leloup78
Posts: 150
Joined: 21. Oct 2017, 15:13

Re: How to shrink a VirtualBox

Post by Leloup78 »

Bonjour mpack
Thank you for your message. Cloning with your appli allows to gain about 360M on the size of the VDI file.
The goal here is different. It is to reduce the size of the file by 28G by deleting the freed space as shown on the picture.

Does anyone have an idea?

Regards,
Leloup
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to shrink a VirtualBox

Post by mpack »

If you only got back 360M then it was probably not done correctly. If you don't set the Compact option then nothing will happen, except you'll have a copy of the VDI. And if CloneVDI compaction doesn't work then nothing else will work either, since it means that the drive is already compacted.
Leloup78
Posts: 150
Joined: 21. Oct 2017, 15:13

Re: How to shrink a VirtualBox

Post by Leloup78 »

Sorry. I don't know how to do subtraction. :lol: :lol: :lol:
The use of your application allows to gain 1358M or 1.3G. ~ - 16% That's not bad. :!:
To recap, right now we are gaining real memory space on the hard drive, while I was looking to decrease the size of the virtual memory by 28G by removing the non-allocated space.
So I wonder if there is any point in reducing the size of the virtual memory. :?: :?: :?:
Attachments
cocoClone.png
cocoClone.png (20.44 KiB) Viewed 3601 times
coco.png
coco.png (9.62 KiB) Viewed 3601 times
CloneVDI.png
CloneVDI.png (7.5 KiB) Viewed 3601 times
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to shrink a VirtualBox

Post by mpack »

Ok, the terms you are using are unfamiliar, but I believe that "virtual memory" refers to the capacity of the virtual hard drive, the size you selected when you created the drive.

If you have already reduced the partition sizes inside the guest OS then the guest OS can no longer access that disk space. CloneVDI will have ensured that no physical (host) disk space is allocated to unpartitioned parts of the virtual drive. In other words, the unaccessible (unpartitioned) parts of the virtual drive now occupy no space on the host, and being partitioned the guest OS can no longer write to those areas so cannot cause blocks to be allocated to them.

In which case: no, you will not see any significant change in host file size if you reduced the virtual drive capacity.
Post Reply