2013-02-14

How to grow a raw disk image

The problem: I have a raw disk image for use in a virtual machine, and it's too small. I want to make it bigger. In other words, I want to increase the size of the disk.

When I poked around, I found this amusing blog entry by Michael Orlitzky that showed me how to do it. Michael has some extra steps in there, because he wanted to grow a KVM disk image. In this blog entry I will only show the bare minimum, and it is very, very easy:

Step 0: Install qemu-tools package for your distribution (I'm using openSUSE 12.2):
# zypper install qemu-tools

Step 1: Create some additional space (8 GB in this example):
$ qemu-img create -f raw additional.raw 8G

Step 2: Append the additional space to the end of the raw image:
$ cat additional.raw >> too_small_image.raw
$ mv too_small_image.raw big_enough_now_image.raw
$ rm additional.raw

That's all there is to it. It may be possible to replace the qemu-img command in Step 1 with a dd command that creates a file consisting of all zeroes. That way, I wouldn't have had to install an extra package.

Convert the raw image into a VDI container for VirtualBox


$ VBoxManage convertfromraw big_enough_now_image.raw big_enough_now_image.vdi \
--format vdi

Convert the raw image into a qcow2 container for Qemu/KVM


$ qemu-img convert -f raw big_enough_now_image.raw -O qcow2 \
big_enough_now_image.img

No comments:

Post a Comment