Skip to content

Instantly share code, notes, and snippets.

@jlebon
Last active October 28, 2022 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlebon/fb6e7c6dcc3ce17d3e2a86f5938ec033 to your computer and use it in GitHub Desktop.
Save jlebon/fb6e7c6dcc3ce17d3e2a86f5938ec033 to your computer and use it in GitHub Desktop.
mock-mount.sh -- compat script for bwrap in mock
#!/bin/bash
set -euo pipefail
# This is a small compatibility script that ensures mock
# chroots are compatible with applications that expect / to
# be a mount point, such as bubblewrap.
cleanup() {
for mnt in sys proc; do
umount /mnt/mock-mount/$mnt
done
umount /mnt/mock-mount
umount /mnt/mock-mount
}
trap cleanup EXIT
# The parent of mount in which we'll chroot can't be shared
# or pivot_root will barf. So we just remount onto itself,
# but make sure to make the first parent mount private.
mkdir -p /mnt/mock-mount
mount --bind / /mnt/mock-mount
mount --make-private /mnt/mock-mount
mount --bind /mnt/mock-mount /mnt/mock-mount
for mnt in proc sys; do
mount --bind /$mnt /mnt/mock-mount/$mnt
done
chroot /mnt/mock-mount "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment