This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
sonic-buildimage/src/initramfs-tools/loopback-file-offset-support.patch
Samuel Angebault 67987e9c0e
[secureboot] Add secureboot support for Arista devices (#4741)
* Add secureboot support in boot0
* Initramfs changes for secureboot on Aboot devices
* Do not compress squashfs and gz in fs.zip
It doesn't make much sense to do so since these files are already
compressed.
Also not compressing the squashfs has the advantage of making it
mountable via a loop device.
* Add loopoffset parameter to initramfs-tools
2020-06-22 09:30:31 -07:00

74 lines
2.0 KiB
Diff

From: Samuel Angebault <staphylo@arista.com>
Date: Tue, 9 Jun 2020 14:43:31 -0700
Subject: Add loopback from file support
By providing the extra loopoffset= parameter, it becomes possible to
mount a rootfs from within the file pointed by loop= at a given offset.
This mechanism uses losetup to create a loopdevice
---
init | 4 ++++
initramfs-tools.7 | 5 +++++
scripts/functions | 8 ++++++++
3 files changed, 17 insertions(+)
diff --git a/init b/init
index fe1005a..5fb054f 100755
--- a/init
+++ b/init
@@ -52,6 +52,7 @@ export ROOTFSTYPE=
export LOOP=
export LOOPFLAGS=
export LOOPFSTYPE=
+export LOOPOFFSET=
export IP=
export DEVICE=
export BOOT=
@@ -116,6 +117,9 @@ for x in $(cat /proc/cmdline); do
loopfstype=*)
LOOPFSTYPE="${x#loopfstype=}"
;;
+ loopoffset=*)
+ LOOPOFFSET="${x#loopoffset=}"
+ ;;
nfsroot=*)
# shellcheck disable=SC2034
NFSROOT="${x#nfsroot=}"
diff --git a/initramfs-tools.7 b/initramfs-tools.7
index 745e7a0..a5d92b0 100644
--- a/initramfs-tools.7
+++ b/initramfs-tools.7
@@ -66,6 +66,11 @@ set the loop file system mount option string, if applicable.
\fB\fI loopfstype
set the loop file system type, if applicable.
+.TP
+\fB\fI loopoffset
+set the loop file offset from which to mount the loop, if applicable.
+The default is 0 and requires loop to be defined.
+
.TP
\fB\fI nfsroot
can be either "auto" to try to get the relevant information from DHCP or a
diff --git a/scripts/functions b/scripts/functions
index a17e740..2bef5cb 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -473,6 +473,14 @@ mount_loop_root()
modprobe loop
modprobe "${FSTYPE}"
+ if [ ! -z "${LOOPOFFSET}" ]; then
+ # create a loop device for the fs within the file
+ loopdev="$(losetup -f)"
+ losetup -o "${LOOPOFFSET:-0}" "${loopdev}" "${loopfile}" || \
+ panic "ALERT! $loopdev could not be setup using $loopfile"
+ loopfile="$loopdev"
+ fi
+
# FIXME This has no error checking
if [ -z "${LOOPFLAGS}" ]; then
mount ${roflag} -o loop -t "${FSTYPE}" "$loopfile" "${rootmnt}"
--
2.26.2