Custommize mountdisks.BASE as well
Also use parted to get the offset and size of the partitions in bytes.
We need to know the size of the root partition (not just its offset)
because the end of the disk is gpt.
Bug: N/A
Test: cd package/modules/Virtualization/build/debian &&
sudo docker run -v $(pwd):/root/git --privileged -it ubuntu::22.04
bash /root/git/build.sh
Change-Id: Ic4367ff7fd8555ee89735e0cc1cd7f98ca5b41ff
diff --git a/build/debian/build.sh b/build/debian/build.sh
index 24de78a..4d59981 100755
--- a/build/debian/build.sh
+++ b/build/debian/build.sh
@@ -106,3 +106,4 @@
download_debian_cloud_image
copy_android_config
run_fai
+fdisk -l image.raw
diff --git a/build/debian/fai_config/hooks/mountdisks.BASE b/build/debian/fai_config/hooks/mountdisks.BASE
new file mode 100755
index 0000000..33ebb05
--- /dev/null
+++ b/build/debian/fai_config/hooks/mountdisks.BASE
@@ -0,0 +1,25 @@
+#!/bin/bash
+set -eu
+touch $LOGDIR/skip.mountdisks
+
+# Set filesystem context if running with SELinux enabled
+options="context=$(cat /proc/self/attr/current 2>/dev/null || :)"
+
+set -- $disklist
+device=/dev/$1
+file=$(losetup -O BACK-FILE ${device} | tail -1)
+parted -m ${device} unit B print
+root_offset=$(parted -m ${device} unit B print | awk -F '[B:]' '/1:/{ print $2 }')
+efi_offset=$( parted -m ${device} unit B print | awk -F '[B:]' '/15:/{ print $2 }')
+device_root=$(losetup -O NAME,OFFSET -j ${file} | grep ${root_offset} | cut -d ' ' -f 1)
+device_efi=$(losetup -O NAME,OFFSET -j ${file} | grep ${efi_offset} | cut -d ' ' -f 1)
+
+echo root=${device_root} efi=${device_efi}
+
+mount -o noatime -o "$options" "$device_root" "$FAI_ROOT"
+if ifclass -o AMD64 ARM64 RISCV64; then
+ mkdir -p "${FAI_ROOT}/boot/efi"
+ mount -o noatime -o "$options" "$device_efi" "${FAI_ROOT}/boot/efi"
+fi
+
+mount
diff --git a/build/debian/fai_config/hooks/partition.ARM64 b/build/debian/fai_config/hooks/partition.ARM64
index ead2388..56f239c 100755
--- a/build/debian/fai_config/hooks/partition.ARM64
+++ b/build/debian/fai_config/hooks/partition.ARM64
@@ -4,13 +4,6 @@
set -- $disklist
device=/dev/$1
-file=$(losetup -O BACK-FILE ${device} | tail -1)
-log_sec=$(losetup -O LOG-SEC ${device} | tail -1)
-root_offset_bytes=$(expr 262144 \* ${log_sec})
-efi_offset_bytes=$(expr 2048 \* ${log_sec})
-efi_sizelimit_bytes=$(expr 260096 \* ${log_sec})
-device_root=$(losetup -o ${root_offset_bytes} --show -f ${file})
-device_efi=$(losetup -o ${efi_offset_bytes} --sizelimit ${efi_sizelimit_bytes} --show -f ${file})
wait_for_device() {
for s in $(seq 10); do
@@ -31,8 +24,17 @@
p1 : start=262144, type="Linux root (ARM-64)", uuid=${PARTUUID_ROOT}
EOF
-ls -al /dev/loop*
+file=$(losetup -O BACK-FILE ${device} | tail -1)
+
+root_offset=$(parted -m ${device} unit B print | awk -F '[B:]' '/1:/{ print $2 }')
+root_size=$( parted -m ${device} unit B print | awk -F '[B:]' '/1:/{ print $6 }')
+efi_offset=$( parted -m ${device} unit B print | awk -F '[B:]' '/15:/{ print $2 }')
+efi_size=$( parted -m ${device} unit B print | awk -F '[B:]' '/15:/{ print $6 }')
+device_root=$(losetup -o ${root_offset} --sizelimit ${root_size} --show -f ${file})
+device_efi=$(losetup -o ${efi_offset} --sizelimit ${efi_size} --show -f ${file})
+
losetup -a -l
+parted ${device} unit B print
partprobe "$device"