[1/4] initramfs-module-setup-live: support union fs

Submitted by Hongxu Jia on Dec. 3, 2018, 10:13 a.m. | Patch ID: 156815

Details

Message ID 1543832010-8787-1-git-send-email-hongxu.jia@windriver.com
State New
Headers show

Commit Message

Hongxu Jia Dec. 3, 2018, 10:13 a.m.
Since commit [882ae0dc core-image-minimal-initramfs: use initramfs-framework
for initialization] applied. The setup-live module of initramfs-framework is
introduced to integrate the functionality of init-live.sh, but it missed to
setup union filesystem which caused the rootfs is not writable.

Refer init-live.sh, add scriptlet named `union-fs' after scriptlet `rootfs'

Here are test steps:
$ echo 'IMAGE_FSTYPES_pn-core-image-minimal_append = " live"' >> conf/local.conf
$ echo 'KERNEL_FEATURES_append = " features/overlayfs/overlayfs.scc"' >> conf/local.conf
$ bitbake core-image-minimal
$ runqemu core-image-minimal slirp iso
qemux86-64 login: root
root@qemux86-64:~# touch /abc

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 .../initrdscripts/initramfs-framework/union-fs     | 55 ++++++++++++++++++++++
 .../initramfs-module-setup-live_1.0.bb             |  9 +++-
 2 files changed, 62 insertions(+), 2 deletions(-)
 create mode 100644 meta/recipes-core/initrdscripts/initramfs-framework/union-fs

Patch hide | download patch | download mbox

diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/union-fs b/meta/recipes-core/initrdscripts/initramfs-framework/union-fs
new file mode 100644
index 0000000..2fb6241
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/union-fs
@@ -0,0 +1,55 @@ 
+union_enabled() {
+    if touch $ROOTFS_DIR/bin 2>/dev/null; then
+        # The root image is read-write, directly return.
+        return 1
+    fi
+    return 0
+}
+
+union_run() {
+    # determine which unification filesystem to use
+    union_fs_type=""
+    if grep -q -w "overlay" /proc/filesystems; then
+        union_fs_type="overlay"
+    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
+        "overlay")
+            mkdir -p /rootfs.ro /rootfs.rw
+            if ! mount -n --move $ROOTFS_DIR /rootfs.ro; then
+                rm -rf /rootfs.ro /rootfs.rw
+                fatal "overlay: Could not move rootfs mount point to /rootfs.ro"
+            else
+                mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
+                mkdir -p /rootfs.rw/upperdir /rootfs.rw/work
+                mount -t overlay overlay -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw/upperdir,workdir=/rootfs.rw/work" $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 "aufs: Could not move rootfs mount point to /rootfs.ro"
+            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
+
+    debug "setup union filesystem $union_fs_type"
+}
diff --git a/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb
index 4d2fe9d..30831c2 100644
--- a/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb
+++ b/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb
@@ -8,13 +8,18 @@  PR = "r4"
 inherit allarch
 
 FILESEXTRAPATHS_prepend := "${THISDIR}/initramfs-framework:"
-SRC_URI = "file://setup-live"
+SRC_URI = "file://setup-live \
+           file://union-fs \
+"
 
 S = "${WORKDIR}"
 
 do_install() {
     install -d ${D}/init.d
     install -m 0755 ${WORKDIR}/setup-live ${D}/init.d/80-setup-live
+    install -m 0755 ${WORKDIR}/union-fs ${D}/init.d/91-union-fs
 }
 
-FILES_${PN} = "/init.d/80-setup-live"
+FILES_${PN} = "/init.d/80-setup-live \
+               /init.d/91-union-fs \
+              "