15

The official images supplied are raw disk images, which could have been created using dd.

How do I make an image bigger? I'm not interested in repartitioning said image as that has already been answered in How can I resize my / (root) partition?.

Alex Chamberlain
  • 15,120
  • 13
  • 63
  • 112
  • Not exactly sure what you mean by expanding. Are you looking to perform the 'resizing of the partition' on the image _before_ dd'ing it to the disk? – Joost Jul 12 '12 at 08:52
  • That is one goal, but in order to do that, one must expand the disk image. – Alex Chamberlain Jul 12 '12 at 08:55

2 Answers2

14

As explained in this question there are two methods of expanding the image. Below are two examples to expand the file by 1 kilobyte.

DD creates a non-sparse file

dd if=/dev/zero bs=1k count=1 >> myimage.img

Truncate creates a sparse file

truncate -s +1024 myimage

You probably want to use truncate. A sparse file only writes the metadata of the blocks it uses, instead of actually writing the blocks. This makes creating the file faster (as it does not have to write actual zero's to the disk) and it saves space on your disk.

Note Apple's HFS+ filesystem does not support sparse files.

Joost
  • 761
  • 7
  • 13
11

An incredibly easy way of resizing the image is to use one of the qemu tools called qemu-img. This of course depends on the fact that you have qemu installed (which I know you already do Alex).

The command looks like this:

qemu-img resize filename [+|-]size[K|M|G|T]

Where filename is the image file, and size is the size you want to enlarge (or shrink) the image.

For example, if you want to extend the image archarm.img by 2GB you would execute:

qemu-img resize archarm.img +2G
Jivings
  • 22,208
  • 11
  • 88
  • 138
  • Refering to manpage, Before using this command to shrink a disk image, you MUST use file system and partitioning tools inside the VM to reduce allocated file systems and partition sizes accordingly. Failure to do so will result in data loss! – AntonioK Oct 10 '15 at 14:24