@@ -16,6 +16,7 @@ function mount_chroot() {
16
16
local target
17
17
target=" $( realpath " $1 " ) " # normalize, remove last slash if dir
18
18
display_alert " mount_chroot" " $target " " debug"
19
+
19
20
mkdir -p " ${target} /run/user/0"
20
21
21
22
# tmpfs size=50% is the Linux default, but we need more.
@@ -26,6 +27,27 @@ function mount_chroot() {
26
27
mount -t sysfs chsys " ${target} " /sys
27
28
mount --bind /dev " ${target} " /dev
28
29
mount -t devpts chpts " ${target} " /dev/pts || mount --bind /dev/pts " ${target} " /dev/pts
30
+
31
+ # ─── Cache bind logic ───────────────────────────────────────────────────────
32
+ # The build framework relies on a host-side cache at /armbian/cache:
33
+ # - In Docker: compile.sh mounts './cache' → /armbian/cache automatically.
34
+ # - On bare-metal: /armbian/cache may not exist.
35
+ # If /armbian/cache exists on the host:
36
+ # • mkdir inside chroot
37
+ # • bind-mount host cache → chroot cache
38
+ # • touch '/run/user/0/cache_mounted.flag' in tmpfs to signal success.
39
+ # The flag auto-expires when /run/user/0 unmounts.
40
+ if [[ -d /armbian/cache ]]; then
41
+ mkdir -p " ${target} /armbian/cache"
42
+ if mount --bind /armbian/cache " ${target} /armbian/cache" ; then
43
+ # leave a temporary marker inside the chroot so processes there can detect it
44
+ touch " ${target} /run/user/0/cache_mounted.flag"
45
+ else
46
+ display_alert " cache bind failed" " /armbian/cache → ${target} /armbian/cache" " warn"
47
+ fi
48
+ else
49
+ display_alert " Host /armbian/cache not found — skipping cache mount" " " " warn"
50
+ fi
29
51
}
30
52
31
53
# umount_chroot <target>
@@ -36,6 +58,15 @@ function umount_chroot() {
36
58
local target
37
59
target=" $( realpath " $1 " ) " # normalize, remove last slash if dir
38
60
display_alert " Unmounting" " $target " " info"
61
+
62
+ # ─── Conditional cache unmount ─────────────────────────────────────────────
63
+ # Only unmount cache if we previously mounted it (flag file present)
64
+ if [[ -f " ${target} /run/user/0/cache_mounted.flag" ]]; then
65
+ umount " ${target} /armbian/cache" || true
66
+ rm -f " ${target} /run/user/0/cache_mounted.flag" || true
67
+ fi
68
+ # ──────────────────────────────────────────────────────────────────────────
69
+
39
70
while grep -Eq " ${target} \/(dev|proc|sys|tmp|var\/tmp|run\/user\/0)" /proc/mounts; do
40
71
display_alert " Unmounting..." " target: ${target} " " debug"
41
72
umount " ${target} " /dev/pts || true
0 commit comments