initscripts: read-only-rootfs-hook: Use overlay if available
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.
Signed-off-by Joshua Watt <[email protected]>
--- .../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
@@ -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