Page 2 of 2

Re: Shrink VDI Disk Size to Parition Size

Posted: 12. Mar 2016, 19:19
by WFV
CloneVDI doesn't have a compact option, nor does its cli counterpart. From cli, modifyhd has compact option to compact the vdi (in this case it is not a snapshot, it's a cloned unlinked current state vdi from CloneVDI from the VirtualBox Machine menu), but it only allows compacting the vdi, not making a compacted copy. When its done, it still reports "(Normal 320GB)" in the guest machine setup. The XP partition inside is 40GB, but it can be extended to fill the entire 280GB empty space when booted using Windows diskmgmt.msc app. On one attempt, I did grow it to fill the entire 320GB disk, then while in Windows XP, ran "sdelete -z" from command prompt which zeroes the empty space, I think compacting produced a 180GB vdi that I discarded, probably misunderstanding the results. Perhaps I should grow it again to fill the existing 320GB, zero the empty space, and then compact it?

Re: Shrink VDI Disk Size to Parition Size

Posted: 12. Mar 2016, 22:07
by mpack
? Don't be ridiculous. Of course CloneVDI has a compact option. It may even be the main reason people use it. I don't know what it is you're describing after that, but it clearly isn't CloneVDI.

Re: Shrink VDI Disk Size to Parition Size

Posted: 12. Mar 2016, 22:19
by WFV
I'm concluding that booting into the guest with a live linux disk and running dd to copy the drive from 0 sector thru the end +1 of the primary partition does not work. I've tried it dd'ing to a USB FAT32 (which was a mistake as the *.img is >4GB), tried it to exfat to a second ntfs partition in the vdi mounted in a temporary location which was successful only for dd'ing the primary partition w/o its boot sector (successful in that it copied a useless 40gb image... :? ); tried it to the USB formatted ntfs from Windows which fails with permission error regardless of if you chmod it 755 (its already root:root but 755 gives it full drwx control in theory), tried it formatted NTFS via gparted within the live boot session, tried it formatted ext4 from the host. It always stops somewhere between .5GB and 2GB, the last stop showed no errors, said it created a read only image 572MB (should have been a 40GB image...). I did during all this get a copy of the boot sector:

Code: Select all

dd bs=512 count=1 if=/dev/sda of=/mnt/flash/xpmbr.img
So will also try to cat the two images into one, then vboxmanage that into a vdi and see if it will boot - I'm a little lost on the cat option at present (it will be final last ditch effort).

Re: Shrink VDI Disk Size to Parition Size

Posted: 12. Mar 2016, 22:24
by WFV
mpack wrote:? Don't be ridiculous. Of course CloneVDI has a compact option. It may even be the main reason people use it. I don't know what it is you're describing after that, but it clearly isn't CloneVDI.
You're right, my mistake. I was referring to the Clone operation in Virtualbox itself. I apologize people. I do have CloneVDI and will run it again.

Correct me if I'm wrong, in order for CloneVDI to compact an image, I first need to fill the original VDI (not snapshot) into the empty space, then zero the empty space with Windows utility sdelete -z (for this Windows XP Home Edition guest). Then close the guest, and run the CloneVDI software on the XP vdi with the compact option set (it runs in Wine on the Linux host). Thank you.

Re: Shrink VDI Disk Size to Parition Size

Posted: 13. Mar 2016, 00:37
by mpack
You are wrong. Zero filling the filesystem is unnecessary for CloneVDI, and pointless in this discussion, since the relevant portion of the disk is outside the filesystem anyway after the partition has been shrunk by GParted.

Re: Shrink VDI Disk Size to Parition Size

Posted: 13. Mar 2016, 02:24
by WFV
I think you misunderstood. I launched the guest and grew Windows into all the empty space, so now the guest is truly a 320GB install, granted only 23gb is used, if I right click on C drive it will show that it is 320Gb with 19% used, 81% free in the pie. I used Partition Wizard 9.1 while booted in the Windows XP guest to "resize" C drive. Then defragged it and then ran sdelete -z. Although defragging shouldn't make any real difference being the guest is a "file" on a linux host, it nonetheless reported 30% fragmented before defragging, and 5% after. I then created a new Virtualbox machine with no hard disk. Then I ran CloneVDI cloning the original mentioned here (which is not a snapshot but is a base vdi) with the compact setting checked with the output set to the new machine file location:
input = <Z:\home\me\VirtualBox VMs\WinXP\WinXP-disk1.vdi>
output = <Z:\home\me\VirtualBox VMs\XP\XP.vdi> compact = yes.
Once that finished, I opened VirtualBox and pointed the new machine to this new vdi.
The new vdi won't launch, it boots to the "Windows didn't close properly start in safe mode, last good config, blah, blah,,, black & white screen" none of the selections work, but even still it shows up as a "(Normal 320gb)" in the new machine Storage anyway.
The original boots up without any issue, the CloneVDI doesn't.

Re: Shrink VDI Disk Size to Parition Size

Posted: 13. Mar 2016, 11:38
by mpack
Well, certainly I misunderstood, because I assumed your discussion was on topic. The discussion in this topic is on how to shrink a VDI, i.e. permanently reduce the logical disk capacity or partition capacity such that the drive can never again grow to the old size. I confess that I see no connection between that goal and your post.

On rereading your posts I suspect you have misunderstood the purpose of this topic as dealing with compaction (another subject entirely).

Re: Shrink VDI Disk Size to Parition Size

Posted: 13. Mar 2016, 23:55
by WFV
Ok, the topic is "Shrink VDI Disk Size to Partition Size". There is no one/two step process to do this in VirtualBox or CloneVDI. Here is an unproven method using a 200GB Windows XP vdi, it's C drive partition is 40GB, with 20GB used. 1. Vboxmanage clonehd <guest.vdi> <guest.img> --raw. 2. Create a new VBox guest machine set to XP, insert the XP install disk and boot the new guest to CD, drop to "R" recovery console, and create a 40GB NTFS partition and then exit install, close the new guest. 3. Vboxmanage clonehd <newguest.vdi> <newguest.img> --raw. 4. You'll need two empty partitions formatted to NTFS on the host machine for this step; mount guest.img in partitionX (as you would mount any iso), mount newguest.img in partitionY. 5. copy all the files from partitionX to partitionY. 6. unmount partitionX and partitionY. 7. Vboxmanage newguest.img newguest.vdi (replace existing). 8. Start Virtualbox newguest, you might have to insert the XP disk and fixmbr to make the new vdi bootable.

Re: Shrink VDI Disk Size to Parition Size

Posted: 14. Mar 2016, 11:11
by mpack
Why do you insist on ignoring all previous discussion of the subject? A two step method using GParted and CloneVDI has already been outlined, it works, and is done in minutes.

Re: Shrink VDI Disk Size to Parition Size

Posted: 14. Mar 2016, 16:57
by WFV
I haven't ignored any of it, I did what was suggested earlier all except the clonezilla mention, and regardless, it creates a vdi that still reports its size as 320GB in VirtualBox, and Windows diskmgmt.msc will still show there is 280gb unallocated space in the guest with a 40GB ntfs healthy partition. If I'm insisting anything, is that those methods don't work. Granted the disk cant grow of its own volition past its partition limitation - but that does not "Shrink VDI to Partition Size". The method I mention is time consuming, and requires some hardware (the additional partitions for mounting the images) so is not recommended if someone doesn't have the time or resources. I'll report on how it turns out as I am testing it however, it might be 2 weeks before I get back with results (not that it will take 2wks to perform, but have other obligations).
EDIT: I decided to forego the operation due to hardware and time limitations - still may try to cat merge the two img files (boot img, and partition img) down the road but for now I deleted the original 320gb vdi lock-stock-n-barrel, and just did a fresh install on a fixed 40gb vdi.