All of lore.kernel.org
 help / color / mirror / Atom feed
From: <Qi.Chen@windriver.com>
To: <openembedded-core@lists.openembedded.org>
Cc: qingtao.cao@windriver.com
Subject: [PATCH 2/2] init-live.sh: try to make a union mount when possible
Date: Fri, 28 Jun 2013 15:48:53 +0800	[thread overview]
Message-ID: <5a7156829bb79f87af58c12105ad4e35545f6e96.1372394016.git.Qi.Chen@windriver.com> (raw)
In-Reply-To: <cover.1372394016.git.Qi.Chen@windriver.com>

From: Chen Qi <Qi.Chen@windriver.com>

This patch tries to make a union mount in live image. For example,
if aufs is enabled with the aufs-enable.scc configuration fragment,
the init-live.sh script will use aufs to make a union mount.

Although overlayfs is not supported by Yocto kernel yet, this patch
still takes it into consideration with the expect that the related
code should at least serve as a placeholder.

[YOCTO #1487]
[YOCTO #4761]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 meta/recipes-core/initrdscripts/files/init-live.sh |   63 +++++++++++++++++---
 1 file changed, 56 insertions(+), 7 deletions(-)

diff --git a/meta/recipes-core/initrdscripts/files/init-live.sh b/meta/recipes-core/initrdscripts/files/init-live.sh
index 00c2558..9804504 100644
--- a/meta/recipes-core/initrdscripts/files/init-live.sh
+++ b/meta/recipes-core/initrdscripts/files/init-live.sh
@@ -135,15 +135,64 @@ do
   sleep 1
 done
 
+# Try to make a union mount of the root image.
+# If no unification filesystem is available, mount the image read-only.
+mount_and_boot() {
+    mkdir $ROOT_MOUNT
+    mknod /dev/loop0 b 7 0 2>/dev/null
+
+    # 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 -o rw,loop,noatime,nodiratime /media/$i/$ISOLINUX/$ROOT_IMAGE /rootfs.ro; then
+		rm -rf /rootfs.ro /rootfs.rw
+		fatal "Could not mount rootfs image"
+	    else
+		mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
+		mount -t overlayfs -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw" overlayfs $ROOT_MOUNT
+		mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
+		mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
+		mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
+	    fi
+	    ;;
+	"aufs")
+	    mkdir -p /rootfs.ro /rootfs.rw
+	    if ! mount -o rw,loop,noatime,nodiratime /media/$i/$ISOLINUX/$ROOT_IMAGE /rootfs.ro; then
+		rm -rf /rootfs.ro /rootfs.rw
+		fatal "Could not mount rootfs image"
+	    else
+		mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
+		mount -t aufs -o "dirs=/rootfs.rw=rw:/rootfs.ro=ro" aufs $ROOT_MOUNT
+		mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
+		mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
+		mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
+	    fi
+	    ;;
+	"")
+	    if ! mount -o rw,loop,noatime,nodiratime /media/$i/$ISOLINUX/$ROOT_IMAGE $ROOT_MOUNT ; then
+		fatal "Could not mount rootfs image"
+	    fi
+	    ;;
+    esac
+
+    # boot the image
+    boot_live_root
+}
+
 case $label in
     boot)
-	mkdir $ROOT_MOUNT
-	mknod /dev/loop0 b 7 0 2>/dev/null
-	if ! $MOUNT -o rw,loop,noatime,nodiratime /media/$i/$ISOLINUX/$ROOT_IMAGE $ROOT_MOUNT ; then
-	    fatal "Could not mount rootfs image"
-	else
-	    boot_live_root
-	fi
+	mount_and_boot
 	;;
     install|install-efi)
 	if [ -f /media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then
-- 
1.7.9.5



      parent reply	other threads:[~2013-06-28  7:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-28  7:48 [PATCH 0/2] live image: try to make a valid union mount Qi.Chen
2013-06-28  7:48 ` [PATCH 1/2] initrdscripts: unionfs cleanup Qi.Chen
2013-06-28  7:48 ` Qi.Chen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5a7156829bb79f87af58c12105ad4e35545f6e96.1372394016.git.Qi.Chen@windriver.com \
    --to=qi.chen@windriver.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=qingtao.cao@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.