Skip to content

Commit 4003369

Browse files
committed
guestfs: add configurable VM image size with custom image resize support
Base images were using hardcoded 20G size while custom images remained at their original download size, causing disk space issues. This adds LIBVIRT_IMAGE_SIZE config option (default: 20G) that: - Replaces hardcoded "20G" in base image creation - Adds automatic resizing for custom images using qemu-img resize Both image types now consistently use the same configurable size, resolving "No space left on device" errors in custom image VMs. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]>
1 parent ec0a16c commit 4003369

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

kconfigs/Kconfig.libvirt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ config LIBVIRT_MEM_MB
458458
help
459459
How much MiB of RAM to use per guest.
460460

461+
config LIBVIRT_IMAGE_SIZE
462+
string "VM image size"
463+
output yaml
464+
default "20G"
465+
depends on GUESTFS
466+
help
467+
The size of the VM disk image for all libvirt images, whether they
468+
are base images (created with virt-builder) or custom images
469+
(downloaded and resized with qemu-img resize).
470+
461471
config HAVE_LIBVIRT_PCIE_PASSTHROUGH
462472
bool
463473
default $(shell, scripts/check_pciepassthrough_kconfig.sh passthrough_libvirt.generated)

playbooks/roles/base_image/tasks/base-image.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
- "-o"
4545
- "{{ base_image_pathname }}"
4646
- "--size"
47-
- "20G"
47+
- "{{ libvirt_image_size }}"
4848
- "--format"
4949
- "raw"
5050
- "--commands-from-file"
@@ -63,7 +63,7 @@
6363
- "-o"
6464
- "{{ base_image_pathname }}"
6565
- "--size"
66-
- "20G"
66+
- "{{ libvirt_image_size }}"
6767
- "--format"
6868
- "raw"
6969
- "--commands-from-file"

playbooks/roles/base_image/tasks/custom-image.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@
4141
url: "{{ guestfs_custom_raw_image_url }}"
4242
dest: "{{ custom_image_dir }}"
4343
mode: "u=rw,g=r,o=r"
44+
register: custom_image_download
4445
when:
4546
- not custom_image_stat.stat.exists
4647
- guestfs_has_custom_raw_image_url|bool
4748

49+
- name: Resize custom image to match configured size
50+
become: true
51+
become_method: ansible.builtin.sudo
52+
ansible.builtin.command:
53+
cmd: "qemu-img resize {{ custom_image }} {{ libvirt_image_size }}"
54+
changed_when: true
55+
when:
56+
- custom_image_download is changed or custom_image_stat.stat.exists
57+
- guestfs_has_custom_raw_image_url|bool
58+
4859
- name: Check if the custom image sentinel file already exists
4960
ansible.builtin.stat:
5061
path: "{{ custom_image_ok }}"

0 commit comments

Comments
 (0)