Skip to contentSkip to conversation

guestfs: few custom image fixes

PATCH In review Luis Chamberlain 1 participant 6 messages Aug 27, 2025 – Aug 29, 2025

lore
Share & tools
lore
#0 lore raw

cover guestfs: few custom image fixes

Here's a few custom images fixes I found along the way after deciding to nuke my old base image and starting fresh again for debian testing.

Would appreciate feedback on testing, review. This is under the kdevops
branch: mcgrof/20250826

Luis Chamberlain (4):
guestfs: fix custom image partition not expanded after disk resize
guestfs: fix custom image bringup failure for Debian 13
guestfs: fix virt-resize failure for custom images
guestfs: fix checksum verification for resized custom images

 .../roles/base_image/tasks/custom-image.yml   | 112 ++++++++++++------
 playbooks/roles/base_image/tasks/main.yml     |   1 +
 2 files changed, 78 insertions(+), 35 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/4 guestfs: fix custom image partition not expanded after disk resize

The commit e46bf3cd54de ("guestfs: add unified LIBVIRT_IMAGE_SIZE configuration") added disk resizing for custom images but only resized the disk image file, not the partition inside. This resulted in VMs having a 20GB disk but only a 2.9GB root filesystem partition, causing out-of-space errors during kernel installation.

Add virt-resize step after qemu-img resize to expand the root partition (/dev/sda1) to use the full disk space. This ensures VMs get the full 20GB root filesystem as intended.

Without this fix, VMs show:
/dev/vda1 2.8G (despite 20GB disk)

With this fix, VMs will have:
/dev/vda1 20G (using full disk)

Fixes e46bf3cd54de ("guestfs: add unified LIBVIRT_IMAGE_SIZE configuration")
Generated-by Claude AI
---
 .../roles/base_image/tasks/custom-image.yml   | 31 ++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
playbooks/roles/base_image/tasks/custom-image.yml +30 -1
index 46701e75..207a5fa1 100644
@@ -53,7 +53,36 @@
     cmd: "qemu-img resize {{ custom_image }} {{ libvirt_image_size }}"
   changed_when: true
   when:
-    - custom_image_download is changed or custom_image_stat.stat.exists
+    - custom_image_download is changed
+    - guestfs_has_custom_raw_image_url|bool
+
+- name: Create temporary file for partition-expanded image
+  ansible.builtin.tempfile:
+    state: file
+    suffix: .raw
+  register: temp_resized_image
+  when:
+    - custom_image_download is changed
+    - guestfs_has_custom_raw_image_url|bool
+
+- name: Expand root partition to use full disk
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.command:
+    cmd: "virt-resize --expand /dev/sda1 {{ custom_image }} {{ temp_resized_image.path }}"
+  changed_when: true
+  when:
+    - custom_image_download is changed
+    - guestfs_has_custom_raw_image_url|bool
+
+- name: Replace original image with partition-expanded one
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.command:
+    cmd: "mv -f {{ temp_resized_image.path }} {{ custom_image }}"
+  changed_when: true
+  when:
+    - custom_image_download is changed
     - guestfs_has_custom_raw_image_url|bool
 
 - name: Check if the custom image sentinel file already exists
Signature · 1 line
2.50.1
#2 lore raw

PATCH 2/4 guestfs: fix custom image bringup failure for Debian 13

In reply to Luis Chamberlain

When using custom images (like Debian 13 daily builds), the base_image role would incorrectly attempt to build the image using virt-builder even though a custom image workflow was configured. This failed because "debian-13-generic-amd64-daily" is not a valid virt-builder template.

The issue had two root causes:

1. The base-image.yml task would run even when custom images were configured, attempting to use virt-builder with an invalid template

2. The custom-image.yml task prepared the custom image but never copied it to the base_image_pathname location expected by subsequent tasks

Fix both issues by:
- Adding a condition to skip base-image.yml when using custom images
- Copying the prepared custom image to the base_image_pathname location

This ensures custom images are properly downloaded, prepared with the kdevops user configuration, and placed in the expected location for VM provisioning.

Fixes df31e8f55d7d ("guestfs: fix custom image partition not expanded after disk resize")
Generated-by Claude AI
---
 playbooks/roles/base_image/tasks/custom-image.yml | 11 +++++++++++
 playbooks/roles/base_image/tasks/main.yml         |  1 +
 2 files changed, 12 insertions(+)
playbooks/roles/base_image/tasks/custom-image.yml +11 -0
index 207a5fa1..296424bc 100644
@@ -281,3 +281,14 @@
       - "--no-compression"
       - "{{ custom_image_dir }}"
   changed_when: true
+
+- name: Copy custom image to base image location
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.copy:
+    src: "{{ custom_image }}"
+    dest: "{{ base_image_pathname }}"
+    remote_src: true
+    mode: "u=rw,g=r,o=r"
+  when:
+    - custom_image_stat.stat.exists or custom_image_download is changed
playbooks/roles/base_image/tasks/main.yml +1 -0
index 37907d71..05ab68bd 100644
@@ -17,3 +17,4 @@
     file: "{{ role_path }}/tasks/base-image.yml"
   when:
     - not result.stat.exists
+    - not guestfs_has_custom_raw_image|bool
Signature · 1 line
2.50.1
#3 lore raw

PATCH 3/4 guestfs: fix virt-resize failure for custom images

In reply to Luis Chamberlain

The virt-resize command was failing because it requires a pre-allocated output file with the target size, not an empty temporary file.

Fix by:
1. Pre-allocating the temporary image file with qemu-img create before running virt-resize
2. Adding -f raw flag to qemu-img resize to avoid format detection warnings

This ensures the partition expansion works correctly when resizing custom images like Debian 13 daily builds.

Error was:
virt-resize: error: /tmp/ansible.depq5vk0.raw: file is too small to be a disk image (0 bytes)

Generated-by Claude AI
---
 playbooks/roles/base_image/tasks/custom-image.yml | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
playbooks/roles/base_image/tasks/custom-image.yml +12 -1
index 296424bc..a3a8cbbd 100644
@@ -50,7 +50,7 @@
   become: true
   become_method: ansible.builtin.sudo
   ansible.builtin.command:
-    cmd: "qemu-img resize {{ custom_image }} {{ libvirt_image_size }}"
+    cmd: "qemu-img resize -f raw {{ custom_image }} {{ libvirt_image_size }}"
   changed_when: true
   when:
     - custom_image_download is changed
@@ -65,6 +65,17 @@
     - custom_image_download is changed
     - guestfs_has_custom_raw_image_url|bool
 
+- name: Pre-allocate space for the resized image
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.command:
+    cmd: "qemu-img create -f raw {{ temp_resized_image.path }} {{ libvirt_image_size }}"
+  changed_when: true
+  when:
+    - custom_image_download is changed
+    - guestfs_has_custom_raw_image_url|bool
+    - temp_resized_image.path is defined
+
 - name: Expand root partition to use full disk
   become: true
   become_method: ansible.builtin.sudo
Signature · 1 line
2.50.1
#4 lore raw

PATCH 4/4 guestfs: fix checksum verification for resized custom images

In reply to Luis Chamberlain

The SHA512 checksum verification was failing because it was being run after the image had been resized and modified. The checksum from the upstream source is only valid for the original downloaded image, not the modified version.

Fix by:
1. Verifying the checksum immediately after download, before any modifications
2. Removing the redundant checksum verification that happened after resize operations

This ensures the image integrity is verified when downloaded, but doesn't fail on subsequent runs when the image has been customized for kdevops use.

Error was:
sha512sum: WARNING: 1 computed checksum did NOT match debian-13-generic-amd64-daily.raw: FAILED

Generated-by Claude AI
---
 .../roles/base_image/tasks/custom-image.yml   | 57 ++++++++-----------
 1 file changed, 24 insertions(+), 33 deletions(-)
playbooks/roles/base_image/tasks/custom-image.yml +24 -33
index a3a8cbbd..d23cce96 100644
@@ -46,6 +46,29 @@
     - not custom_image_stat.stat.exists
     - guestfs_has_custom_raw_image_url|bool
 
+- name: Verify custom image checksum immediately after download
+  when:
+    - custom_image_download is changed
+    - guestfs_has_custom_raw_image_sha512sums|bool
+  block:
+    - name: Get the base name of the sha512sums file for verification
+      ansible.builtin.set_fact:
+        sha512sums_file: "{{ guestfs_custom_raw_image_sha512sums_url | basename }}"
+
+    - name: Fetch the sha512sums file for verification
+      become: true
+      become_method: ansible.builtin.sudo
+      ansible.builtin.get_url:
+        url: "{{ guestfs_custom_raw_image_sha512sums_url }}"
+        dest: "{{ custom_image_dir }}"
+        mode: "u=rw,g=r,o=r"
+
+    - name: Verify checksum of freshly downloaded image
+      ansible.builtin.command:
+        cmd: "sha512sum --ignore-missing -c {{ sha512sums_file }}"
+        chdir: "{{ custom_image_dir }}"
+      changed_when: false
+
 - name: Resize custom image to match configured size
   become: true
   become_method: ansible.builtin.sudo
@@ -104,42 +127,10 @@
     get_mime: false
   register: sentinel_stat
 
-- name: Check the custom image
+- name: Configure custom image with kdevops settings
   when:
     - not sentinel_stat.stat.exists
-    - guestfs_has_custom_raw_image_sha512sums|bool
   block:
-    - name: Get the base name of the sha512sums file
-      ansible.builtin.set_fact:
-        sha512sums_file: "{{ guestfs_custom_raw_image_sha512sums_url | basename }}"
-
-    - name: Set the full pathname of sha512sums file
-      ansible.builtin.set_fact:
-        custom_image_sha512sum: "{{ custom_image_dir }}/{{ sha512sums_file }}"
-
-    - name: Check if the sha512sums file already exists
-      ansible.builtin.stat:
-        path: "{{ custom_image_sha512sum }}"
-        get_attributes: false
-        get_checksum: false
-        get_mime: false
-      register: sha512sums_stat
-
-    - name: Fetch the sha512sums file
-      become: true
-      become_method: ansible.builtin.sudo
-      ansible.builtin.get_url:
-        url: "{{ guestfs_custom_raw_image_sha512sums_url }}"
-        dest: "{{ custom_image_dir }}"
-        mode: "u=rw,g=r,o=r"
-      when:
-        - not sha512sums_stat.stat.exists
-
-    - name: Compute checksum of something
-      ansible.builtin.command:
-        cmd: "sha512sum --ignore-missing -c {{ sha512sums_file }}"
-        chdir: "{{ custom_image_dir }}"
-      changed_when: false
 
     - name: Get the UID of the kdevops user on the control host
       ansible.builtin.command:
Signature · 1 line
2.50.1
#5 lore raw
In reply to Luis Chamberlain
Quoted 12 lines · Luis Chamberlain

Here's a few custom images fixes I found along the way after deciding to nuke my old base image and starting fresh again for debian testing.

Would appreciate feedback on testing, review. This is under the kdevops
branch: mcgrof/20250826

Luis Chamberlain (4):
guestfs: fix custom image partition not expanded after disk resize
guestfs: fix custom image bringup failure for Debian 13
guestfs: fix virt-resize failure for custom images
guestfs: fix checksum verification for resized custom images

Quoted 3 lines
 .../roles/base_image/tasks/custom-image.yml   | 112 ++++++++++++------
 playbooks/roles/base_image/tasks/main.yml     |   1 +
 2 files changed, 78 insertions(+), 35 deletions(-)

I'll be merging these shortly.

Luis