Kevin Deldycke - gpartedhttps://kevin.deldycke.com/2007-04-08T16:10:56+02:00How-To Grow Any Qemu System Image2007-04-08T16:10:56+02:002007-04-08T16:10:56+02:00Kevin Deldycketag:kevin.deldycke.com,2007-04-08:/2007/04/how-to-grow-any-qemu-system-image/<p>Qemu images can&rsquo;t be growed. In this example I will show you a little hack to grow a 6GiB <code>qcow</code> image to a 10GiB image. Beware: these operations can take a lot of time to perform and require lots of free&nbsp;space.</p> <p>First, convert your <code>qcow</code> image to a …</p><p>Qemu images can&rsquo;t be growed. In this example I will show you a little hack to grow a 6GiB <code>qcow</code> image to a 10GiB image. Beware: these operations can take a lot of time to perform and require lots of free&nbsp;space.</p> <p>First, convert your <code>qcow</code> image to a plain raw&nbsp;file:</p> <div class="highlight"><pre><span></span>$ qemu-img convert system.qcow -O raw system.raw </pre></div> <p>Then, create a dummy file (filled with zeros) of the size of extra space you want to add to your image. In this case, 4GiB (=10GiB -&nbsp;6GiB):</p> <div class="highlight"><pre><span></span>$ dd <span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span>zeros.raw <span class="nv">bs</span><span class="o">=</span>1024k <span class="nv">count</span><span class="o">=</span><span class="m">4096</span> </pre></div> <p>Fearlessly, add your extra space to your raw system&nbsp;image:</p> <div class="highlight"><pre><span></span>$ cat system.raw zeros.raw &gt; big10G.raw </pre></div> <p>After that you can boot qemu to verify that added free space is&nbsp;available:</p> <div class="highlight"><pre><span></span>$ qemu -hda big10G.raw </pre></div> <p>Here is an real case example of what you can see in a qemu image on which Windows <span class="caps">XP</span> was&nbsp;installed:</p> <p><img alt="" src="/uploads/2007/growed-image1.png"></p> <p>Now, to grow your primary partition, I suggest you to download a Live <span class="caps">CD</span> like <a href="https://gparted.sourceforge.net/livecd.php">gparted Live <span class="caps">CD</span></a> or <a href="https://www.sysresccd.org">System Rescue <span class="caps">CD</span></a>, and boot on the <code>.iso</code> file with&nbsp;qemu:</p> <div class="highlight"><pre><span></span>$ qemu -hda big10G.raw -cdrom gparted-livecd-0.3.4-5.iso -boot d </pre></div> <p>This will allow you to grow and manipulate all your partitions safely thanks to <a href="https://www.gnu.org/software/parted/index.shtml">parted</a> and other open source system&nbsp;tools.</p> <p>Finally you can convert back your <code>raw</code> image to a <code>qcow</code> one to not waste&nbsp;space:</p> <div class="highlight"><pre><span></span>$ qemu-img convert big10G.raw -O qcow growed-system.qcow </pre></div> <p>That&rsquo;s&nbsp;all!</p> <p>By the way, I think it&rsquo;s possible to perform the second and third step of this how-to in a single operation using <code>dd</code> only.</p> <p><em>Update</em>: I missed it, but this issue is also described in the <span class="caps">FAQ</span> from the <a href="https://kidsquid.com/cgi-bin/moin.cgi">unofficial #qemu wiki</a> (look at &ldquo;<a href="https://kidsquid.com/cgi-bin/moin.cgi/FrequentlyAskedQuestions#head-b46370d3ad030e6c1712338f0e5112228c51212a">How do I resize a disk image?</a>&rdquo;&nbsp;question).</p>