* [PATCH] initscripts: read-only-rootfs-hook: Use overlay if available
@ 2018-10-11 18:09 Joshua Watt
0 siblings, 0 replies; only message in thread
From: Joshua Watt @ 2018-10-11 18:09 UTC (permalink / raw)
To: openembedded-core
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-10-11 18:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-11 18:09 [PATCH] initscripts: read-only-rootfs-hook: Use overlay if available Joshua Watt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox