Skip to main content

Virtualbox : Shrink VM disk


So you've finally succeeded running a windows virtual machine (VM) on your desktop. You play around the vm; copying files, installing & deleting applications and so on. After a while, you found out that your vm is using let say 20gb out of 100gb (which you set during creating the vm) disk but your local machine (host) report that you have used up 50gb. So how can you claim back that extra 30gb in your host ?



Briefly you have to do these :
1) (VM) Defrag your vm.
2) (VM) Zero-rise your vm disk clear space.
3) (Host) Compact your vm's vdi/disk.

1) (VM) Defrag your vm.
- Start your windows VM & defrag your virtual disk using your choice of defragment utility. This is to rearrange all your files back & to improve your vm performance.

2) (VM) Zero-rise your vm disk clear space.
- Use sdelete to zero-rise those clean space. This has something to do with high-watermark thing
   eg. you have use 10gb space & then you copy in a 4gb file = 14gb. Then you delete that 4gb file, so your vm will report you have 10gb back right ? Yes, but your host will not recognize that & still hold on to that 14gb usage of disk.
- Get the sdelete utility & extract it to a folder eg. C:\Apps\sdelete
- To use sdelete, open up a command prompt (Start => Run => cmd) . 
- Go to the folder where you extract the sdelete utility. eg cd apps\sdelete
- Then run this 'sdelete -z' without the quote & let the utility runs till finish. 
- To know what else sdelete can do, just run 'sdelete' & it will show what other options are available.
- After the sdelete complete, shutdown your vm. So the vm part is finish.



3) (Host) Compact your vm's vdi/disk.
- Take note of your vdi size, you can find the location in your vm settings in the virtualbox.
- Close your Virtualbox & starts the command prompt in your host or local pc.
- Go to your Virtualbox installation folder. eg. cd Program Files\Oracle\VirtualBox
- Type in 'vboxmanage list hdds', this will list out all your vdi or virtual disk image. Take not of the UUID or Location info.
- Lastly, to shrink that vdi type 'vboxmanage modifyhd <uuid/location> --compact'.
     eg. vboxmanage modifyhd 9b1ea8fb-b72b-49db-a7b8-9bfdbfb3664e --compact or
          vboxmanage modifyhd  < full path to your vdi file > --compact 
- And then just wait for the vdi to be automagically shrink like picture below.





Lastly, check again your vdi size, it should be almost the same size as it in you virtual machine.
Hope it works for you as it works for me. Happy trying.

Comments

Popular posts from this blog

Why I Can't Move/Import VM in XenServer.

Ok this is what i found out, the metadata export/import via ' Backup, Restore and Update ' menu in xsconsole OR using ' xe vm-export filename=xxx metadata=true vm= ' will export all vm's metadata eventhough you've specify the vm in the latter, the former is ok because it is backup & restore tool. Problem happens when you want to restore the metadata or import to another xenserver. If you follow the method from 'Backup and Restore' in the reference guide, it should be ok if you're using pool because all pools are using shared storage; and if you don't use pool, your xenserver store all the VMs in the shared storage ONLY, means the Local SR is not use at all. This way, you wont face any problem. But, what if you have a mix of local & shared storage use. 

SQL using partition and connect by clause.

select id, max(ltrim(sys_connect_by_path(gred,' , '),' , ')) as mygred from (select b.KJ19SIJIL||b.KJ19KOD as id, b.KJ19GRED as gred, row_number() over(partition by b.KJ19SIJIL||b.KJ19KOD order by b.KJ19GRED) as myrow from kj19setara b) start with myrow = 1 connect by prior myrow = myrow -1 and prior id = id group by id order by 1;

Use raw disk for Apache Trafficserver in Centos 7

I want to use raw disk for my Trafficserver 5.1.0. I've created a partition at /dev/sda5 and in order to allow trafficserver to use the disk, please follow these steps. 1) Edit/create a file in /etc/udev/rules.d . I named it 50-ats.rules eg. vi /etc/udev/rules.d/50-ats.rules 2) Add these text. SUBSYSTEM=="block", KERNEL=="sda5", GROUP:="trafficserver", OWNER:="nobody" note : - sda5 is the disk/partition I want to use with trafficserver. - OWNER:="nobody" is the default owner when you compile trafficserver.