Modify debian build script to integrate disk resize

This commit modifys debian image build script for aarch64 to split
image.raw for composite disk. And update the vm_config.json with the
GUID of the partitions

Bug: 376194294
Test: Manually on pixel device and build in a container.
Change-Id: I11aae4c881dd0b367b2eadba36cea021cb7caed0
diff --git a/build/debian/build.sh b/build/debian/build.sh
index b4436c1..7fc9035 100755
--- a/build/debian/build.sh
+++ b/build/debian/build.sh
@@ -169,6 +169,19 @@
 	mv "${debian_cloud_image}/image_bookworm_nocloud_${debian_arch}.raw" "${out}"
 }
 
+extract_partitions() {
+	root_partition_num=1
+	efi_partition_num=15
+
+	loop=$(losetup -f --show --partscan image.raw)
+	dd if=${loop}p$root_partition_num of=root_part
+	dd if=${loop}p$efi_partition_num of=efi_part
+	losetup -d ${loop}
+
+	sed -i "s/{root_part_guid}/$(sfdisk --part-uuid image.raw $root_partition_num)/g" vm_config.json
+	sed -i "s/{efi_part_guid}/$(sfdisk --part-uuid image.raw $efi_partition_num)/g" vm_config.json
+}
+
 clean_up() {
 	rm -rf "${workdir}"
 }
@@ -191,18 +204,29 @@
 copy_android_config
 run_fai
 fdisk -l image.raw
-images=(image.raw)
+images=()
+
+cp $(dirname $0)/vm_config.json.${arch} vm_config.json
+
+if [[ "$arch" == "aarch64" ]]; then
+	extract_partitions
+	images+=(
+		root_part
+		efi_part
+	)
+fi
+
 # 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+=(
+		image.raw
 		vmlinuz
 		initrd.img
 	)
 fi
 
-cp $(dirname $0)/vm_config.json.${arch} vm_config.json
 # --sparse option isn't supported in apache-commons-compress
-tar czv -f images.tar.gz ${images[@]} vm_config.json
\ No newline at end of file
+tar czv -f images.tar.gz ${images[@]} vm_config.json