forked from AaltoSciComp/isolate-namespace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisolate-old.sh
executable file
·40 lines (34 loc) · 872 Bytes
/
isolate-old.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
MNTDIRS="bin lib etc usr lib64 proc"
set -x
BASEDIR="$1"
shift
PHASE=$1
DIR="$BASEDIR"/new
if [ "$PHASE" != "phase2" ] ; then
mkdir -p "$BASEDIR"
mkdir -p "$DIR"
#unshare -m -r -U bash <<EOF
unshare --user --map-root-user --mount-proc --pid --net --uts --fork bash "$0" "$BASEDIR" phase2 "$@"
rm -d "$DIR" "$BASEDIR"
elif [ "$PHASE" = "phase2" ] ; then
shift
mount -t tmpfs -o size=10k tmpfs "$DIR"
whoami
for dir in $MNTDIRS; do
mkdir -p "$DIR/$dir"
mount --bind "/$dir" "$DIR/$dir"
done
# Basic method, using chroot
#chroot $DIR $@
# Using pivot_root. One comment I saw said this was more secure,
# but I haven't verified this working yet.
mkdir -p "$BASEDIR/oldroot"
cd "$DIR"
pivot_root . ../oldroot
pwd
ls ..
ls ../oldroot
umount ../oldroot
chroot . "$@"
fi