Resizing a VDI
-
andygoldberg
- Posts: 4
- Joined: 27. Sep 2009, 04:33
- Primary OS: Ubuntu other
- VBox Version: OSE other
- Guest OSses: Windows 7
Resizing a VDI
I have made a 120GB XP Guest OS dynamic VDI that takes up 2.3GB on my hard drive. I repartition the VDI to 12GB, using GParted, and now the VDI takes up 9.9GB. I tried running sdelete and then using modifyhd --compact, but that caused the VDI to go to 11.6GB instead. When I run the VM it still shows only 3.0GB used out of 12GB. The other thing is that VBox still states that the VDI is 120GB.
Is there a way to tell VBox to resize the VDI to a smaller size? What would be a better way to reduce the size of a VDI, both partition and VDI, from 120GB to 12GB? Is there a way to clone a guest OS from a large VDI to a smaller VDI?
My end goal is to get the VM to be as small as possible on the HDD.
Thanks for the help!
Is there a way to tell VBox to resize the VDI to a smaller size? What would be a better way to reduce the size of a VDI, both partition and VDI, from 120GB to 12GB? Is there a way to clone a guest OS from a large VDI to a smaller VDI?
My end goal is to get the VM to be as small as possible on the HDD.
Thanks for the help!
-
MarkCranness
- Volunteer
- Posts: 875
- Joined: 10. Oct 2009, 06:27
- Primary OS: MS Windows 7
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows Server 2008 R2; Ubuntu 11.04; Windows 2000 Server; Windows XP
Re: Resizing a VDI
Be aware that the sdelete options are backwards: -C Zeros and -Z securely Cleans. If you used -Z then you have filled your VDI with random bytes which explains its new size.
To get your VDI 100% the smallest it should be will require imaging it and restoring to another VDI, the same as you would image a physical drive to another physical drive.
BUT easier and almost as good would be this:
- Repartition it back to max=120GB,
- Defrag (multiple times if needed) it to get all the files contigious, then either:
- CloneVDI with 'Compact drive while copying' set, OR
- Run sdelete -C, then modifyhd --compact (I would use CloneVDI myself, see the sticky in the Windows hosts forum)
- Repartition back to 12GB.
It is possible that CloneVDI will zero out (not copy) the non-partitioned part of the VDI, in which case the first and last repartition steps would not be needed. mpack?
Likely the growth when you repartitioned was that GParted had to move files down out of the >12GB are into the <12GB area so it could then resize the partition. This left used/non-zero (as far as VirtualBox knows) data out beyond the >12GB area, namely the old file data that was there.
To keep it small: periodically defrag followed by CloneVDI and/or consider these good suggestions by Donut:
How To: minimise the amount of writes in a Windows guest
To get your VDI 100% the smallest it should be will require imaging it and restoring to another VDI, the same as you would image a physical drive to another physical drive.
BUT easier and almost as good would be this:
- Repartition it back to max=120GB,
- Defrag (multiple times if needed) it to get all the files contigious, then either:
- CloneVDI with 'Compact drive while copying' set, OR
- Run sdelete -C, then modifyhd --compact (I would use CloneVDI myself, see the sticky in the Windows hosts forum)
- Repartition back to 12GB.
It is possible that CloneVDI will zero out (not copy) the non-partitioned part of the VDI, in which case the first and last repartition steps would not be needed. mpack?
Likely the growth when you repartitioned was that GParted had to move files down out of the >12GB are into the <12GB area so it could then resize the partition. This left used/non-zero (as far as VirtualBox knows) data out beyond the >12GB area, namely the old file data that was there.
To keep it small: periodically defrag followed by CloneVDI and/or consider these good suggestions by Donut:
How To: minimise the amount of writes in a Windows guest
-
Sasquatch
- Volunteer
- Posts: 17798
- Joined: 17. Mar 2008, 13:41
- Primary OS: Debian other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows XP, Windows 7, Linux
- Location: /dev/random
Re: Resizing a VDI
An easier method is to use the CloneVDI tool from mpack that you can grab from the sticky in Windows Hosts. Please read the same sticky in Linux Hosts too.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
-
mpack
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Mostly XP
Re: Resizing a VDI
No, CloneVDI can only detect unused blocks from a recognized filesystem. It doesn't have any way to be sure that data outside any recognized partition is unwanted (think GPT).MarkCranness wrote:It is possible that CloneVDI will zero out (not copy) the non-partitioned part of the VDI, in which case the first and last repartition steps would not be needed. mpack?
IMHO the OP is confusing the issues of reducing virtual drive size vs reducing actual VDI file size. I would go with Mark's suggestion of using gparted to expand the partition back to the full size (120GB) - now almost the entire drive falls under the control of a recognized filesystem, in which case CloneVDI (with compact option) will be able to detect the unused blocks.
-
Sasquatch
- Volunteer
- Posts: 17798
- Joined: 17. Mar 2008, 13:41
- Primary OS: Debian other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows XP, Windows 7, Linux
- Location: /dev/random
Re: Resizing a VDI
But, the file used to be just 3 GB, which after the partition shrinking, became 12 GB. That 12 GB is the size of the partition, so your tool will work either way. The used blocks are inside the partition, not outside. That's what I understand anyway.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
-
mpack
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Mostly XP
Re: Resizing a VDI
From VirtualBox's point of view, a "used block" is any 1MB block which has been written to in the past, and (in the context of shrinking) which contains something other than zeros. The used block does not have to fall inside a partition currently used by the guest.Sasquatch wrote:But, the file used to be just 3 GB, which after the partition shrinking, became 12 GB. That 12 GB is the size of the partition, so your tool will work either way. The used blocks are inside the partition, not outside. That's what I understand anyway.
So if you have a large 120GB VDI, and you attempt to shrink it by (lets say) copying all the data in the second half of the drive into previously unused blocks in the first half, then from VBox's point of view the number of used blocks has increased (the used blocks in the second half of the drive are still used, in addition to which you now also have more used blocks in the first half). Shrinking the partition will not eliminate the used blocks in the second half, neither (after shrinking the partition) will running sdelete/zerofree, neither will running CloneVDI with compact - all of the latter only work inside a recognized filesystem, not on unallocated regions of the drive.
-
Sasquatch
- Volunteer
- Posts: 17798
- Joined: 17. Mar 2008, 13:41
- Primary OS: Debian other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows XP, Windows 7, Linux
- Location: /dev/random
Re: Resizing a VDI
That makes sense.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
-
andygoldberg
- Posts: 4
- Joined: 27. Sep 2009, 04:33
- Primary OS: Ubuntu other
- VBox Version: OSE other
- Guest OSses: Windows 7
Re: Resizing a VDI
Thanks for all the suggestions. I found a potential fix. What I have done is create a blank 12GB VDI and linked that VDI and the 120GB VDI to the VM. I then ran Ghost on a boot image and ghosted the 120GB to the 12GB. The VDI went from 12GB to 1.5GB! I have several of these VDI's to do but it will be worth it.
Thanks!
Thanks!
-
mpack
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Mostly XP
Re: Resizing a VDI
No, it isn't worth it. You have discovered a very longwinded way of doing what CloneVDI (with the compact option enabled) can do in a single step. Shrinking the VDI size was completely unnecessary, the important step was finding a way to detect and discard unused clusters, which I assume Ghost does (certainly Acronis does).andygoldberg wrote:I found a potential fix. What I have done is create a blank 12GB VDI and linked that VDI and the 120GB VDI to the VM. I then ran Ghost on a boot image and ghosted the 120GB to the 12GB. The VDI went from 12GB to 1.5GB! I have several of these VDI's to do but it will be worth it.
-
Sasquatch
- Volunteer
- Posts: 17798
- Joined: 17. Mar 2008, 13:41
- Primary OS: Debian other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows XP, Windows 7, Linux
- Location: /dev/random
Re: Resizing a VDI
Ghost and Acronis (the latter I'm sure of) have an option to copy the data, or do a sector by sector copy. The prior will result in a faster and smaller clone, the latter might be useful when going to the same drive and you need hidden partitions and all with it.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.