-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
set -e | ||
|
||
# Re-exec ourselves in a private mount namespace so that our bind | ||
# mounts get cleaned up automatically. | ||
if [ -z "$NIXOS_ENTER_REEXEC" ]; then | ||
export NIXOS_ENTER_REEXEC=1 | ||
if [ "$(id -u)" != 0 ]; then | ||
extraFlags="-r" | ||
fi | ||
exec unshare --fork --mount --uts --mount-proc --pid $extraFlags -- "$0" "$@" | ||
else | ||
mount --make-rprivate / | ||
fi | ||
|
||
mountPoint=/mnt | ||
|
||
while [ "$#" -gt 0 ]; do | ||
i="$1"; shift 1 | ||
case "$i" in | ||
--root) | ||
mountPoint="$1"; shift 1 | ||
;; | ||
--) | ||
command=("$@") | ||
break | ||
;; | ||
*) | ||
echo "$0: unknown option \`$i'" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
mkdir -p "$mountPoint/dev" "$mountPoint/sys" "$mountPoint/tmp" "$mountPoint/etc" "$mountPoint/proc" | ||
chmod 0755 "$mountPoint/dev" "$mountPoint/sys" "$mountPoint/tmp" "$mountPoint/etc" "$mountPoint/proc" | ||
mount --rbind /dev "$mountPoint/dev" | ||
mount --rbind /sys "$mountPoint/sys" | ||
mount --rbind /proc "$mountPoint/proc" | ||
|
||
touch "$mountPoint/etc/mtab" || true # might be already a working system | ||
(cd "$mountPoint" && ln -snf "../proc/self/mounts" "etc/mtab") # Grub needs an mtab. | ||
|
||
export CHROOTED=1 | ||
exec chroot "$mountPoint" "${command[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters