Fetch initramfs-tools with script

This commit is contained in:
Qi Luo 2016-03-09 14:19:54 -08:00
parent c9abaf4b3d
commit ab870f190a
2 changed files with 165 additions and 0 deletions

19
get_deps.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
## This script is to build the dependencies of an ONIE installer image
##
## USAGE:
## ./get_deps.sh
# Obtaining the initramfs-tools
rm -rf deps/initramfs-tools
git clone --branch v0.120 https://anonscm.debian.org/git/kernel/initramfs-tools.git deps/initramfs-tools
# Patch
pushd deps/initramfs-tools
patch -p1 < $OLDPWD/patch/initramfs-tools/loopback-file-system-support.patch
# Build the package
fakeroot debian/rules clean
fakeroot debian/rules binary
popd

View File

@ -0,0 +1,146 @@
https://bugs.debian.org/cgi-bin/bugreport.cgi?att=0;bug=468114;msg=32
On 2015-08-11, Vagrant Cascadian wrote:
> On 2015-08-11, Vagrant Cascadian wrote:
>> 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.
>
> Made some small changes, updated and *tested* this time! Patch below...
And added NFS support! Full patch below...
live well,
vagrant
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..2ed3ce3 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -426,6 +426,42 @@ mountfs()
${type}_mount_fs "$1"
}
+# Mount a loopback device, which is present on the mounted filesystem.
+mount_loop_root()
+{
+ mkdir -p /host
+ mount -o move ${rootmnt} /host
+ loopfile="/host/${LOOP#/}"
+
+ while [ ! -e "$loopfile" ]; do
+ panic "ALERT! $loopfile does not exist. Dropping to a shell!"
+ done
+
+ if [ ${readonly} = y ]; then
+ roflag=-r
+ else
+ roflag=-w
+ fi
+
+ # Get the loop filesystem type if not set
+ if [ -z "${LOOPFSTYPE}" ]; then
+ FSTYPE=$(get_fstype "$loopfile")
+ else
+ FSTYPE=${LOOPFSTYPE}
+ fi
+
+ # FIXME This has no error checking
+ modprobe loop
+ modprobe ${FSTYPE}
+
+ # FIXME This has no error checking
+ mount ${roflag} -o loop -t ${FSTYPE} ${LOOPFLAGS} "$loopfile" ${rootmnt}
+
+ if [ -d ${rootmnt}/host ]; then
+ mount -o move /host ${rootmnt}/host
+ 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..072013e 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,10 @@ local_mount_root()
else
mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt}
fi
+
+ if [ "${LOOP}" ]; then
+ mount_loop_root
+ fi
}
local_mount_fs()
diff --git a/scripts/nfs b/scripts/nfs
index 1c29850..d382413 100644
--- a/scripts/nfs
+++ b/scripts/nfs
@@ -72,6 +72,10 @@ nfs_mount_root_impl()
fi
nfsmount -o nolock ${roflag} ${NFSOPTS} ${NFSROOT} ${rootmnt}
+
+ if [ "${LOOP}" ]; then
+ mount_loop_root
+ fi
}
# NFS root mounting