<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LinuxReaders &#187; Shrink Virtualbox VM</title>
	<atom:link href="http://www.linuxreaders.com/tag/shrink-virtualbox-vm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.linuxreaders.com</link>
	<description></description>
	<lastBuildDate>Wed, 08 Sep 2010 05:06:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How To Shrink Your Virtualbox VM</title>
		<link>http://www.linuxreaders.com/2009/04/21/how-to-shrink-your-virtualbox-vm/</link>
		<comments>http://www.linuxreaders.com/2009/04/21/how-to-shrink-your-virtualbox-vm/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 19:34:26 +0000</pubDate>
		<dc:creator>Dhaval Thakar</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Shrink Virtualbox VM]]></category>

		<guid isPermaLink="false">http://www.linuxreaders.com/?p=212</guid>
		<description><![CDATA[While using Virtualbox, one thing that I have found is that the size of the VM (a file with .VDI extension) expands over time. If you have selected the “Dynamically Expanding Storage” option when first creating the VM, you will find that the file size expands whenever you install new applications in the VM. That [...]<p><a href="http://www.linuxreaders.com/2009/04/21/how-to-shrink-your-virtualbox-vm/">How To Shrink Your Virtualbox VM</a> is a post from: <a href="http://www.linuxreaders.com">LinuxReaders</a>
 <br />
<!-- AddThis Button BEGIN -->
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;username=dpthakar"><img src="http://s7.addthis.com/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=dpthakar"></script>
<!-- AddThis Button END -->
</p>
]]></description>
			<content:encoded><![CDATA[<p>While using Virtualbox, one thing that I have found is that the size of the VM (a file with .VDI extension) expands over time. If you have selected the “<em>Dynamically Expanding Storage</em>” option when first creating the VM, you will find that the file size expands whenever you install new applications in the VM. That is perfectly normal. However, when you uninstall or delete applications in the VM, the file size does not shrink or return to its previous size. That is to say, if you are constantly installing and uninstalling applications in your VM, the VDI file could be taking up more space than it is actually using.</p>
<p>If you have a great deal of hard disk space to spare, you can simply ignore this. However, if you find yourself always running short of hard disk space, you might want to consider shrinking the VM and free up unused disk space.</p>
<p>This tutorial will go through the steps to shrink your Virtualbox VM.</p>
<p>It doesn’t matter if you are using Windows/Linux host. The instructions for a Windows and Linux guest are slightly different though. (I have not tried this on a Mac host yet. Theoretically it should work, but do it at your own risk.)</p>
<h3>For Windows guest</h3>
<p>If you are using Windows guest, do the following:</p>
<ul>
<li>Uninstall all unnecessary applications</li>
<li>Perform a hard disk defragmentation. If you are using WinXP, you You can access the inbuilt disk fragmenter from <em>Start -&gt; All Programs -&gt; Accessories -&gt; System Tools -&gt; Disk Defragmenter</em>.</li>
</ul>
<p>Download <a target="_blank" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx');" href="http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx" target="_blank">sdelete</a> and extract it to your desktop.</p>
<p>Open a command prompt and <em>cd</em> to the sdelete directory. Type in the following command:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">sdelete <span style="color: #660033;">-c</span> c:<span style="color: #000000; font-weight: bold;">/</span></pre>
</div>
</div>
<p>This will add zeroes to all the free space in your C: drive.</p>
<p>Once it is done, shutdown the VM.</p>
<h3>For Linux guest</h3>
<p>If you are using Linux guest (this tutorial assumes you are using Ubuntu and is running on ext2/ext3 filesytem. It does not work on ext4), here is what you need to do:</p>
<ul>
<li>Remove any unused applications.</li>
<li><a target="_blank" href="http://maketecheasier.com/8-ways-to-maintain-a-clean-lean-ubuntu-machine/2008/10/07" target="_blank">Clean up your Linux</a> VM</li>
</ul>
<p>Install zerofree</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> zerofree</pre>
</div>
</div>
<p>Restart and boot your Linux VM into Recovery mode. (This is generally the second option in the Grub boot up screen.)</p>
<p>In the root shell prompt, type</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;"><span style="color: #c20cb9; font-weight: bold;">df</span></pre>
</div>
</div>
<p>This will display all the available filesystem in your OS. Record down the filesystem where the main directory lies. (it should be in <em>/dev/sdaX</em> or <em>/dev/hdaX</em> format)</p>
<p><img class="alignnone size-full wp-image-3887" title="vdi-filesystem" src="http://images.maketecheasier.com/2009/04/vdi-filesystem.jpg" alt="vdi filesystem How To Shrink Your Virtualbox VM" width="577" height="151" /></p>
<p>Mount the filesystem in read-only mode with the following command:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-o</span> remount,ro <span style="color: #660033;">-t</span> ext3 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1 <span style="color: #000000; font-weight: bold;">/</span></pre>
</div>
</div>
<p>replacing the <em>/dev/sda1</em> with the filesytem info that you have recorded just now.</p>
<p>Next, type the following command to zero out all the free space.</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">zerofree <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1</pre>
</div>
</div>
<p>Once again, replace the <em>/dev/sda1</em> with your own filesystem info.</p>
<p>Once you are done, shutdown the Linux VM:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">shutdown <span style="color: #660033;">-h</span> now</pre>
</div>
</div>
<h3>Shrinking the VM</h3>
<p>Now that we are done with clearing up the VM and zero out all the free space, it’s time to shrink the file size using the <em>VboxManage</em> command.</p>
<p>If you are still using the older Virtualbox 2.0.x version, you can easily shrink the hard disk with the following command:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">VboxManage modifyvdi <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>VM.vdi compact</pre>
</div>
</div>
<p>If you have upgraded your Virtualbox to the 2.1.x version, you will find that the above command will no longer work. There is a bug in the software that disable the use of the <em>modifyhd</em> command. An alternative solution is to use the <em>clonehd</em> command to creat a smaller clone copy of the original VM.</p>
<p>In your terminal (or command prompt), type the following:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">VboxManage clonehd name-of-original-vm.vdi name-of-clone-vm.vdi</pre>
</div>
</div>
<p>This will create a clone of the original VM with the name that you have specified in the command above.</p>
<h3>Result</h3>
<p>After shrinking my VM, I manage to shave 45% off the size of the oirginal VM and free up a whopping 4.5GB of hard disk space to store my other stuff.</p>
<p>The original VDI: 10GB</p>
<p><img class="alignnone" src="http://images.maketecheasier.com/2009/04/vdi-original.jpg" alt="vdi original How To Shrink Your Virtualbox VM" width="538" height="361" title="How To Shrink Your Virtualbox VM" /></p>
<p>The cloned VDI: 5.5GB</p>
<p><img class="alignnone" src="http://images.maketecheasier.com/2009/04/vdi-resize.jpg" alt="vdi resize How To Shrink Your Virtualbox VM" width="538" height="361" title="How To Shrink Your Virtualbox VM" /></p>
<h3>Importing the clone VM into Virtualbox</h3>
<p>The whole process is not finished yet. You still need to import the clone VM into Virtualbox and remove/delete the original VM from your system.</p>
<p>In your Virtualbox console, click on the <em>New</em> button.</p>
<p>Follow the instructions to create a new VM. When it reaches the screen to ask you to choose the hard disk, select <em>Existing</em>.</p>
<p><img class="alignnone" src="http://images.maketecheasier.com/2009/04/vdi-new-vm.jpg" alt="vdi new vm How To Shrink Your Virtualbox VM" width="520" height="464" title="How To Shrink Your Virtualbox VM" /></p>
<p>In the Virtual media manager window, click <em>Add</em> to add the newly cloned VM.</p>
<p><img class="alignnone" src="http://images.maketecheasier.com/2009/04/vdi-add-vm.jpg" alt="vdi add vm How To Shrink Your Virtualbox VM" width="577" height="448" title="How To Shrink Your Virtualbox VM" /></p>
<p>Highlight the newly added VM and click <em>Select</em>.</p>
<p>Back to the Hard disk selection window, you should see your new VM in the dropdown selection. Click on <em>Next</em> to finish up the import.</p>
<p>Once everything is in place, run the newly added VM to make sure that it is working fine.</p>
<p>On the main Virtualbox screen, highlight  the original VM and go to <em>Machine -&gt; Delete</em>. This will remove the entry from the console.</p>
<p>Go to <em>File -&gt; Virtual Media Manager</em>. Highlight the original VM and click the <em>Remove</em> button. When prompt if you want to keep the file, select <em>Delete</em>. This will delete the vdi file from your system.</p>
<p>That’s it.</p>
<p><a target="_blank" href="http://maketecheasier.com/shrink-your-virtualbox-vm/2009/04/06" target="_blank">Source</a></p>
<p><a href="http://www.linuxreaders.com/2009/04/21/how-to-shrink-your-virtualbox-vm/">How To Shrink Your Virtualbox VM</a> is a post from: <a href="http://www.linuxreaders.com">LinuxReaders</a>
 <br />
<!-- AddThis Button BEGIN -->
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<a target="_blank" class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;username=dpthakar"><img src="http://s7.addthis.com/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0" title="How To Shrink Your Virtualbox VM" /></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=dpthakar"></script>
<!-- AddThis Button END -->
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxreaders.com/2009/04/21/how-to-shrink-your-virtualbox-vm/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
