Skip to contentSkip to conversation

initscripts: read-only-rootfs-hook: Use overlay if available

PATCH New Joshua Watt 1 participant 1 message Oct 11, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 initscripts: read-only-rootfs-hook: Use overlay if available

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.

---
 .../initscripts/initscripts-1.0/read-only-rootfs-hook.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh +7 -2
index 1a0328d63e4..bd445ddb070 100644
@@ -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
 
Signature · 1 line
2.17.1