Move packaging logic from kokoro/**/build.sh to build.sh

Bug: 373248801
Bug: 374244795
Test: build and run
Change-Id: I0a4575b33340dafd24babe61008da419bb77064e
diff --git a/build/debian/build.sh b/build/debian/build.sh
index 71a9d3b..62304a4 100755
--- a/build/debian/build.sh
+++ b/build/debian/build.sh
@@ -79,7 +79,14 @@
 		)
 	else
 		packages+=(
-			qemu-system
+			qemu-
+		)
+	fi
+
+	# TODO(b/365955006): remove these lines when uboot supports x86_64 EFI application
+	if [[ "$arch" == "x86_64" ]]; then
+		packages+=(
+			libguestfs-tools
 		)
 	fi
 	DEBIAN_FRONTEND=noninteractive \
@@ -160,3 +167,16 @@
 copy_android_config
 run_fai
 fdisk -l image.raw
+images=(image.raw)
+# TODO(b/365955006): remove these lines when uboot supports x86_64 EFI application
+if [[ "$arch" == "x86_64" ]]; then
+	virt-get-kernel -a image.raw
+	mv vmlinuz* vmlinuz
+	mv initrd.img* initrd.img
+	images+=(
+		vmlinuz
+		initrd.img
+	)
+fi
+# --sparse option isn't supported in apache-commons-compress
+tar czv -f ${KOKORO_ARTIFACTS_DIR}/images.tar.gz ${images[@]} vm_config.json.${arch} --transform s/vm_config.json.${arch}/vm_config.json/
\ No newline at end of file