How do I get more space on QEMU running UC?

When running Ubuntu Core images that do a lot of downloads I am running out of space when I run the image on QEMU.

I know I can change the gadget snap and make the ubuntu-data section bigger, like this:

      - name: ubuntu-data
        role: system-data
        filesystem: ext4
        type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
        size: 10G

However, the result is that the image file grows by that same size! Which I find very strange. We’d have to choose to either have all our images this size, or to maintain different gadget snap for real hardware and QEMU. Both I don’t find a good idea.

Is there any option to get more space when running Ubuntu Core images in QEMU that don’t require a separate gadget snap, and that doesn’t grow the image to some ridiculous size?

Using Ubuntu Core 22, snapcraft 8.0.5 and ubuntu-image 3.2

Hi ! @Charlee .

Here’s a general approach :

  1. Backup your disk image before making changes to avoid data loss.

  2. If you use a sparse raw image, you can resize it by using the dd command.

For example:

dd if=/dev/zero of=<your-target-image-name>.img bs=1M seek=<the-disired-size-in-addition> count=0

The value of the option seek is an integer. Example : On base of the command above → For seek=2, we will obtain 2M in addition). The seek option depends on bs option.

After increasing the size of the disk image, it is necessary to repartition and resize the file system inside the image to utilize the extra space. You can achieve this goal by using parted or fdisk … command

Below another approach (via the link).

From redhat

Hey @baldeuniversel

Thanks a lot! Doing

qemu-img resize pc.img +10G

on an image that had never booted before did not need any fdisk steps, so that is probably the easiest!


dd if=/dev/zero of=pc.img bs=1G seek=10 count=0

also worked, however, I guess it only adds 10G - the existing size of the image, which in my case was 6.3G.

1 Like