I've taken a quick stab as refreshing this, though I haven't yet tested
it. I did move mounting of the loopback to mount_loop_root in functions,
as I would like to eventually support loopback mounted files from NFS.

live well,
  vagrant

commit aab4c43f484fa44b6f35e9bf0b358a70b165bcbd
Author: Vagrant Cascadian <vagr...@debian.org>
Date:   Tue Aug 11 16:17:09 2015 +0200

    Refreshed patch from Luke Yelavich to add loopback support to
    initramfs-tools.

diff --git a/init b/init
index abf7f25..2760bcb 100755
--- a/init
+++ b/init
@@ -98,6 +98,15 @@ for x in $(cat /proc/cmdline); do
                        ;;
                esac
                ;;
+       loop=*)
+               LOOP="${x#loop=}"
+               ;;
+       loopflags=*)
+               LOOPFLAGS="-o ${x#loopflags=}"
+               ;;
+       loopfstype=*)
+               LOOPFSTYPE="${x#loopfstype=}"
+               ;;
        nfsroot=*)
                NFSROOT="${x#nfsroot=}"
                ;;
diff --git a/initramfs-tools.8 b/initramfs-tools.8
index ea8c098..ce8e830 100644
--- a/initramfs-tools.8
+++ b/initramfs-tools.8
@@ -42,6 +42,19 @@ The default is 180 seconds.
 set the file system mount option string.
 
 .TP
+\fB\fI loop
+path within the original root file system to loop-mount and use as the
+real root file system.
+
+.TP
+\fB\fI loopflags
+set the loop file system mount option string, if applicable.
+
+.TP
+\fB\fI loopfstype
+set the loop file system type, if applicable.
+
+.TP
 \fB\fI nfsroot
 can be either "auto" to try to get the relevant information from DHCP or a
 string of the form NFSSERVER:NFSPATH or NFSSERVER:NFSPATH:NFSOPTS.
diff --git a/scripts/functions b/scripts/functions
index 8c1bb1f..99de1aa 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -426,6 +426,36 @@ mountfs()
        ${type}_mount_fs "$1"
 }
 
+# Mount a loopback device, which is present on the mounted filesystem.
+mount_loop_root()
+{
+       if [ "$LOOP" ]; then
+               mkdir -p /host
+               mount -o move ${rootmnt} /host
+
+               while [ ! -e "/host/${LOOP#/}" ]; do
+                       panic "ALERT!  /host/${LOOP#/} does not exist.  
Dropping to a shell!"
+               done
+
+               if [ ${readonly} = y ]; then
+                       roflag=-r
+               else
+                       roflag=-w
+               fi
+
+               # FIXME This has no error checking
+               modprobe loop
+               modprobe ${FSTYPE}
+
+               # FIXME This has no error checking
+               mount ${roflag} -o loop -t ${FSTYPE} ${LOOPFLAGS} 
"/host/${LOOP#/}" ${rootmnt}
+
+               if [ -d ${rootmnt}/host ]; then
+                       mount -o move /host ${rootmnt}/host
+               fi
+       fi
+}
+
 # Mount the root file system.  It should be overridden by all
 # boot scripts.
 mountroot()
diff --git a/scripts/local b/scripts/local
index f6424f0..94d6ddc 100644
--- a/scripts/local
+++ b/scripts/local
@@ -135,7 +135,8 @@ local_mount_root()
 
        ROOT=$(resolve_device "$ROOT")
 
-       if [ "${readonly}" = "y" ]; then
+       if [ "${readonly}" = "y" ] && \
+          ([ -z "$LOOP" ] || [ "${FSTYPE#ntfs}" = "$FSTYPE" ]); then
                roflag=-r
        else
                roflag=-w
@@ -153,6 +154,8 @@ local_mount_root()
        else
                mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt}
        fi
+
+       mount_loop_root
 }
 
 local_mount_fs()

Attachment: signature.asc
Description: PGP signature

Reply via email to