Package: initramfs-tools Severity: wishlist Version: 0.91e User: [EMAIL PROTECTED] Usertags: origin-ubuntu ubuntu-patch hardy ubuntu
Attached is a patch to allow an initramfs to use a root filesystem as a loop device, on top of another file system. A good example and use of this code is for Ubuntu's Windows installer, which creates a loopback filesystem on top of the Windows NTFS partition. The Windows partition is mounted, then the loopback filesystem is mounted from the Windows partition. The patch applies against git head.
diff -urN initramfs-tools/init initramfs-tools.new/init --- initramfs-tools/init 2008-02-26 10:36:10.347676705 +1100 +++ initramfs-tools.new/init 2008-02-26 13:50:26.459676705 +1100 @@ -85,6 +85,15 @@ ;; esac ;; + loop=*) + LOOP="${x#loop=}" + ;; + loopflags=*) + LOOPFLAGS="-o ${x#loopflags=}" + ;; + loopfstype=*) + LOOPFSTYPE="${x#loopfstype=}" + ;; nfsroot=*) NFSROOT="${x#nfsroot=}" ;; diff -urN initramfs-tools/initramfs-tools.8 initramfs-tools.new/initramfs-tools.8 --- initramfs-tools/initramfs-tools.8 2008-02-26 13:48:37.435676705 +1100 +++ initramfs-tools.new/initramfs-tools.8 2008-02-26 13:49:26.251676705 +1100 @@ -52,6 +52,19 @@ set the root file system type. .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 -urN initramfs-tools/scripts/local initramfs-tools.new/scripts/local --- initramfs-tools/scripts/local 2008-02-26 13:48:37.423676705 +1100 +++ initramfs-tools.new/scripts/local 2008-02-26 13:49:26.239676705 +1100 @@ -101,7 +101,8 @@ run_scripts /scripts/local-premount [ "$quiet" != "y" ] && log_end_msg - if [ "${readonly}" = "y" ]; then + if [ ${readonly} = y ] && \ + ([ -z "$LOOP" ] || [ "${FSTYPE#ntfs}" = "$FSTYPE" ]); then roflag=-r else roflag=-w @@ -114,6 +115,43 @@ # Mount root mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt} + 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 + + # Get the loop filesystem type if not set + if [ -z "${LOOPFSTYPE}" ]; then + eval $(fstype < "/host/${LOOP#/}") + else + FSTYPE="${LOOPFSTYPE}" + fi + if [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then + FSTYPE=$(/lib/udev/vol_id -t "/host/${LOOP#/}") + [ -z "$FSTYPE" ] && FSTYPE="unknown" + fi + + 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 + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom" run_scripts /scripts/local-bottom [ "$quiet" != "y" ] && log_end_msg
signature.asc
Description: Digital signature