kubernetes-sigs/image-builder

Capi Ubuntu 22.04 image built with Qemu are big

chess-knight opened this issue · 0 comments

What steps did you take and what happened:

  • Built an Ubuntu 22.04 image using the qemu provider
  • Created image has 10-15 GB disk size

What did you expect to happen:
Ubuntu qcow2 image has a small disk size

Anything else you would like to add:

  • I tried it with many different Kubernetes versions but the disk remains big
  • See also #1137 with the same experience
  • I did these steps and:
    $ qemu-img info output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3
    image: output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3
    file format: qcow2
    virtual size: 20G (21474836480 bytes)
    disk size: 12G
    cluster_size: 65536
    Format specific information:
        compat: 1.1
        lazy refcounts: false
        refcount bits: 16
        corrupt: false
    
  • It seems like packer qcow2 compaction doesn't work properly, when I run qemu-img convert -O qcow2 output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3 output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3-compact the qemu-img info command has same output(disk size: 12G)
  • But when I run virt-sparsify output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3 output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3-sparse then the disk size seems fine:
    $ qemu-img info output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3-sparse 
    image: output/ubuntu-2204-kube-v1.26.3/ubuntu-2204-kube-v1.26.3-sparse
    file format: qcow2
    virtual size: 20G (21474836480 bytes)
    disk size: 4.6G
    cluster_size: 65536
    Format specific information:
        compat: 1.1
        lazy refcounts: false
        refcount bits: 16
        corrupt: false
    
  • Maybe we can try "disk_detect_zeroes": "unmap" in the packer qemu options, but I do not know if it should help at all
  • I also noticed, that in Ubuntu 22.04 the /swapfile was renamed to /swap.img(it has 2GB for mentioned image) and is not deleted
    • Maybe we can use this(see Action-based config section) to disable swap completely:
      autoinstall:
        storage:
          swap:
            size: 0
      

Environment:

Project Image Builder for Cluster API:

Additional info for Image Builder for Cluster API related issues:

  • OS (e.g. from /etc/os-release, or cmd /c ver): Ubuntu 18.04.6 LTS
  • Packer Version: v1.8.3
  • Packer Provider: QEMU
  • Ansible Version: 2.9.27
  • Cluster-api version (if using):
  • Kubernetes version: (use kubectl version): 1.26.3

/kind bug