Skip to content

Commit dea3962

Browse files
committed
guestfs: fix custom image partition not expanded after disk resize
The commit e46bf3c ("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: e46bf3c ("guestfs: add unified LIBVIRT_IMAGE_SIZE configuration") Generated-by: Claude AI Signed-off-by: Luis Chamberlain <[email protected]>
1 parent d908dbd commit dea3962

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,36 @@
5353
cmd: "qemu-img resize {{ custom_image }} {{ libvirt_image_size }}"
5454
changed_when: true
5555
when:
56-
- custom_image_download is changed or custom_image_stat.stat.exists
56+
- custom_image_download is changed
57+
- guestfs_has_custom_raw_image_url|bool
58+
59+
- name: Create temporary file for partition-expanded image
60+
ansible.builtin.tempfile:
61+
state: file
62+
suffix: .raw
63+
register: temp_resized_image
64+
when:
65+
- custom_image_download is changed
66+
- guestfs_has_custom_raw_image_url|bool
67+
68+
- name: Expand root partition to use full disk
69+
become: true
70+
become_method: ansible.builtin.sudo
71+
ansible.builtin.command:
72+
cmd: "virt-resize --expand /dev/sda1 {{ custom_image }} {{ temp_resized_image.path }}"
73+
changed_when: true
74+
when:
75+
- custom_image_download is changed
76+
- guestfs_has_custom_raw_image_url|bool
77+
78+
- name: Replace original image with partition-expanded one
79+
become: true
80+
become_method: ansible.builtin.sudo
81+
ansible.builtin.command:
82+
cmd: "mv -f {{ temp_resized_image.path }} {{ custom_image }}"
83+
changed_when: true
84+
when:
85+
- custom_image_download is changed
5786
- guestfs_has_custom_raw_image_url|bool
5887

5988
- name: Check if the custom image sentinel file already exists

0 commit comments

Comments
 (0)