[OE-core] [PATCH 06/10] initramfs-framework: support live images

Patrick Ohly patrick.ohly at intel.com
Wed Sep 2 15:48:42 UTC 2015


Now initramfs-framework can be used as a replacement for
initramfs-live-boot. The "live" module was copied from init-live.sh
and adapted to the framework.

The intended usage is like this:

INITRAMFS_IMAGE = "core-image-minimal-initramfs"

PACKAGE_INSTALL_remove_pn-core-image-minimal-initramfs = "initramfs-live-boot initramfs-live-install initramfs-live-install-efi"

PACKAGE_INSTALL_append_pn-core-image-minimal-initramfs = " \
   initramfs-module-udev \
   initramfs-module-e2fs \
   initramfs-module-debug \
   initramfs-module-live \
   udev-extraconf \
"

SYSLINUX_LABELS_remove = "install"

Signed-off-by: Patrick Ohly <patrick.ohly at intel.com>
---
 .../initrdscripts/initramfs-framework/live         | 131 +++++++++++++++++++++
 .../initrdscripts/initramfs-framework_1.0.bb       |   9 ++
 2 files changed, 140 insertions(+)
 create mode 100644 meta/recipes-core/initrdscripts/initramfs-framework/live

diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/live b/meta/recipes-core/initrdscripts/initramfs-framework/live
new file mode 100644
index 0000000..42125f7
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/live
@@ -0,0 +1,131 @@
+#!/bin/sh
+#
+# Corresponds to and derived from initramfs-live-boot's "live" init-live.
+#
+# It will wait until a (potentially removable) disk with
+# a "rootfs.img" file on it shows up, then loop-mount that
+# file as rootfs.
+#
+# Relies on "udev" or "mdev" having run already.
+#
+# To skip this module in an initramfs which needs to support live
+# images as well as regular partitions, boot with "root" kernel
+# parameter set to something other than /dev/ram0 (the value set
+# by image-live.bbclass for SYSLINUX_ROOT, which then becomes the root
+# kernel parameter).
+
+LIVE_ROOT_IMAGE="rootfs.img"
+LIVE_ISOLINUX=""
+LIVE_ROOT_DISK=""
+LIVE_FAILURE_TIMEOUT=5
+
+live_enabled() {
+    if [ -n "$bootparam_root" ] && [ "$bootparam_root" != "/dev/ram0" ]; then
+        return 1
+    fi
+}
+
+live_run() {
+    if [ -n "$ROOTFS_DIR" ]; then
+	msg "Waiting for removable media..."
+        C=0
+        while true
+        do
+            for i in `ls /run/media 2>/dev/null`; do
+                if [ -f /run/media/$i/$LIVE_ROOT_IMAGE ] ; then
+		    found="yes"
+		    LIVE_ROOT_DISK="$i"
+		    break
+	        elif [ -f /run/media/$i/isolinux/$LIVE_ROOT_IMAGE ]; then
+		    found="yes"
+		    LIVE_ISOLINUX="isolinux"
+		    LIVE_ROOT_DISK="$i"
+		    break
+                fi
+            done
+            if [ "$found" = "yes" ]; then
+                break;
+            fi
+            # don't wait for more than "shelltimeout" seconds, if it's set
+            if [ -n "$bootparam_shelltimeout" ]; then
+                msg -n " " $(( $bootparam_shelltimeout - $C ))
+                if [ $C -ge $bootparam_shelltimeout ]; then
+                    msg "..."
+	            msg "Mounted filesystems"
+                    mount | grep media
+                    msg "Available block devices"
+                    cat /proc/partitions
+                    msg "Cannot find $LIVE_ROOT_IMAGE file in /run/media/* , giving up booting live image in $LIVE_FAILURE_TIMEOUT seconds"
+                    # Sleep a bit because continuing to boot may
+                    # generate further output that pushes the
+                    # important message of the screen. init-live
+                    # starts a shell at this point (hence the
+                    # parameter name). With initramfs-framework, use
+                    # shell=after:live to achieve something similar.
+                    sleep $LIVE_FAILURE_TIMEOUT
+                    break
+                fi
+                C=$(( C + 1 ))
+            fi
+            sleep 1
+        done
+
+        if [ "$found" = "yes" ]; then
+            mknod /dev/loop0 b 7 0 2>/dev/null
+
+            if ! mount -o rw,loop,noatime,nodiratime /run/media/$LIVE_ROOT_DISK/$LIVE_ISOLINUX/$LIVE_ROOT_IMAGE $ROOTFS_DIR ; then
+	        fatal "Could not mount rootfs image"
+            fi
+
+            if touch $ROOTFS_DIR/bin 2>/dev/null; then
+	        # The root image is read-write, directly boot it up.
+	        return
+            fi
+
+            # determine which unification filesystem to use
+            union_fs_type=""
+            if grep -q -w "overlayfs" /proc/filesystems; then
+	        union_fs_type="overlayfs"
+            elif grep -q -w "aufs" /proc/filesystems; then
+	        union_fs_type="aufs"
+            else
+	        union_fs_type=""
+            fi
+
+            # make a union mount if possible
+            case $union_fs_type in
+	        "overlayfs")
+	            mkdir -p /rootfs.ro /rootfs.rw
+	            if ! mount -n --move $ROOTFS_DIR /rootfs.ro; then
+		        rm -rf /rootfs.ro /rootfs.rw
+		        fatal "Could not move rootfs mount point"
+	            else
+		        mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
+		        mount -t overlayfs -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw" overlayfs $ROOTFS_DIR
+		        mkdir -p $ROOTFS_DIR/rootfs.ro $ROOTFS_DIR/rootfs.rw
+		        mount --move /rootfs.ro $ROOTFS_DIR/rootfs.ro
+		        mount --move /rootfs.rw $ROOTFS_DIR/rootfs.rw
+	            fi
+	            ;;
+	        "aufs")
+	            mkdir -p /rootfs.ro /rootfs.rw
+	            if ! mount -n --move $ROOTFS_DIR /rootfs.ro; then
+		        rm -rf /rootfs.ro /rootfs.rw
+		        fatal "Could not move rootfs mount point"
+	            else
+		        mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
+		        mount -t aufs -o "dirs=/rootfs.rw=rw:/rootfs.ro=ro" aufs $ROOTFS_DIR
+		        mkdir -p $ROOTFS_DIR/rootfs.ro $ROOTFS_DIR/rootfs.rw
+		        mount --move /rootfs.ro $ROOTFS_DIR/rootfs.ro
+		        mount --move /rootfs.rw $ROOTFS_DIR/rootfs.rw
+	            fi
+	            ;;
+	        "")
+	            mount -t tmpfs -o rw,noatime,mode=755 tmpfs $ROOTFS_DIR/media
+	            ;;
+            esac
+        fi
+    else
+	debug "No rootfs has been set"
+    fi
+}
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
index 6c37b9a..7eccc08 100644
--- a/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
+++ b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
@@ -12,6 +12,7 @@ SRC_URI = "file://init \
            file://mdev \
            file://udev \
            file://e2fs \
+           file://live \
            file://debug"
 
 S = "${WORKDIR}"
@@ -32,6 +33,9 @@ do_install() {
     # e2fs
     install -m 0755 ${WORKDIR}/e2fs ${D}/init.d/10-e2fs
 
+    # live image booting
+    install -m 0755 ${WORKDIR}/live ${D}/init.d/15-live
+
     # debug
     install -m 0755 ${WORKDIR}/debug ${D}/init.d/00-debug
 
@@ -45,6 +49,7 @@ PACKAGES = "${PN}-base \
             initramfs-module-mdev \
             initramfs-module-udev \
             initramfs-module-e2fs \
+            initramfs-module-live \
             initramfs-module-debug"
 
 FILES_${PN}-base = "/init /init.d/99-finish /dev"
@@ -61,6 +66,10 @@ SUMMARY_initramfs-module-e2fs = "initramfs support for ext4/ext3/ext2 filesystem
 RDEPENDS_initramfs-module-e2fs = "${PN}-base"
 FILES_initramfs-module-e2fs = "/init.d/10-e2fs"
 
+SUMMARY_initramfs-module-live = "initramfs live image support"
+RDEPENDS_initramfs-module-live = "${PN}-base"
+FILES_initramfs-module-live = "/init.d/15-live"
+
 SUMMARY_initramfs-module-debug = "initramfs dynamic debug support"
 RDEPENDS_initramfs-module-debug = "${PN}-base"
 FILES_initramfs-module-debug = "/init.d/00-debug"
-- 
2.1.4




More information about the Openembedded-core mailing list