aboutsummaryrefslogtreecommitdiffstats
path: root/main/mkinitfs/0002-support-for-tmpfs-overlay-over-root.patch
blob: cbeeef99e64f43b21ff18a23c88665013dc28c19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
From af4168c70ec5fc1982c83dc22d75de2ba6aa30d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Sat, 7 Feb 2015 22:21:32 +0200
Subject: [PATCH] support for tmpfs overlay over root

useful if wanting to optimize boot time, and do device updates
via read-only system image. package management is not too useful
in these situations.
---
 features.d/base.modules |  1 +
 initramfs-init.in       | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/features.d/base.modules b/features.d/base.modules
index 038335d..f8f271d 100644
--- a/features.d/base.modules
+++ b/features.d/base.modules
@@ -1 +1,2 @@
 kernel/drivers/block/loop.ko
+kernel/fs/overlayfs
diff --git a/initramfs-init.in b/initramfs-init.in
index 6357965..fd3e510 100755
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -387,7 +387,8 @@ eval set -- `cat /proc/cmdline`
 
 myopts="alpine_dev autodetect autoraid chart cryptroot cryptdm debug_init
 	dma init_args keep_apk_new modules ovl_dev pkgs quiet root_size root
-	usbdelay ip alpine_repo apkovl alpine_start splash blacklist"
+	usbdelay ip alpine_repo apkovl alpine_start splash blacklist
+	overlaytmpfs"
 
 for opt; do
 	case "$opt" in
@@ -544,7 +545,16 @@ if [ -n "$KOPT_root" ]; then
 		start_$i
 	done
 	ebegin "Mounting root"
-	retry_mount -o ro $KOPT_root $sysroot 2>/dev/null
+	if [ "$KOPT_overlaytmpfs" = "yes" ]; then
+		mkdir -p /media/root-ro /media/root-rw $sysroot/media/root-ro $sysroot/media/root-rw
+		retry_mount -o ro $KOPT_root /media/root-ro 2>/dev/null
+		mount -t tmpfs root-tmpfs /media/root-rw
+		mkdir -p /media/root-rw/work /media/root-rw/root
+		mount -t overlay -o lowerdir=/media/root-ro,upperdir=/media/root-rw/root,workdir=/media/root-rw/work overlayfs $sysroot
+	else
+		retry_mount -o ro $KOPT_root $sysroot 2>/dev/null
+	fi
+
 	eend $?
 	cat /proc/mounts | while read DEV DIR TYPE OPTS ; do
 		if [ "$DIR" != "/" -a "$DIR" != "$sysroot" -a -d "$DIR" ]; then
-- 
2.2.2