Move images.tar.gz creation into the function

Bug: N/A
Test: sudo build.sh -a aarch64
Change-Id: If438dccb8d3e83a2444925417ac01b2f9bb7727e
diff --git a/build/debian/build.sh b/build/debian/build.sh
index 7a849a9..e0c28c9 100755
--- a/build/debian/build.sh
+++ b/build/debian/build.sh
@@ -307,7 +307,8 @@
 	mv "${debian_cloud_image}/image_bookworm_nocloud_${debian_arch}.raw" "${out}"
 }
 
-extract_partitions() {
+generate_output_package() {
+	fdisk -l "${raw_disk_image}"
 	root_partition_num=1
 	bios_partition_num=14
 	efi_partition_num=15
@@ -320,11 +321,36 @@
 	dd if="${loop}p$efi_partition_num" of=efi_part
 	losetup -d "${loop}"
 
+	cp "$(dirname "$0")/vm_config.json.${arch}" vm_config.json
 	sed -i "s/{root_part_guid}/$(sfdisk --part-uuid $raw_disk_image $root_partition_num)/g" vm_config.json
 	if [[ "$arch" == "x86_64" ]]; then
 		sed -i "s/{bios_part_guid}/$(sfdisk --part-uuid $raw_disk_image $bios_partition_num)/g" vm_config.json
 	fi
 	sed -i "s/{efi_part_guid}/$(sfdisk --part-uuid $raw_disk_image $efi_partition_num)/g" vm_config.json
+
+	images=()
+	if [[ "$arch" == "aarch64" ]]; then
+		images+=(
+			root_part
+			efi_part
+		)
+	# TODO(b/365955006): remove these lines when uboot supports x86_64 EFI application
+	elif [[ "$arch" == "x86_64" ]]; then
+		rm -f vmlinuz initrd.img
+		virt-get-kernel -a "${raw_disk_image}"
+		mv vmlinuz* vmlinuz
+		mv initrd.img* initrd.img
+		images+=(
+			bios_part
+			root_part
+			efi_part
+			vmlinuz
+			initrd.img
+		)
+	fi
+
+	# --sparse option isn't supported in apache-commons-compress
+	tar czv -f ${output} ${build_id} "${images[@]}" vm_config.json
 }
 
 clean_up() {
@@ -354,32 +380,4 @@
 copy_android_config
 package_custom_kernel
 run_fai
-fdisk -l "${raw_disk_image}"
-images=()
-
-cp "$(dirname "$0")/vm_config.json.${arch}" vm_config.json
-
-extract_partitions
-
-if [[ "$arch" == "aarch64" ]]; then
-	images+=(
-		root_part
-		efi_part
-	)
-# TODO(b/365955006): remove these lines when uboot supports x86_64 EFI application
-elif [[ "$arch" == "x86_64" ]]; then
-	rm -f vmlinuz initrd.img
-	virt-get-kernel -a "${raw_disk_image}"
-	mv vmlinuz* vmlinuz
-	mv initrd.img* initrd.img
-	images+=(
-		bios_part
-		root_part
-		efi_part
-		vmlinuz
-		initrd.img
-	)
-fi
-
-# --sparse option isn't supported in apache-commons-compress
-tar czv -f ${output} ${build_id} "${images[@]}" vm_config.json
+generate_output_package