Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Joshua Watt <jpewhacker@gmail.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH] initscripts: read-only-rootfs-hook: Use overlay if available
Date: Thu, 11 Oct 2018 13:09:04 -0500	[thread overview]
Message-ID: <20181011180904.20169-1-JPEWhacker@gmail.com> (raw)

Copying files from the read-only /var/lib to tmpfs can be slow and waste
memory. If the kernel supports the overlay file system, use it to mount
a writable tmpfs on top of the read-only /var/lib and avoid the file
copy.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 .../initscripts/initscripts-1.0/read-only-rootfs-hook.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh b/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh
index 1a0328d63e4..bd445ddb070 100644
--- a/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh
+++ b/meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh
@@ -31,8 +31,13 @@ if [ "$1" = "start" ] ; then
 	if [ `is_on_read_only_partition /var/lib` = "yes" ]; then
 		grep -q "tmpfs /var/volatile" /proc/mounts || mount /var/volatile
 		mkdir -p /var/volatile/lib
-		cp -a /var/lib/* /var/volatile/lib
-		mount --bind /var/volatile/lib /var/lib
+		mkdir -p /var/volatile/.lib-work
+		# Try to mount using overlay, which is much faster than copying
+		# files. If that fails, fallback to the slower copy
+		if ! mount -t overlay overlay -olowerdir=/var/lib,upperdir=/var/volatile/lib,workdir=/var/volatile/.lib-work /var/lib > /dev/null 2>&1; then
+			cp -a /var/lib/* /var/volatile/lib
+			mount --bind /var/volatile/lib /var/lib
+		fi
 	fi
 fi
 
-- 
2.17.1



                 reply	other threads:[~2018-10-11 18:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20181011180904.20169-1-JPEWhacker@gmail.com \
    --to=jpewhacker@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox