Allow booting from an image file (/data/postmarketOS.img) instead of flashing to a partition
Created by: ollieparanoid
@NotKit wrote in #postmarketOS
:
can something like this be accepted to allow using /data/postmarketOS.img instead of flashing pmOS rootfs to /system partition?
Further discussion with @drebrez was about automatically resizing the image to the full partition width or not, and that it should be made optional (it is not desired in the Android multiboot scenario).
diff --git a/aports/main/postmarketos-mkinitfs/init.sh.in b/aports/main/postmarketos-mkinitfs/init.sh.in
index d0af68c..c4e3c96 100644
--- a/aports/main/postmarketos-mkinitfs/init.sh.in
+++ b/aports/main/postmarketos-mkinitfs/init.sh.in
@@ -13,6 +13,7 @@ setup_log
# shellcheck disable=SC2154,SC2086
[ -d /lib/modules ] && modprobe -a ${deviceinfo_modules_initfs} ext4
setup_mdev
+mount_loopback_device
mount_subpartitions
# Start msm-fb-refresher workaround for qualcomm devices
diff --git a/aports/main/postmarketos-mkinitfs/init_functions.sh b/aports/main/postmarketos-mkinitfs/init_functions.sh
index a3564dd..5647f47 100644
--- a/aports/main/postmarketos-mkinitfs/init_functions.sh
+++ b/aports/main/postmarketos-mkinitfs/init_functions.sh
@@ -38,6 +38,21 @@ setup_mdev() {
mdev -s
}
+mount_loopback_device() {
+ if [ ! -z "$deviceinfo_data_partition" ]; then
+ mkdir /data
+ mount $deviceinfo_data_partition /data
+
+ loopback_img=/data/postmarketOS.img
+
+ if [ -f "$loopback_img" ]; then
+ loopback_device=$(losetup -f)
+ losetup $loopback_device $loopback_img
+ kpartx -afs $loopback_device
+ fi
+ fi
+}
+
mount_subpartitions() {
# Do not create subpartition mappings if pmOS_boot
# already exists (e.g. installed on an sdcard)
Yes please! in fact a similar idea was proposed here:
[...] have one big ext4/yaffs partition, and include the whole system image file inside that. Then we would adjust the initramfs code to find the boot and root partitions inside that, and teach it how to resize the whole thing to the maximum partition size. We already did some experiments, and so far everything worked (talk to drebrez or ollieparanoid).