From d3fa51e4faff1d1239998d2bc1b93b159de6b76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Tue, 1 Apr 2025 13:11:59 +0200 Subject: [PATCH] Use qcow2 for disk image instead of raw image This make the release bundle much smaller, the disk image size change from 512M to 2xsizeof(squashimage) --- board/common/mkdisk.sh | 8 +++++--- board/common/post-image.sh | 4 ++-- board/common/qemu/qemu.sh | 10 +++++----- test/env | 16 ++++++++++------ test/qeneth | 2 +- test/test.mk | 2 +- test/virt/quad/topology.dot.in | 2 +- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/board/common/mkdisk.sh b/board/common/mkdisk.sh index 79516aaf..ababde0f 100755 --- a/board/common/mkdisk.sh +++ b/board/common/mkdisk.sh @@ -127,7 +127,7 @@ bootdata= diskimg=disk.img bootimg= bootpart= - +tmpimage=$(mktemp) while getopts "a:b:B:n:s:" opt; do case ${opt} in a) @@ -166,7 +166,7 @@ awk \ -vimgsize=$imgsize \ -vcfgsize=$cfgsize \ -vvarsize=$varsize \ - -vdiskimg=$diskimg \ + -vdiskimg=$tmpimage \ -vbootimg="$bootimg" -vbootpart="$bootpart" \ '{ sub(/@TOTALSIZE@/, total); @@ -211,5 +211,7 @@ genimage \ --rootpath "$root" \ --tmppath "$tmp" \ --inputpath "$BINARIES_DIR" \ - --outputpath "$BINARIES_DIR" \ --config "$root/genimage.cfg" + +qemu-img convert -c -O qcow2 "$tmpimage" "$BINARIES_DIR/$diskimg" +rm "$tmpimage" diff --git a/board/common/post-image.sh b/board/common/post-image.sh index ad3cbbe1..c78078c5 100755 --- a/board/common/post-image.sh +++ b/board/common/post-image.sh @@ -23,7 +23,7 @@ if [ -n "$IMAGE_ID" ]; then else NAME="$INFIX_ID"-$(echo "$BR2_ARCH" | tr _ - | sed 's/x86-64/x86_64/') fi -diskimg=disk.img +diskimg=disk.qcow2 ver() { @@ -48,7 +48,7 @@ fi load_cfg DISK_IMAGE if [ "$DISK_IMAGE" = "y" ]; then ixmsg "Creating Disk Image" - diskimg="${NAME}-disk$(ver).img" + diskimg="${NAME}-disk$(ver).qcow2" bootcfg= if [ "$DISK_IMAGE_BOOT_DATA" ]; then bootcfg="-b $DISK_IMAGE_BOOT_DATA -B $DISK_IMAGE_BOOT_OFFSET" diff --git a/board/common/qemu/qemu.sh b/board/common/qemu/qemu.sh index 4830cb96..0de195da 100755 --- a/board/common/qemu/qemu.sh +++ b/board/common/qemu/qemu.sh @@ -120,7 +120,7 @@ rootfs_args() echo -n "-device sd-card,drive=mmc " echo -n "-drive id=mmc,file=$CONFIG_QEMU_ROOTFS,if=none,format=raw " elif [ "$CONFIG_QEMU_ROOTFS_VSCSI" = "y" ]; then - echo -n "-drive file=$CONFIG_QEMU_ROOTFS.qcow2,if=virtio,format=qcow2,bus=0,unit=0 " + echo -n "-drive file=qemu.qcow2,if=virtio,format=qcow2,bus=0,unit=0 " fi } @@ -316,13 +316,13 @@ gdb_args() run_qemu() { if [ "$CONFIG_QEMU_ROOTFS_VSCSI" = "y" ]; then - if ! qemu-img check "${CONFIG_QEMU_ROOTFS}.qcow2"; then - rm -f "${CONFIG_QEMU_ROOTFS}.qcow2" + if ! qemu-img check "qemu.qcow2"; then + rm -f "qemu.qcow2" fi - if [ ! -f "${CONFIG_QEMU_ROOTFS}.qcow2" ]; then + if [ ! -f "qemu.qcow2" ]; then echo "Creating qcow2 disk image for Qemu ..." qemu-img create -f qcow2 -o backing_file="$CONFIG_QEMU_ROOTFS" \ - -F raw "${CONFIG_QEMU_ROOTFS}.qcow2" > /dev/null + -F qcow2 "qemu.qcow2" > /dev/null fi fi diff --git a/test/env b/test/env index a79682ef..f79f1ba5 100755 --- a/test/env +++ b/test/env @@ -74,7 +74,7 @@ get_base_img() { local files="$1" local base_img_file - base_img_file=$(echo "$files" | tr ' ' '\n' | grep -- '-disk.img$') + base_img_file=$(echo "$files" | tr ' ' '\n' | grep -- '-disk.qcow2$') echo "$envdir/qeneth/$(basename "$base_img_file")" } @@ -96,16 +96,20 @@ start_topology() done base_img=$(get_base_img "$files") - test_img="${base_img%-disk.img}-disk-test.img" - - $testdir/inject-test-mode -b "$base_img" -o "$test_img" + test_img_name="${base_img%-disk.qcow2}-disk-test" + base_img_name="${base_img%-disk.qcow2}-disk" + test_img_raw="${test_img_name}.img" + base_img_raw="${base_img_name}.img" + test_img_qcow2="${test_img_name}.qcow2" - img_name=$(basename "$test_img") + qemu-img convert -f qcow2 -O raw "$base_img" "$base_img_raw" + $testdir/inject-test-mode -b "$base_img_raw" -o "$test_img_raw" + qemu-img convert -f raw -O qcow2 "$test_img_raw" "$test_img_qcow2" + img_name=$(basename $test_img_qcow2) sed -i "s/qn_image=\".*\"/qn_image=\"$img_name\"/" "$envdir/qeneth/topology.dot.in" (cd "$envdir/qeneth/" && $qeneth generate && $qeneth start) INFAMY_ARGS="$INFAMY_ARGS $envdir/qeneth/topology.dot" - cat <"$envdir/bin/qeneth" #!/bin/sh cd $envdir/qeneth && exec $testdir/qeneth/qeneth "\$@" diff --git a/test/qeneth b/test/qeneth index e17e0b80..f1ff8c23 160000 --- a/test/qeneth +++ b/test/qeneth @@ -1 +1 @@ -Subproject commit e17e0b80581e8ea60ffe97ec2683729cfcf75222 +Subproject commit f1ff8c235d16a9e9945392140100cd0b28dda2c5 diff --git a/test/test.mk b/test/test.mk index 3b5fed9f..53c3391d 100644 --- a/test/test.mk +++ b/test/test.mk @@ -16,7 +16,7 @@ mode-run := -t $(BINARIES_DIR)/qemu.dot mode := $(mode-$(TEST_MODE)) INFIX_IMAGE_ID := $(call qstrip,$(INFIX_IMAGE_ID)) -binaries-$(ARCH) := $(addprefix $(INFIX_IMAGE_ID),.img -disk.img) +binaries-$(ARCH) := $(addprefix $(INFIX_IMAGE_ID),.img -disk.qcow2) pkg-$(ARCH) := -p $(O)/images/$(addprefix $(INFIX_IMAGE_ID),.pkg) binaries-x86_64 += OVMF.fd binaries := $(foreach bin,$(binaries-$(ARCH)),-f $(BINARIES_DIR)/$(bin)) diff --git a/test/virt/quad/topology.dot.in b/test/virt/quad/topology.dot.in index f548c857..a2b3fb10 100644 --- a/test/virt/quad/topology.dot.in +++ b/test/virt/quad/topology.dot.in @@ -9,7 +9,7 @@ graph "quad" { edge [color="cornflowerblue", penwidth="2"]; qn_template="infix-bios-x86_64"; - qn_image="infix-x86_64-disk-test.img" + qn_image="infix-x86_64-disk-test.qcow2" qn_oui="00:a0:85"; qn_append="quiet";