WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit dc6f301

Browse files
committed
Add configurable cache bind for chroot
1 parent d5bceb9 commit dc6f301

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/functions/general/chroot-helpers.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function mount_chroot() {
1313
display_alert "mount_chroot called outside of logging section..." "mount_chroot '$1'\n$(stack_color="${magenta_color:-}" show_caller_full)" "warn"
1414
fi
1515

16-
local target
16+
local target cache_src
1717
target="$(realpath "$1")" # normalize, remove last slash if dir
1818
display_alert "mount_chroot" "$target" "debug"
1919
mkdir -p "${target}/run/user/0"
@@ -26,16 +26,35 @@ function mount_chroot() {
2626
mount -t sysfs chsys "${target}"/sys
2727
mount --bind /dev "${target}"/dev
2828
mount -t devpts chpts "${target}"/dev/pts || mount --bind /dev/pts "${target}"/dev/pts
29+
30+
# Bind host cache into chroot if present (configurable via ARMBIAN_CACHE_DIR)
31+
cache_src="${ARMBIAN_CACHE_DIR:-/armbian/cache}"
32+
if [[ -d "${cache_src}" ]]; then
33+
mkdir -p "${target}/armbian/cache"
34+
if ! mountpoint -q "${target}/armbian/cache" && mount --bind "${cache_src}" "${target}/armbian/cache"; then
35+
:
36+
else
37+
display_alert "cache bind failed or already bound" "${cache_src} -> ${target}/armbian/cache" "warn"
38+
fi
39+
else
40+
display_alert "Host cache not found — skipping cache mount" "${cache_src}" "warn"
41+
fi
2942
}
3043

3144
# umount_chroot <target>
3245
function umount_chroot() {
3346
if [[ "x${LOG_SECTION}x" == "xx" ]]; then
3447
display_alert "umount_chroot called outside of logging section..." "umount_chroot '$1'\n$(stack_color="${magenta_color:-}" show_caller_full)" "warn"
3548
fi
36-
local target
49+
local target cache_src
3750
target="$(realpath "$1")" # normalize, remove last slash if dir
3851
display_alert "Unmounting" "$target" "info"
52+
53+
cache_src="${ARMBIAN_CACHE_DIR:-/armbian/cache}"
54+
if mountpoint -q "${target}/armbian/cache"; then
55+
umount "${target}/armbian/cache" || true
56+
fi
57+
3958
while grep -Eq "${target}\/(dev|proc|sys|tmp|var\/tmp|run\/user\/0)" /proc/mounts; do
4059
display_alert "Unmounting..." "target: ${target}" "debug"
4160
umount "${target}"/dev/pts || true

0 commit comments

Comments
 (0)