How to reduce the dynamic size of .vdi VM to smaller size?

Discussions related to using VirtualBox on Linux hosts.
Post Reply
qiubosu
Posts: 6
Joined: 10. May 2010, 01:38
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: windows server 2003

How to reduce the dynamic size of .vdi VM to smaller size?

Post by qiubosu »

Dear VirtualBox Community,

I have an VM image (with Ubuntu 12.04 server OS installed) OldVMImage.vdi, and its acutal size (shown with "ls -l OldVMImage.vdi") is about 15GB, but its maximum size (dynamic size) is 1T (when installed the Ubuntu OS, configured the harddrive as one dynamic disk with 1T size and was formatted as lvm2 format as a whole). I converted it to RAW format with "VBoxManage internalcommands converttoraw OldVMImage.vdi NewVMImage.img", but the size of the RAW format NewVMImage.img tends to be as large as 1T (Note: the host machine only has about 30GB space left) and this is not what I want. I want the size of the RAW format NewVMImage.img is closed to the actual size of OldVMImage.vdi, i.e. about 15GB.

In order to get the smaller size of the converted RAW format VM disk. I tried to shrink the dynamic size of OldVMImage.vdi first, and then do the convertion. I used Gparted, but the 1T lvm2 partition can't be resized. I used the system-config-lvm to resize the root partition (1T) to smaller size, say 20GB, but after this was done, the Ubuntu OS can't be sucessfully started anymore, while stop at initramfs with some errors after reboot.

How and what should do in order to shrink the dynamic size of OldVMImage.vdi, and then convert it to the RAW format VM to get the reduced size NewVMImage.img, and the OS still works well when reboot?

Thank you.
Last edited by qiubosu on 23. Aug 2014, 06:26, edited 4 times in total.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: How to reduce the dynamic size of .vdi VM to smaller siz

Post by Perryg »

You can do this with gparted but be aware it could trash the image. Shrinking is always iffy.
qiubosu
Posts: 6
Joined: 10. May 2010, 01:38
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: windows server 2003

Re: How to reduce the dynamic size of .vdi VM to smaller siz

Post by qiubosu »

Thank you Perrryg. I update the post. Can you check it out again? Thanks.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: How to reduce the dynamic size of .vdi VM to smaller siz

Post by Perryg »

I am not sure gparted supports LVM yet and even if so how it would deal with shrinking an image. You need to ask some place that deals with drive manipulation since this is not part of VirtualBox and outside the scope here.
qiubosu
Posts: 6
Joined: 10. May 2010, 01:38
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: windows server 2003

Re: How to reduce the dynamic size of .vdi VM to smaller siz

Post by qiubosu »

Thanks Perryg. If the actual size of .vdi is 15GB and its dynamic size is 1T. After convert it to RAW format, .img, what is the actual size? still 1T? (due to my host only has 30GB space left, when convert acutal size 15GB .vdi to RAW format, when the RAW format VM grows over 25GB and closed to 30GB, I stop the convertion, so I don't know how big size of the RAW format VM will be at the end of convertion). Thanks.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to reduce the dynamic size of .vdi VM to smaller siz

Post by mpack »

A raw image of a disk will by definition be the same size as the disk or partition it represents. The space currently used by the guest OS filesystem isn't relevant in that calculation.

Since "raw" is obviousy a blind alley, I suggest that you return to using VDI.

I'm afraid that the fact that LVM has been used makes manipulation of the disk structures impossible using any tools that I'm familiar with. Otherwise you could have just used GParted and shrink the partition to whatever size suits you, then compact using CloneVDI. If it was me, I'd Google for advice on how to convert an LVM drive(s) to legacy MBR partitioning.

I should also perhaps say: compaction (e.g. as done by CloneVDI) is useful when a disk has been expanded significantly due to an uncommon event that ate up a lot of space. But, compaction is kind of pointless if it reduces the VDI below it's "normal" working size. The VM will just return to that size again very quickly. If the latter is the case then a larger disk drive is a much better option.

p.s. This reply was originally given in your cross-post of this discussion, which I'm about to delete. Please do not cross post again.
Post Reply