]> code.ossystems Code Review - openembedded-core.git/commitdiff
initscripts: read-only-rootfs-hook: Use overlay if available
authorJoshua Watt <jpewhacker@gmail.com>
Thu, 11 Oct 2018 18:09:04 +0000 (13:09 -0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 12 Oct 2018 07:44:05 +0000 (08:44 +0100)
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>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-core/initscripts/initscripts-1.0/read-only-rootfs-hook.sh

index 1a0328d63e401fcb2d5d4fe4e2aed03384b5194f..bd445ddb070fb0f1bc45373f19b38f7a270ccd49 100644 (file)
@@ -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