Thursday, February 20, 2014

Resizing a disk image for MARSS (QEMU)

Assuming you are running on Ubuntu with “qemu”, “qemu-system”, and “gparted” installed. 
(If you haven’t: $ sudo apt-get install qemu qemu-system gparted)

Also assume you have already downloaded an image with an OS installed.
(Download disk image from MARSS: http://marss86.org/~marss86/index.php/Disk_Images)

To increase the size of a raw disk image, first create an additional image
$ qemu-img create –f raw additional.img 10G
additional.img is the file name you want to create, and 10G is the size for it.

After you get the additional image, append it to your existing image
$ cat additional.img >> exisiting.img

For example, if the original exisiting.img is 5G, then the new exisiting.img is 15G. You can check the size with $ ls -lh

To have the new existing.img properly partitioned (from now on I’ll just refer new exisiting.img as exisiting.img), we need to use gparted to partition it.

First associate exisiting.img to a loop device by
$ sudo losetup -f # this will return the path to a free loopback device, most likely /dev/loop0
$ sudo losetup /dev/loop0 existing.img # this will make /dev/loop0 a representation of existing.img
$ sudo partprobe /dev/loop0 # this will ask the kernel to load the partitions that are already on the image

Then open gparted to do the magic
$ sudo gparted /dev/loop0

A GUI window will pop out, and resizing the disk image should be intuitive. 
(Here is an example: http://softwarebakery.com/shrinking-images-on-linux)

After the image is successfully resized, close gparted, and unload the loop device
$ sudo losetup –d /dev/loop0

You can now check whether the image has the desired size
$ qemu-img info exisiting.img
Both the virtual and actual disk size should be 15G in this example.

You should also check if the disk image properly boots up
$ qemu-system-x86_64 existing.img

Once boot up, inside QEMU you should also see that the disk size is 15G in this example
$ df -h 

Now you have a resized image. You can convert it to qcow2 format if necessary.

Reference:
- http://michael.orlitzky.com/articles/resizing_a_kvm_or_qemu_disk_image.php
- http://softwarebakery.com/shrinking-images-on-linux

No comments:

Post a Comment