armbian-build/lib/functions/general/chroot-helpers.sh

34 lines
782 B
Bash
Raw Normal View History

#!/usr/bin/env bash
2022-10-03 03:14:57 +00:00
# mount_chroot <target>
#
# helper to reduce code duplication
#
2022-10-08 11:17:30 +00:00
mount_chroot() {
2022-10-03 03:14:57 +00:00
local target=$1
mount -t tmpfs tmpfs "${target}/tmp"
mount -t proc chproc "${target}"/proc
mount -t sysfs chsys "${target}"/sys
mount -t devtmpfs chdev "${target}"/dev || mount --bind /dev "${target}"/dev
mount -t devpts chpts "${target}"/dev/pts
}
# umount_chroot <target>
#
# helper to reduce code duplication
#
2022-10-08 11:17:30 +00:00
umount_chroot() {
2022-10-03 03:14:57 +00:00
local target=$1
display_alert "Unmounting" "$target" "info"
2022-10-08 11:17:30 +00:00
while grep -Eq "${target}/*(dev|proc|sys|tmp)" /proc/mounts; do
umount -l --recursive "${target}"/dev > /dev/null 2>&1
umount -l "${target}"/proc > /dev/null 2>&1
umount -l "${target}"/sys > /dev/null 2>&1
umount -l "${target}"/tmp > /dev/null 2>&1
2022-10-03 03:14:57 +00:00
sleep 5
done
}